From c7283625a9efa64377597e7e098a0f9965ff259a Mon Sep 17 00:00:00 2001 From: Lucas Ste <38472950+LucasSte@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:36:03 +0800 Subject: [PATCH] Use checked math for `_new_from_parent` (#2859) * Use checked math * Use checked operations --- runtime/src/bank.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 7a9a900bd8e019..77661a4bc43cf2 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -1217,8 +1217,15 @@ impl Bank { epoch_schedule, collected_rent: AtomicU64::new(0), rent_collector: Self::get_rent_collector_from(&parent.rent_collector, epoch), - max_tick_height: (slot + 1) * parent.ticks_per_slot, - block_height: parent.block_height + 1, + max_tick_height: slot + .checked_add(1) + .expect("max tick height addition overflowed") + .checked_mul(parent.ticks_per_slot) + .expect("max tick height multiplication overflowed"), + block_height: parent + .block_height + .checked_add(1) + .expect("block height addition overflowed"), fee_rate_governor, capitalization: AtomicU64::new(parent.capitalization()), vote_only_bank,