Skip to content

Multiple threads using the same client, transaction outdated #1886

@th7nder

Description

@th7nder

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:

  1. pipeline when it calls an extrinsic (ref)
  2. RPC when it also calls an extrinsic (ref)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions