Enable rolling upgrade of system_instruction_processor
This commit is contained in:
parent
1331c9a680
commit
9c631a01c1
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
accounts_db::{ErrorCounters, SnapshotStorages},
|
accounts_db::{ErrorCounters, SnapshotStorages},
|
||||||
accounts_index::Ancestors,
|
accounts_index::Ancestors,
|
||||||
blockhash_queue::BlockhashQueue,
|
blockhash_queue::BlockhashQueue,
|
||||||
builtin_programs::get_builtin_programs,
|
builtin_programs::{get_builtin_programs, get_epoch_activated_builtin_programs},
|
||||||
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
||||||
message_processor::MessageProcessor,
|
message_processor::MessageProcessor,
|
||||||
nonce_utils,
|
nonce_utils,
|
||||||
|
@ -457,6 +457,14 @@ impl Bank {
|
||||||
{
|
{
|
||||||
entered_epoch_callback(&mut new)
|
entered_epoch_callback(&mut new)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(builtin_programs) =
|
||||||
|
get_epoch_activated_builtin_programs(new.operating_mode(), new.epoch)
|
||||||
|
{
|
||||||
|
for program in builtin_programs.iter() {
|
||||||
|
new.add_builtin_program(&program.name, program.id, program.process_instruction);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new.update_epoch_stakes(leader_schedule_epoch);
|
new.update_epoch_stakes(leader_schedule_epoch);
|
||||||
|
@ -2049,7 +2057,7 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finish_init(&mut self) {
|
pub fn finish_init(&mut self) {
|
||||||
let builtin_programs = get_builtin_programs();
|
let builtin_programs = get_builtin_programs(self.operating_mode(), self.epoch);
|
||||||
for program in builtin_programs.iter() {
|
for program in builtin_programs.iter() {
|
||||||
self.add_builtin_program(&program.name, program.id, program.process_instruction);
|
self.add_builtin_program(&program.name, program.id, program.process_instruction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use crate::system_instruction_processor;
|
use crate::{legacy_system_instruction_processor0, system_instruction_processor};
|
||||||
use solana_sdk::{entrypoint_native::ProcessInstruction, pubkey::Pubkey, system_program};
|
use solana_sdk::{
|
||||||
|
clock::Epoch, entrypoint_native::ProcessInstruction, genesis_config::OperatingMode,
|
||||||
|
pubkey::Pubkey, system_program,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct BuiltinProgram {
|
pub struct BuiltinProgram {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -16,13 +19,30 @@ impl BuiltinProgram {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_builtin_programs() -> Vec<BuiltinProgram> {
|
fn new_system_program_activation_epoch(operating_mode: OperatingMode) -> Epoch {
|
||||||
|
match operating_mode {
|
||||||
|
OperatingMode::Development => 0,
|
||||||
|
OperatingMode::Preview => std::u64::MAX / 2,
|
||||||
|
OperatingMode::Stable => std::u64::MAX / 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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![
|
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(
|
BuiltinProgram::new(
|
||||||
"system_program",
|
"system_program",
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
system_instruction_processor::process_instruction,
|
system_instruction_processor::process_instruction,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
BuiltinProgram::new(
|
BuiltinProgram::new(
|
||||||
"config_program",
|
"config_program",
|
||||||
solana_config_program::id(),
|
solana_config_program::id(),
|
||||||
|
@ -40,3 +60,19 @@ pub fn get_builtin_programs() -> Vec<BuiltinProgram> {
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use log::*;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{get_signers, Account, KeyedAccount},
|
account::{get_signers, Account, KeyedAccount},
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
nonce::{Account as NonceAccount},
|
nonce::Account as NonceAccount,
|
||||||
program_utils::{limited_deserialize, next_keyed_account},
|
program_utils::{limited_deserialize, next_keyed_account},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
||||||
|
|
Loading…
Reference in New Issue