Skip to content

Commit f649ddb

Browse files
authored
Refactor transaction count update logic in EoaExecutorWorker (#47)
- Moved the cached transaction count update logic to ensure it always executes, regardless of the presence of transactions to confirm. - Added error logging for cases where the latest fetched transaction count is lower than the cached count, indicating potential re-orgs or RPC block lag. - This change enhances the robustness of transaction management and improves error handling in the EoaExecutorWorker.
1 parent 3c8240e commit f649ddb

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

executors/src/eoa/worker/confirm.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ impl<C: Chain> EoaExecutorWorker<C> {
146146
"Processing confirmations"
147147
);
148148

149+
// Always update cached transaction count first, regardless of whether there are transactions to confirm
150+
if transaction_counts.latest != cached_transaction_count {
151+
if transaction_counts.latest < cached_transaction_count {
152+
tracing::error!(
153+
current_chain_transaction_count = transaction_counts.latest,
154+
cached_transaction_count = cached_transaction_count,
155+
"Fresh fetched chain transaction count is lower than cached transaction count. \
156+
This indicates a re-org or RPC block lag. Engine will use the newest fetched transaction count from now (assuming re-org).\
157+
Transactions already confirmed will not be attempted again, even if their nonce was higher than the new chain transaction count.
158+
In case this is RPC misbehaviour not reflective of actual chain state, Engine's nonce management might be affected."
159+
);
160+
}
161+
162+
self.store
163+
.update_cached_transaction_count(transaction_counts.latest)
164+
.await?;
165+
}
166+
149167
// Get all pending transactions below the current chain transaction count
150168
// ie, if transaction count is 1, nonce 0 should have mined
151169
let waiting_txs = self
@@ -209,23 +227,6 @@ impl<C: Chain> EoaExecutorWorker<C> {
209227
)
210228
.await?;
211229

212-
if transaction_counts.latest != cached_transaction_count {
213-
if transaction_counts.latest < cached_transaction_count {
214-
tracing::error!(
215-
current_chain_transaction_count = transaction_counts.latest,
216-
cached_transaction_count = cached_transaction_count,
217-
"Fresh fetched chain transaction count is lower than cached transaction count. \
218-
This indicates a re-org or RPC block lag. Engine will use the newest fetched transaction count from now (assuming re-org).\
219-
Transactions already confirmed will not be attempted again, even if their nonce was higher than the new chain transaction count.
220-
In case this is RPC misbehaviour not reflective of actual chain state, Engine's nonce management might be affected."
221-
);
222-
}
223-
224-
self.store
225-
.update_cached_transaction_count(transaction_counts.latest)
226-
.await?;
227-
}
228-
229230
Ok(report)
230231
}
231232

0 commit comments

Comments
 (0)