Skip to content

Commit

Permalink
runtime: bank: wire in core bpf migration feature activations
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Feb 8, 2024
1 parent 38b648c commit 86e2125
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
49 changes: 45 additions & 4 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5960,7 +5960,16 @@ impl Bank {
.iter()
.chain(additional_builtins.unwrap_or(&[]).iter())
{
if builtin.enable_feature_id.is_none() {
let should_add_builtin = builtin.enable_feature_id.is_none() && {
if let Some(core_bpf_migration) = &builtin.core_bpf_migration {
// The built-in should be added if the feature to
// migrate it to Core BPF is not active
!self.feature_set.is_active(&core_bpf_migration.feature_id)
} else {
true
}
};
if should_add_builtin {
self.add_builtin(
builtin.program_id,
builtin.name.to_string(),
Expand Down Expand Up @@ -6050,6 +6059,10 @@ impl Bank {
self.load_slow(&self.ancestors, pubkey)
}

pub fn get_builtins(&self) -> &HashSet<Pubkey> {
&self.builtin_programs
}

fn load_slow(
&self,
ancestors: &Ancestors,
Expand Down Expand Up @@ -7298,14 +7311,42 @@ impl Bank {
new_feature_activations: &HashSet<Pubkey>,
) {
for builtin in BUILTINS.iter() {
let mut builtin_disabled = false;
if let Some(core_bpf_migration) = &builtin.core_bpf_migration {
// If the built-in is set to be migrated to Core BPF on feature
// activation, perform the migration and do not add the program
// to the bank's builtins. The migration will remove it from
// the builtins list and the cache.
//
// There should never be a case where a built-in is set to be
// migrated to Core BPF and is also set to be enabled on feature
// activation. However, the `builtin_disabled` flag is used to
// handle this case.
if new_feature_activations.contains(&core_bpf_migration.feature_id) {
if let Err(e) = builtin.migrate_to_core_bpf(self) {
warn!(
"Failed to migrate built-in {} to core BPF: {}",
builtin.name, e
);
} else {
builtin_disabled = true;
}
} else {
// If the built-in has already been migrated to Core BPF, do not
// add it to the bank's builtins.
builtin_disabled = self.feature_set.is_active(&core_bpf_migration.feature_id);
}
};

if let Some(feature_id) = builtin.enable_feature_id {
let should_apply_action_for_feature_transition =
if only_apply_transitions_for_new_features {
let should_enable_builtin_on_feature_transition = !builtin_disabled
&& if only_apply_transitions_for_new_features {
new_feature_activations.contains(&feature_id)
} else {
self.feature_set.is_active(&feature_id)
};
if should_apply_action_for_feature_transition {

if should_enable_builtin_on_feature_transition {
self.add_builtin(
builtin.program_id,
builtin.name.to_string(),
Expand Down
9 changes: 3 additions & 6 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,8 +113,8 @@ 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_builtins().iter().for_each(|program_id| {
self.minimized_account_set.insert(*program_id);
});
}

Expand Down

0 comments on commit 86e2125

Please sign in to comment.