Storage: use saturating_add for cumulative_generated_coins (#275)

* use `saturating_add` for `cumulative_generated_coins`

* cargo fmt
This commit is contained in:
Boog900 2024-09-10 01:15:04 +01:00 committed by GitHub
parent 967537fae1
commit 49d1344aa1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -89,9 +89,10 @@ pub fn add_block(
// RCT output count needs account for _this_ block's outputs. // RCT output count needs account for _this_ block's outputs.
let cumulative_rct_outs = get_rct_num_outputs(tables.rct_outputs())?; let cumulative_rct_outs = get_rct_num_outputs(tables.rct_outputs())?;
// `saturating_add` is used here as cumulative generated coins overflows due to tail emission.
let cumulative_generated_coins = let cumulative_generated_coins =
cumulative_generated_coins(&block.height.saturating_sub(1), tables.block_infos())? cumulative_generated_coins(&block.height.saturating_sub(1), tables.block_infos())?
+ block.generated_coins; .saturating_add(block.generated_coins);
let (cumulative_difficulty_low, cumulative_difficulty_high) = let (cumulative_difficulty_low, cumulative_difficulty_high) =
split_u128_into_low_high_bits(block.cumulative_difficulty); split_u128_into_low_high_bits(block.cumulative_difficulty);