Skip to content

Commit

Permalink
Runtime: Expose builtin program IDs to crate (#318)
Browse files Browse the repository at this point in the history
* runtime: bank: rename `builtin_programs` to `builtin_program_ids`

* runtime: snapshot minimizer: use builtin IDs from bank
  • Loading branch information
buffalojoec authored Mar 22, 2024
1 parent 8463944 commit f799c9f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
24 changes: 14 additions & 10 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl PartialEq for Bank {
epoch_stakes,
is_delta,
// TODO: Confirm if all these fields are intentionally ignored!
builtin_programs: _,
builtin_program_ids: _,
runtime_config: _,
rewards: _,
cluster_type: _,
Expand Down Expand Up @@ -779,7 +779,7 @@ pub struct Bank {
/// stream for the slot == self.slot
is_delta: AtomicBool,

builtin_programs: HashSet<Pubkey>,
builtin_program_ids: HashSet<Pubkey>,

/// Optional config parameters that can override runtime behavior
pub(crate) runtime_config: Arc<RuntimeConfig>,
Expand Down Expand Up @@ -1001,7 +1001,7 @@ impl Bank {
stakes_cache: StakesCache::default(),
epoch_stakes: HashMap::<Epoch, EpochStakes>::default(),
is_delta: AtomicBool::default(),
builtin_programs: HashSet::<Pubkey>::default(),
builtin_program_ids: HashSet::<Pubkey>::default(),
runtime_config: Arc::<RuntimeConfig>::default(),
rewards: RwLock::<Vec<(Pubkey, RewardInfo)>>::default(),
cluster_type: Option::<ClusterType>::default(),
Expand Down Expand Up @@ -1258,8 +1258,8 @@ impl Bank {

let (epoch_stakes, epoch_stakes_time_us) = measure_us!(parent.epoch_stakes.clone());

let (builtin_programs, builtin_programs_time_us) =
measure_us!(parent.builtin_programs.clone());
let (builtin_program_ids, builtin_program_ids_time_us) =
measure_us!(parent.builtin_program_ids.clone());

let (rewards_pool_pubkeys, rewards_pool_pubkeys_time_us) =
measure_us!(parent.rewards_pool_pubkeys.clone());
Expand Down Expand Up @@ -1315,7 +1315,7 @@ impl Bank {
ancestors: Ancestors::default(),
hash: RwLock::new(Hash::default()),
is_delta: AtomicBool::new(false),
builtin_programs,
builtin_program_ids,
tick_height: AtomicU64::new(parent.tick_height.load(Relaxed)),
signature_count: AtomicU64::new(0),
runtime_config: parent.runtime_config.clone(),
Expand Down Expand Up @@ -1477,7 +1477,7 @@ impl Bank {
blockhash_queue_time_us,
stakes_cache_time_us,
epoch_stakes_time_us,
builtin_programs_time_us,
builtin_program_ids_time_us,
rewards_pool_pubkeys_time_us,
executor_cache_time_us: 0,
transaction_debug_keys_time_us,
Expand Down Expand Up @@ -1872,7 +1872,7 @@ impl Bank {
stakes_cache: StakesCache::new(stakes),
epoch_stakes: fields.epoch_stakes,
is_delta: AtomicBool::new(fields.is_delta),
builtin_programs: HashSet::<Pubkey>::default(),
builtin_program_ids: HashSet::<Pubkey>::default(),
runtime_config,
rewards: RwLock::new(vec![]),
cluster_type: Some(genesis_config.cluster_type),
Expand Down Expand Up @@ -4681,7 +4681,7 @@ impl Bank {
recording_config,
timings,
account_overrides,
self.builtin_programs.iter(),
self.builtin_program_ids.iter(),
log_messages_bytes_limit,
limit_to_load_programs,
);
Expand Down Expand Up @@ -6162,6 +6162,10 @@ impl Bank {
}
}

pub(crate) fn get_builtin_program_ids(&self) -> &HashSet<Pubkey> {
&self.builtin_program_ids
}

// Hi! leaky abstraction here....
// try to use get_account_with_fixed_root() if it's called ONLY from on-chain runtime account
// processing. That alternative fn provides more safety.
Expand Down Expand Up @@ -7190,7 +7194,7 @@ impl Bank {
pub fn add_builtin(&mut self, program_id: Pubkey, name: String, builtin: LoadedProgram) {
debug!("Adding program {} under {:?}", name, program_id);
self.add_builtin_account(name.as_str(), &program_id, false);
self.builtin_programs.insert(program_id);
self.builtin_program_ids.insert(program_id);
self.program_cache
.write()
.unwrap()
Expand Down
8 changes: 6 additions & 2 deletions runtime/src/bank/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) struct NewBankTimings {
pub(crate) blockhash_queue_time_us: u64,
pub(crate) stakes_cache_time_us: u64,
pub(crate) epoch_stakes_time_us: u64,
pub(crate) builtin_programs_time_us: u64,
pub(crate) builtin_program_ids_time_us: u64,
pub(crate) rewards_pool_pubkeys_time_us: u64,
pub(crate) executor_cache_time_us: u64,
pub(crate) transaction_debug_keys_time_us: u64,
Expand Down Expand Up @@ -125,7 +125,11 @@ pub(crate) fn report_new_bank_metrics(
("blockhash_queue_us", timings.blockhash_queue_time_us, i64),
("stakes_cache_us", timings.stakes_cache_time_us, i64),
("epoch_stakes_time_us", timings.epoch_stakes_time_us, i64),
("builtin_programs_us", timings.builtin_programs_time_us, i64),
(
"builtin_programs_us",
timings.builtin_program_ids_time_us,
i64
),
(
"rewards_pool_pubkeys_us",
timings.rewards_pool_pubkeys_time_us,
Expand Down
14 changes: 7 additions & 7 deletions runtime/src/snapshot_minimizer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Used to create minimal snapshots - separated here to keep accounts_db simpler
use {
crate::{
bank::{builtins::BUILTINS, Bank},
static_ids,
},
crate::{bank::Bank, static_ids},
dashmap::DashSet,
log::info,
rayon::{
Expand Down Expand Up @@ -116,9 +113,12 @@ impl<'a> SnapshotMinimizer<'a> {

/// Used to get builtin accounts in `minimize`
fn get_builtins(&self) {
BUILTINS.iter().for_each(|e| {
self.minimized_account_set.insert(e.program_id);
});
self.bank
.get_builtin_program_ids()
.iter()
.for_each(|program_id| {
self.minimized_account_set.insert(*program_id);
});
}

/// Used to get static runtime accounts in `minimize`
Expand Down

0 comments on commit f799c9f

Please sign in to comment.