Skip to content

Commit

Permalink
SVM: Unify different instances of epoch_schedule in SVM and Bank into…
Browse files Browse the repository at this point in the history
… one (anza-xyz#1736)
  • Loading branch information
pgarg66 authored and samkim-crypto committed Jul 31, 2024
1 parent aba84d8 commit c5ddb7f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 70 deletions.
31 changes: 10 additions & 21 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,12 +1004,8 @@ impl Bank {
transaction_account_lock_limit: None,
};

bank.transaction_processor = TransactionBatchProcessor::new(
bank.slot,
bank.epoch,
bank.epoch_schedule.clone(),
HashSet::default(),
);
bank.transaction_processor =
TransactionBatchProcessor::new(bank.slot, bank.epoch, HashSet::default());

let accounts_data_size_initial = bank.get_total_accounts_stats().unwrap().data_len as u64;
bank.accounts_data_size_initial = accounts_data_size_initial;
Expand Down Expand Up @@ -1281,12 +1277,17 @@ impl Bank {
}
});

let (_epoch, slot_index) = new.epoch_schedule.get_epoch_and_slot_index(new.slot);
let slots_in_epoch = new.epoch_schedule.get_slots_in_epoch(new.epoch);

let (_, cache_preparation_time_us) = measure_us!(new
.transaction_processor
.prepare_program_cache_for_upcoming_feature_set(
&new,
&new.compute_active_feature_set(true).0,
&new.compute_budget.unwrap_or_default(),
slot_index,
slots_in_epoch,
));

// Update sysvars before processing transactions
Expand Down Expand Up @@ -1639,12 +1640,8 @@ impl Bank {
transaction_account_lock_limit: runtime_config.transaction_account_lock_limit,
};

bank.transaction_processor = TransactionBatchProcessor::new(
bank.slot,
bank.epoch,
bank.epoch_schedule.clone(),
HashSet::default(),
);
bank.transaction_processor =
TransactionBatchProcessor::new(bank.slot, bank.epoch, HashSet::default());

let thread_pool = ThreadPoolBuilder::new()
.thread_name(|i| format!("solBnkNewFlds{i:02}"))
Expand Down Expand Up @@ -2969,7 +2966,6 @@ impl Bank {
self.slots_per_year = genesis_config.slots_per_year();

self.epoch_schedule = genesis_config.epoch_schedule.clone();
self.transaction_processor.epoch_schedule = genesis_config.epoch_schedule.clone();

self.inflation = Arc::new(RwLock::new(genesis_config.inflation));

Expand Down Expand Up @@ -7163,14 +7159,7 @@ impl Bank {
let environments = self
.transaction_processor
.get_environments_for_epoch(effective_epoch)?;
load_program_with_pubkey(
self,
&environments,
pubkey,
self.slot(),
self.epoch_schedule(),
reload,
)
load_program_with_pubkey(self, &environments, pubkey, self.slot(), reload)
}
}

Expand Down
5 changes: 1 addition & 4 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9116,10 +9116,7 @@ fn test_epoch_schedule_from_genesis_config() {
Arc::default(),
));

assert_eq!(
&bank.transaction_processor.epoch_schedule,
&genesis_config.epoch_schedule
);
assert_eq!(bank.epoch_schedule(), &genesis_config.epoch_schedule);
}

fn check_stake_vote_account_validity<F>(check_owner_change: bool, load_vote_and_stake_accounts: F)
Expand Down
11 changes: 0 additions & 11 deletions svm/src/program_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use {
bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable::UpgradeableLoaderState,
clock::Slot,
epoch_schedule::EpochSchedule,
instruction::InstructionError,
loader_v4::{self, LoaderV4State, LoaderV4Status},
pubkey::Pubkey,
Expand Down Expand Up @@ -126,7 +125,6 @@ pub fn load_program_with_pubkey<CB: TransactionProcessingCallback>(
environments: &ProgramRuntimeEnvironments,
pubkey: &Pubkey,
slot: Slot,
_epoch_schedule: &EpochSchedule,
reload: bool,
) -> Option<Arc<ProgramCacheEntry>> {
let mut load_program_metrics = LoadProgramMetrics {
Expand Down Expand Up @@ -494,7 +492,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(50).unwrap(),
&key,
500,
&batch_processor.epoch_schedule,
false,
);
assert!(result.is_none());
Expand All @@ -517,7 +514,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(20).unwrap(),
&key,
0, // Slot 0
&batch_processor.epoch_schedule,
false,
);

Expand Down Expand Up @@ -552,7 +548,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(20).unwrap(),
&key,
200,
&batch_processor.epoch_schedule,
false,
);
let loaded_program = ProgramCacheEntry::new_tombstone(
Expand Down Expand Up @@ -580,7 +575,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(20).unwrap(),
&key,
200,
&batch_processor.epoch_schedule,
false,
);

Expand Down Expand Up @@ -634,7 +628,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(0).unwrap(),
&key1,
0,
&batch_processor.epoch_schedule,
false,
);
let loaded_program = ProgramCacheEntry::new_tombstone(
Expand Down Expand Up @@ -672,7 +665,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(20).unwrap(),
&key1,
200,
&batch_processor.epoch_schedule,
false,
);

Expand Down Expand Up @@ -722,7 +714,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(0).unwrap(),
&key,
0,
&batch_processor.epoch_schedule,
false,
);
let loaded_program = ProgramCacheEntry::new_tombstone(
Expand Down Expand Up @@ -756,7 +747,6 @@ mod tests {
&batch_processor.get_environments_for_epoch(20).unwrap(),
&key,
200,
&batch_processor.epoch_schedule,
false,
);

Expand Down Expand Up @@ -807,7 +797,6 @@ mod tests {
.unwrap(),
&key,
200,
&batch_processor.epoch_schedule,
false,
)
.unwrap();
Expand Down
29 changes: 5 additions & 24 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use {
solana_sdk::{
account::{AccountSharedData, ReadableAccount, PROGRAM_OWNERS},
clock::{Epoch, Slot},
epoch_schedule::EpochSchedule,
feature_set::{
include_loaded_accounts_data_size_in_fee_calculation,
remove_rounding_in_fee_calculation, FeatureSet,
Expand Down Expand Up @@ -146,9 +145,6 @@ pub struct TransactionBatchProcessor<FG: ForkGraph> {
/// Bank epoch
epoch: Epoch,

/// initialized from genesis
pub epoch_schedule: EpochSchedule,

/// Transaction fee structure
pub fee_structure: FeeStructure,

Expand All @@ -169,7 +165,6 @@ impl<FG: ForkGraph> Debug for TransactionBatchProcessor<FG> {
f.debug_struct("TransactionBatchProcessor")
.field("slot", &self.slot)
.field("epoch", &self.epoch)
.field("epoch_schedule", &self.epoch_schedule)
.field("fee_structure", &self.fee_structure)
.field("sysvar_cache", &self.sysvar_cache)
.field("program_cache", &self.program_cache)
Expand All @@ -182,7 +177,6 @@ impl<FG: ForkGraph> Default for TransactionBatchProcessor<FG> {
Self {
slot: Slot::default(),
epoch: Epoch::default(),
epoch_schedule: EpochSchedule::default(),
fee_structure: FeeStructure::default(),
sysvar_cache: RwLock::<SysvarCache>::default(),
program_cache: Arc::new(RwLock::new(ProgramCache::new(
Expand All @@ -195,16 +189,10 @@ impl<FG: ForkGraph> Default for TransactionBatchProcessor<FG> {
}

impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
pub fn new(
slot: Slot,
epoch: Epoch,
epoch_schedule: EpochSchedule,
builtin_program_ids: HashSet<Pubkey>,
) -> Self {
pub fn new(slot: Slot, epoch: Epoch, builtin_program_ids: HashSet<Pubkey>) -> Self {
Self {
slot,
epoch,
epoch_schedule,
fee_structure: FeeStructure::default(),
sysvar_cache: RwLock::<SysvarCache>::default(),
program_cache: Arc::new(RwLock::new(ProgramCache::new(slot, epoch))),
Expand All @@ -216,7 +204,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
Self {
slot,
epoch,
epoch_schedule: self.epoch_schedule.clone(),
fee_structure: self.fee_structure.clone(),
sysvar_cache: RwLock::<SysvarCache>::default(),
program_cache: self.program_cache.clone(),
Expand Down Expand Up @@ -589,7 +576,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
&program_cache.get_environments_for_epoch(self.epoch),
&key,
self.slot,
&self.epoch_schedule,
false,
)
.expect("called load_program_with_pubkey() with nonexistent account");
Expand Down Expand Up @@ -637,10 +623,10 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
callbacks: &CB,
upcoming_feature_set: &FeatureSet,
compute_budget: &ComputeBudget,
slot_index: u64,
slots_in_epoch: u64,
) {
// Recompile loaded programs one at a time before the next epoch hits
let (_epoch, slot_index) = self.epoch_schedule.get_epoch_and_slot_index(self.slot);
let slots_in_epoch = self.epoch_schedule.get_slots_in_epoch(self.epoch);
let slots_in_recompilation_phase =
(solana_program_runtime::loaded_programs::MAX_LOADED_ENTRY_COUNT as u64)
.min(slots_in_epoch)
Expand All @@ -661,7 +647,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
&environments_for_epoch,
&key,
self.slot,
&self.epoch_schedule,
false,
) {
recompiled
Expand Down Expand Up @@ -1003,6 +988,7 @@ mod tests {
bpf_loader,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
compute_budget::ComputeBudgetInstruction,
epoch_schedule::EpochSchedule,
feature_set::FeatureSet,
fee::FeeDetails,
fee_calculator::FeeCalculator,
Expand Down Expand Up @@ -1849,12 +1835,7 @@ mod tests {
#[test]
fn fast_concur_test() {
let mut mock_bank = MockBankCallback::default();
let batch_processor = TransactionBatchProcessor::<TestForkGraph>::new(
5,
5,
EpochSchedule::default(),
HashSet::new(),
);
let batch_processor = TransactionBatchProcessor::<TestForkGraph>::new(5, 5, HashSet::new());
batch_processor.program_cache.write().unwrap().fork_graph =
Some(Arc::new(RwLock::new(TestForkGraph {})));

Expand Down
9 changes: 1 addition & 8 deletions svm/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use {
solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount},
bpf_loader_upgradeable,
epoch_schedule::EpochSchedule,
feature_set::{FeatureSet, FEATURE_NAMES},
hash::Hash,
instruction::AccountMeta,
Expand Down Expand Up @@ -247,12 +246,7 @@ fn run_fixture(fixture: InstrFixture, filename: OsString, execute_as_instr: bool
create_program_runtime_environment_v1(&feature_set, &compute_budget, false, false).unwrap();

mock_bank.override_feature_set(feature_set);
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new(
42,
2,
EpochSchedule::default(),
HashSet::new(),
);
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new(42, 2, HashSet::new());

{
let mut program_cache = batch_processor.program_cache.write().unwrap();
Expand Down Expand Up @@ -445,7 +439,6 @@ fn execute_fixture_as_instr(
&batch_processor.get_environments_for_epoch(2).unwrap(),
&program_id,
42,
&batch_processor.epoch_schedule,
false,
)
.unwrap();
Expand Down
2 changes: 0 additions & 2 deletions svm/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use {
account::{AccountSharedData, ReadableAccount, WritableAccount},
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::{Clock, Epoch, Slot, UnixTimestamp},
epoch_schedule::EpochSchedule,
hash::Hash,
instruction::AccountMeta,
pubkey::Pubkey,
Expand Down Expand Up @@ -445,7 +444,6 @@ fn svm_integration() {
let batch_processor = TransactionBatchProcessor::<MockForkGraph>::new(
EXECUTION_SLOT,
EXECUTION_EPOCH,
EpochSchedule::default(),
HashSet::new(),
);

Expand Down

0 comments on commit c5ddb7f

Please sign in to comment.