Skip to content

Commit 6f87137

Browse files
authored
Refactor optimistic nonce handling in AtomicEoaExecutorStore (#35)
- Updated the logic for retrieving the optimistic transaction count to handle cases where synchronization is required, returning `None` when necessary. - Enhanced logging to differentiate between updating the optimistic nonce and initializing it for new EOAs, improving clarity in transaction processing. These changes improve the robustness of the optimistic nonce management and provide better insights during execution.
1 parent 9788924 commit 6f87137

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

executors/src/eoa/store/atomic.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,11 @@ impl AtomicEoaExecutorStore {
401401

402402
// First, read current health data
403403
let current_health = self.get_eoa_health().await?;
404-
let optimistic_nonce = self.get_optimistic_transaction_count().await?;
404+
let optimistic_nonce = match self.get_optimistic_transaction_count().await {
405+
Ok(nonce) => Some(nonce),
406+
Err(TransactionStoreError::NonceSyncRequired { .. }) => None,
407+
Err(e) => return Err(e),
408+
};
405409

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

421-
if current_chain_tx_count > optimistic_nonce {
422-
tracing::warn!(
425+
if let Some(optimistic_nonce) = optimistic_nonce {
426+
if current_chain_tx_count > optimistic_nonce {
427+
tracing::warn!(
428+
current_chain_tx_count = current_chain_tx_count,
429+
optimistic_nonce = optimistic_nonce,
430+
"Optimistic nonce was behind fresh chain transaction count, updating to match"
431+
);
432+
pipeline.set(
433+
self.optimistic_transaction_count_key_name(),
434+
current_chain_tx_count,
435+
);
436+
}
437+
} else {
438+
// Initialize optimistic nonce for new EOAs
439+
tracing::info!(
423440
current_chain_tx_count = current_chain_tx_count,
424-
optimistic_nonce = optimistic_nonce,
425-
"Optimistic nonce was behind fresh chain transaction count, updating to match"
441+
"Initializing optimistic nonce for new EOA"
426442
);
427443
pipeline.set(
428444
self.optimistic_transaction_count_key_name(),

0 commit comments

Comments
 (0)