From 225bed11c7046c56aa6ac1a1485eccccb39bde85 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 29 Oct 2020 16:17:36 -0700 Subject: [PATCH] Remove Entrypoint type --- bench-exchange/tests/bench_exchange.rs | 2 +- ledger/src/builtins.rs | 6 +- programs/bpf/benches/bpf_loader.rs | 2 +- programs/bpf/tests/programs.rs | 14 +- programs/budget/src/budget_processor.rs | 2 +- programs/exchange/src/exchange_processor.rs | 2 +- programs/ownable/src/ownable_processor.rs | 2 +- programs/vest/src/vest_processor.rs | 2 +- runtime/benches/bank.rs | 2 +- runtime/src/bank.rs | 195 +++++++------------- runtime/src/builtins.rs | 12 +- runtime/src/message_processor.rs | 12 +- sdk/src/process_instruction.rs | 8 - 13 files changed, 98 insertions(+), 163 deletions(-) diff --git a/bench-exchange/tests/bench_exchange.rs b/bench-exchange/tests/bench_exchange.rs index ea24fffd14..99446d9516 100644 --- a/bench-exchange/tests/bench_exchange.rs +++ b/bench-exchange/tests/bench_exchange.rs @@ -86,7 +86,7 @@ fn test_exchange_bank_client() { solana_logger::setup(); let (genesis_config, identity) = create_genesis_config(100_000_000_000_000); let mut bank = Bank::new(&genesis_config); - bank.add_builtin_program("exchange_program", id(), process_instruction); + bank.add_builtin("exchange_program", id(), process_instruction); let clients = vec![BankClient::new(bank)]; let mut config = Config::default(); diff --git a/ledger/src/builtins.rs b/ledger/src/builtins.rs index 14d657589d..2a99f865cb 100644 --- a/ledger/src/builtins.rs +++ b/ledger/src/builtins.rs @@ -1,4 +1,4 @@ -use solana_runtime::bank::{Builtin, Builtins, Entrypoint}; +use solana_runtime::bank::{Builtin, Builtins}; use solana_sdk::{feature_set, genesis_config::ClusterType, pubkey::Pubkey}; /// Builtin programs that are always available @@ -16,7 +16,7 @@ fn genesis_builtins(cluster_type: ClusterType) -> Vec { builtins .into_iter() - .map(|b| Builtin::new(&b.0, b.1, Entrypoint::Loader(b.2))) + .map(|b| Builtin::new(&b.0, b.1, b.2)) .collect() } @@ -29,7 +29,7 @@ fn feature_builtins() -> Vec<(Builtin, Pubkey)> { builtins .into_iter() - .map(|(b, p)| (Builtin::new(&b.0, b.1, Entrypoint::Loader(b.2)), p)) + .map(|(b, p)| (Builtin::new(&b.0, b.1, b.2), p)) .collect() } diff --git a/programs/bpf/benches/bpf_loader.rs b/programs/bpf/benches/bpf_loader.rs index b45f27da27..e8ec3e79c6 100644 --- a/programs/bpf/benches/bpf_loader.rs +++ b/programs/bpf/benches/bpf_loader.rs @@ -162,7 +162,7 @@ fn bench_program_execute_noop(bencher: &mut Bencher) { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank = Arc::new(bank); let bank_client = BankClient::new_shared(&bank); diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index a28050e7e5..9a194dece0 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -183,7 +183,7 @@ fn test_program_bpf_sanity() { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank = Arc::new(bank); // Create bank with a specific slot, used by solana_bpf_rust_sysvar test @@ -237,7 +237,7 @@ fn test_program_bpf_loader_deprecated() { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_deprecated_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank_client = BankClient::new(bank); let program_id = load_bpf_program( @@ -277,7 +277,7 @@ fn test_program_bpf_duplicate_accounts() { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank = Arc::new(bank); let bank_client = BankClient::new_shared(&bank); let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program); @@ -362,7 +362,7 @@ fn test_program_bpf_error_handling() { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank_client = BankClient::new(bank); let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program); let account_metas = vec![AccountMeta::new(mint_keypair.pubkey(), true)]; @@ -479,7 +479,7 @@ fn test_program_bpf_invoke() { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank = Arc::new(bank); let bank_client = BankClient::new_shared(&bank); @@ -710,7 +710,7 @@ fn test_program_bpf_call_depth() { } = create_genesis_config(50); let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank_client = BankClient::new(bank); let program_id = load_bpf_program( &bank_client, @@ -792,7 +792,7 @@ fn test_program_bpf_instruction_introspection() { let mut bank = Bank::new(&genesis_config); let (name, id, entrypoint) = solana_bpf_loader_program!(); - bank.add_builtin_loader(&name, id, entrypoint); + bank.add_builtin(&name, id, entrypoint); let bank = Arc::new(bank); let bank_client = BankClient::new_shared(&bank); diff --git a/programs/budget/src/budget_processor.rs b/programs/budget/src/budget_processor.rs index f1cef89025..f79ff118ce 100644 --- a/programs/budget/src/budget_processor.rs +++ b/programs/budget/src/budget_processor.rs @@ -240,7 +240,7 @@ mod tests { fn create_bank(lamports: u64) -> (Bank, Keypair) { let (genesis_config, mint_keypair) = create_genesis_config(lamports); let mut bank = Bank::new(&genesis_config); - bank.add_builtin_program("budget_program", id(), process_instruction); + bank.add_builtin("budget_program", id(), process_instruction); (bank, mint_keypair) } diff --git a/programs/exchange/src/exchange_processor.rs b/programs/exchange/src/exchange_processor.rs index 99d2640ed4..2cf146ee72 100644 --- a/programs/exchange/src/exchange_processor.rs +++ b/programs/exchange/src/exchange_processor.rs @@ -579,7 +579,7 @@ mod test { fn create_bank(lamports: u64) -> (Bank, Keypair) { let (genesis_config, mint_keypair) = create_genesis_config(lamports); let mut bank = Bank::new(&genesis_config); - bank.add_builtin_program("exchange_program", id(), process_instruction); + bank.add_builtin("exchange_program", id(), process_instruction); (bank, mint_keypair) } diff --git a/programs/ownable/src/ownable_processor.rs b/programs/ownable/src/ownable_processor.rs index 8169752774..ecfda56da1 100644 --- a/programs/ownable/src/ownable_processor.rs +++ b/programs/ownable/src/ownable_processor.rs @@ -73,7 +73,7 @@ mod tests { fn create_bank(lamports: u64) -> (Bank, Keypair) { let (genesis_config, mint_keypair) = create_genesis_config(lamports); let mut bank = Bank::new(&genesis_config); - bank.add_builtin_program("ownable_program", crate::id(), process_instruction); + bank.add_builtin("ownable_program", crate::id(), process_instruction); (bank, mint_keypair) } diff --git a/programs/vest/src/vest_processor.rs b/programs/vest/src/vest_processor.rs index 8c9efa52a5..bd40f31ae5 100644 --- a/programs/vest/src/vest_processor.rs +++ b/programs/vest/src/vest_processor.rs @@ -164,7 +164,7 @@ mod tests { fn create_bank(lamports: u64) -> (Bank, Keypair) { let (genesis_config, mint_keypair) = create_genesis_config(lamports); let mut bank = Bank::new(&genesis_config); - bank.add_builtin_program("vest_program", id(), process_instruction); + bank.add_builtin("vest_program", id(), process_instruction); (bank, mint_keypair) } diff --git a/runtime/benches/bank.rs b/runtime/benches/bank.rs index 7ebced83ab..3e84cbbbdf 100644 --- a/runtime/benches/bank.rs +++ b/runtime/benches/bank.rs @@ -125,7 +125,7 @@ fn do_bench_transactions( let (mut genesis_config, mint_keypair) = create_genesis_config(100_000_000); genesis_config.ticks_per_slot = 100; let mut bank = Bank::new(&genesis_config); - bank.add_builtin_program( + bank.add_builtin( "builtin_program", Pubkey::new(&BUILTIN_PROGRAM_ID), process_instruction, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 101c040bb8..d21a98e109 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -51,9 +51,7 @@ use solana_sdk::{ native_loader, native_token::sol_to_lamports, nonce, nonce_account, - process_instruction::{ - ErasedProcessInstructionWithContext, Executor, ProcessInstructionWithContext, - }, + process_instruction::{Executor, ProcessInstructionWithContext}, program_utils::limited_deserialize, pubkey::Pubkey, recent_blockhashes_account, @@ -137,52 +135,33 @@ type RentCollectionCycleParams = ( type EpochCount = u64; -#[derive(Copy, Clone)] -pub enum Entrypoint { - Program(ProcessInstructionWithContext), - Loader(ProcessInstructionWithContext), -} - -impl fmt::Debug for Entrypoint { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - #[derive(Debug)] - enum EntrypointForDebug { - Program(String), - Loader(String), - } - // rustc doesn't compile due to bug without this work around - // https://github.com/rust-lang/rust/issues/50280 - // https://users.rust-lang.org/t/display-function-pointer/17073/2 - let entrypoint = match self { - Entrypoint::Program(instruction) => EntrypointForDebug::Program(format!( - "{:p}", - *instruction as ErasedProcessInstructionWithContext - )), - Entrypoint::Loader(instruction) => EntrypointForDebug::Loader(format!( - "{:p}", - *instruction as ErasedProcessInstructionWithContext - )), - }; - write!(f, "{:?}", entrypoint) - } -} - -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Builtin { pub name: String, pub id: Pubkey, - pub entrypoint: Entrypoint, + pub process_instruction_with_context: ProcessInstructionWithContext, } + impl Builtin { - pub fn new(name: &str, id: Pubkey, entrypoint: Entrypoint) -> Self { + pub fn new( + name: &str, + id: Pubkey, + process_instruction_with_context: ProcessInstructionWithContext, + ) -> Self { Self { name: name.to_string(), id, - entrypoint, + 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 { @@ -223,7 +202,7 @@ impl AbiExample for Builtin { Self { name: String::default(), id: Pubkey::default(), - entrypoint: Entrypoint::Program(|_, _, _, _| Ok(())), + process_instruction_with_context: |_, _, _, _| Ok(()), } } } @@ -3364,7 +3343,11 @@ impl Bank { .extend_from_slice(&additional_builtins.feature_builtins); } for builtin in builtins.genesis_builtins { - self.add_builtin(&builtin.name, builtin.id, builtin.entrypoint); + self.add_builtin( + &builtin.name, + builtin.id, + builtin.process_instruction_with_context, + ); } self.feature_builtins = Arc::new(builtins.feature_builtins); @@ -3822,47 +3805,17 @@ impl Bank { !self.is_delta.load(Relaxed) } - pub fn add_builtin_program( - &mut self, - name: &str, - program_id: Pubkey, - process_instruction_with_context: ProcessInstructionWithContext, - ) { - self.add_builtin( - name, - program_id, - Entrypoint::Program(process_instruction_with_context), - ); - } - - pub fn add_builtin_loader( - &mut self, - name: &str, - program_id: Pubkey, - process_instruction_with_context: ProcessInstructionWithContext, - ) { - self.add_builtin( - name, - program_id, - Entrypoint::Loader(process_instruction_with_context), - ); - } - /// Add an instruction processor to intercept instructions before the dynamic loader. - pub fn add_builtin(&mut self, name: &str, program_id: Pubkey, entrypoint: Entrypoint) { + pub fn add_builtin( + &mut self, + name: &str, + program_id: Pubkey, + process_instruction_with_context: ProcessInstructionWithContext, + ) { + debug!("Added program {} under {:?}", name, program_id); self.add_native_program(name, &program_id); - match entrypoint { - Entrypoint::Program(process_instruction) => { - self.message_processor - .add_program(program_id, process_instruction); - debug!("Added builtin program {} under {:?}", name, program_id); - } - Entrypoint::Loader(process_instruction_with_context) => { - self.message_processor - .add_loader(program_id, process_instruction_with_context); - debug!("Added builtin loader {} under {:?}", name, program_id); - } - } + self.message_processor + .add_program(program_id, process_instruction_with_context); } pub fn clean_accounts(&self, skip_last: bool) { @@ -3998,7 +3951,11 @@ impl Bank { let should_populate = init_or_warp && self.feature_set.is_active(&feature) || !init_or_warp && new_feature_activations.contains(&feature); if should_populate { - self.add_builtin(&builtin.name, builtin.id, builtin.entrypoint); + self.add_builtin( + &builtin.name, + builtin.id, + builtin.process_instruction_with_context, + ); } } } @@ -4581,7 +4538,7 @@ mod tests { ) as u64, ); bank.rent_collector.slots_per_year = 421_812.0; - bank.add_builtin_program("mock_program", mock_program_id, mock_process_instruction); + bank.add_builtin("mock_program", mock_program_id, mock_process_instruction); bank } @@ -7717,7 +7674,7 @@ mod tests { } #[test] - fn test_add_builtin_program() { + fn test_add_builtin() { let (genesis_config, mint_keypair) = create_genesis_config(500); let mut bank = Bank::new(&genesis_config); @@ -7737,7 +7694,7 @@ mod tests { } assert!(bank.get_account(&mock_vote_program_id()).is_none()); - bank.add_builtin_program( + bank.add_builtin( "mock_vote_program", mock_vote_program_id(), mock_vote_processor, @@ -7811,7 +7768,7 @@ mod tests { ); let vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap(); - bank.add_builtin_program( + bank.add_builtin( "solana_vote_program", solana_vote_program::id(), mock_vote_processor, @@ -7857,15 +7814,15 @@ mod tests { assert!(!bank.stakes.read().unwrap().stake_delegations().is_empty()); assert_eq!(bank.calculate_capitalization(), bank.capitalization()); - bank.add_builtin_program("mock_program1", vote_id, mock_ix_processor); - bank.add_builtin_program("mock_program2", stake_id, mock_ix_processor); + bank.add_builtin("mock_program1", vote_id, mock_ix_processor); + bank.add_builtin("mock_program2", stake_id, mock_ix_processor); assert!(bank.stakes.read().unwrap().vote_accounts().is_empty()); assert!(bank.stakes.read().unwrap().stake_delegations().is_empty()); assert_eq!(bank.calculate_capitalization(), bank.capitalization()); // Re-adding builtin programs should be no-op - bank.add_builtin_program("mock_program1", vote_id, mock_ix_processor); - bank.add_builtin_program("mock_program2", stake_id, mock_ix_processor); + bank.add_builtin("mock_program1", vote_id, mock_ix_processor); + bank.add_builtin("mock_program2", stake_id, mock_ix_processor); assert!(bank.stakes.read().unwrap().vote_accounts().is_empty()); assert!(bank.stakes.read().unwrap().stake_delegations().is_empty()); assert_eq!(bank.calculate_capitalization(), bank.capitalization()); @@ -8521,7 +8478,7 @@ mod tests { } let mock_program_id = Pubkey::new(&[2u8; 32]); - bank.add_builtin_program("mock_program", mock_program_id, mock_process_instruction); + bank.add_builtin("mock_program", mock_program_id, mock_process_instruction); let from_pubkey = solana_sdk::pubkey::new_rand(); let to_pubkey = solana_sdk::pubkey::new_rand(); @@ -8565,7 +8522,7 @@ mod tests { } let mock_program_id = Pubkey::new(&[2u8; 32]); - bank.add_builtin_program("mock_program", mock_program_id, mock_process_instruction); + bank.add_builtin("mock_program", mock_program_id, mock_process_instruction); let from_pubkey = solana_sdk::pubkey::new_rand(); let to_pubkey = solana_sdk::pubkey::new_rand(); @@ -8617,7 +8574,7 @@ mod tests { tx.message.account_keys.push(solana_sdk::pubkey::new_rand()); - bank.add_builtin_program( + bank.add_builtin( "mock_vote", solana_vote_program::id(), mock_ok_vote_processor, @@ -8671,7 +8628,7 @@ mod tests { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin_program( + bank.add_builtin( "mock_vote", solana_vote_program::id(), mock_ok_vote_processor, @@ -8704,7 +8661,7 @@ mod tests { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin_program( + bank.add_builtin( "mock_vote", solana_vote_program::id(), mock_ok_vote_processor, @@ -8760,7 +8717,7 @@ mod tests { AccountMeta::new(to_pubkey, false), ]; - bank.add_builtin_program( + bank.add_builtin( "mock_vote", solana_vote_program::id(), mock_ok_vote_processor, @@ -8796,7 +8753,7 @@ mod tests { .map(|i| { let key = solana_sdk::pubkey::new_rand(); let name = format!("program{:?}", i); - bank.add_builtin_program(&name, key, mock_ok_vote_processor); + bank.add_builtin(&name, key, mock_ok_vote_processor); (key, name.as_bytes().to_vec()) }) .collect(); @@ -9005,7 +8962,7 @@ mod tests { // Add a new program let program1_pubkey = solana_sdk::pubkey::new_rand(); - bank.add_builtin_program("program", program1_pubkey, nested_processor); + bank.add_builtin("program", program1_pubkey, nested_processor); // Add a new program owned by the first let program2_pubkey = solana_sdk::pubkey::new_rand(); @@ -9167,7 +9124,7 @@ mod tests { } #[test] - fn test_add_builtin_program_no_overwrite() { + fn test_add_builtin_no_overwrite() { let (genesis_config, _mint_keypair) = create_genesis_config(100_000); fn mock_ix_processor( @@ -9189,19 +9146,15 @@ mod tests { )); assert_eq!(bank.get_account_modified_slot(&program_id), None); - Arc::get_mut(&mut bank).unwrap().add_builtin_program( - "mock_program", - program_id, - mock_ix_processor, - ); + Arc::get_mut(&mut bank) + .unwrap() + .add_builtin("mock_program", program_id, mock_ix_processor); assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot); let mut bank = Arc::new(new_from_parent(&bank)); - Arc::get_mut(&mut bank).unwrap().add_builtin_program( - "mock_program", - program_id, - mock_ix_processor, - ); + Arc::get_mut(&mut bank) + .unwrap() + .add_builtin("mock_program", program_id, mock_ix_processor); assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot); } @@ -9228,19 +9181,15 @@ mod tests { )); assert_eq!(bank.get_account_modified_slot(&loader_id), None); - Arc::get_mut(&mut bank).unwrap().add_builtin_loader( - "mock_program", - loader_id, - mock_ix_processor, - ); + Arc::get_mut(&mut bank) + .unwrap() + .add_builtin("mock_program", loader_id, mock_ix_processor); assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot); let mut bank = Arc::new(new_from_parent(&bank)); - Arc::get_mut(&mut bank).unwrap().add_builtin_loader( - "mock_program", - loader_id, - mock_ix_processor, - ); + Arc::get_mut(&mut bank) + .unwrap() + .add_builtin("mock_program", loader_id, mock_ix_processor); assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot); } @@ -10074,18 +10023,4 @@ mod tests { let debug = format!("{:#?}", bank); assert!(!debug.is_empty()); } - - #[test] - fn test_debug_entrypoint() { - fn mock_processor( - _pubkey: &Pubkey, - _ka: &[KeyedAccount], - _data: &[u8], - _invoke_context: &mut dyn InvokeContext, - ) -> std::result::Result<(), InstructionError> { - Ok(()) - } - assert!(!format!("{:?}", Entrypoint::Program(mock_processor)).is_empty()); - assert!(!format!("{:?}", Entrypoint::Loader(mock_processor)).is_empty()); - } } diff --git a/runtime/src/builtins.rs b/runtime/src/builtins.rs index beb8294480..845438fc1a 100644 --- a/runtime/src/builtins.rs +++ b/runtime/src/builtins.rs @@ -1,5 +1,5 @@ use crate::{ - bank::{Builtin, Builtins, Entrypoint}, + bank::{Builtin, Builtins}, feature_set, system_instruction_processor, }; use solana_sdk::{pubkey::Pubkey, system_program}; @@ -10,22 +10,22 @@ fn genesis_builtins() -> Vec { Builtin::new( "system_program", system_program::id(), - Entrypoint::Program(system_instruction_processor::process_instruction), + system_instruction_processor::process_instruction, ), Builtin::new( "vote_program", solana_vote_program::id(), - Entrypoint::Program(solana_vote_program::vote_instruction::process_instruction), + solana_vote_program::vote_instruction::process_instruction, ), Builtin::new( "stake_program", solana_stake_program::id(), - Entrypoint::Program(solana_stake_program::stake_instruction::process_instruction), + solana_stake_program::stake_instruction::process_instruction, ), Builtin::new( "config_program", solana_config_program::id(), - Entrypoint::Program(solana_config_program::config_processor::process_instruction), + solana_config_program::config_processor::process_instruction, ), ] } @@ -36,7 +36,7 @@ fn feature_builtins() -> Vec<(Builtin, Pubkey)> { Builtin::new( "secp256k1_program", solana_sdk::secp256k1_program::id(), - Entrypoint::Program(solana_secp256k1_program::process_instruction), + solana_secp256k1_program::process_instruction, ), feature_set::secp256k1_program_enabled::id(), )] diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index cf91d5ebc4..829f9dd603 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -15,8 +15,7 @@ use solana_sdk::{ message::Message, native_loader, process_instruction::{ - ComputeBudget, ComputeMeter, ErasedProcessInstructionWithContext, Executor, InvokeContext, - Logger, ProcessInstructionWithContext, + ComputeBudget, ComputeMeter, Executor, InvokeContext, Logger, ProcessInstructionWithContext, }, pubkey::Pubkey, rent::Rent, @@ -338,6 +337,15 @@ impl std::fmt::Debug for MessageProcessor { programs: Vec, native_loader: &'a NativeLoader, } + + // These are just type aliases for work around of Debug-ing above pointers + type ErasedProcessInstructionWithContext = fn( + &'static Pubkey, + &'static [KeyedAccount<'static>], + &'static [u8], + &'static mut dyn InvokeContext, + ) -> Result<(), InstructionError>; + // rustc doesn't compile due to bug without this work around // https://github.com/rust-lang/rust/issues/50280 // https://users.rust-lang.org/t/display-function-pointer/17073/2 diff --git a/sdk/src/process_instruction.rs b/sdk/src/process_instruction.rs index b90e76fb43..ee442b1783 100644 --- a/sdk/src/process_instruction.rs +++ b/sdk/src/process_instruction.rs @@ -27,14 +27,6 @@ pub type LoaderEntrypoint = unsafe extern "C" fn( pub type ProcessInstructionWithContext = fn(&Pubkey, &[KeyedAccount], &[u8], &mut dyn InvokeContext) -> Result<(), InstructionError>; -// These are just type aliases for work around of Debug-ing above function pointers -pub type ErasedProcessInstructionWithContext = fn( - &'static Pubkey, - &'static [KeyedAccount<'static>], - &'static [u8], - &'static mut dyn InvokeContext, -) -> Result<(), InstructionError>; - /// Invocation context passed to loaders pub trait InvokeContext { /// Push a program ID on to the invocation stack