From 0809a4df787d5585291c5d25cb1592d1effcf825 Mon Sep 17 00:00:00 2001 From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Date: Fri, 2 Dec 2022 10:21:25 -0600 Subject: [PATCH] remove redundant internal functions (#29035) remove redundant _internal functions --- runtime/src/cost_tracker.rs | 60 +++++++------------------------------ 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/runtime/src/cost_tracker.rs b/runtime/src/cost_tracker.rs index 7734d87d73..9e974e06aa 100644 --- a/runtime/src/cost_tracker.rs +++ b/runtime/src/cost_tracker.rs @@ -160,22 +160,8 @@ impl CostTracker { } fn would_fit(&self, tx_cost: &TransactionCost) -> Result<(), CostTrackerError> { - self.would_fit_internal( - tx_cost.writable_accounts.iter(), - tx_cost.sum(), - tx_cost.is_simple_vote, - tx_cost.account_data_size, - ) - } - - fn would_fit_internal<'a>( - &self, - write_lock_accounts: impl Iterator, - cost: u64, - is_vote: bool, - account_data_size: u64, - ) -> Result<(), CostTrackerError> { - let vote_cost = if is_vote { cost } else { 0 }; + let cost: u64 = tx_cost.sum(); + let vote_cost = if tx_cost.is_simple_vote { cost } else { 0 }; // check against the total package cost if self.block_cost.saturating_add(cost) > self.block_cost_limit { @@ -194,7 +180,9 @@ impl CostTracker { // NOTE: Check if the total accounts data size is exceeded *before* the block accounts data // size. This way, transactions are not unnecessarily retried. - let account_data_size = self.account_data_size.saturating_add(account_data_size); + let account_data_size = self + .account_data_size + .saturating_add(tx_cost.account_data_size); if let Some(account_data_size_limit) = self.account_data_size_limit { if account_data_size > account_data_size_limit { return Err(CostTrackerError::WouldExceedAccountDataTotalLimit); @@ -206,7 +194,7 @@ impl CostTracker { } // check each account against account_cost_limit, - for account_key in write_lock_accounts { + for account_key in tx_cost.writable_accounts.iter() { match self.cost_by_writable_accounts.get(account_key) { Some(chained_cost) => { if chained_cost.saturating_add(cost) > self.account_cost_limit { @@ -223,23 +211,8 @@ impl CostTracker { } fn add_transaction_cost(&mut self, tx_cost: &TransactionCost) { - self.add_transaction_cost_internal( - tx_cost.writable_accounts.iter(), - tx_cost.sum(), - tx_cost.is_simple_vote, - tx_cost.account_data_size, - ) - } - - fn add_transaction_cost_internal<'a>( - &mut self, - write_lock_accounts: impl Iterator, - cost: u64, - is_vote: bool, - account_data_size: u64, - ) { - self.add_transaction_execution_cost_internal(write_lock_accounts, is_vote, cost); - saturating_add_assign!(self.account_data_size, account_data_size); + self.add_transaction_execution_cost(tx_cost, tx_cost.sum()); + saturating_add_assign!(self.account_data_size, tx_cost.account_data_size); saturating_add_assign!(self.transaction_count, 1); } @@ -254,20 +227,7 @@ impl CostTracker { /// Apply additional actual execution units to cost_tracker fn add_transaction_execution_cost(&mut self, tx_cost: &TransactionCost, adjustment: u64) { - self.add_transaction_execution_cost_internal( - tx_cost.writable_accounts.iter(), - tx_cost.is_simple_vote, - adjustment, - ) - } - - fn add_transaction_execution_cost_internal<'a>( - &mut self, - write_lock_accounts: impl Iterator, - is_vote: bool, - adjustment: u64, - ) { - for account_key in write_lock_accounts { + for account_key in tx_cost.writable_accounts.iter() { let account_cost = self .cost_by_writable_accounts .entry(*account_key) @@ -275,7 +235,7 @@ impl CostTracker { *account_cost = account_cost.saturating_add(adjustment); } self.block_cost = self.block_cost.saturating_add(adjustment); - if is_vote { + if tx_cost.is_simple_vote { self.vote_cost = self.vote_cost.saturating_add(adjustment); } }