Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: Expose builtin program IDs to crate #318

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,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 @@ -758,7 +758,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 @@ -977,7 +977,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 @@ -1233,8 +1233,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 @@ -1290,7 +1290,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 @@ -1451,7 +1451,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 @@ -1846,7 +1846,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 @@ -4653,7 +4653,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 @@ -6064,6 +6064,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 @@ -7092,7 +7096,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
Loading