Runtime feature activation framework (bp #12376) (#12497)

* Runtime feature activation framework

(cherry picked from commit 93259f0bae)

# Conflicts:
#	runtime/src/bank.rs

* Add feature set identifier to gossiped version information

(cherry picked from commit 35f5f9fc7b)

# Conflicts:
#	Cargo.lock
#	version/Cargo.toml

* Port instructions sysvar and secp256k1 program activation to FeatureSet

(cherry picked from commit c10da16d7b)

# Conflicts:
#	runtime/src/bank.rs
#	runtime/src/message_processor.rs

* Add feature management commands

(cherry picked from commit 93ed0ab2bb)

# Conflicts:
#	Cargo.lock
#	cli/Cargo.toml

* Make test_process_rest_api less fragile

(cherry picked from commit 7526bb96f3)

* Remove id field

(cherry picked from commit cc6ba1e131)

* FeatureSet test

(cherry picked from commit 92406cf9a0)

* cargo fmt

(cherry picked from commit 199940d683)

* cli review feedback

(cherry picked from commit 3a2b8c5e5b)

* Rename active() to is_active()

(cherry picked from commit e39fac9f01)

* Resolve merge conflicts

* Remove continues from compute_active_feature_set()

Co-authored-by: Michael Vines <mvines@gmail.com>
This commit is contained in:
mergify[bot]
2020-09-26 17:49:53 +00:00
committed by GitHub
parent 6a698af235
commit bc3aa53e02
32 changed files with 808 additions and 233 deletions

View File

@@ -1,18 +1,21 @@
use crate::{
bank::{Builtin, Entrypoint},
system_instruction_processor,
feature_set, system_instruction_processor,
};
use solana_sdk::{
clock::{Epoch, GENESIS_EPOCH},
genesis_config::ClusterType,
pubkey::Pubkey,
system_program,
};
use log::*;
/// The entire set of available builtin programs that should be active at the given cluster_type
pub fn get_builtins(cluster_type: ClusterType) -> Vec<(Builtin, Epoch)> {
trace!("get_builtins: {:?}", cluster_type);
/// Builtin programs that should be active for the given cluster_type
///
/// Old style. Use `get_feature_builtins()` instead
pub fn get_cluster_builtins(cluster_type: ClusterType) -> Vec<(Builtin, Epoch)> {
trace!("get_cluster_builtins: {:?}", cluster_type);
let mut builtins = vec![];
builtins.extend(
@@ -46,8 +49,8 @@ pub fn get_builtins(cluster_type: ClusterType) -> Vec<(Builtin, Epoch)> {
// repurpose Testnet for test_get_builtins because the Development is overloaded...
#[cfg(test)]
if cluster_type == ClusterType::Testnet {
use solana_sdk::account::KeyedAccount;
use solana_sdk::instruction::InstructionError;
use solana_sdk::{account::KeyedAccount, pubkey::Pubkey};
use std::str::FromStr;
fn mock_ix_processor(
_pubkey: &Pubkey,
@@ -57,35 +60,33 @@ pub fn get_builtins(cluster_type: ClusterType) -> Vec<(Builtin, Epoch)> {
Err(InstructionError::Custom(42))
}
let program_id = Pubkey::from_str("7saCc6X5a2syoYANA5oUUnPZLcLMfKoSjiDhFU5fbpoK").unwrap();
builtins.extend(vec![(
builtins.push((
Builtin::new("mock", program_id, Entrypoint::Program(mock_ix_processor)),
2,
)]);
));
}
let secp256k1_builtin = Builtin::new(
"secp256k1_program",
solana_sdk::secp256k1_program::id(),
Entrypoint::Program(solana_secp256k1_program::process_instruction),
);
let secp_epoch = solana_sdk::secp256k1::is_enabled_epoch(cluster_type);
builtins.push((secp256k1_builtin, secp_epoch));
builtins
}
/// Builtin programs that are activated dynamically by feature
pub fn get_feature_builtins() -> Vec<(Builtin, Pubkey)> {
vec![(
Builtin::new(
"secp256k1_program",
solana_sdk::secp256k1_program::id(),
Entrypoint::Program(solana_secp256k1_program::process_instruction),
),
feature_set::secp256k1_program_enabled::id(),
)]
}
#[cfg(test)]
mod tests {
use super::*;
use crate::bank::Bank;
use solana_sdk::{
genesis_config::{create_genesis_config, ClusterType},
pubkey::Pubkey,
};
use std::collections::HashSet;
use std::str::FromStr;
use std::sync::Arc;
use solana_sdk::genesis_config::create_genesis_config;
use std::{collections::HashSet, str::FromStr, sync::Arc};
fn do_test_uniqueness(builtins: Vec<(Builtin, Epoch)>) {
let mut unique_ids = HashSet::new();
@@ -101,10 +102,10 @@ mod tests {
#[test]
fn test_uniqueness() {
do_test_uniqueness(get_builtins(ClusterType::Development));
do_test_uniqueness(get_builtins(ClusterType::Devnet));
do_test_uniqueness(get_builtins(ClusterType::Testnet));
do_test_uniqueness(get_builtins(ClusterType::MainnetBeta));
do_test_uniqueness(get_cluster_builtins(ClusterType::Development));
do_test_uniqueness(get_cluster_builtins(ClusterType::Devnet));
do_test_uniqueness(get_cluster_builtins(ClusterType::Testnet));
do_test_uniqueness(get_cluster_builtins(ClusterType::MainnetBeta));
}
#[test]