Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Merge 8c14233 into 71ad121
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavis103 authored Apr 27, 2022
2 parents 71ad121 + 8c14233 commit 72c427c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
21 changes: 19 additions & 2 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ fn aggregate_total_execution_units(execute_timings: &ExecuteTimings) -> u64 {
execute_cost_units
}

fn sum_additional_costs(batch: &TransactionBatch) -> u64 {
let mut additional_costs: u64 = 0;
let transactions = batch.sanitized_transactions();
let cost_model = CostModel::new();

for transaction in transactions {
let transaction_cost = cost_model.calculate_cost(transaction);
additiona_costs.saturating_add_in_place(transaction_cost.signature_cost);
additiona_costs.saturating_add_in_place(transaction_cost.write_lock_cost);
additiona_costs.saturating_add_in_place(transaction_cost.data_bytes_cost);
additiona_costs.saturating_add_in_place(transaction_cost.builtins_execution_cost);
}
additional_costs
}

fn execute_batch(
batch: &TransactionBatch,
bank: &Arc<Bank>,
Expand Down Expand Up @@ -189,16 +204,18 @@ fn execute_batch(
.is_active(&feature_set::gate_large_block::id())
{
let execution_cost_units = aggregate_total_execution_units(timings) - pre_process_units;
let additional_cost_units = sum_additional_costs(batch);
let remaining_block_cost_cap = cost_capacity_meter
.write()
.unwrap()
.accumulate(execution_cost_units);
.accumulate(execution_cost_units + additional_cost_units);

debug!(
"bank {} executed a batch, number of transactions {}, total execute cu {}, remaining block cost cap {}",
"bank {} executed a batch, number of transactions {}, total execute cu {}, total additional cu {}, remaining block cost cap {}",
bank.slot(),
batch.sanitized_transactions().len(),
execution_cost_units,
additional_cost_units,
remaining_block_cost_cap,
);

Expand Down
12 changes: 6 additions & 6 deletions runtime/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl CostModel {
let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS);

tx_cost.signature_cost = self.get_signature_cost(transaction);
self.get_write_lock_cost(&mut tx_cost, transaction);
tx_cost.write_lock_cost = self.get_write_lock_cost(&mut tx_cost, transaction);
tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction);
(tx_cost.builtins_execution_cost, tx_cost.bpf_execution_cost) =
self.get_transaction_cost(transaction);
Expand Down Expand Up @@ -133,20 +133,20 @@ impl CostModel {
&self,
tx_cost: &mut TransactionCost,
transaction: &SanitizedTransaction,
) {
) -> u64 {
let mut write_lock_cost: u64 = 0;
let message = transaction.message();
message
.account_keys()
.iter()
.enumerate()
.for_each(|(i, k)| {
let is_writable = message.is_writable(i);

if is_writable {
if message.is_writable(i) {
tx_cost.writable_accounts.push(*k);
tx_cost.write_lock_cost += WRITE_LOCK_UNITS;
write_lock_cost.saturating_add_in_place(WRITE_LOCK_UNITS);
}
});
write_lock_cost
}

fn get_data_bytes_cost(&self, transaction: &SanitizedTransaction) -> u64 {
Expand Down

0 comments on commit 72c427c

Please sign in to comment.