Skip to content

Commit cc3afa5

Browse files
authored
Remove public visibility of program cache from bank (pyth-network#279)
1 parent b27c80a commit cc3afa5

File tree

7 files changed

+43
-39
lines changed

7 files changed

+43
-39
lines changed

core/benches/banking_stage.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,7 @@ fn simulate_process_entries(
398398
let bank_fork = BankForks::new_rw_arc(bank);
399399
let bank = bank_fork.read().unwrap().get_with_scheduler(slot).unwrap();
400400
bank.clone_without_scheduler()
401-
.loaded_programs_cache
402-
.write()
403-
.unwrap()
404-
.set_fork_graph(bank_fork.clone());
401+
.set_fork_graph_in_program_cache(bank_fork.clone());
405402

406403
for i in 0..(num_accounts / 2) {
407404
bank.transfer(initial_lamports, mint_keypair, &keypairs[i * 2].pubkey())

core/src/replay_stage.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,11 +1686,7 @@ impl ReplayStage {
16861686
root_bank.clear_slot_signatures(slot);
16871687

16881688
// Remove cached entries of the programs that were deployed in this slot.
1689-
root_bank
1690-
.loaded_programs_cache
1691-
.write()
1692-
.unwrap()
1693-
.prune_by_deployment_slot(slot);
1689+
root_bank.prune_program_cache_by_deployment_slot(slot);
16941690

16951691
if let Some(bank_hash) = blockstore.get_bank_hash(slot) {
16961692
// If a descendant was successfully replayed and chained from a duplicate it must

ledger-tool/src/program.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,9 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
514514
with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);
515515

516516
// Adding `DELAY_VISIBILITY_SLOT_OFFSET` to slots to accommodate for delay visibility of the program
517-
let mut loaded_programs = LoadedProgramsForTxBatch::new(
518-
bank.slot() + DELAY_VISIBILITY_SLOT_OFFSET,
519-
bank.loaded_programs_cache
520-
.read()
521-
.unwrap()
522-
.environments
523-
.clone(),
524-
);
517+
let slot = bank.slot() + DELAY_VISIBILITY_SLOT_OFFSET;
518+
let mut loaded_programs =
519+
LoadedProgramsForTxBatch::new(slot, bank.get_runtime_environments_for_slot(slot));
525520
for key in cached_account_keys {
526521
loaded_programs.replenish(key, bank.load_program(&key, false, bank.epoch()));
527522
debug!("Loaded program {}", key);

ledger/src/blockstore_processor.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,11 +1674,7 @@ fn load_frozen_forks(
16741674
root = new_root_bank.slot();
16751675

16761676
leader_schedule_cache.set_root(new_root_bank);
1677-
new_root_bank
1678-
.loaded_programs_cache
1679-
.write()
1680-
.unwrap()
1681-
.prune(root, new_root_bank.epoch());
1677+
new_root_bank.prune_program_cache(root, new_root_bank.epoch());
16821678
let _ = bank_forks.write().unwrap().set_root(
16831679
root,
16841680
accounts_background_request_sender,

runtime/src/bank.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ use {
9898
solana_program_runtime::{
9999
compute_budget_processor::process_compute_budget_instructions,
100100
invoke_context::BuiltinFunctionWithContext,
101-
loaded_programs::{LoadedProgram, LoadedProgramType, LoadedPrograms},
101+
loaded_programs::{
102+
LoadedProgram, LoadedProgramType, LoadedPrograms, ProgramRuntimeEnvironments,
103+
},
102104
runtime_config::RuntimeConfig,
103105
timings::{ExecuteTimingType, ExecuteTimings},
104106
},
@@ -803,7 +805,7 @@ pub struct Bank {
803805

804806
pub incremental_snapshot_persistence: Option<BankIncrementalSnapshotPersistence>,
805807

806-
pub loaded_programs_cache: Arc<RwLock<LoadedPrograms<BankForks>>>,
808+
loaded_programs_cache: Arc<RwLock<LoadedPrograms<BankForks>>>,
807809

808810
epoch_reward_status: EpochRewardStatus,
809811

@@ -1467,6 +1469,36 @@ impl Bank {
14671469
new
14681470
}
14691471

1472+
pub fn set_fork_graph_in_program_cache(&self, fork_graph: Arc<RwLock<BankForks>>) {
1473+
self.loaded_programs_cache
1474+
.write()
1475+
.unwrap()
1476+
.set_fork_graph(fork_graph);
1477+
}
1478+
1479+
pub fn prune_program_cache(&self, new_root_slot: Slot, new_root_epoch: Epoch) {
1480+
self.loaded_programs_cache
1481+
.write()
1482+
.unwrap()
1483+
.prune(new_root_slot, new_root_epoch);
1484+
}
1485+
1486+
pub fn prune_program_cache_by_deployment_slot(&self, deployment_slot: Slot) {
1487+
self.loaded_programs_cache
1488+
.write()
1489+
.unwrap()
1490+
.prune_by_deployment_slot(deployment_slot);
1491+
}
1492+
1493+
pub fn get_runtime_environments_for_slot(&self, slot: Slot) -> ProgramRuntimeEnvironments {
1494+
let epoch = self.epoch_schedule.get_epoch(slot);
1495+
self.loaded_programs_cache
1496+
.read()
1497+
.unwrap()
1498+
.get_environments_for_epoch(epoch)
1499+
.clone()
1500+
}
1501+
14701502
/// Epoch in which the new cooldown warmup rate for stake was activated
14711503
pub fn new_warmup_cooldown_rate_epoch(&self) -> Option<Epoch> {
14721504
self.feature_set

runtime/src/bank_forks.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,7 @@ impl BankForks {
126126
scheduler_pool: None,
127127
}));
128128

129-
root_bank
130-
.loaded_programs_cache
131-
.write()
132-
.unwrap()
133-
.set_fork_graph(bank_forks.clone());
134-
129+
root_bank.set_fork_graph_in_program_cache(bank_forks.clone());
135130
bank_forks
136131
}
137132

@@ -451,11 +446,7 @@ impl BankForks {
451446

452447
pub fn prune_program_cache(&self, root: Slot) {
453448
if let Some(root_bank) = self.banks.get(&root) {
454-
root_bank
455-
.loaded_programs_cache
456-
.write()
457-
.unwrap()
458-
.prune(root, root_bank.epoch());
449+
root_bank.prune_program_cache(root, root_bank.epoch());
459450
}
460451
}
461452

unified-scheduler-pool/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,7 @@ mod tests {
941941
let slot = bank.slot();
942942
let bank_fork = BankForks::new_rw_arc(bank);
943943
let bank = bank_fork.read().unwrap().get(slot).unwrap();
944-
bank.loaded_programs_cache
945-
.write()
946-
.unwrap()
947-
.set_fork_graph(bank_fork);
944+
bank.set_fork_graph_in_program_cache(bank_fork);
948945
bank
949946
}
950947

0 commit comments

Comments
 (0)