Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions executors/src/eoa/store/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ impl AtomicEoaExecutorStore {

// First, read current health data
let current_health = self.get_eoa_health().await?;
let optimistic_nonce = self.get_optimistic_transaction_count().await?;
let optimistic_nonce = match self.get_optimistic_transaction_count().await {
Ok(nonce) => Some(nonce),
Err(TransactionStoreError::NonceSyncRequired { .. }) => None,
Err(e) => return Err(e),
};

// Prepare health update if health data exists
let health_update = if let Some(mut health) = current_health {
Expand All @@ -418,11 +422,23 @@ impl AtomicEoaExecutorStore {
// Update cached transaction count
pipeline.set(&tx_count_key, current_chain_tx_count);

if current_chain_tx_count > optimistic_nonce {
tracing::warn!(
if let Some(optimistic_nonce) = optimistic_nonce {
if current_chain_tx_count > optimistic_nonce {
tracing::warn!(
current_chain_tx_count = current_chain_tx_count,
optimistic_nonce = optimistic_nonce,
"Optimistic nonce was behind fresh chain transaction count, updating to match"
);
pipeline.set(
self.optimistic_transaction_count_key_name(),
current_chain_tx_count,
);
}
Comment on lines +425 to +436
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Missing branch when chain nonce < optimistic nonce

You update the optimistic nonce when current_chain_tx_count > optimistic_nonce but leave the store unchanged if the chain nonce is behind.
A chain that has been reset or re-orged would leave the optimistic nonce ahead, breaking future submissions.

Consider adding a safeguard:

- if current_chain_tx_count > optimistic_nonce {
+ if current_chain_tx_count > optimistic_nonce {
     /* … */
+ } else if current_chain_tx_count < optimistic_nonce {
+     tracing::warn!(
+         %current_chain_tx_count,
+         %optimistic_nonce,
+         "Chain nonce is behind optimistic nonce – forcing downward sync"
+     );
+     pipeline.set(self.optimistic_transaction_count_key_name(), current_chain_tx_count);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if let Some(optimistic_nonce) = optimistic_nonce {
if current_chain_tx_count > optimistic_nonce {
tracing::warn!(
current_chain_tx_count = current_chain_tx_count,
optimistic_nonce = optimistic_nonce,
"Optimistic nonce was behind fresh chain transaction count, updating to match"
);
pipeline.set(
self.optimistic_transaction_count_key_name(),
current_chain_tx_count,
);
}
if let Some(optimistic_nonce) = optimistic_nonce {
if current_chain_tx_count > optimistic_nonce {
tracing::warn!(
current_chain_tx_count = current_chain_tx_count,
optimistic_nonce = optimistic_nonce,
"Optimistic nonce was behind fresh chain transaction count, updating to match"
);
pipeline.set(
self.optimistic_transaction_count_key_name(),
current_chain_tx_count,
);
} else if current_chain_tx_count < optimistic_nonce {
tracing::warn!(
%current_chain_tx_count,
%optimistic_nonce,
"Chain nonce is behind optimistic nonce – forcing downward sync"
);
pipeline.set(
self.optimistic_transaction_count_key_name(),
current_chain_tx_count,
);
}
🤖 Prompt for AI Agents
In executors/src/eoa/store/atomic.rs around lines 425 to 436, the code updates
the optimistic nonce only when the current chain transaction count is greater
than the optimistic nonce, but does not handle the case when the chain nonce is
less than the optimistic nonce. To fix this, add a branch to detect when the
chain nonce is behind the optimistic nonce and reset or update the optimistic
nonce accordingly to prevent future submission errors after chain resets or
re-orgs.

} else {
// Initialize optimistic nonce for new EOAs
tracing::info!(
current_chain_tx_count = current_chain_tx_count,
optimistic_nonce = optimistic_nonce,
"Optimistic nonce was behind fresh chain transaction count, updating to match"
"Initializing optimistic nonce for new EOA"
);
pipeline.set(
self.optimistic_transaction_count_key_name(),
Expand Down