add cost tracking for each bank during replay (#30035)
* add cost tracking for each bank during replay * add feature gate
This commit is contained in:
parent
f4fe550004
commit
51bace2123
|
@ -39,6 +39,7 @@ use {
|
|||
},
|
||||
solana_sdk::{
|
||||
clock::{Slot, MAX_PROCESSING_AGE},
|
||||
feature_set,
|
||||
genesis_config::GenesisConfig,
|
||||
hash::Hash,
|
||||
pubkey::Pubkey,
|
||||
|
@ -337,10 +338,22 @@ 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![];
|
||||
|
@ -348,23 +361,26 @@ fn execute_batches(
|
|||
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
|
||||
|
@ -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,
|
||||
|
|
|
@ -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> = [
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue