Rename native_program.rs to instruction_processor_utils.rs
Prefer the term "instruction processor" over "program". Reserve the term "native" for the loader and shared object it loads. Compiling an instruction processor to BPF shouldn't imply changing to a non-native entrypoint.
This commit is contained in:
@ -347,19 +347,25 @@ impl Bank {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add native programs mandatory for the runtime to function
|
// Add native programs mandatory for the runtime to function
|
||||||
self.add_native_program("solana_system_program", &solana_sdk::system_program::id());
|
self.register_native_instruction_processor(
|
||||||
self.add_native_program("solana_bpf_loader", &solana_sdk::bpf_loader::id());
|
"solana_system_program",
|
||||||
self.add_native_program("solana_vote_program", &solana_vote_api::id());
|
&solana_sdk::system_program::id(),
|
||||||
|
);
|
||||||
|
self.register_native_instruction_processor(
|
||||||
|
"solana_bpf_loader",
|
||||||
|
&solana_sdk::bpf_loader::id(),
|
||||||
|
);
|
||||||
|
self.register_native_instruction_processor("solana_vote_program", &solana_vote_api::id());
|
||||||
|
|
||||||
// Add additional native programs specified in the genesis block
|
// Add additional native programs specified in the genesis block
|
||||||
for (name, program_id) in &genesis_block.native_programs {
|
for (name, program_id) in &genesis_block.native_programs {
|
||||||
self.add_native_program(name, program_id);
|
self.register_native_instruction_processor(name, program_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_native_program(&self, name: &str, program_id: &Pubkey) {
|
pub fn register_native_instruction_processor(&self, name: &str, program_id: &Pubkey) {
|
||||||
debug!("Adding native program {} under {:?}", name, program_id);
|
debug!("Adding native program {} under {:?}", name, program_id);
|
||||||
let account = native_loader::create_program_account(name);
|
let account = native_loader::create_loadable_account(name);
|
||||||
self.accounts
|
self.accounts
|
||||||
.store_slow(self.accounts_id, program_id, &account);
|
.store_slow(self.accounts_id, program_id, &account);
|
||||||
}
|
}
|
||||||
@ -931,15 +937,8 @@ impl Bank {
|
|||||||
self.runtime
|
self.runtime
|
||||||
.add_instruction_processor(program_id, process_instruction);
|
.add_instruction_processor(program_id, process_instruction);
|
||||||
|
|
||||||
// Add a bogus executable account to load.
|
// Register a bogus executable account, which will be loaded and ignored.
|
||||||
let bogus_account = Account {
|
self.register_native_instruction_processor("", &program_id);
|
||||||
lamports: 1,
|
|
||||||
data: vec![],
|
|
||||||
owner: native_loader::id(),
|
|
||||||
executable: true,
|
|
||||||
};
|
|
||||||
self.accounts
|
|
||||||
.store_slow(self.accounts_id, &program_id, &bogus_account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_in_subtree_of(&self, parent: u64) -> bool {
|
pub fn is_in_subtree_of(&self, parent: u64) -> bool {
|
||||||
|
@ -7,8 +7,8 @@ use libloading::os::windows::*;
|
|||||||
use log::*;
|
use log::*;
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
|
use solana_sdk::instruction_processor_utils;
|
||||||
use solana_sdk::loader_instruction::LoaderInstruction;
|
use solana_sdk::loader_instruction::LoaderInstruction;
|
||||||
use solana_sdk::native_program;
|
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -69,14 +69,14 @@ pub fn entrypoint(
|
|||||||
// TODO linux tls bug can cause crash on dlclose(), workaround by never unloading
|
// TODO linux tls bug can cause crash on dlclose(), workaround by never unloading
|
||||||
match Library::open(Some(&path), libc::RTLD_NODELETE | libc::RTLD_NOW) {
|
match Library::open(Some(&path), libc::RTLD_NODELETE | libc::RTLD_NOW) {
|
||||||
Ok(library) => unsafe {
|
Ok(library) => unsafe {
|
||||||
let entrypoint: Symbol<native_program::Entrypoint> =
|
let entrypoint: Symbol<instruction_processor_utils::Entrypoint> =
|
||||||
match library.get(native_program::ENTRYPOINT.as_bytes()) {
|
match library.get(instruction_processor_utils::ENTRYPOINT.as_bytes()) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!(
|
warn!(
|
||||||
"{:?}: Unable to find {:?} in program",
|
"{:?}: Unable to find {:?} in program",
|
||||||
e,
|
e,
|
||||||
native_program::ENTRYPOINT
|
instruction_processor_utils::ENTRYPOINT
|
||||||
);
|
);
|
||||||
return Err(InstructionError::GenericError);
|
return Err(InstructionError::GenericError);
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ pub mod fee_calculator;
|
|||||||
pub mod genesis_block;
|
pub mod genesis_block;
|
||||||
pub mod hash;
|
pub mod hash;
|
||||||
pub mod instruction;
|
pub mod instruction;
|
||||||
|
pub mod instruction_processor_utils;
|
||||||
pub mod loader_instruction;
|
pub mod loader_instruction;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod native_loader;
|
pub mod native_loader;
|
||||||
pub mod native_program;
|
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
pub mod pubkey;
|
pub mod pubkey;
|
||||||
pub mod rpc_port;
|
pub mod rpc_port;
|
||||||
|
@ -14,7 +14,7 @@ pub fn check_id(program_id: &Pubkey) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create an executable account with the given shared object name.
|
/// Create an executable account with the given shared object name.
|
||||||
pub fn create_program_account(name: &str) -> Account {
|
pub fn create_loadable_account(name: &str) -> Account {
|
||||||
Account {
|
Account {
|
||||||
lamports: 1,
|
lamports: 1,
|
||||||
owner: id(),
|
owner: id(),
|
||||||
|
Reference in New Issue
Block a user