Skip to content

Commit

Permalink
use checked_add for stat
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Dec 25, 2023
1 parent 1a88a04 commit e934ca8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tx-pool/src/component/pool_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,22 @@ impl PoolMap {

/// Update size and cycles statistics for add tx
fn update_stat_for_add_tx(&mut self, tx_size: usize, cycles: Cycle) {
self.total_tx_size += tx_size;
self.total_tx_cycles += cycles;
let total_tx_size = self.total_tx_size.checked_add(tx_size).unwrap_or_else(|| {
error!(
"total_tx_size {} overflown by add {}",
self.total_tx_size, tx_size
);
self.total_tx_size
});
let total_tx_cycles = self.total_tx_cycles.checked_add(cycles).unwrap_or_else(|| {
error!(
"total_tx_cycles {} overflown by add {}",
self.total_tx_cycles, cycles
);
self.total_tx_cycles
});
self.total_tx_size = total_tx_size;
self.total_tx_cycles = total_tx_cycles;
}

/// Update size and cycles statistics for remove tx
Expand Down

0 comments on commit e934ca8

Please sign in to comment.