Boot remote native loads, take 2 (#5106)
* Drop dependencies on remote native loads * Remove remote native loads
This commit is contained in:
parent
92d78451b1
commit
04649de6a6
|
@ -1,24 +1,23 @@
|
|||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
use solana_runtime::loader_utils::{create_invoke_instruction, load_program};
|
||||
use solana_runtime::loader_utils::create_invoke_instruction;
|
||||
use solana_sdk::client::SyncClient;
|
||||
use solana_sdk::genesis_block::create_genesis_block;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::native_loader;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::KeypairUtil;
|
||||
use solana_sdk::transaction::TransactionError;
|
||||
|
||||
#[test]
|
||||
fn test_program_native_failure() {
|
||||
let (genesis_block, alice_keypair) = create_genesis_block(50);
|
||||
let program_id = Pubkey::new_rand();
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
let program = "solana_failure_program".as_bytes().to_vec();
|
||||
let program_id = load_program(&bank_client, &alice_keypair, &native_loader::id(), program);
|
||||
bank.register_native_instruction_processor("solana_failure_program", &program_id);
|
||||
|
||||
// Call user program
|
||||
let instruction = create_invoke_instruction(alice_keypair.pubkey(), program_id, &1u8);
|
||||
let bank_client = BankClient::new(bank);
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_instruction(&alice_keypair, instruction)
|
||||
|
|
|
@ -5,13 +5,12 @@ extern crate test;
|
|||
use log::*;
|
||||
use solana_runtime::bank::*;
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
use solana_runtime::loader_utils::{create_invoke_instruction, load_program};
|
||||
use solana_runtime::loader_utils::create_invoke_instruction;
|
||||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::client::AsyncClient;
|
||||
use solana_sdk::client::SyncClient;
|
||||
use solana_sdk::genesis_block::create_genesis_block;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::native_loader;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
|
@ -25,6 +24,11 @@ const BUILTIN_PROGRAM_ID: [u8; 32] = [
|
|||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
const NOOP_PROGRAM_ID: [u8; 32] = [
|
||||
098, 117, 105, 108, 116, 105, 110, 095, 112, 114, 111, 103, 114, 097, 109, 095, 105, 100, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
];
|
||||
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_keyed_accounts: &mut [KeyedAccount],
|
||||
|
@ -59,8 +63,7 @@ pub fn create_native_loader_transactions(
|
|||
bank_client: &BankClient,
|
||||
mint_keypair: &Keypair,
|
||||
) -> Vec<Transaction> {
|
||||
let program = "solana_noop_program".as_bytes().to_vec();
|
||||
let program_id = load_program(&bank_client, &mint_keypair, &native_loader::id(), program);
|
||||
let program_id = Pubkey::new(&NOOP_PROGRAM_ID);
|
||||
|
||||
(0..4096)
|
||||
.into_iter()
|
||||
|
@ -120,6 +123,10 @@ fn do_bench_transactions(
|
|||
let (genesis_block, mint_keypair) = create_genesis_block(100_000_000);
|
||||
let mut bank = Bank::new(&genesis_block);
|
||||
bank.add_instruction_processor(Pubkey::new(&BUILTIN_PROGRAM_ID), process_instruction);
|
||||
bank.register_native_instruction_processor(
|
||||
"solana_noop_program",
|
||||
&Pubkey::new(&NOOP_PROGRAM_ID),
|
||||
);
|
||||
let bank = Arc::new(bank);
|
||||
let bank_client = BankClient::new_shared(&bank);
|
||||
let transactions = create_transactions(&bank_client, &mint_keypair);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Native loader
|
||||
use crate::message_processor::SymbolCache;
|
||||
use bincode::deserialize;
|
||||
#[cfg(unix)]
|
||||
use libloading::os::unix::*;
|
||||
#[cfg(windows)]
|
||||
|
@ -9,7 +8,6 @@ use log::*;
|
|||
use solana_sdk::account::KeyedAccount;
|
||||
use solana_sdk::instruction::InstructionError;
|
||||
use solana_sdk::instruction_processor_utils;
|
||||
use solana_sdk::loader_instruction::LoaderInstruction;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
@ -109,45 +107,15 @@ pub fn entrypoint(
|
|||
.write()
|
||||
.unwrap()
|
||||
.insert(name_vec.to_vec(), entrypoint);
|
||||
return ret;
|
||||
ret
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Unable to load: {:?}", e);
|
||||
return Err(InstructionError::GenericError);
|
||||
}
|
||||
}
|
||||
} else if let Ok(instruction) = deserialize(ix_data) {
|
||||
if keyed_accounts[0].signer_key().is_none() {
|
||||
warn!("key[0] did not sign the transaction");
|
||||
return Err(InstructionError::GenericError);
|
||||
}
|
||||
match instruction {
|
||||
LoaderInstruction::Write { offset, bytes } => {
|
||||
trace!("NativeLoader::Write offset {} bytes {:?}", offset, bytes);
|
||||
let offset = offset as usize;
|
||||
if keyed_accounts[0].account.data.len() < offset + bytes.len() {
|
||||
warn!(
|
||||
"Error: Overflow, {} < {}",
|
||||
keyed_accounts[0].account.data.len(),
|
||||
offset + bytes.len()
|
||||
);
|
||||
return Err(InstructionError::GenericError);
|
||||
}
|
||||
// native loader takes a name and we assume it all comes in at once
|
||||
keyed_accounts[0].account.data = bytes;
|
||||
}
|
||||
|
||||
LoaderInstruction::Finalize => {
|
||||
keyed_accounts[0].account.executable = true;
|
||||
trace!(
|
||||
"NativeLoader::Finalize prog: {:?}",
|
||||
keyed_accounts[0].signer_key().unwrap()
|
||||
);
|
||||
Err(InstructionError::GenericError)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!("Invalid data in instruction: {:?}", ix_data);
|
||||
return Err(InstructionError::GenericError);
|
||||
Err(InstructionError::GenericError)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::bank_client::BankClient;
|
||||
use solana_runtime::loader_utils::{create_invoke_instruction, load_program};
|
||||
use solana_runtime::loader_utils::create_invoke_instruction;
|
||||
use solana_sdk::client::SyncClient;
|
||||
use solana_sdk::genesis_block::create_genesis_block;
|
||||
use solana_sdk::native_loader;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::KeypairUtil;
|
||||
|
||||
#[test]
|
||||
|
@ -11,14 +11,13 @@ fn test_program_native_noop() {
|
|||
solana_logger::setup();
|
||||
|
||||
let (genesis_block, alice_keypair) = create_genesis_block(50);
|
||||
let program_id = Pubkey::new_rand();
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let bank_client = BankClient::new(bank);
|
||||
|
||||
let program = "solana_noop_program".as_bytes().to_vec();
|
||||
let program_id = load_program(&bank_client, &alice_keypair, &native_loader::id(), program);
|
||||
bank.register_native_instruction_processor("solana_noop_program", &program_id);
|
||||
|
||||
// Call user program
|
||||
let instruction = create_invoke_instruction(alice_keypair.pubkey(), program_id, &1u8);
|
||||
let bank_client = BankClient::new(bank);
|
||||
bank_client
|
||||
.send_instruction(&alice_keypair, instruction)
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in New Issue