remove redundant internal functions (#29035)

remove redundant _internal functions
This commit is contained in:
Tao Zhu 2022-12-02 10:21:25 -06:00 committed by GitHub
parent fd3b5d08d7
commit 0809a4df78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 50 deletions

View File

@ -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<Item = &'a Pubkey>,
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<Item = &'a Pubkey>,
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<Item = &'a Pubkey>,
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);
}
}