Remove Entrypoint type

This commit is contained in:
Michael Vines 2020-10-29 16:17:36 -07:00
parent 2664a1f7ef
commit 225bed11c7
13 changed files with 98 additions and 163 deletions

View File

@ -86,7 +86,7 @@ fn test_exchange_bank_client() {
solana_logger::setup(); solana_logger::setup();
let (genesis_config, identity) = create_genesis_config(100_000_000_000_000); let (genesis_config, identity) = create_genesis_config(100_000_000_000_000);
let mut bank = Bank::new(&genesis_config); 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 clients = vec![BankClient::new(bank)];
let mut config = Config::default(); let mut config = Config::default();

View File

@ -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}; use solana_sdk::{feature_set, genesis_config::ClusterType, pubkey::Pubkey};
/// Builtin programs that are always available /// Builtin programs that are always available
@ -16,7 +16,7 @@ fn genesis_builtins(cluster_type: ClusterType) -> Vec<Builtin> {
builtins builtins
.into_iter() .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() .collect()
} }
@ -29,7 +29,7 @@ fn feature_builtins() -> Vec<(Builtin, Pubkey)> {
builtins builtins
.into_iter() .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() .collect()
} }

View File

@ -162,7 +162,7 @@ fn bench_program_execute_noop(bencher: &mut Bencher) {
} = create_genesis_config(50); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank); let bank_client = BankClient::new_shared(&bank);

View File

@ -183,7 +183,7 @@ fn test_program_bpf_sanity() {
} = create_genesis_config(50); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 = Arc::new(bank);
// Create bank with a specific slot, used by solana_bpf_rust_sysvar test // 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); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_deprecated_program!(); 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 bank_client = BankClient::new(bank);
let program_id = load_bpf_program( let program_id = load_bpf_program(
@ -277,7 +277,7 @@ fn test_program_bpf_duplicate_accounts() {
} = create_genesis_config(50); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank); let bank_client = BankClient::new_shared(&bank);
let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program); 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); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 bank_client = BankClient::new(bank);
let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program); let program_id = load_bpf_program(&bank_client, &bpf_loader::id(), &mint_keypair, program);
let account_metas = vec![AccountMeta::new(mint_keypair.pubkey(), true)]; let account_metas = vec![AccountMeta::new(mint_keypair.pubkey(), true)];
@ -479,7 +479,7 @@ fn test_program_bpf_invoke() {
} = create_genesis_config(50); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank); let bank_client = BankClient::new_shared(&bank);
@ -710,7 +710,7 @@ fn test_program_bpf_call_depth() {
} = create_genesis_config(50); } = create_genesis_config(50);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 bank_client = BankClient::new(bank);
let program_id = load_bpf_program( let program_id = load_bpf_program(
&bank_client, &bank_client,
@ -792,7 +792,7 @@ fn test_program_bpf_instruction_introspection() {
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
let (name, id, entrypoint) = solana_bpf_loader_program!(); 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 = Arc::new(bank);
let bank_client = BankClient::new_shared(&bank); let bank_client = BankClient::new_shared(&bank);

View File

@ -240,7 +240,7 @@ mod tests {
fn create_bank(lamports: u64) -> (Bank, Keypair) { fn create_bank(lamports: u64) -> (Bank, Keypair) {
let (genesis_config, mint_keypair) = create_genesis_config(lamports); let (genesis_config, mint_keypair) = create_genesis_config(lamports);
let mut bank = Bank::new(&genesis_config); 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) (bank, mint_keypair)
} }

View File

@ -579,7 +579,7 @@ mod test {
fn create_bank(lamports: u64) -> (Bank, Keypair) { fn create_bank(lamports: u64) -> (Bank, Keypair) {
let (genesis_config, mint_keypair) = create_genesis_config(lamports); let (genesis_config, mint_keypair) = create_genesis_config(lamports);
let mut bank = Bank::new(&genesis_config); 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) (bank, mint_keypair)
} }

View File

@ -73,7 +73,7 @@ mod tests {
fn create_bank(lamports: u64) -> (Bank, Keypair) { fn create_bank(lamports: u64) -> (Bank, Keypair) {
let (genesis_config, mint_keypair) = create_genesis_config(lamports); let (genesis_config, mint_keypair) = create_genesis_config(lamports);
let mut bank = Bank::new(&genesis_config); 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) (bank, mint_keypair)
} }

View File

@ -164,7 +164,7 @@ mod tests {
fn create_bank(lamports: u64) -> (Bank, Keypair) { fn create_bank(lamports: u64) -> (Bank, Keypair) {
let (genesis_config, mint_keypair) = create_genesis_config(lamports); let (genesis_config, mint_keypair) = create_genesis_config(lamports);
let mut bank = Bank::new(&genesis_config); 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) (bank, mint_keypair)
} }

View File

@ -125,7 +125,7 @@ fn do_bench_transactions(
let (mut genesis_config, mint_keypair) = create_genesis_config(100_000_000); let (mut genesis_config, mint_keypair) = create_genesis_config(100_000_000);
genesis_config.ticks_per_slot = 100; genesis_config.ticks_per_slot = 100;
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
bank.add_builtin_program( bank.add_builtin(
"builtin_program", "builtin_program",
Pubkey::new(&BUILTIN_PROGRAM_ID), Pubkey::new(&BUILTIN_PROGRAM_ID),
process_instruction, process_instruction,

View File

@ -51,9 +51,7 @@ use solana_sdk::{
native_loader, native_loader,
native_token::sol_to_lamports, native_token::sol_to_lamports,
nonce, nonce_account, nonce, nonce_account,
process_instruction::{ process_instruction::{Executor, ProcessInstructionWithContext},
ErasedProcessInstructionWithContext, Executor, ProcessInstructionWithContext,
},
program_utils::limited_deserialize, program_utils::limited_deserialize,
pubkey::Pubkey, pubkey::Pubkey,
recent_blockhashes_account, recent_blockhashes_account,
@ -137,52 +135,33 @@ type RentCollectionCycleParams = (
type EpochCount = u64; type EpochCount = u64;
#[derive(Copy, Clone)] #[derive(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)]
pub struct Builtin { pub struct Builtin {
pub name: String, pub name: String,
pub id: Pubkey, pub id: Pubkey,
pub entrypoint: Entrypoint, pub process_instruction_with_context: ProcessInstructionWithContext,
} }
impl Builtin { 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 { Self {
name: name.to_string(), name: name.to_string(),
id, 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 /// Copy-on-write holder of CachedExecutors
#[derive(AbiExample, Debug, Default)] #[derive(AbiExample, Debug, Default)]
struct CowCachedExecutors { struct CowCachedExecutors {
@ -223,7 +202,7 @@ impl AbiExample for Builtin {
Self { Self {
name: String::default(), name: String::default(),
id: Pubkey::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); .extend_from_slice(&additional_builtins.feature_builtins);
} }
for builtin in builtins.genesis_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); self.feature_builtins = Arc::new(builtins.feature_builtins);
@ -3822,47 +3805,17 @@ impl Bank {
!self.is_delta.load(Relaxed) !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. /// 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); self.add_native_program(name, &program_id);
match entrypoint { self.message_processor
Entrypoint::Program(process_instruction) => { .add_program(program_id, process_instruction_with_context);
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);
}
}
} }
pub fn clean_accounts(&self, skip_last: bool) { 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) let should_populate = init_or_warp && self.feature_set.is_active(&feature)
|| !init_or_warp && new_feature_activations.contains(&feature); || !init_or_warp && new_feature_activations.contains(&feature);
if should_populate { 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, ) as u64,
); );
bank.rent_collector.slots_per_year = 421_812.0; 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 bank
} }
@ -7717,7 +7674,7 @@ mod tests {
} }
#[test] #[test]
fn test_add_builtin_program() { fn test_add_builtin() {
let (genesis_config, mint_keypair) = create_genesis_config(500); let (genesis_config, mint_keypair) = create_genesis_config(500);
let mut bank = Bank::new(&genesis_config); let mut bank = Bank::new(&genesis_config);
@ -7737,7 +7694,7 @@ mod tests {
} }
assert!(bank.get_account(&mock_vote_program_id()).is_none()); assert!(bank.get_account(&mock_vote_program_id()).is_none());
bank.add_builtin_program( bank.add_builtin(
"mock_vote_program", "mock_vote_program",
mock_vote_program_id(), mock_vote_program_id(),
mock_vote_processor, mock_vote_processor,
@ -7811,7 +7768,7 @@ mod tests {
); );
let vote_loader_account = bank.get_account(&solana_vote_program::id()).unwrap(); 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",
solana_vote_program::id(), solana_vote_program::id(),
mock_vote_processor, mock_vote_processor,
@ -7857,15 +7814,15 @@ mod tests {
assert!(!bank.stakes.read().unwrap().stake_delegations().is_empty()); assert!(!bank.stakes.read().unwrap().stake_delegations().is_empty());
assert_eq!(bank.calculate_capitalization(), bank.capitalization()); assert_eq!(bank.calculate_capitalization(), bank.capitalization());
bank.add_builtin_program("mock_program1", vote_id, mock_ix_processor); bank.add_builtin("mock_program1", vote_id, mock_ix_processor);
bank.add_builtin_program("mock_program2", stake_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().vote_accounts().is_empty());
assert!(bank.stakes.read().unwrap().stake_delegations().is_empty()); assert!(bank.stakes.read().unwrap().stake_delegations().is_empty());
assert_eq!(bank.calculate_capitalization(), bank.capitalization()); assert_eq!(bank.calculate_capitalization(), bank.capitalization());
// Re-adding builtin programs should be no-op // Re-adding builtin programs should be no-op
bank.add_builtin_program("mock_program1", vote_id, mock_ix_processor); bank.add_builtin("mock_program1", vote_id, mock_ix_processor);
bank.add_builtin_program("mock_program2", stake_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().vote_accounts().is_empty());
assert!(bank.stakes.read().unwrap().stake_delegations().is_empty()); assert!(bank.stakes.read().unwrap().stake_delegations().is_empty());
assert_eq!(bank.calculate_capitalization(), bank.capitalization()); assert_eq!(bank.calculate_capitalization(), bank.capitalization());
@ -8521,7 +8478,7 @@ mod tests {
} }
let mock_program_id = Pubkey::new(&[2u8; 32]); 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 from_pubkey = solana_sdk::pubkey::new_rand();
let to_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]); 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 from_pubkey = solana_sdk::pubkey::new_rand();
let to_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()); tx.message.account_keys.push(solana_sdk::pubkey::new_rand());
bank.add_builtin_program( bank.add_builtin(
"mock_vote", "mock_vote",
solana_vote_program::id(), solana_vote_program::id(),
mock_ok_vote_processor, mock_ok_vote_processor,
@ -8671,7 +8628,7 @@ mod tests {
AccountMeta::new(to_pubkey, false), AccountMeta::new(to_pubkey, false),
]; ];
bank.add_builtin_program( bank.add_builtin(
"mock_vote", "mock_vote",
solana_vote_program::id(), solana_vote_program::id(),
mock_ok_vote_processor, mock_ok_vote_processor,
@ -8704,7 +8661,7 @@ mod tests {
AccountMeta::new(to_pubkey, false), AccountMeta::new(to_pubkey, false),
]; ];
bank.add_builtin_program( bank.add_builtin(
"mock_vote", "mock_vote",
solana_vote_program::id(), solana_vote_program::id(),
mock_ok_vote_processor, mock_ok_vote_processor,
@ -8760,7 +8717,7 @@ mod tests {
AccountMeta::new(to_pubkey, false), AccountMeta::new(to_pubkey, false),
]; ];
bank.add_builtin_program( bank.add_builtin(
"mock_vote", "mock_vote",
solana_vote_program::id(), solana_vote_program::id(),
mock_ok_vote_processor, mock_ok_vote_processor,
@ -8796,7 +8753,7 @@ mod tests {
.map(|i| { .map(|i| {
let key = solana_sdk::pubkey::new_rand(); let key = solana_sdk::pubkey::new_rand();
let name = format!("program{:?}", i); 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()) (key, name.as_bytes().to_vec())
}) })
.collect(); .collect();
@ -9005,7 +8962,7 @@ mod tests {
// Add a new program // Add a new program
let program1_pubkey = solana_sdk::pubkey::new_rand(); 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 // Add a new program owned by the first
let program2_pubkey = solana_sdk::pubkey::new_rand(); let program2_pubkey = solana_sdk::pubkey::new_rand();
@ -9167,7 +9124,7 @@ mod tests {
} }
#[test] #[test]
fn test_add_builtin_program_no_overwrite() { fn test_add_builtin_no_overwrite() {
let (genesis_config, _mint_keypair) = create_genesis_config(100_000); let (genesis_config, _mint_keypair) = create_genesis_config(100_000);
fn mock_ix_processor( fn mock_ix_processor(
@ -9189,19 +9146,15 @@ mod tests {
)); ));
assert_eq!(bank.get_account_modified_slot(&program_id), None); assert_eq!(bank.get_account_modified_slot(&program_id), None);
Arc::get_mut(&mut bank).unwrap().add_builtin_program( Arc::get_mut(&mut bank)
"mock_program", .unwrap()
program_id, .add_builtin("mock_program", program_id, mock_ix_processor);
mock_ix_processor,
);
assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot); assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot);
let mut bank = Arc::new(new_from_parent(&bank)); let mut bank = Arc::new(new_from_parent(&bank));
Arc::get_mut(&mut bank).unwrap().add_builtin_program( Arc::get_mut(&mut bank)
"mock_program", .unwrap()
program_id, .add_builtin("mock_program", program_id, mock_ix_processor);
mock_ix_processor,
);
assert_eq!(bank.get_account_modified_slot(&program_id).unwrap().1, slot); 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); assert_eq!(bank.get_account_modified_slot(&loader_id), None);
Arc::get_mut(&mut bank).unwrap().add_builtin_loader( Arc::get_mut(&mut bank)
"mock_program", .unwrap()
loader_id, .add_builtin("mock_program", loader_id, mock_ix_processor);
mock_ix_processor,
);
assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot); assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot);
let mut bank = Arc::new(new_from_parent(&bank)); let mut bank = Arc::new(new_from_parent(&bank));
Arc::get_mut(&mut bank).unwrap().add_builtin_loader( Arc::get_mut(&mut bank)
"mock_program", .unwrap()
loader_id, .add_builtin("mock_program", loader_id, mock_ix_processor);
mock_ix_processor,
);
assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot); assert_eq!(bank.get_account_modified_slot(&loader_id).unwrap().1, slot);
} }
@ -10074,18 +10023,4 @@ mod tests {
let debug = format!("{:#?}", bank); let debug = format!("{:#?}", bank);
assert!(!debug.is_empty()); 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());
}
} }

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
bank::{Builtin, Builtins, Entrypoint}, bank::{Builtin, Builtins},
feature_set, system_instruction_processor, feature_set, system_instruction_processor,
}; };
use solana_sdk::{pubkey::Pubkey, system_program}; use solana_sdk::{pubkey::Pubkey, system_program};
@ -10,22 +10,22 @@ fn genesis_builtins() -> Vec<Builtin> {
Builtin::new( Builtin::new(
"system_program", "system_program",
system_program::id(), system_program::id(),
Entrypoint::Program(system_instruction_processor::process_instruction), system_instruction_processor::process_instruction,
), ),
Builtin::new( Builtin::new(
"vote_program", "vote_program",
solana_vote_program::id(), solana_vote_program::id(),
Entrypoint::Program(solana_vote_program::vote_instruction::process_instruction), solana_vote_program::vote_instruction::process_instruction,
), ),
Builtin::new( Builtin::new(
"stake_program", "stake_program",
solana_stake_program::id(), solana_stake_program::id(),
Entrypoint::Program(solana_stake_program::stake_instruction::process_instruction), solana_stake_program::stake_instruction::process_instruction,
), ),
Builtin::new( Builtin::new(
"config_program", "config_program",
solana_config_program::id(), 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( Builtin::new(
"secp256k1_program", "secp256k1_program",
solana_sdk::secp256k1_program::id(), solana_sdk::secp256k1_program::id(),
Entrypoint::Program(solana_secp256k1_program::process_instruction), solana_secp256k1_program::process_instruction,
), ),
feature_set::secp256k1_program_enabled::id(), feature_set::secp256k1_program_enabled::id(),
)] )]

View File

@ -15,8 +15,7 @@ use solana_sdk::{
message::Message, message::Message,
native_loader, native_loader,
process_instruction::{ process_instruction::{
ComputeBudget, ComputeMeter, ErasedProcessInstructionWithContext, Executor, InvokeContext, ComputeBudget, ComputeMeter, Executor, InvokeContext, Logger, ProcessInstructionWithContext,
Logger, ProcessInstructionWithContext,
}, },
pubkey::Pubkey, pubkey::Pubkey,
rent::Rent, rent::Rent,
@ -338,6 +337,15 @@ impl std::fmt::Debug for MessageProcessor {
programs: Vec<String>, programs: Vec<String>,
native_loader: &'a NativeLoader, 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 // rustc doesn't compile due to bug without this work around
// https://github.com/rust-lang/rust/issues/50280 // https://github.com/rust-lang/rust/issues/50280
// https://users.rust-lang.org/t/display-function-pointer/17073/2 // https://users.rust-lang.org/t/display-function-pointer/17073/2

View File

@ -27,14 +27,6 @@ pub type LoaderEntrypoint = unsafe extern "C" fn(
pub type ProcessInstructionWithContext = pub type ProcessInstructionWithContext =
fn(&Pubkey, &[KeyedAccount], &[u8], &mut dyn InvokeContext) -> Result<(), InstructionError>; 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 /// Invocation context passed to loaders
pub trait InvokeContext { pub trait InvokeContext {
/// Push a program ID on to the invocation stack /// Push a program ID on to the invocation stack