v1.1: Enable rolling update of "Permit paying oneself" / "No longer allow create-account to add funds to an existing account" (#10394)
automerge
This commit is contained in:
@ -10,6 +10,7 @@ use crate::{
|
|||||||
accounts_db::{AccountsDBSerialize, ErrorCounters, SnapshotStorage, SnapshotStorages},
|
accounts_db::{AccountsDBSerialize, ErrorCounters, SnapshotStorage, SnapshotStorages},
|
||||||
accounts_index::Ancestors,
|
accounts_index::Ancestors,
|
||||||
blockhash_queue::BlockhashQueue,
|
blockhash_queue::BlockhashQueue,
|
||||||
|
builtin_programs::{get_builtin_programs, get_epoch_activated_builtin_programs},
|
||||||
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
||||||
message_processor::{MessageProcessor, ProcessInstruction},
|
message_processor::{MessageProcessor, ProcessInstruction},
|
||||||
nonce_utils,
|
nonce_utils,
|
||||||
@ -21,7 +22,7 @@ use crate::{
|
|||||||
status_cache::{SlotDelta, StatusCache},
|
status_cache::{SlotDelta, StatusCache},
|
||||||
storage_utils,
|
storage_utils,
|
||||||
storage_utils::StorageAccounts,
|
storage_utils::StorageAccounts,
|
||||||
system_instruction_processor::{self, get_system_account_kind, SystemAccountKind},
|
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
|
||||||
transaction_batch::TransactionBatch,
|
transaction_batch::TransactionBatch,
|
||||||
transaction_utils::OrderedIterator,
|
transaction_utils::OrderedIterator,
|
||||||
};
|
};
|
||||||
@ -513,6 +514,13 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(builtin_programs) =
|
||||||
|
get_epoch_activated_builtin_programs(new.operating_mode(), new.epoch)
|
||||||
|
{
|
||||||
|
for program in builtin_programs.iter() {
|
||||||
|
new.add_static_program(&program.name, program.id, program.process_instruction);
|
||||||
|
}
|
||||||
|
}
|
||||||
new.update_epoch_stakes(leader_schedule_epoch);
|
new.update_epoch_stakes(leader_schedule_epoch);
|
||||||
new.ancestors.insert(new.slot(), 0);
|
new.ancestors.insert(new.slot(), 0);
|
||||||
new.parents().iter().enumerate().for_each(|(i, p)| {
|
new.parents().iter().enumerate().for_each(|(i, p)| {
|
||||||
@ -2123,26 +2131,10 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish_init(&mut self) {
|
pub fn finish_init(&mut self) {
|
||||||
self.add_static_program(
|
let builtin_programs = get_builtin_programs(self.operating_mode(), self.epoch);
|
||||||
"system_program",
|
for program in builtin_programs.iter() {
|
||||||
solana_sdk::system_program::id(),
|
self.add_static_program(&program.name, program.id, program.process_instruction);
|
||||||
system_instruction_processor::process_instruction,
|
}
|
||||||
);
|
|
||||||
self.add_static_program(
|
|
||||||
"config_program",
|
|
||||||
solana_config_program::id(),
|
|
||||||
solana_config_program::config_processor::process_instruction,
|
|
||||||
);
|
|
||||||
self.add_static_program(
|
|
||||||
"stake_program",
|
|
||||||
solana_stake_program::id(),
|
|
||||||
solana_stake_program::stake_instruction::process_instruction,
|
|
||||||
);
|
|
||||||
self.add_static_program(
|
|
||||||
"vote_program",
|
|
||||||
solana_vote_program::id(),
|
|
||||||
solana_vote_program::vote_instruction::process_instruction,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_parent(&mut self, parent: &Arc<Bank>) {
|
pub fn set_parent(&mut self, parent: &Arc<Bank>) {
|
||||||
@ -2659,6 +2651,7 @@ mod tests {
|
|||||||
use crate::{
|
use crate::{
|
||||||
accounts_db::{get_temp_accounts_paths, tests::copy_append_vecs},
|
accounts_db::{get_temp_accounts_paths, tests::copy_append_vecs},
|
||||||
accounts_index::Ancestors,
|
accounts_index::Ancestors,
|
||||||
|
builtin_programs::new_system_program_activation_epoch,
|
||||||
genesis_utils::{
|
genesis_utils::{
|
||||||
create_genesis_config_with_leader, GenesisConfigInfo, BOOTSTRAP_VALIDATOR_LAMPORTS,
|
create_genesis_config_with_leader, GenesisConfigInfo, BOOTSTRAP_VALIDATOR_LAMPORTS,
|
||||||
},
|
},
|
||||||
@ -6823,6 +6816,77 @@ mod tests {
|
|||||||
assert_eq!(bank.capitalization(), pre_capitalization - burn_amount);
|
assert_eq!(bank.capitalization(), pre_capitalization - burn_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_legacy_system_instruction_processor0_stable() {
|
||||||
|
let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000);
|
||||||
|
genesis_config.operating_mode = OperatingMode::Stable;
|
||||||
|
let bank0 = Arc::new(Bank::new(&genesis_config));
|
||||||
|
|
||||||
|
let activation_epoch = new_system_program_activation_epoch(bank0.operating_mode());
|
||||||
|
assert!(activation_epoch > bank0.epoch());
|
||||||
|
|
||||||
|
// Transfer to self is not supported by legacy_system_instruction_processor0
|
||||||
|
bank0
|
||||||
|
.transfer(1, &mint_keypair, &mint_keypair.pubkey())
|
||||||
|
.unwrap_err();
|
||||||
|
|
||||||
|
// Activate system_instruction_processor
|
||||||
|
let bank = Bank::new_from_parent(
|
||||||
|
&bank0,
|
||||||
|
&Pubkey::default(),
|
||||||
|
genesis_config
|
||||||
|
.epoch_schedule
|
||||||
|
.get_first_slot_in_epoch(activation_epoch),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Transfer to self is supported by system_instruction_processor
|
||||||
|
bank.transfer(2, &mint_keypair, &mint_keypair.pubkey())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_legacy_system_instruction_processor0_preview() {
|
||||||
|
let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000);
|
||||||
|
genesis_config.operating_mode = OperatingMode::Preview;
|
||||||
|
let bank0 = Arc::new(Bank::new(&genesis_config));
|
||||||
|
|
||||||
|
let activation_epoch = new_system_program_activation_epoch(bank0.operating_mode());
|
||||||
|
assert!(activation_epoch > bank0.epoch());
|
||||||
|
|
||||||
|
// Transfer to self is not supported by legacy_system_instruction_processor0
|
||||||
|
bank0
|
||||||
|
.transfer(1, &mint_keypair, &mint_keypair.pubkey())
|
||||||
|
.unwrap_err();
|
||||||
|
|
||||||
|
// Activate system_instruction_processor
|
||||||
|
let bank = Bank::new_from_parent(
|
||||||
|
&bank0,
|
||||||
|
&Pubkey::default(),
|
||||||
|
genesis_config
|
||||||
|
.epoch_schedule
|
||||||
|
.get_first_slot_in_epoch(activation_epoch),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Transfer to self is supported by system_instruction_processor
|
||||||
|
bank.transfer(2, &mint_keypair, &mint_keypair.pubkey())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_legacy_system_instruction_processor0_development() {
|
||||||
|
let (mut genesis_config, mint_keypair) = create_genesis_config(1_000_000);
|
||||||
|
genesis_config.operating_mode = OperatingMode::Development;
|
||||||
|
let bank0 = Arc::new(Bank::new(&genesis_config));
|
||||||
|
|
||||||
|
let activation_epoch = new_system_program_activation_epoch(bank0.operating_mode());
|
||||||
|
assert!(activation_epoch == bank0.epoch());
|
||||||
|
|
||||||
|
// Transfer to self is supported by system_instruction_processor
|
||||||
|
bank0
|
||||||
|
.transfer(2, &mint_keypair, &mint_keypair.pubkey())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_duplicate_account_key() {
|
fn test_duplicate_account_key() {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
|
78
runtime/src/builtin_programs.rs
Normal file
78
runtime/src/builtin_programs.rs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
use crate::{
|
||||||
|
legacy_system_instruction_processor0, message_processor::ProcessInstruction,
|
||||||
|
system_instruction_processor,
|
||||||
|
};
|
||||||
|
use solana_sdk::{clock::Epoch, genesis_config::OperatingMode, pubkey::Pubkey, system_program};
|
||||||
|
|
||||||
|
pub struct BuiltinProgram {
|
||||||
|
pub name: String,
|
||||||
|
pub id: Pubkey,
|
||||||
|
pub process_instruction: ProcessInstruction,
|
||||||
|
}
|
||||||
|
impl BuiltinProgram {
|
||||||
|
pub fn new(name: &str, id: Pubkey, process_instruction: ProcessInstruction) -> Self {
|
||||||
|
Self {
|
||||||
|
name: name.to_string(),
|
||||||
|
id,
|
||||||
|
process_instruction,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn new_system_program_activation_epoch(operating_mode: OperatingMode) -> Epoch {
|
||||||
|
match operating_mode {
|
||||||
|
OperatingMode::Development => 0,
|
||||||
|
OperatingMode::Preview => 1_000_000,
|
||||||
|
OperatingMode::Stable => 1_000_000,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// All builtin programs that should be active at the given (operating_mode, epoch)
|
||||||
|
pub fn get_builtin_programs(operating_mode: OperatingMode, epoch: Epoch) -> Vec<BuiltinProgram> {
|
||||||
|
vec![
|
||||||
|
if epoch < new_system_program_activation_epoch(operating_mode) {
|
||||||
|
BuiltinProgram::new(
|
||||||
|
"system_program",
|
||||||
|
system_program::id(),
|
||||||
|
legacy_system_instruction_processor0::process_instruction,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
BuiltinProgram::new(
|
||||||
|
"system_program",
|
||||||
|
system_program::id(),
|
||||||
|
system_instruction_processor::process_instruction,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
BuiltinProgram::new(
|
||||||
|
"config_program",
|
||||||
|
solana_config_program::id(),
|
||||||
|
solana_config_program::config_processor::process_instruction,
|
||||||
|
),
|
||||||
|
BuiltinProgram::new(
|
||||||
|
"stake_program",
|
||||||
|
solana_stake_program::id(),
|
||||||
|
solana_stake_program::stake_instruction::process_instruction,
|
||||||
|
),
|
||||||
|
BuiltinProgram::new(
|
||||||
|
"vote_program",
|
||||||
|
solana_vote_program::id(),
|
||||||
|
solana_vote_program::vote_instruction::process_instruction,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builtin programs that activate at the given (operating_mode, epoch)
|
||||||
|
pub fn get_epoch_activated_builtin_programs(
|
||||||
|
operating_mode: OperatingMode,
|
||||||
|
epoch: Epoch,
|
||||||
|
) -> Option<Vec<BuiltinProgram>> {
|
||||||
|
if epoch == new_system_program_activation_epoch(operating_mode) {
|
||||||
|
Some(vec![BuiltinProgram::new(
|
||||||
|
"system_program",
|
||||||
|
system_program::id(),
|
||||||
|
system_instruction_processor::process_instruction,
|
||||||
|
)])
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
1498
runtime/src/legacy_system_instruction_processor0.rs
Normal file
1498
runtime/src/legacy_system_instruction_processor0.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,10 @@ pub mod bank;
|
|||||||
pub mod bank_client;
|
pub mod bank_client;
|
||||||
mod blockhash_queue;
|
mod blockhash_queue;
|
||||||
pub mod bloom;
|
pub mod bloom;
|
||||||
|
mod builtin_programs;
|
||||||
pub mod epoch_stakes;
|
pub mod epoch_stakes;
|
||||||
pub mod genesis_utils;
|
pub mod genesis_utils;
|
||||||
|
mod legacy_system_instruction_processor0;
|
||||||
pub mod loader_utils;
|
pub mod loader_utils;
|
||||||
pub mod message_processor;
|
pub mod message_processor;
|
||||||
mod native_loader;
|
mod native_loader;
|
||||||
|
Reference in New Issue
Block a user