Skip to content

Commit 50ef162

Browse files
apollo_mempool: use saturating_sub for n_stuck_txs accounting (#14560)
Replace the two unchecked `n_stuck_txs -=` subtractions in decrement_stuck_txs_if_gap_account and remove_from_accounts_with_gap with saturating_sub. Guards against a latent underflow that would panic under overflow-checked builds and silently wrap the MEMPOOL_STUCK_TXS gauge in release. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9fb88b4 commit 50ef162

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

crates/apollo_mempool/src/mempool.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,15 +922,16 @@ impl Mempool {
922922

923923
fn decrement_stuck_txs_if_gap_account(&mut self, address: ContractAddress, n: usize) {
924924
if self.accounts_with_gap.contains(&address) {
925-
self.n_stuck_txs -= n;
925+
self.n_stuck_txs = self.n_stuck_txs.saturating_sub(n);
926926
}
927927
}
928928

929929
// Removes address from the gap-account set and deducts its remaining pool txs from
930930
// n_stuck_txs. No-op if the address was not tracked.
931931
fn remove_from_accounts_with_gap(&mut self, address: ContractAddress) {
932932
if self.accounts_with_gap.swap_remove(&address) {
933-
self.n_stuck_txs -= self.tx_pool.n_txs_for_address(address);
933+
self.n_stuck_txs =
934+
self.n_stuck_txs.saturating_sub(self.tx_pool.n_txs_for_address(address));
934935
}
935936
}
936937

0 commit comments

Comments
 (0)