Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race Condition With sendAndConfirmNonceTransaction #53

Open
0xIchigo opened this issue Jan 7, 2025 · 1 comment
Open

Race Condition With sendAndConfirmNonceTransaction #53

0xIchigo opened this issue Jan 7, 2025 · 1 comment

Comments

@0xIchigo
Copy link

0xIchigo commented Jan 7, 2025

I sometimes get an ephemeral error when using sendAndConfirmNonceTransaction that the nonce is invalid and has already been advanced despite the transaction being successful. This is the error in question:

SolanaError: The nonce `3myBceoXbBzN7cAY5kaymDuJTNpmd8tZPuhsfEPU8QDS` is no longer valid. It has advanced to `BMkGEQPkyJWXTwAKywcZB6DUaK2Z2zNy39bLJtLXJF6w`
    at E:\HeliusCoding\solana-web3.js2.0-experiments\node_modules\@solana\transaction-confirmation\src\confirmation-strategy-nonce.ts:72:27
    at processTicksAndRejections (node:internal/process/task_queues:105:5) {
  cause: undefined,
  context: {
    __code: 2,
    actualNonceValue: 'BMkGEQPkyJWXTwAKywcZB6DUaK2Z2zNy39bLJtLXJF6w',
    expectedNonceValue: '3myBceoXbBzN7cAY5kaymDuJTNpmd8tZPuhsfEPU8QDS'
  }
}

It seems that the notification handler is bugged. The notification of the nonce advancing arrives before the notification of the confirmed signature. Upon discovering that the nonce has advanced, the confirmation algorithm should determine if it advanced because the transaction landed or before the transaction landed.

I posted the issue on the Solana Stack Exchange with the full code snippet I was using to get this error

@steveluscher
Copy link
Collaborator

It looks like this is because the signature notifications are driven by the CompletedDataSetsService which runs in the solComplDataSet thread, and RpcSubscriptions::process_notifications() that runs in a series of solRpcNotifier threads. I don't think these notifiers are synchronized in any way, which implies that the confirmation algorithm sometimes hears about the nonce advancing before it hears about the transaction signature being confirmed, and vice versa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants