-
Notifications
You must be signed in to change notification settings - Fork 290
Multiple threads using the same client, transaction outdated #1886
Description
Context
We're building a system parachain for data storage and heavily utilizing subxt.
We have a off-chain service, which is running a pipeline and RPC at the same time.
Pipeline periodically performs a operation on-chain (and waits for finalization), and RPC as well.
We just put a OnlineClient behind an and are using it in multiple places (threads).
E.g:
Problem
There is a moment, where pipeline (1.) waits for the extrinsic to be finalized and RPC (2.) wants to submit the extrinsic, using the same client.
It ends up being an error:
Error: RpcClient(Call(ErrorObject { code: InternalError, message: "RPC error: ErrorObject { code: ServerError(1014), message: \"Priority is too low: (17955 vs 11737)\", data: Some(RawValue(\"The transaction has too low priority to replace another transaction already in the pool.\")) }", data: None }))
I think this is because, while we waiting for the extrinsic to be finalized, the Account Nonce is the same for both of the calls. The second call tries to override it (has a lower priority and it fails)
Discussion
Potential solutions from our side are:
- put the client behind a Mutex and unlock only after finalization (tragically slow, DoS attacks, etc.)
- create some kind of queue that will be processing the chain request in-order (simpler, but not that fast)
- keep track of the nonce in a shared state and increment it (complex, but fast)
However, I wanna discuss this with you guys. Is this the right approach? Should we handle it on our side, should the client be resilient on its own for this kind of behaviours?
Looking for your feedback, thanks!
P.S couldn't find the better title, feel free to change it to something more fitting.