Skip to content

Commit

Permalink
add cost tracking for each bank during replay (solana-labs#30035)
Browse files Browse the repository at this point in the history
* add cost tracking for each bank during replay
* add feature gate
  • Loading branch information
tao-stones authored Feb 13, 2023
1 parent f4fe550 commit 51bace2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
53 changes: 34 additions & 19 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use {
},
solana_sdk::{
clock::{Slot, MAX_PROCESSING_AGE},
feature_set,
genesis_config::GenesisConfig,
hash::Hash,
pubkey::Pubkey,
Expand Down Expand Up @@ -337,34 +338,49 @@ fn execute_batches(
let cost = tx_cost.sum();
minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost);
total_cost = total_cost.saturating_add(cost);
cost
tx_cost
})
.collect::<Vec<_>>();

if bank
.feature_set
.is_active(&feature_set::apply_cost_tracker_during_replay::id())
{
let mut cost_tracker = bank.write_cost_tracker().unwrap();
for tx_cost in &tx_costs {
cost_tracker
.try_add(tx_cost)
.map_err(TransactionError::from)?;
}
}

let target_batch_count = get_thread_count() as u64;

let mut tx_batches: Vec<TransactionBatchWithIndexes> = vec![];
let rebatched_txs = if total_cost > target_batch_count.saturating_mul(minimal_tx_cost) {
let target_batch_cost = total_cost / target_batch_count;
let mut batch_cost: u64 = 0;
let mut slice_start = 0;
tx_costs.into_iter().enumerate().for_each(|(index, cost)| {
let next_index = index + 1;
batch_cost = batch_cost.saturating_add(cost);
if batch_cost >= target_batch_cost || next_index == sanitized_txs.len() {
let tx_batch = rebatch_transactions(
&lock_results,
bank,
&sanitized_txs,
slice_start,
index,
&transaction_indexes,
);
slice_start = next_index;
tx_batches.push(tx_batch);
batch_cost = 0;
}
});
tx_costs
.into_iter()
.enumerate()
.for_each(|(index, tx_cost)| {
let next_index = index + 1;
batch_cost = batch_cost.saturating_add(tx_cost.sum());
if batch_cost >= target_batch_cost || next_index == sanitized_txs.len() {
let tx_batch = rebatch_transactions(
&lock_results,
bank,
&sanitized_txs,
slice_start,
index,
&transaction_indexes,
);
slice_start = next_index;
tx_batches.push(tx_batch);
batch_cost = 0;
}
});
&tx_batches[..]
} else {
batches
Expand Down Expand Up @@ -1767,7 +1783,6 @@ pub mod tests {
solana_sdk::{
account::{AccountSharedData, WritableAccount},
epoch_schedule::EpochSchedule,
feature_set,
hash::Hash,
native_token::LAMPORTS_PER_SOL,
pubkey::Pubkey,
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ pub mod delay_visibility_of_program_deployment {
solana_sdk::declare_id!("GmuBvtFb2aHfSfMXpuFeWZGHyDeCLPS79s48fmCWCfM5");
}

pub mod apply_cost_tracker_during_replay {
solana_sdk::declare_id!("2ry7ygxiYURULZCrypHhveanvP5tzZ4toRwVp89oCNSj");
}

lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -762,6 +766,7 @@ lazy_static! {
(enable_request_heap_frame_ix::id(), "Enable transaction to request heap frame using compute budget instruction #30076"),
(prevent_rent_paying_rent_recipients::id(), "prevent recipients of rent rewards from ending in rent-paying state #30151"),
(delay_visibility_of_program_deployment::id(), "delay visibility of program upgrades #30085"),
(apply_cost_tracker_during_replay::id(), "apply cost tracker to blocks during replay #29595"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down

0 comments on commit 51bace2

Please sign in to comment.