Replies: 2 comments 2 replies
Please bear with me as I pick up on context. Would this concurrent access problem not be solved by making the relevant associated fns of the Client Pseudocode for illustration: impl Client {
pub fn get_head(&self) -> Result
pub fn post_transaction(&mut self) -> Result
}I would expect Send+Sync only to be a problem if we have rc, refcell, etc under the hood. |
|
Recently, there's been discussions for making upstream components So if we want to make the client |
Uh oh!
There was an error while loading. Please reload this page.
Stemming from #849 but it seems to be a recurring issue.
Context
Currently the
Clientis notSend+Syncwhich means that it is only able to be used in single-threaded controlled accesses. There was a previous experimental attempt (#738) which spanned multiple repositories, but it seemed to work in making the clientSend+Sync.Main points
I feel like there are two main discussions that somewhat clash with each other:
Dev experience
A lot of projects nowadays use asynchronous tokio contexts to deal with concurrency. As discussed in the mentioned PR:
Which means that our current implementation, a lot of devs won't be able to use the SDK in their projects. At least not out of the box.
There are workarounds like managing access of the client behind a channel or instantiating a new client for every use (although this won't solve the next issue discussed). These workarounds fall on the client's users which isn't ideal and makes the client more cumbersome to use which is something we are trying to avoid (see #854).
Another problem with these workarounds is that the users may introduce concurrency problems anyway. If two separate instances of the client that use the same store try to execute a transaction against the same account then we also have the same problem. The database manager will deal with the concurrent accesses but we are not sure how this will happen (especially with different implementations of
Store).Concurrency in the client
Conceptually it doesn't make sense for the client to allow concurrent access. The actor model in Miden's protocol means that for concurrent transactions only one will go through and the others will fail, even if they access totally separate information. But maybe for the sake of improving usability and dev experience we want to support it.
If we allow concurrent access to the same account in the client we can just return an error for subsequent transactions on the same account state, it will be up to the user to deal with these errors.
There's another option that will open once we finish with #814. We could let multiple transactions go through and the client will discard the transaction chains that don't go through. The user will have to deal with transactions that went through but later got discarded.
Final thoughts
I think one of the current objectives of the client is to make it as easy to use as possible, and making the necessary changes (even if they span multiple repositories) may be worthwhile as it will be easier for users to create different kinds of projects with the
Client.All reactions