solana-program-library icon indicating copy to clipboard operation
solana-program-library copied to clipboard

`Token` type is `!Send + !Sync`

Open greged93 opened this issue 1 year ago • 6 comments
trafficstars

The Token type in token/client/src/token.rs seems to have been designed in order to be Send + Sync, given the fact that Arc was used for the different fields. However, marker traits Send + Sync are not added to the traits objects and as such fails Token fails to capture this feature.

I'm willing to implement this if the issue is accepted.

greged93 avatar Mar 22 '24 11:03 greged93

Hey there, are you talking about right here?

https://github.com/solana-labs/solana-program-library/blob/ce0389be112bed8da01dd0fc3088204a62408cbc/token/client/src/token.rs#L383-L386

And could you maybe elaborate on what the motivation would be to add this change? It's not immediately clear from the description.

Thanks!

buffalojoec avatar Mar 22 '24 14:03 buffalojoec

hey @buffalojoec, I was talking about the type below. From what I can see from the fields, it seems like the type was made in order to be Send + Sync? Otherwise why use Arc for client, payer,... ? I think we could make Token thread-safe by adding Send + Sync as a bounds for client, payer and nonce_authority.

https://github.com/solana-labs/solana-program-library/blob/ce0389be112bed8da01dd0fc3088204a62408cbc/token/client/src/token.rs#L331-L342

greged93 avatar Mar 22 '24 14:03 greged93

@greged93 Sorry I'm just getting back here!

Yeah I think making Token thread-safe makes sense. If you think it's important go for it!

buffalojoec avatar Mar 26 '24 13:03 buffalojoec

Great! Can you assign the issue?

greged93 avatar Mar 26 '24 18:03 greged93

Why can't we directly send Token between threads? I think this is necessary to fully utilize multithreading

1500256797 avatar Mar 28 '24 03:03 1500256797

If ProgramClient cannot be sent or synchronized directly between threads, how should it be handled in concurrent scenarios? I believe it needs to be implemented with the Send and Sync traits to address multithreading concurrency issues.

1500256797 avatar Mar 28 '24 10:03 1500256797