solana/sdk/src/feature_set.rs

176 lines
5.7 KiB
Rust
Raw Normal View History

use lazy_static::lazy_static;
2020-09-21 14:03:35 -07:00
use solana_sdk::{
clock::Slot,
2020-09-21 14:03:35 -07:00
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");
}
pub mod consistent_recent_blockhashes_sysvar {
solana_sdk::declare_id!("3h1BQWPDS5veRsq6mDBWruEpgPxRJkfwGexg5iiQ9mYg");
}
pub mod deprecate_rewards_sysvar {
solana_sdk::declare_id!("GaBtBJvmS4Arjj5W1NmFcyvPjsHN38UGYDq2MDwbs9Qu");
}
2020-09-25 16:19:03 -07:00
pub mod pico_inflation {
solana_sdk::declare_id!("4RWNif6C2WCNiKVW7otP4G7dkmkHGyKQWRpuZ1pxKU5m");
2020-09-25 16:19:03 -07:00
}
pub mod full_inflation {
solana_sdk::declare_id!("DT4n6ABDqs6w4bnfwrXT9rsprcPf6cdDga1egctaPkLC");
2020-10-08 17:35:48 -07:00
}
pub mod spl_token_v2_multisig_fix {
solana_sdk::declare_id!("E5JiFDQCwyC6QfT9REFyMpfK2mHcmv1GUDySU1Ue7TYv");
}
pub mod bpf_loader2_program {
solana_sdk::declare_id!("DFBnrgThdzH4W6wZ12uGPoWcMnvfZj11EHnxHcVxLPhD");
}
2020-10-28 13:16:13 -07:00
pub mod bpf_compute_budget_balancing {
solana_sdk::declare_id!("HxvjqDSiF5sYdSYuCXsUnS8UeAoWsMT9iGoFP8pgV1mB");
}
2020-09-29 23:29:20 -07:00
pub mod sha256_syscall_enabled {
solana_sdk::declare_id!("D7KfP7bZxpkYtD4Pc38t9htgs1k5k47Yhxe4rp6WDVi8");
}
pub mod no_overflow_rent_distribution {
solana_sdk::declare_id!("4kpdyrcj5jS47CZb2oJGfVxjYbsMm2Kx97gFyZrxxwXz");
}
pub mod ristretto_mul_syscall_enabled {
solana_sdk::declare_id!("HRe7A6aoxgjKzdjbBv6HTy7tJ4YWqE6tVmYCGho6S9Aq");
}
2020-10-09 10:33:12 -07:00
pub mod max_invoke_depth_4 {
solana_sdk::declare_id!("EdM9xggY5y7AhNMskRG8NgGMnaP4JFNsWi8ZZtyT1af5");
}
pub mod max_program_call_depth_64 {
solana_sdk::declare_id!("YCKSgA6XmjtkQrHBQjpyNrX6EMhJPcYcLWMVgWn36iv");
}
pub mod timestamp_correction {
solana_sdk::declare_id!("3zydSLUwuqqsV3wL5wBsaVgyvMox3XTHx7zLEuQf1U2Z");
}
pub mod cumulative_rent_related_fixes {
solana_sdk::declare_id!("FtjnuAtJTWwX3Kx9m24LduNEhzaGuuPfDW6e14SX2Fy5");
}
2020-10-28 12:39:48 -07:00
pub mod sol_log_compute_units_syscall {
solana_sdk::declare_id!("BHuZqHAj7JdZc68wVgZZcy51jZykvgrx4zptR44RyChe");
}
2020-10-15 09:11:54 -07:00
pub mod pubkey_log_syscall_enabled {
solana_sdk::declare_id!("MoqiU1vryuCGQSxFKA1SZ316JdLEFFhoAu6cKUNk7dN");
}
pub mod pull_request_ping_pong_check {
solana_sdk::declare_id!("5RzEHTnf6D7JPZCvwEzjM19kzBsyjSU3HoMfXaQmVgnZ");
}
2020-10-26 11:45:09 -07:00
pub mod timestamp_bounding {
solana_sdk::declare_id!("2cGj3HJYPhBrtQizd7YbBxEsifFs5qhzabyFjUAp6dBa");
2020-10-26 11:45:09 -07:00
}
pub mod stake_program_v2 {
solana_sdk::declare_id!("Gvd9gGJZDHGMNf1b3jkxrfBQSR5etrfTQSBNKCvLSFJN");
}
pub mod rewrite_stake {
solana_sdk::declare_id!("6ap2eGy7wx5JmsWUmQ5sHwEWrFSDUxSti2k5Hbfv5BZG");
}
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"),
(consistent_recent_blockhashes_sysvar::id(), "consistent recentblockhashes sysvar"),
(deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
2020-09-25 16:19:03 -07:00
(pico_inflation::id(), "pico-inflation"),
(full_inflation::id(), "full-inflation"),
(spl_token_v2_multisig_fix::id(), "spl-token multisig fix"),
(bpf_loader2_program::id(), "bpf_loader2 program"),
2020-10-28 13:16:13 -07:00
(bpf_compute_budget_balancing::id(), "compute budget balancing"),
(sha256_syscall_enabled::id(), "sha256 syscall"),
(no_overflow_rent_distribution::id(), "no overflow rent distribution"),
(ristretto_mul_syscall_enabled::id(), "ristretto multiply syscall"),
2020-10-09 10:33:12 -07:00
(max_invoke_depth_4::id(), "max invoke call depth 4"),
(max_program_call_depth_64::id(), "max program call depth 64"),
(timestamp_correction::id(), "correct bank timestamps"),
(cumulative_rent_related_fixes::id(), "rent fixes (#10206, #10468, #11342)"),
2020-10-28 12:39:48 -07:00
(sol_log_compute_units_syscall::id(), "sol_log_compute_units syscall (#13243)"),
2020-10-15 09:11:54 -07:00
(pubkey_log_syscall_enabled::id(), "pubkey log syscall"),
(pull_request_ping_pong_check::id(), "ping-pong packet check #12794"),
2020-10-26 11:45:09 -07:00
(timestamp_bounding::id(), "add timestamp-correction bounding #13120"),
(stake_program_v2::id(), "solana_stake_program v2"),
(rewrite_stake::id(), "rewrite stake"),
/*************** 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-10-20 09:05:45 -07:00
#[derive(AbiExample, Debug, Clone)]
2020-09-21 14:03:35 -07:00
pub struct FeatureSet {
pub active: HashMap<Pubkey, Slot>,
2020-09-21 14:03:35 -07:00
pub inactive: HashSet<Pubkey>,
}
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: HashMap::new(),
inactive: FEATURE_NAMES.keys().cloned().collect(),
2020-09-21 14:03:35 -07:00
}
}
}
impl FeatureSet {
pub fn is_active(&self, feature_id: &Pubkey) -> bool {
self.active.contains_key(feature_id)
}
pub fn activated_slot(&self, feature_id: &Pubkey) -> Option<Slot> {
self.active.get(feature_id).copied()
}
pub fn cumulative_rent_related_fixes_enabled(&self) -> bool {
self.is_active(&cumulative_rent_related_fixes::id())
}
/// All features enabled, useful for testing
pub fn all_enabled() -> Self {
Self {
active: FEATURE_NAMES.keys().cloned().map(|key| (key, 0)).collect(),
inactive: HashSet::new(),
}
}
}