From 170927b7c41e0db94ac01ba0b1d8df0c7ee385e9 Mon Sep 17 00:00:00 2001 From: Jack May Date: Thu, 2 Sep 2021 21:29:11 -0700 Subject: [PATCH] nit: Move builtins types to builtins file (#19597) --- ledger/src/builtins.rs | 5 +-- program-test/src/lib.rs | 3 +- runtime/src/bank.rs | 49 +------------------------ runtime/src/builtins.rs | 68 +++++++++++++++++++++++++++++------ runtime/src/serde_snapshot.rs | 3 +- runtime/src/snapshot_utils.rs | 3 +- 6 files changed, 66 insertions(+), 65 deletions(-) diff --git a/ledger/src/builtins.rs b/ledger/src/builtins.rs index 63311e263..ca5ddc649 100644 --- a/ledger/src/builtins.rs +++ b/ledger/src/builtins.rs @@ -1,7 +1,4 @@ -use solana_runtime::{ - bank::{Builtin, Builtins}, - builtins::ActivationType, -}; +use solana_runtime::builtins::{ActivationType, Builtin, Builtins}; use solana_sdk::pubkey::Pubkey; macro_rules! to_builtin { diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index 41f3e14d3..0db2d01c1 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -11,8 +11,9 @@ use { solana_banks_server::banks_server::start_local_server, solana_program_runtime::InstructionProcessor, solana_runtime::{ - bank::{Bank, Builtin, ExecuteTimings}, + bank::{Bank, ExecuteTimings}, bank_forks::BankForks, + builtins::Builtin, commitment::BlockCommitmentCache, genesis_utils::{create_genesis_config_with_leader_ex, GenesisConfigInfo}, }, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 0697df6ad..3360db669 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -45,7 +45,7 @@ use crate::{ }, ancestors::{Ancestors, AncestorsForSerialization}, blockhash_queue::BlockhashQueue, - builtins::{self, ActivationType}, + builtins::{self, ActivationType, Builtin, Builtins}, epoch_stakes::{EpochStakes, NodeVoteAccounts}, inline_spl_token_v2_0, instruction_recorder::InstructionRecorder, @@ -211,33 +211,6 @@ type RentCollectionCycleParams = ( type EpochCount = u64; -#[derive(Clone)] -pub struct Builtin { - pub name: String, - pub id: Pubkey, - pub process_instruction_with_context: ProcessInstructionWithContext, -} - -impl Builtin { - pub fn new( - name: &str, - id: Pubkey, - process_instruction_with_context: ProcessInstructionWithContext, - ) -> Self { - Self { - name: name.to_string(), - id, - process_instruction_with_context, - } - } -} - -impl fmt::Debug for Builtin { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Builtin [name={}, id={}]", self.name, self.id) - } -} - /// Copy-on-write holder of CachedExecutors #[derive(AbiExample, Debug, Default)] struct CowCachedExecutors { @@ -283,26 +256,6 @@ impl CowCachedExecutors { } } -#[cfg(RUSTC_WITH_SPECIALIZATION)] -impl AbiExample for Builtin { - fn example() -> Self { - Self { - name: String::default(), - id: Pubkey::default(), - process_instruction_with_context: |_, _, _| Ok(()), - } - } -} - -#[derive(Clone, Debug)] -pub struct Builtins { - /// Builtin programs that are always available - pub genesis_builtins: Vec, - - /// Builtin programs activated dynamically by feature - pub feature_builtins: Vec<(Builtin, Pubkey, ActivationType)>, -} - const MAX_CACHED_EXECUTORS: usize = 100; // 10 MB assuming programs are around 100k #[derive(Debug)] struct CachedExecutorsEntry { diff --git a/runtime/src/builtins.rs b/runtime/src/builtins.rs index f71a2eb0d..b7c7aaf24 100644 --- a/runtime/src/builtins.rs +++ b/runtime/src/builtins.rs @@ -1,7 +1,4 @@ -use crate::{ - bank::{Builtin, Builtins}, - system_instruction_processor, -}; +use crate::system_instruction_processor; use solana_sdk::{ feature_set, instruction::InstructionError, @@ -9,6 +6,10 @@ use solana_sdk::{ pubkey::Pubkey, stake, system_program, }; +use std::fmt; + +#[cfg(RUSTC_WITH_SPECIALIZATION)] +use solana_frozen_abi::abi_example::AbiExample; fn process_instruction_with_program_logging( process_instruction: ProcessInstructionWithContext, @@ -41,6 +42,59 @@ macro_rules! with_program_logging { }; } +#[derive(AbiExample, Debug, Clone)] +pub enum ActivationType { + NewProgram, + NewVersion, +} + +#[derive(Clone)] +pub struct Builtin { + pub name: String, + pub id: Pubkey, + pub process_instruction_with_context: ProcessInstructionWithContext, +} + +impl Builtin { + pub fn new( + name: &str, + id: Pubkey, + process_instruction_with_context: ProcessInstructionWithContext, + ) -> Self { + Self { + name: name.to_string(), + id, + process_instruction_with_context, + } + } +} + +impl fmt::Debug for Builtin { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Builtin [name={}, id={}]", self.name, self.id) + } +} + +#[cfg(RUSTC_WITH_SPECIALIZATION)] +impl AbiExample for Builtin { + fn example() -> Self { + Self { + name: String::default(), + id: Pubkey::default(), + process_instruction_with_context: |_, _, _| Ok(()), + } + } +} + +#[derive(Clone, Debug)] +pub struct Builtins { + /// Builtin programs that are always available + pub genesis_builtins: Vec, + + /// Builtin programs activated dynamically by feature + pub feature_builtins: Vec<(Builtin, Pubkey, ActivationType)>, +} + /// Builtin programs that are always available fn genesis_builtins() -> Vec { vec![ @@ -72,12 +126,6 @@ fn genesis_builtins() -> Vec { ] } -#[derive(AbiExample, Debug, Clone)] -pub enum ActivationType { - NewProgram, - NewVersion, -} - /// Builtin programs activated dynamically by feature /// /// Note: If the feature_builtin is intended to replace another builtin program, it must have a new diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index 5069eb194..edd9dda24 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -7,8 +7,9 @@ use { accounts_index::{AccountSecondaryIndexes, AccountsIndexConfig}, ancestors::Ancestors, append_vec::{AppendVec, StoredMetaWriteVersion}, - bank::{Bank, BankFieldsToDeserialize, BankRc, Builtins}, + bank::{Bank, BankFieldsToDeserialize, BankRc}, blockhash_queue::BlockhashQueue, + builtins::Builtins, epoch_stakes::EpochStakes, hardened_unpack::UnpackedAppendVecMap, rent_collector::RentCollector, diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index b6960b2ba..b04c1e6ae 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -2,7 +2,8 @@ use { crate::{ accounts_db::AccountShrinkThreshold, accounts_index::{AccountSecondaryIndexes, AccountsIndexConfig}, - bank::{Bank, BankSlotDelta, Builtins}, + bank::{Bank, BankSlotDelta}, + builtins::Builtins, hardened_unpack::{unpack_snapshot, ParallelSelector, UnpackError, UnpackedAppendVecMap}, serde_snapshot::{ bank_from_streams, bank_to_stream, SerdeStyle, SnapshotStorage, SnapshotStorages,