Skip to content

Commit

Permalink
fix(NonceManager): off-by-one error resyncing onchain nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Jan 7, 2025
1 parent f18abe3 commit ca44d34
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ethers-middleware/src/nonce_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ where
tracing::debug!(?nonce, "Sent transaction");
let tx_count_for_resync = self.get_tx_count_for_resync();
if new_txs_since_resync >= tx_count_for_resync {
let onchain_nonce = self.get_transaction_count(self.address, block).await?;
// subtract 1 because the nonce returned by `get_transaction_count`
// is the next one to be used, whereas we want the last one that landed
let onchain_nonce = self
.get_transaction_count(self.address, block)
.await?
.saturating_sub(1.into());
self.nonce.store(onchain_nonce.as_u64(), Ordering::SeqCst);
self.txs_since_resync.store(0, Ordering::SeqCst);
tracing::debug!(?nonce, "Resynced internal nonce with onchain nonce");
Expand Down

0 comments on commit ca44d34

Please sign in to comment.