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::{
|
solana_sdk::{
|
||||||
clock::{Slot, MAX_PROCESSING_AGE},
|
clock::{Slot, MAX_PROCESSING_AGE},
|
||||||
|
feature_set,
|
||||||
genesis_config::GenesisConfig,
|
genesis_config::GenesisConfig,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
@ -337,10 +338,22 @@ fn execute_batches(
|
||||||
let cost = tx_cost.sum();
|
let cost = tx_cost.sum();
|
||||||
minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost);
|
minimal_tx_cost = std::cmp::min(minimal_tx_cost, cost);
|
||||||
total_cost = total_cost.saturating_add(cost);
|
total_cost = total_cost.saturating_add(cost);
|
||||||
cost
|
tx_cost
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.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 target_batch_count = get_thread_count() as u64;
|
||||||
|
|
||||||
let mut tx_batches: Vec<TransactionBatchWithIndexes> = vec![];
|
let mut tx_batches: Vec<TransactionBatchWithIndexes> = vec![];
|
||||||
|
@ -348,23 +361,26 @@ fn execute_batches(
|
||||||
let target_batch_cost = total_cost / target_batch_count;
|
let target_batch_cost = total_cost / target_batch_count;
|
||||||
let mut batch_cost: u64 = 0;
|
let mut batch_cost: u64 = 0;
|
||||||
let mut slice_start = 0;
|
let mut slice_start = 0;
|
||||||
tx_costs.into_iter().enumerate().for_each(|(index, cost)| {
|
tx_costs
|
||||||
let next_index = index + 1;
|
.into_iter()
|
||||||
batch_cost = batch_cost.saturating_add(cost);
|
.enumerate()
|
||||||
if batch_cost >= target_batch_cost || next_index == sanitized_txs.len() {
|
.for_each(|(index, tx_cost)| {
|
||||||
let tx_batch = rebatch_transactions(
|
let next_index = index + 1;
|
||||||
&lock_results,
|
batch_cost = batch_cost.saturating_add(tx_cost.sum());
|
||||||
bank,
|
if batch_cost >= target_batch_cost || next_index == sanitized_txs.len() {
|
||||||
&sanitized_txs,
|
let tx_batch = rebatch_transactions(
|
||||||
slice_start,
|
&lock_results,
|
||||||
index,
|
bank,
|
||||||
&transaction_indexes,
|
&sanitized_txs,
|
||||||
);
|
slice_start,
|
||||||
slice_start = next_index;
|
index,
|
||||||
tx_batches.push(tx_batch);
|
&transaction_indexes,
|
||||||
batch_cost = 0;
|
);
|
||||||
}
|
slice_start = next_index;
|
||||||
});
|
tx_batches.push(tx_batch);
|
||||||
|
batch_cost = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
&tx_batches[..]
|
&tx_batches[..]
|
||||||
} else {
|
} else {
|
||||||
batches
|
batches
|
||||||
|
@ -1767,7 +1783,6 @@ pub mod tests {
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, WritableAccount},
|
account::{AccountSharedData, WritableAccount},
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
feature_set,
|
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
native_token::LAMPORTS_PER_SOL,
|
native_token::LAMPORTS_PER_SOL,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
|
|
|
@ -614,6 +614,10 @@ pub mod delay_visibility_of_program_deployment {
|
||||||
solana_sdk::declare_id!("GmuBvtFb2aHfSfMXpuFeWZGHyDeCLPS79s48fmCWCfM5");
|
solana_sdk::declare_id!("GmuBvtFb2aHfSfMXpuFeWZGHyDeCLPS79s48fmCWCfM5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod apply_cost_tracker_during_replay {
|
||||||
|
solana_sdk::declare_id!("2ry7ygxiYURULZCrypHhveanvP5tzZ4toRwVp89oCNSj");
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Map of feature identifiers to user-visible description
|
/// Map of feature identifiers to user-visible description
|
||||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
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"),
|
(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"),
|
(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"),
|
(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 ***************/
|
/*************** ADD NEW FEATURES HERE ***************/
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Reference in New Issue