Skip to content

Commit 9a5dd7a

Browse files
authored
feat: remove redundant tx status network call for finalized transactions (#7551)
1 parent 22b6e35 commit 9a5dd7a

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

rust/main/lander/src/dispatcher/stages/finality_stage.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,17 @@ impl FinalityStage {
159159
state: &DispatcherState,
160160
) -> Result<(), LanderError> {
161161
info!(?tx, "Processing finality stage transaction");
162-
let tx_status = call_until_success_or_nonretryable_error(
163-
|| state.adapter.tx_status(&tx),
164-
"Querying transaction status",
165-
state,
166-
)
167-
.await?;
162+
let tx_status = match &tx.status {
163+
TransactionStatus::Finalized => tx.status.clone(),
164+
_ => {
165+
call_until_success_or_nonretryable_error(
166+
|| state.adapter.tx_status(&tx),
167+
"Querying transaction status",
168+
state,
169+
)
170+
.await?
171+
}
172+
};
168173

169174
match tx_status {
170175
TransactionStatus::Included => {

rust/main/lander/src/dispatcher/stages/finality_stage/tests.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ async fn test_processing_reorged_txs() {
188188
}
189189
}
190190

191+
#[tokio::test]
192+
async fn test_processing_already_finalized_txs_does_not_call_tx_status() {
193+
const TXS_TO_PROCESS: usize = 3;
194+
195+
let mut mock_adapter = MockAdapter::new();
196+
mock_adapter
197+
.expect_estimated_block_time()
198+
.return_const(Duration::from_millis(10));
199+
200+
// tx_status should never be called because txs are already finalized
201+
mock_adapter.expect_tx_status().times(0);
202+
203+
mock_adapter
204+
.expect_reverted_payloads()
205+
.returning(|_| Ok(vec![]));
206+
207+
let (txs_created, txs_received, tx_db, payload_db, pool, _) =
208+
set_up_test_and_run_stage(mock_adapter, TXS_TO_PROCESS, TransactionStatus::Finalized).await;
209+
210+
// verify transactions were removed from pool
211+
assert!(are_no_txs_in_pool(txs_created.clone(), &pool).await);
212+
213+
// verify transaction status was maintained as finalized
214+
assert_tx_status(
215+
txs_received.clone(),
216+
&tx_db,
217+
&payload_db,
218+
TransactionStatus::Finalized,
219+
)
220+
.await;
221+
}
222+
191223
async fn set_up_test_and_run_stage(
192224
mock_adapter: MockAdapter,
193225
txs_to_process: usize,

0 commit comments

Comments
 (0)