Skip to content

Commit 09ae587

Browse files
authored
Rename LoadedPrograms to ProgramCache for readability (#339)
1 parent 3038d47 commit 09ae587

File tree

5 files changed

+110
-123
lines changed

5 files changed

+110
-123
lines changed

program-runtime/src/loaded_programs.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub struct LoadedProgram {
145145
pub latest_access_slot: AtomicU64,
146146
}
147147

148-
/// Global cache statistics for [LoadedPrograms].
148+
/// Global cache statistics for [ProgramCache].
149149
#[derive(Debug, Default)]
150150
pub struct Stats {
151151
/// a program was already in the cache
@@ -568,7 +568,7 @@ struct SecondLevel {
568568
/// - allows for cooperative loading of TX batches which hit the same missing programs simultaneously.
569569
/// - enforces that all programs used in a batch are eagerly loaded ahead of execution.
570570
/// - is not persisted to disk or a snapshot, so it needs to cold start and warm up first.
571-
pub struct LoadedPrograms<FG: ForkGraph> {
571+
pub struct ProgramCache<FG: ForkGraph> {
572572
/// A two level index:
573573
///
574574
/// The first level is for the address at which programs are deployed and the second level for the slot (and thus also fork).
@@ -595,9 +595,9 @@ pub struct LoadedPrograms<FG: ForkGraph> {
595595
pub loading_task_waiter: Arc<LoadingTaskWaiter>,
596596
}
597597

598-
impl<FG: ForkGraph> Debug for LoadedPrograms<FG> {
598+
impl<FG: ForkGraph> Debug for ProgramCache<FG> {
599599
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
600-
f.debug_struct("LoadedPrograms")
600+
f.debug_struct("ProgramCache")
601601
.field("root slot", &self.latest_root_slot)
602602
.field("root epoch", &self.latest_root_epoch)
603603
.field("stats", &self.stats)
@@ -606,11 +606,11 @@ impl<FG: ForkGraph> Debug for LoadedPrograms<FG> {
606606
}
607607
}
608608

609-
/// Local view into [LoadedPrograms] which was extracted for a specific TX batch.
609+
/// Local view into [ProgramCache] which was extracted for a specific TX batch.
610610
///
611-
/// This isolation enables the global [LoadedPrograms] to continue to evolve (e.g. evictions),
611+
/// This isolation enables the global [ProgramCache] to continue to evolve (e.g. evictions),
612612
/// while the TX batch is guaranteed it will continue to find all the programs it requires.
613-
/// For program management instructions this also buffers them before they are merged back into the global [LoadedPrograms].
613+
/// For program management instructions this also buffers them before they are merged back into the global [ProgramCache].
614614
#[derive(Clone, Debug, Default)]
615615
pub struct LoadedProgramsForTxBatch {
616616
/// Pubkey is the address of a program.
@@ -681,7 +681,7 @@ pub enum LoadedProgramMatchCriteria {
681681
NoCriteria,
682682
}
683683

684-
impl<FG: ForkGraph> LoadedPrograms<FG> {
684+
impl<FG: ForkGraph> ProgramCache<FG> {
685685
pub fn new(root_slot: Slot, root_epoch: Epoch) -> Self {
686686
Self {
687687
entries: HashMap::new(),
@@ -734,7 +734,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
734734
(LoadedProgramType::Unloaded(_), LoadedProgramType::TestLoaded(_)) => {}
735735
_ => {
736736
// Something is wrong, I can feel it ...
737-
error!("LoadedPrograms::assign_program() failed key={:?} existing={:?} entry={:?}", key, slot_versions, entry);
737+
error!("ProgramCache::assign_program() failed key={:?} existing={:?} entry={:?}", key, slot_versions, entry);
738738
debug_assert!(false, "Unexpected replacement of an entry");
739739
self.stats.replacements.fetch_add(1, Ordering::Relaxed);
740740
return true;
@@ -1146,9 +1146,9 @@ impl solana_frozen_abi::abi_example::AbiExample for LoadedProgram {
11461146
}
11471147

11481148
#[cfg(RUSTC_WITH_SPECIALIZATION)]
1149-
impl<FG: ForkGraph> solana_frozen_abi::abi_example::AbiExample for LoadedPrograms<FG> {
1149+
impl<FG: ForkGraph> solana_frozen_abi::abi_example::AbiExample for ProgramCache<FG> {
11501150
fn example() -> Self {
1151-
// LoadedPrograms isn't serializable by definition.
1151+
// ProgramCache isn't serializable by definition.
11521152
Self::new(Slot::default(), Epoch::default())
11531153
}
11541154
}
@@ -1158,7 +1158,7 @@ mod tests {
11581158
use {
11591159
crate::loaded_programs::{
11601160
BlockRelation, ForkGraph, LoadedProgram, LoadedProgramMatchCriteria, LoadedProgramType,
1161-
LoadedPrograms, LoadedProgramsForTxBatch, ProgramRuntimeEnvironment,
1161+
LoadedProgramsForTxBatch, ProgramCache, ProgramRuntimeEnvironment,
11621162
ProgramRuntimeEnvironments, DELAY_VISIBILITY_SLOT_OFFSET,
11631163
},
11641164
assert_matches::assert_matches,
@@ -1178,8 +1178,8 @@ mod tests {
11781178
static MOCK_ENVIRONMENT: std::sync::OnceLock<ProgramRuntimeEnvironment> =
11791179
std::sync::OnceLock::<ProgramRuntimeEnvironment>::new();
11801180

1181-
fn new_mock_cache<FG: ForkGraph>() -> LoadedPrograms<FG> {
1182-
let mut cache = LoadedPrograms::new(0, 0);
1181+
fn new_mock_cache<FG: ForkGraph>() -> ProgramCache<FG> {
1182+
let mut cache = ProgramCache::new(0, 0);
11831183

11841184
cache.environments.program_runtime_v1 = MOCK_ENVIRONMENT
11851185
.get_or_init(|| Arc::new(BuiltinProgram::new_mock()))
@@ -1220,7 +1220,7 @@ mod tests {
12201220
}
12211221

12221222
fn set_tombstone<FG: ForkGraph>(
1223-
cache: &mut LoadedPrograms<FG>,
1223+
cache: &mut ProgramCache<FG>,
12241224
key: Pubkey,
12251225
slot: Slot,
12261226
reason: LoadedProgramType,
@@ -1231,7 +1231,7 @@ mod tests {
12311231
}
12321232

12331233
fn insert_unloaded_program<FG: ForkGraph>(
1234-
cache: &mut LoadedPrograms<FG>,
1234+
cache: &mut ProgramCache<FG>,
12351235
key: Pubkey,
12361236
slot: Slot,
12371237
) -> Arc<LoadedProgram> {
@@ -1254,7 +1254,7 @@ mod tests {
12541254
unloaded
12551255
}
12561256

1257-
fn num_matching_entries<P, FG>(cache: &LoadedPrograms<FG>, predicate: P) -> usize
1257+
fn num_matching_entries<P, FG>(cache: &ProgramCache<FG>, predicate: P) -> usize
12581258
where
12591259
P: Fn(&LoadedProgramType) -> bool,
12601260
FG: ForkGraph,
@@ -1302,7 +1302,7 @@ mod tests {
13021302
}
13031303

13041304
fn program_deploy_test_helper(
1305-
cache: &mut LoadedPrograms<TestForkGraph>,
1305+
cache: &mut ProgramCache<TestForkGraph>,
13061306
program: Pubkey,
13071307
deployment_slots: Vec<Slot>,
13081308
usage_counters: Vec<u64>,
@@ -2574,28 +2574,28 @@ mod tests {
25742574
let tombstone = Arc::new(LoadedProgram::new_tombstone(0, LoadedProgramType::Closed));
25752575

25762576
assert!(
2577-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2577+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
25782578
&tombstone,
25792579
&LoadedProgramMatchCriteria::NoCriteria
25802580
)
25812581
);
25822582

25832583
assert!(
2584-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2584+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
25852585
&tombstone,
25862586
&LoadedProgramMatchCriteria::Tombstone
25872587
)
25882588
);
25892589

25902590
assert!(
2591-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2591+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
25922592
&tombstone,
25932593
&LoadedProgramMatchCriteria::DeployedOnOrAfterSlot(0)
25942594
)
25952595
);
25962596

25972597
assert!(
2598-
!LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2598+
!ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
25992599
&tombstone,
26002600
&LoadedProgramMatchCriteria::DeployedOnOrAfterSlot(1)
26012601
)
@@ -2604,28 +2604,28 @@ mod tests {
26042604
let program = new_test_loaded_program(0, 1);
26052605

26062606
assert!(
2607-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2607+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26082608
&program,
26092609
&LoadedProgramMatchCriteria::NoCriteria
26102610
)
26112611
);
26122612

26132613
assert!(
2614-
!LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2614+
!ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26152615
&program,
26162616
&LoadedProgramMatchCriteria::Tombstone
26172617
)
26182618
);
26192619

26202620
assert!(
2621-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2621+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26222622
&program,
26232623
&LoadedProgramMatchCriteria::DeployedOnOrAfterSlot(0)
26242624
)
26252625
);
26262626

26272627
assert!(
2628-
!LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2628+
!ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26292629
&program,
26302630
&LoadedProgramMatchCriteria::DeployedOnOrAfterSlot(1)
26312631
)
@@ -2638,28 +2638,28 @@ mod tests {
26382638
));
26392639

26402640
assert!(
2641-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2641+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26422642
&program,
26432643
&LoadedProgramMatchCriteria::NoCriteria
26442644
)
26452645
);
26462646

26472647
assert!(
2648-
!LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2648+
!ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26492649
&program,
26502650
&LoadedProgramMatchCriteria::Tombstone
26512651
)
26522652
);
26532653

26542654
assert!(
2655-
LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2655+
ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26562656
&program,
26572657
&LoadedProgramMatchCriteria::DeployedOnOrAfterSlot(0)
26582658
)
26592659
);
26602660

26612661
assert!(
2662-
!LoadedPrograms::<TestForkGraph>::matches_loaded_program_criteria(
2662+
!ProgramCache::<TestForkGraph>::matches_loaded_program_criteria(
26632663
&program,
26642664
&LoadedProgramMatchCriteria::DeployedOnOrAfterSlot(1)
26652665
)

0 commit comments

Comments
 (0)