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

fix(NonceManager): off-by-one error resyncing onchain nonce #27

Closed
wants to merge 1 commit into from

Conversation

daniel-savu
Copy link

The get_transaction_count RPC returns the latest nonce that landed onchain + 1. The intended behavior when resyncing internal nonce is to set it to that latest nonce (without the +1). This wasn't the case so far, which made it possible to still get stuck nonces.

Will add a follow up test PR where the escalator randomly drops every Nth tx (and implicitly its nonce), to make sure nonce resyncing works.

@daniel-savu daniel-savu force-pushed the dan/noncemanager-fix branch from ac6b057 to ca44d34 Compare January 7, 2025 13:19
let onchain_nonce = self
.get_transaction_count(self.address, block)
.await?
.saturating_sub(1.into());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's an edge case here if it's the first ever tx, where get_transaction_count returns 0. Think it's a concern or that it's fine for now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this branch would only be hit after tx_count_for_resync txs which is >0 so we're good, but it would be a concern if tx_count_for_resync was 0

Copy link
Author

@daniel-savu daniel-savu Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually if none of the tx_count_for_resync land this would be a problem, but I think it's very unlikely we run into that
even if we store 0, because of next() we end up using 1 so we're good even if all initial tx_count_for_resync txs get stuck

@daniel-savu
Copy link
Author

closing as this was a false alarm, fetch_add returns the old value so there is no off-by-one bug

@daniel-savu daniel-savu closed this Jan 7, 2025
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

Successfully merging this pull request may close these issues.

3 participants