solana/runtime/src/feature_set.rs

70 lines
1.8 KiB
Rust
Raw Normal View History

use lazy_static::lazy_static;
2020-09-21 14:03:35 -07:00
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! {
2020-09-24 00:22:49 -07:00
/// 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();
2020-09-24 00:22:49 -07:00
/// 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()
};
}
2020-09-21 14:03:35 -07:00
2020-09-24 00:22:49 -07:00
/// `FeatureSet` holds the set of currently active/inactive runtime features
2020-09-24 08:53:50 -07:00
#[derive(AbiExample, Clone)]
2020-09-21 14:03:35 -07:00
pub struct FeatureSet {
pub active: HashSet<Pubkey>,
pub inactive: HashSet<Pubkey>,
}
impl FeatureSet {
2020-09-24 13:31:51 -07:00
pub fn is_active(&self, feature_id: &Pubkey) -> bool {
2020-09-21 14:03:35 -07:00
self.active.contains(feature_id)
}
}
impl Default for FeatureSet {
fn default() -> Self {
2020-09-24 00:22:49 -07:00
// All features disabled
2020-09-21 14:03:35 -07:00
Self {
active: HashSet::new(),
inactive: FEATURE_NAMES.keys().cloned().collect(),
2020-09-21 14:03:35 -07:00
}
}
}
impl FeatureSet {
pub fn enabled() -> Self {
2020-09-21 14:03:35 -07:00
Self {
active: FEATURE_NAMES.keys().cloned().collect(),
2020-09-21 14:03:35 -07:00
inactive: HashSet::new(),
}
}
}