Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

additional costs in block capacity calc #25059

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use {
};

// it tracks the block cost available capacity - number of compute-units allowed
// by max block cost limit
// by max block cost limit, plus a 10% buffer by default
tao-stones marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug)]
pub struct BlockCostCapacityMeter {
pub capacity: u64,
Expand All @@ -74,7 +74,7 @@ pub struct BlockCostCapacityMeter {

impl Default for BlockCostCapacityMeter {
fn default() -> Self {
BlockCostCapacityMeter::new(MAX_BLOCK_UNITS)
BlockCostCapacityMeter::new((MAX_BLOCK_UNITS as f64 * 1.10) as u64)
jdavis103 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -156,13 +156,28 @@ fn aggregate_total_execution_units(execute_timings: &ExecuteTimings) -> u64 {
execute_cost_units
}

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

for transaction in transactions {
let transaction_cost = cost_model.calculate_cost(transaction);
costs = costs.saturating_add(transaction_cost.signature_cost);
costs = costs.saturating_add(transaction_cost.write_lock_cost);
costs = costs.saturating_add(transaction_cost.data_bytes_cost);
costs = costs.saturating_add(transaction_cost.builtins_execution_cost);
jdavis103 marked this conversation as resolved.
Show resolved Hide resolved
}
costs
}

fn execute_batch(
batch: &TransactionBatch,
bank: &Arc<Bank>,
transaction_status_sender: Option<&TransactionStatusSender>,
replay_vote_sender: Option<&ReplayVoteSender>,
timings: &mut ExecuteTimings,
cost_capacity_meter: Arc<RwLock<BlockCostCapacityMeter>>,
cost_model: &CostModel,
) -> Result<()> {
let record_token_balances = transaction_status_sender.is_some();

Expand Down Expand Up @@ -191,16 +206,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, cost_model);
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 Expand Up @@ -262,6 +279,7 @@ fn execute_batches_internal(
replay_vote_sender: Option<&ReplayVoteSender>,
timings: &mut ExecuteTimings,
cost_capacity_meter: Arc<RwLock<BlockCostCapacityMeter>>,
cost_model: &CostModel,
) -> Result<()> {
inc_new_counter_debug!("bank-par_execute_entries-count", batches.len());
let (results, new_timings): (Vec<Result<()>>, Vec<ExecuteTimings>) =
Expand All @@ -277,6 +295,7 @@ fn execute_batches_internal(
replay_vote_sender,
&mut timings,
cost_capacity_meter.clone(),
cost_model,
);
if let Some(entry_callback) = entry_callback {
entry_callback(bank);
Expand All @@ -302,6 +321,7 @@ fn execute_batches(
replay_vote_sender: Option<&ReplayVoteSender>,
timings: &mut ExecuteTimings,
cost_capacity_meter: Arc<RwLock<BlockCostCapacityMeter>>,
cost_model: &CostModel,
) -> Result<()> {
let lock_results = batches
.iter()
Expand All @@ -312,7 +332,6 @@ fn execute_batches(
.flat_map(|batch| batch.sanitized_transactions().to_vec())
.collect::<Vec<_>>();

let cost_model = CostModel::new();
let mut minimal_tx_cost = u64::MAX;
let mut total_cost: u64 = 0;
// Allowing collect here, since it also computes the minimal tx cost, and aggregate cost.
Expand Down Expand Up @@ -360,6 +379,7 @@ fn execute_batches(
replay_vote_sender,
timings,
cost_capacity_meter,
cost_model,
)
}

Expand Down Expand Up @@ -416,6 +436,7 @@ fn process_entries_with_callback(
let mut batches = vec![];
let mut tick_hashes = vec![];
let mut rng = thread_rng();
let cost_model = CostModel::new();
tao-stones marked this conversation as resolved.
Show resolved Hide resolved

for entry in entries {
match entry {
Expand All @@ -433,6 +454,7 @@ fn process_entries_with_callback(
replay_vote_sender,
timings,
cost_capacity_meter.clone(),
&cost_model,
)?;
batches.clear();
for hash in &tick_hashes {
Expand Down Expand Up @@ -490,6 +512,7 @@ fn process_entries_with_callback(
replay_vote_sender,
timings,
cost_capacity_meter.clone(),
&cost_model,
)?;
batches.clear();
}
Expand All @@ -505,6 +528,7 @@ fn process_entries_with_callback(
replay_vote_sender,
timings,
cost_capacity_meter,
&cost_model,
)?;
for hash in tick_hashes {
bank.register_tick(hash);
Expand Down