* Runtime feature activation framework (cherry picked from commit93259f0bae
) # Conflicts: # runtime/src/bank.rs * Add feature set identifier to gossiped version information (cherry picked from commit35f5f9fc7b
) # Conflicts: # Cargo.lock # version/Cargo.toml * Port instructions sysvar and secp256k1 program activation to FeatureSet (cherry picked from commitc10da16d7b
) # Conflicts: # runtime/src/bank.rs # runtime/src/message_processor.rs * Add feature management commands (cherry picked from commit93ed0ab2bb
) # Conflicts: # Cargo.lock # cli/Cargo.toml * Make test_process_rest_api less fragile (cherry picked from commit7526bb96f3
) * Remove id field (cherry picked from commitcc6ba1e131
) * FeatureSet test (cherry picked from commit92406cf9a0
) * cargo fmt (cherry picked from commit199940d683
) * cli review feedback (cherry picked from commit3a2b8c5e5b
) * Rename active() to is_active() (cherry picked from commite39fac9f01
) * Resolve merge conflicts * Remove continues from compute_active_feature_set() Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
69
runtime/src/feature_set.rs
Normal file
69
runtime/src/feature_set.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use lazy_static::lazy_static;
|
||||
use solana_sdk::{
|
||||
hash::{Hash, Hasher},
|
||||
pubkey::Pubkey,
|
||||
};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub mod instructions_sysvar_enabled {
|
||||
solana_sdk::declare_id!("EnvhHCLvg55P7PDtbvR1NwuTuAeodqpusV3MR5QEK8gs");
|
||||
}
|
||||
|
||||
pub mod secp256k1_program_enabled {
|
||||
solana_sdk::declare_id!("E3PHP7w8kB7np3CTQ1qQ2tW3KCtjRSXBQgW9vM2mWv2Y");
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Map of feature identifiers to user-visible description
|
||||
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
|
||||
(instructions_sysvar_enabled::id(), "instructions sysvar"),
|
||||
(secp256k1_program_enabled::id(), "secp256k1 program")
|
||||
/*************** ADD NEW FEATURES HERE ***************/
|
||||
]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
/// Unique identifier of the current software's feature set
|
||||
pub static ref ID: Hash = {
|
||||
let mut hasher = Hasher::default();
|
||||
let mut feature_ids = FEATURE_NAMES.keys().collect::<Vec<_>>();
|
||||
feature_ids.sort();
|
||||
for feature in feature_ids {
|
||||
hasher.hash(feature.as_ref());
|
||||
}
|
||||
hasher.result()
|
||||
};
|
||||
}
|
||||
|
||||
/// `FeatureSet` holds the set of currently active/inactive runtime features
|
||||
#[derive(AbiExample, Clone)]
|
||||
pub struct FeatureSet {
|
||||
pub active: HashSet<Pubkey>,
|
||||
pub inactive: HashSet<Pubkey>,
|
||||
}
|
||||
|
||||
impl FeatureSet {
|
||||
pub fn is_active(&self, feature_id: &Pubkey) -> bool {
|
||||
self.active.contains(feature_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FeatureSet {
|
||||
fn default() -> Self {
|
||||
// All features disabled
|
||||
Self {
|
||||
active: HashSet::new(),
|
||||
inactive: FEATURE_NAMES.keys().cloned().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FeatureSet {
|
||||
pub fn enabled() -> Self {
|
||||
Self {
|
||||
active: FEATURE_NAMES.keys().cloned().collect(),
|
||||
inactive: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user