Skip to content

Commit 08bd0e1

Browse files
authored
bring down optimistic nonce in case recycled transactions fail (#52)
1 parent ac2ed37 commit 08bd0e1

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

executors/src/eoa/store/borrowed.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::eoa::{
1212
},
1313
worker::error::EoaExecutorWorkerError,
1414
};
15-
use crate::metrics::{current_timestamp_ms, calculate_duration_seconds, EoaMetrics};
15+
use crate::metrics::{EoaMetrics, calculate_duration_seconds, current_timestamp_ms};
1616
use crate::webhook::{WebhookJobHandler, queue_webhook_envelopes};
1717

1818
#[derive(Debug, Clone)]
@@ -62,7 +62,10 @@ impl SafeRedisTransaction for ProcessBorrowedTransactions<'_> {
6262
}
6363

6464
fn watch_keys(&self) -> Vec<String> {
65-
vec![self.keys.borrowed_transactions_hashmap_name()]
65+
vec![
66+
self.keys.borrowed_transactions_hashmap_name(),
67+
self.keys.recycled_nonces_zset_name(),
68+
]
6669
}
6770

6871
async fn validation(
@@ -121,15 +124,13 @@ impl SafeRedisTransaction for ProcessBorrowedTransactions<'_> {
121124
SubmissionResultType::Success => {
122125
// Record metrics: transaction queued to sent
123126
let sent_timestamp = current_timestamp_ms();
124-
let queued_to_sent_duration = calculate_duration_seconds(
125-
result.transaction.queued_at,
126-
sent_timestamp
127-
);
127+
let queued_to_sent_duration =
128+
calculate_duration_seconds(result.transaction.queued_at, sent_timestamp);
128129
// Record metrics using the clean EoaMetrics abstraction
129130
self.eoa_metrics.record_transaction_sent(
130131
self.keys.eoa,
131132
self.keys.chain_id,
132-
queued_to_sent_duration
133+
queued_to_sent_duration,
133134
);
134135

135136
// Add to submitted zset
@@ -189,7 +190,7 @@ impl SafeRedisTransaction for ProcessBorrowedTransactions<'_> {
189190
// Update transaction data status
190191
let tx_data_key = self.keys.transaction_data_key_name(transaction_id);
191192
pipeline.hset(&tx_data_key, "status", "pending");
192-
193+
193194
// ask for this nonce to be recycled because we did not consume the nonce
194195
pipeline.zadd(self.keys.recycled_nonces_zset_name(), nonce, nonce);
195196

executors/src/eoa/store/submitted.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ impl SafeRedisTransaction for CleanAndGetRecycledNonces<'_> {
560560
vec![
561561
self.keys.recycled_nonces_zset_name(),
562562
self.keys.last_transaction_count_key_name(),
563+
self.keys.optimistic_transaction_count_key_name(),
563564
self.keys.submitted_transactions_zset_name(),
564565
]
565566
}
@@ -618,6 +619,11 @@ impl SafeRedisTransaction for CleanAndGetRecycledNonces<'_> {
618619
"+inf",
619620
);
620621

622+
pipeline.set(
623+
self.keys.optimistic_transaction_count_key_name(),
624+
highest_submitted_nonce + 1,
625+
);
626+
621627
recycled_nonces
622628
}
623629
}

executors/src/eoa/worker/send.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use engine_core::{chain::Chain, error::AlloyRpcErrorToEngineError};
44
use crate::eoa::{
55
store::{BorrowedTransaction, PendingTransaction, SubmissionResult},
66
worker::{
7-
EoaExecutorWorker,
87
error::{
9-
EoaExecutorWorkerError, SendContext, is_retryable_preparation_error,
10-
should_update_balance_threshold,
11-
},
12-
},
8+
is_retryable_preparation_error, should_update_balance_threshold, EoaExecutorWorkerError, SendContext
9+
}, EoaExecutorWorker
10+
}, EoaExecutorStore,
1311
};
1412

1513
const HEALTH_CHECK_INTERVAL_MS: u64 = 60 * 5 * 1000; // 5 minutes in milliseconds
@@ -20,7 +18,7 @@ impl<C: Chain> EoaExecutorWorker<C> {
2018
pub async fn send_flow(&self) -> Result<u32, EoaExecutorWorkerError> {
2119
// 1. Get EOA health (initializes if needed) and check if we should update balance
2220
let mut health = self.get_eoa_health().await?;
23-
let now = chrono::Utc::now().timestamp_millis().max(0) as u64;
21+
let now = EoaExecutorStore::now();
2422

2523
// Update balance if it's stale
2624
// TODO: refactor this, very ugly

0 commit comments

Comments
 (0)