Skip to content

Commit c3b860b

Browse files
authored
fix(lander): track status of all tx (#7217)
1 parent 1df0f95 commit c3b860b

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

rust/main/lander/src/adapter/chains/ethereum/nonce/state/assign.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ impl NonceManagerState {
1515
old_nonce: &Option<U256>,
1616
) -> NonceResult<U256> {
1717
if let Some(nonce) = old_nonce {
18-
// If the different nonce was assigned to the transaction,
19-
// we clear the tracked nonce for the transaction first.
20-
warn!(
21-
?nonce,
22-
"Reassigning nonce to transaction, clearing currently tracked nonce"
23-
);
24-
self.clear_tracked_tx_uuid(nonce).await?;
25-
self.clear_tracked_tx_nonce(tx_uuid).await?;
18+
// Only clear nonce and tx_uuid linkage if the old_nonce is indeed associated with the tx_uuid in question
19+
if *tx_uuid == self.get_tracked_tx_uuid(nonce).await? {
20+
// If the different nonce was assigned to the transaction,
21+
// we clear the tracked nonce for the transaction first.
22+
warn!(
23+
?nonce,
24+
"Reassigning nonce to transaction, clearing currently tracked nonce"
25+
);
26+
self.clear_tracked_tx_uuid(nonce).await?;
27+
self.clear_tracked_tx_nonce(tx_uuid).await?;
28+
}
2629
}
2730

2831
let (finalized_nonce, upper_nonce) = self.get_boundary_nonces().await?;

rust/main/lander/src/adapter/chains/ethereum/nonce/state/assign/tests/tests_assign.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ fn create_tx(uuid: TransactionUuid, status: TransactionStatus) -> Transaction {
1515
make_tx(uuid, status, None, None)
1616
}
1717

18+
#[tokio::test]
19+
async fn test_assign_next_nonce_and_keep_old_linkage() {
20+
let (_, tx_db, nonce_db) = tmp_dbs();
21+
let address = Address::random();
22+
let metrics = EthereumAdapterMetrics::dummy_instance();
23+
let state = Arc::new(NonceManagerState::new(nonce_db, tx_db, address, metrics));
24+
25+
let other_tx_uuid = TransactionUuid::random();
26+
27+
// Assign nonce and build linkage for other tx
28+
let nonce = state
29+
.assign_next_nonce(&other_tx_uuid, &None)
30+
.await
31+
.unwrap();
32+
state
33+
.set_tracked_tx_uuid(&nonce, &other_tx_uuid)
34+
.await
35+
.unwrap();
36+
37+
let tx_uuid = TransactionUuid::random();
38+
// Now assign a new nonce to a new tx but with an old nonce of the other tx
39+
let new_nonce = state
40+
.assign_next_nonce(&tx_uuid, &Some(nonce))
41+
.await
42+
.unwrap();
43+
44+
let tracked_tx_uuid = state.get_tracked_tx_uuid(&nonce).await.unwrap();
45+
let tracked_nonce = state.get_tx_nonce(&other_tx_uuid).await.unwrap();
46+
// Assert that linkage of the old tx id & nonce was not removed
47+
assert_eq!(tracked_tx_uuid, other_tx_uuid);
48+
assert_eq!(tracked_nonce, Some(nonce));
49+
assert_eq!(nonce + 1, new_nonce);
50+
}
51+
1852
#[tokio::test]
1953
async fn test_assign_next_nonce_no_previous_nonce() {
2054
let (_, tx_db, nonce_db) = tmp_dbs();

rust/main/lander/src/dispatcher/stages/building_stage/building.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ impl BuildingStage {
9696
return Ok(());
9797
};
9898
info!(?tx, "Transaction built successfully");
99+
self.state.store_tx(&tx).await;
100+
// Only send tx to inclusion stage after we stored it
101+
// This prevents TX from dropping in case the send operation fails
99102
call_until_success_or_nonretryable_error(
100103
|| self.send_tx_to_inclusion_stage(tx.clone()),
101104
"Sending transaction to inclusion stage",
102105
&self.state,
103106
)
104107
.await?;
105-
self.state.store_tx(&tx).await;
106108
Ok(())
107109
}
108110

0 commit comments

Comments
 (0)