Refactor: Move sdk::process_instruction in program-runtime-crate (#21180)
* Moves the Executor dyn Trait to instruction_processor.rs * Moves the Logger dyn Trait as well as the ic_msg and ic_logger_msg macros to log_collector.rs, and moves the stable_log to stable_log.rs * Moves the ComputeMeter dyn Trait to invoke_context.rs * Moves the InvokeContext dyn Trait and the ProcessInstructionWithContext type to invoke_context.rs * Updates cargo files. * Re-export InvokeContext in program-test Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
This commit is contained in:
parent
c3e5927d16
commit
e540b1cf3c
|
@ -4707,6 +4707,7 @@ dependencies = [
|
||||||
name = "solana-compute-budget-program"
|
name = "solana-compute-budget-program"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5440,7 +5441,9 @@ dependencies = [
|
||||||
name = "solana-program-runtime"
|
name = "solana-program-runtime"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64 0.13.0",
|
||||||
"bincode",
|
"bincode",
|
||||||
|
"itertools 0.10.1",
|
||||||
"libc",
|
"libc",
|
||||||
"libloading",
|
"libloading",
|
||||||
"log 0.4.14",
|
"log 0.4.14",
|
||||||
|
|
|
@ -10,7 +10,9 @@ documentation = "https://docs.rs/solana-program-runtime"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
base64 = "0.13"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
|
itertools = "0.10.1"
|
||||||
libc = "0.2.101"
|
libc = "0.2.101"
|
||||||
libloading = "0.7.0"
|
libloading = "0.7.0"
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
use crate::native_loader::NativeLoader;
|
use crate::{
|
||||||
|
ic_msg,
|
||||||
|
invoke_context::{InvokeContext, ProcessInstructionWithContext},
|
||||||
|
native_loader::NativeLoader,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||||
feature_set::{demote_program_write_locks, do_support_realloc, remove_native_loader},
|
feature_set::{demote_program_write_locks, do_support_realloc, remove_native_loader},
|
||||||
ic_msg,
|
|
||||||
instruction::{Instruction, InstructionError},
|
instruction::{Instruction, InstructionError},
|
||||||
keyed_account::keyed_account_at_index,
|
keyed_account::keyed_account_at_index,
|
||||||
message::Message,
|
message::Message,
|
||||||
process_instruction::{Executor, InvokeContext, ProcessInstructionWithContext},
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
system_instruction::MAX_PERMITTED_DATA_LENGTH,
|
system_instruction::MAX_PERMITTED_DATA_LENGTH,
|
||||||
|
@ -18,10 +20,23 @@ use solana_sdk::{
|
||||||
use std::{
|
use std::{
|
||||||
cell::{Ref, RefCell, RefMut},
|
cell::{Ref, RefCell, RefMut},
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
fmt::Debug,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Program executor
|
||||||
|
pub trait Executor: Debug + Send + Sync {
|
||||||
|
/// Execute the program
|
||||||
|
fn execute(
|
||||||
|
&self,
|
||||||
|
first_instruction_account: usize,
|
||||||
|
instruction_data: &[u8],
|
||||||
|
invoke_context: &mut dyn InvokeContext,
|
||||||
|
use_jit: bool,
|
||||||
|
) -> Result<(), InstructionError>;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Executors {
|
pub struct Executors {
|
||||||
pub executors: HashMap<Pubkey, Arc<dyn Executor>>,
|
pub executors: HashMap<Pubkey, Arc<dyn Executor>>,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
instruction_processor::{ExecuteDetailsTimings, Executors, PreAccount},
|
ic_logger_msg, ic_msg,
|
||||||
|
instruction_processor::{ExecuteDetailsTimings, Executor, Executors, PreAccount},
|
||||||
instruction_recorder::InstructionRecorder,
|
instruction_recorder::InstructionRecorder,
|
||||||
log_collector::LogCollector,
|
log_collector::LogCollector,
|
||||||
};
|
};
|
||||||
|
@ -12,19 +13,23 @@ use solana_sdk::{
|
||||||
remove_native_loader, requestable_heap_size, tx_wide_compute_cap, FeatureSet,
|
remove_native_loader, requestable_heap_size, tx_wide_compute_cap, FeatureSet,
|
||||||
},
|
},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
ic_logger_msg, ic_msg,
|
|
||||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||||
keyed_account::{create_keyed_accounts_unified, KeyedAccount},
|
keyed_account::{create_keyed_accounts_unified, KeyedAccount},
|
||||||
message::Message,
|
message::Message,
|
||||||
process_instruction::{
|
|
||||||
ComputeMeter, Executor, InvokeContext, Logger, ProcessInstructionWithContext,
|
|
||||||
},
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
sysvar::Sysvar,
|
sysvar::Sysvar,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
use std::{cell::RefCell, rc::Rc, sync::Arc};
|
||||||
|
|
||||||
|
/// Compute meter
|
||||||
|
pub trait ComputeMeter {
|
||||||
|
/// Consume compute units
|
||||||
|
fn consume(&mut self, amount: u64) -> Result<(), InstructionError>;
|
||||||
|
/// Get the number of remaining compute units
|
||||||
|
fn get_remaining(&self) -> u64;
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ThisComputeMeter {
|
pub struct ThisComputeMeter {
|
||||||
remaining: u64,
|
remaining: u64,
|
||||||
}
|
}
|
||||||
|
@ -47,6 +52,17 @@ impl ThisComputeMeter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Log messages
|
||||||
|
pub trait Logger {
|
||||||
|
fn log_enabled(&self) -> bool;
|
||||||
|
|
||||||
|
/// Log a message.
|
||||||
|
///
|
||||||
|
/// Unless explicitly stated, log messages are not considered stable and may change in the
|
||||||
|
/// future as necessary
|
||||||
|
fn log(&self, message: &str);
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ThisLogger {
|
pub struct ThisLogger {
|
||||||
log_collector: Option<Rc<LogCollector>>,
|
log_collector: Option<Rc<LogCollector>>,
|
||||||
}
|
}
|
||||||
|
@ -67,6 +83,36 @@ impl ThisLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience macro to log a message with an `Rc<RefCell<dyn Logger>>`
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_logger_msg {
|
||||||
|
($logger:expr, $message:expr) => {
|
||||||
|
if let Ok(logger) = $logger.try_borrow_mut() {
|
||||||
|
if logger.log_enabled() {
|
||||||
|
logger.log($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
($logger:expr, $fmt:expr, $($arg:tt)*) => {
|
||||||
|
if let Ok(logger) = $logger.try_borrow_mut() {
|
||||||
|
if logger.log_enabled() {
|
||||||
|
logger.log(&format!($fmt, $($arg)*));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience macro to log a message with an `InvokeContext`
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! ic_msg {
|
||||||
|
($invoke_context:expr, $message:expr) => {
|
||||||
|
$crate::ic_logger_msg!($invoke_context.get_logger(), $message)
|
||||||
|
};
|
||||||
|
($invoke_context:expr, $fmt:expr, $($arg:tt)*) => {
|
||||||
|
$crate::ic_logger_msg!($invoke_context.get_logger(), $fmt, $($arg)*)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub struct InvokeContextStackFrame<'a> {
|
pub struct InvokeContextStackFrame<'a> {
|
||||||
pub number_of_program_accounts: usize,
|
pub number_of_program_accounts: usize,
|
||||||
pub keyed_accounts: Vec<KeyedAccount<'a>>,
|
pub keyed_accounts: Vec<KeyedAccount<'a>>,
|
||||||
|
@ -185,6 +231,90 @@ impl<'a> ThisInvokeContext<'a> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Invocation context passed to loaders
|
||||||
|
pub trait InvokeContext {
|
||||||
|
/// Push a stack frame onto the invocation stack
|
||||||
|
fn push(
|
||||||
|
&mut self,
|
||||||
|
message: &Message,
|
||||||
|
instruction: &CompiledInstruction,
|
||||||
|
program_indices: &[usize],
|
||||||
|
account_indices: Option<&[usize]>,
|
||||||
|
) -> Result<(), InstructionError>;
|
||||||
|
/// Pop a stack frame from the invocation stack
|
||||||
|
fn pop(&mut self);
|
||||||
|
/// Current depth of the invocation stake
|
||||||
|
fn invoke_depth(&self) -> usize;
|
||||||
|
/// Verify the results of an instruction
|
||||||
|
fn verify(
|
||||||
|
&mut self,
|
||||||
|
message: &Message,
|
||||||
|
instruction: &CompiledInstruction,
|
||||||
|
program_indices: &[usize],
|
||||||
|
) -> Result<(), InstructionError>;
|
||||||
|
/// Verify and update PreAccount state based on program execution
|
||||||
|
fn verify_and_update(
|
||||||
|
&mut self,
|
||||||
|
instruction: &CompiledInstruction,
|
||||||
|
account_indices: &[usize],
|
||||||
|
write_privileges: &[bool],
|
||||||
|
) -> Result<(), InstructionError>;
|
||||||
|
/// Get the program ID of the currently executing program
|
||||||
|
fn get_caller(&self) -> Result<&Pubkey, InstructionError>;
|
||||||
|
/// Removes the first keyed account
|
||||||
|
#[deprecated(
|
||||||
|
since = "1.9.0",
|
||||||
|
note = "To be removed together with remove_native_loader"
|
||||||
|
)]
|
||||||
|
fn remove_first_keyed_account(&mut self) -> Result<(), InstructionError>;
|
||||||
|
/// Get the list of keyed accounts
|
||||||
|
fn get_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError>;
|
||||||
|
/// Get a list of built-in programs
|
||||||
|
fn get_programs(&self) -> &[(Pubkey, ProcessInstructionWithContext)];
|
||||||
|
/// Get this invocation's logger
|
||||||
|
fn get_logger(&self) -> Rc<RefCell<dyn Logger>>;
|
||||||
|
/// Get this invocation's compute meter
|
||||||
|
fn get_compute_meter(&self) -> Rc<RefCell<dyn ComputeMeter>>;
|
||||||
|
/// Loaders may need to do work in order to execute a program. Cache
|
||||||
|
/// the work that can be re-used across executions
|
||||||
|
fn add_executor(&self, pubkey: &Pubkey, executor: Arc<dyn Executor>);
|
||||||
|
/// Get the completed loader work that can be re-used across executions
|
||||||
|
fn get_executor(&self, pubkey: &Pubkey) -> Option<Arc<dyn Executor>>;
|
||||||
|
/// Set which instruction in the message is currently being recorded
|
||||||
|
fn set_instruction_index(&mut self, instruction_index: usize);
|
||||||
|
/// Record invoked instruction
|
||||||
|
fn record_instruction(&self, instruction: &Instruction);
|
||||||
|
/// Get the bank's active feature set
|
||||||
|
fn is_feature_active(&self, feature_id: &Pubkey) -> bool;
|
||||||
|
/// Find an account_index and account by its key
|
||||||
|
fn get_account(&self, pubkey: &Pubkey) -> Option<(usize, Rc<RefCell<AccountSharedData>>)>;
|
||||||
|
/// Update timing
|
||||||
|
fn update_timing(
|
||||||
|
&mut self,
|
||||||
|
serialize_us: u64,
|
||||||
|
create_vm_us: u64,
|
||||||
|
execute_us: u64,
|
||||||
|
deserialize_us: u64,
|
||||||
|
);
|
||||||
|
/// Get sysvars
|
||||||
|
fn get_sysvars(&self) -> &[(Pubkey, Vec<u8>)];
|
||||||
|
/// Get this invocation's compute budget
|
||||||
|
fn get_compute_budget(&self) -> &ComputeBudget;
|
||||||
|
/// Set this invocation's blockhash
|
||||||
|
fn set_blockhash(&mut self, hash: Hash);
|
||||||
|
/// Get this invocation's blockhash
|
||||||
|
fn get_blockhash(&self) -> &Hash;
|
||||||
|
/// Set this invocation's lamports_per_signature value
|
||||||
|
fn set_lamports_per_signature(&mut self, lamports_per_signature: u64);
|
||||||
|
/// Get this invocation's lamports_per_signature value
|
||||||
|
fn get_lamports_per_signature(&self) -> u64;
|
||||||
|
/// Set the return data
|
||||||
|
fn set_return_data(&mut self, data: Vec<u8>) -> Result<(), InstructionError>;
|
||||||
|
/// Get the return data
|
||||||
|
fn get_return_data(&self) -> (Pubkey, &[u8]);
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
||||||
fn push(
|
fn push(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -552,6 +682,9 @@ pub fn get_sysvar<T: Sysvar>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type ProcessInstructionWithContext =
|
||||||
|
fn(usize, &[u8], &mut dyn InvokeContext) -> Result<(), InstructionError>;
|
||||||
|
|
||||||
pub struct MockInvokeContextPreparation {
|
pub struct MockInvokeContextPreparation {
|
||||||
pub accounts: Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>,
|
pub accounts: Vec<(Pubkey, Rc<RefCell<AccountSharedData>>)>,
|
||||||
pub message: Message,
|
pub message: Message,
|
||||||
|
|
|
@ -6,3 +6,4 @@ pub mod invoke_context;
|
||||||
pub mod log_collector;
|
pub mod log_collector;
|
||||||
pub mod native_loader;
|
pub mod native_loader;
|
||||||
pub mod neon_evm_program;
|
pub mod neon_evm_program;
|
||||||
|
pub mod stable_log;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! Native loader
|
//! Native loader
|
||||||
|
use crate::invoke_context::InvokeContext;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use libloading::os::unix::*;
|
use libloading::os::unix::*;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -12,7 +13,6 @@ use solana_sdk::{
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
keyed_account::{keyed_account_at_index, KeyedAccount},
|
keyed_account::{keyed_account_at_index, KeyedAccount},
|
||||||
native_loader,
|
native_loader,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
//! Stable program log messages
|
||||||
|
//!
|
||||||
|
//! The format of these log messages should not be modified to avoid breaking downstream consumers
|
||||||
|
//! of program logging
|
||||||
|
use crate::{ic_logger_msg, invoke_context::Logger};
|
||||||
|
use itertools::Itertools;
|
||||||
|
use solana_sdk::{instruction::InstructionError, pubkey::Pubkey};
|
||||||
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
|
/// Log a program invoke.
|
||||||
|
///
|
||||||
|
/// The general form is:
|
||||||
|
///
|
||||||
|
/// ```notrust
|
||||||
|
/// "Program <address> invoke [<depth>]"
|
||||||
|
/// ```
|
||||||
|
pub fn program_invoke(logger: &Rc<RefCell<dyn Logger>>, program_id: &Pubkey, invoke_depth: usize) {
|
||||||
|
ic_logger_msg!(logger, "Program {} invoke [{}]", program_id, invoke_depth);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Log a message from the program itself.
|
||||||
|
///
|
||||||
|
/// The general form is:
|
||||||
|
///
|
||||||
|
/// ```notrust
|
||||||
|
/// "Program log: <program-generated output>"
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// That is, any program-generated output is guaranteed to be prefixed by "Program log: "
|
||||||
|
pub fn program_log(logger: &Rc<RefCell<dyn Logger>>, message: &str) {
|
||||||
|
ic_logger_msg!(logger, "Program log: {}", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Emit a program data.
|
||||||
|
///
|
||||||
|
/// The general form is:
|
||||||
|
///
|
||||||
|
/// ```notrust
|
||||||
|
/// "Program data: <binary-data-in-base64>*"
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// That is, any program-generated output is guaranteed to be prefixed by "Program data: "
|
||||||
|
pub fn program_data(logger: &Rc<RefCell<dyn Logger>>, data: &[&[u8]]) {
|
||||||
|
ic_logger_msg!(
|
||||||
|
logger,
|
||||||
|
"Program data: {}",
|
||||||
|
data.iter().map(base64::encode).join(" ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Log return data as from the program itself. This line will not be present if no return
|
||||||
|
/// data was set, or if the return data was set to zero length.
|
||||||
|
///
|
||||||
|
/// The general form is:
|
||||||
|
///
|
||||||
|
/// ```notrust
|
||||||
|
/// "Program return: <program-id> <program-generated-data-in-base64>"
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// That is, any program-generated output is guaranteed to be prefixed by "Program return: "
|
||||||
|
pub fn program_return(logger: &Rc<RefCell<dyn Logger>>, program_id: &Pubkey, data: &[u8]) {
|
||||||
|
ic_logger_msg!(
|
||||||
|
logger,
|
||||||
|
"Program return: {} {}",
|
||||||
|
program_id,
|
||||||
|
base64::encode(data)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Log successful program execution.
|
||||||
|
///
|
||||||
|
/// The general form is:
|
||||||
|
///
|
||||||
|
/// ```notrust
|
||||||
|
/// "Program <address> success"
|
||||||
|
/// ```
|
||||||
|
pub fn program_success(logger: &Rc<RefCell<dyn Logger>>, program_id: &Pubkey) {
|
||||||
|
ic_logger_msg!(logger, "Program {} success", program_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Log program execution failure
|
||||||
|
///
|
||||||
|
/// The general form is:
|
||||||
|
///
|
||||||
|
/// ```notrust
|
||||||
|
/// "Program <address> failed: <program error details>"
|
||||||
|
/// ```
|
||||||
|
pub fn program_failure(
|
||||||
|
logger: &Rc<RefCell<dyn Logger>>,
|
||||||
|
program_id: &Pubkey,
|
||||||
|
err: &InstructionError,
|
||||||
|
) {
|
||||||
|
ic_logger_msg!(logger, "Program {} failed: {}", program_id, err);
|
||||||
|
}
|
|
@ -9,7 +9,10 @@ use {
|
||||||
log::*,
|
log::*,
|
||||||
solana_banks_client::start_client,
|
solana_banks_client::start_client,
|
||||||
solana_banks_server::banks_server::start_local_server,
|
solana_banks_server::banks_server::start_local_server,
|
||||||
solana_program_runtime::instruction_processor::InstructionProcessor,
|
solana_program_runtime::{
|
||||||
|
instruction_processor::InstructionProcessor, invoke_context::ProcessInstructionWithContext,
|
||||||
|
stable_log,
|
||||||
|
},
|
||||||
solana_runtime::{
|
solana_runtime::{
|
||||||
bank::{Bank, ExecuteTimings},
|
bank::{Bank, ExecuteTimings},
|
||||||
bank_forks::BankForks,
|
bank_forks::BankForks,
|
||||||
|
@ -33,7 +36,6 @@ use {
|
||||||
message::Message,
|
message::Message,
|
||||||
native_token::sol_to_lamports,
|
native_token::sol_to_lamports,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
process_instruction::{stable_log, InvokeContext, ProcessInstructionWithContext},
|
|
||||||
program_error::{ProgramError, ACCOUNT_BORROW_FAILED, UNSUPPORTED_SYSVAR},
|
program_error::{ProgramError, ACCOUNT_BORROW_FAILED, UNSUPPORTED_SYSVAR},
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
@ -66,6 +68,7 @@ use {
|
||||||
|
|
||||||
// Export types so test clients can limit their solana crate dependencies
|
// Export types so test clients can limit their solana crate dependencies
|
||||||
pub use solana_banks_client::BanksClient;
|
pub use solana_banks_client::BanksClient;
|
||||||
|
pub use solana_program_runtime::invoke_context::InvokeContext;
|
||||||
|
|
||||||
// Export tokio for test clients
|
// Export tokio for test clients
|
||||||
pub use tokio;
|
pub use tokio;
|
||||||
|
@ -187,7 +190,7 @@ macro_rules! processor {
|
||||||
Some(
|
Some(
|
||||||
|first_instruction_account: usize,
|
|first_instruction_account: usize,
|
||||||
input: &[u8],
|
input: &[u8],
|
||||||
invoke_context: &mut dyn solana_sdk::process_instruction::InvokeContext| {
|
invoke_context: &mut dyn solana_program_test::InvokeContext| {
|
||||||
$crate::builtin_process_instruction(
|
$crate::builtin_process_instruction(
|
||||||
$process_instruction,
|
$process_instruction,
|
||||||
first_instruction_account,
|
first_instruction_account,
|
||||||
|
|
|
@ -2795,6 +2795,7 @@ name = "solana-bpf-rust-mem"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"solana-program 1.9.0",
|
"solana-program 1.9.0",
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-program-test",
|
"solana-program-test",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
@ -2879,6 +2880,7 @@ name = "solana-bpf-rust-sanity"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"solana-program 1.9.0",
|
"solana-program 1.9.0",
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-program-test",
|
"solana-program-test",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
@ -2917,6 +2919,7 @@ name = "solana-bpf-rust-sysvar"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"solana-program 1.9.0",
|
"solana-program 1.9.0",
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-program-test",
|
"solana-program-test",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
@ -3036,6 +3039,7 @@ dependencies = [
|
||||||
name = "solana-compute-budget-program"
|
name = "solana-compute-budget-program"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3047,6 +3051,7 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3310,7 +3315,9 @@ dependencies = [
|
||||||
name = "solana-program-runtime"
|
name = "solana-program-runtime"
|
||||||
version = "1.9.0"
|
version = "1.9.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64 0.13.0",
|
||||||
"bincode",
|
"bincode",
|
||||||
|
"itertools 0.10.1",
|
||||||
"libc",
|
"libc",
|
||||||
"libloading",
|
"libloading",
|
||||||
"log",
|
"log",
|
||||||
|
@ -3578,6 +3585,7 @@ dependencies = [
|
||||||
"solana-frozen-abi-macro 1.9.0",
|
"solana-frozen-abi-macro 1.9.0",
|
||||||
"solana-logger 1.9.0",
|
"solana-logger 1.9.0",
|
||||||
"solana-metrics",
|
"solana-metrics",
|
||||||
|
"solana-program-runtime",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
|
@ -18,14 +18,13 @@ use solana_runtime::{
|
||||||
genesis_utils::{create_genesis_config, GenesisConfigInfo},
|
genesis_utils::{create_genesis_config, GenesisConfigInfo},
|
||||||
loader_utils::load_program,
|
loader_utils::load_program,
|
||||||
};
|
};
|
||||||
use solana_program_runtime::invoke_context::with_mock_invoke_context;
|
use solana_program_runtime::invoke_context::{with_mock_invoke_context, InvokeContext};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
bpf_loader,
|
bpf_loader,
|
||||||
client::SyncClient,
|
client::SyncClient,
|
||||||
entrypoint::SUCCESS,
|
entrypoint::SUCCESS,
|
||||||
instruction::{AccountMeta, Instruction},
|
instruction::{AccountMeta, Instruction},
|
||||||
message::Message,
|
message::Message,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,7 @@ no-entrypoint = []
|
||||||
solana-program = { path = "../../../../sdk/program", version = "=1.9.0" }
|
solana-program = { path = "../../../../sdk/program", version = "=1.9.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
solana-program-runtime = { path = "../../../../program-runtime", version = "=1.9.0" }
|
||||||
solana-program-test = { path = "../../../../program-test", version = "=1.9.0" }
|
solana-program-test = { path = "../../../../program-test", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../../../sdk", version = "=1.9.0" }
|
solana-sdk = { path = "../../../../sdk", version = "=1.9.0" }
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ test-bpf = []
|
||||||
solana-program = { path = "../../../../sdk/program", version = "=1.9.0" }
|
solana-program = { path = "../../../../sdk/program", version = "=1.9.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
solana-program-runtime = { path = "../../../../program-runtime", version = "=1.9.0" }
|
||||||
solana-program-test = { path = "../../../../program-test", version = "=1.9.0" }
|
solana-program-test = { path = "../../../../program-test", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../../../sdk", version = "=1.9.0" }
|
solana-sdk = { path = "../../../../sdk", version = "=1.9.0" }
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ edition = "2018"
|
||||||
solana-program = { path = "../../../../sdk/program", version = "=1.9.0" }
|
solana-program = { path = "../../../../sdk/program", version = "=1.9.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
solana-program-runtime = { path = "../../../../program-runtime", version = "=1.9.0" }
|
||||||
solana-program-test = { path = "../../../../program-test", version = "=1.9.0" }
|
solana-program-test = { path = "../../../../program-test", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../../../sdk", version = "=1.9.0" }
|
solana-sdk = { path = "../../../../sdk", version = "=1.9.0" }
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ use solana_runtime::{
|
||||||
upgrade_program,
|
upgrade_program,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use solana_program_runtime::invoke_context::with_mock_invoke_context;
|
use solana_program_runtime::invoke_context::{with_mock_invoke_context, InvokeContext};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount},
|
account::{AccountSharedData, ReadableAccount},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
|
@ -43,7 +43,6 @@ use solana_sdk::{
|
||||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||||
loader_instruction,
|
loader_instruction,
|
||||||
message::{Message, SanitizedMessage},
|
message::{Message, SanitizedMessage},
|
||||||
process_instruction::InvokeContext,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{keypair_from_seed, Keypair, Signer},
|
signature::{keypair_from_seed, Keypair, Signer},
|
||||||
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
||||||
|
|
|
@ -14,7 +14,12 @@ use crate::{
|
||||||
};
|
};
|
||||||
use log::{log_enabled, trace, Level::Trace};
|
use log::{log_enabled, trace, Level::Trace};
|
||||||
use solana_measure::measure::Measure;
|
use solana_measure::measure::Measure;
|
||||||
use solana_program_runtime::instruction_processor::InstructionProcessor;
|
use solana_program_runtime::{
|
||||||
|
ic_logger_msg, ic_msg,
|
||||||
|
instruction_processor::{Executor, InstructionProcessor},
|
||||||
|
invoke_context::{ComputeMeter, InvokeContext, Logger},
|
||||||
|
stable_log,
|
||||||
|
};
|
||||||
use solana_rbpf::{
|
use solana_rbpf::{
|
||||||
aligned_memory::AlignedMemory,
|
aligned_memory::AlignedMemory,
|
||||||
ebpf::HOST_ALIGN,
|
ebpf::HOST_ALIGN,
|
||||||
|
@ -35,12 +40,10 @@ use solana_sdk::{
|
||||||
reject_deployment_of_unresolved_syscalls, requestable_heap_size,
|
reject_deployment_of_unresolved_syscalls, requestable_heap_size,
|
||||||
stop_verify_mul64_imm_nonzero,
|
stop_verify_mul64_imm_nonzero,
|
||||||
},
|
},
|
||||||
ic_logger_msg, ic_msg,
|
|
||||||
instruction::{AccountMeta, InstructionError},
|
instruction::{AccountMeta, InstructionError},
|
||||||
keyed_account::{from_keyed_account, keyed_account_at_index, KeyedAccount},
|
keyed_account::{from_keyed_account, keyed_account_at_index, KeyedAccount},
|
||||||
loader_instruction::LoaderInstruction,
|
loader_instruction::LoaderInstruction,
|
||||||
loader_upgradeable_instruction::UpgradeableLoaderInstruction,
|
loader_upgradeable_instruction::UpgradeableLoaderInstruction,
|
||||||
process_instruction::{stable_log, ComputeMeter, Executor, InvokeContext, Logger},
|
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
|
|
@ -316,13 +316,14 @@ pub fn deserialize_parameters_aligned(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use solana_program_runtime::invoke_context::{prepare_mock_invoke_context, ThisInvokeContext};
|
use solana_program_runtime::invoke_context::{
|
||||||
|
prepare_mock_invoke_context, InvokeContext, ThisInvokeContext,
|
||||||
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{Account, AccountSharedData},
|
account::{Account, AccountSharedData},
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
bpf_loader,
|
bpf_loader,
|
||||||
entrypoint::deserialize,
|
entrypoint::deserialize,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
use crate::{alloc, BpfError};
|
use crate::{alloc, BpfError};
|
||||||
use alloc::Alloc;
|
use alloc::Alloc;
|
||||||
use solana_program_runtime::instruction_processor::InstructionProcessor;
|
use solana_program_runtime::{
|
||||||
|
ic_msg,
|
||||||
|
instruction_processor::InstructionProcessor,
|
||||||
|
invoke_context::{ComputeMeter, InvokeContext, Logger},
|
||||||
|
stable_log,
|
||||||
|
};
|
||||||
use solana_rbpf::{
|
use solana_rbpf::{
|
||||||
aligned_memory::AlignedMemory,
|
aligned_memory::AlignedMemory,
|
||||||
ebpf,
|
ebpf,
|
||||||
|
@ -25,13 +30,11 @@ use solana_sdk::{
|
||||||
secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled,
|
secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled,
|
||||||
},
|
},
|
||||||
hash::{Hasher, HASH_BYTES},
|
hash::{Hasher, HASH_BYTES},
|
||||||
ic_msg,
|
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
keccak,
|
keccak,
|
||||||
message::Message,
|
message::Message,
|
||||||
native_loader,
|
native_loader,
|
||||||
precompiles::is_precompile,
|
precompiles::is_precompile,
|
||||||
process_instruction::{stable_log, ComputeMeter, InvokeContext, Logger},
|
|
||||||
program::MAX_RETURN_DATA,
|
program::MAX_RETURN_DATA,
|
||||||
pubkey::{Pubkey, PubkeyError, MAX_SEEDS, MAX_SEED_LEN},
|
pubkey::{Pubkey, PubkeyError, MAX_SEEDS, MAX_SEED_LEN},
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
|
|
@ -10,6 +10,7 @@ license = "Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use solana_sdk::{instruction::InstructionError, process_instruction::InvokeContext};
|
use solana_program_runtime::invoke_context::InvokeContext;
|
||||||
|
use solana_sdk::instruction::InstructionError;
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
_first_instruction_account: usize,
|
_first_instruction_account: usize,
|
||||||
|
|
|
@ -14,11 +14,11 @@ bincode = "1.3.3"
|
||||||
chrono = { version = "0.4.11", features = ["serde"] }
|
chrono = { version = "0.4.11", features = ["serde"] }
|
||||||
serde = "1.0.130"
|
serde = "1.0.130"
|
||||||
serde_derive = "1.0.103"
|
serde_derive = "1.0.103"
|
||||||
|
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
solana-logger = { path = "../../logger", version = "=1.9.0" }
|
solana-logger = { path = "../../logger", version = "=1.9.0" }
|
||||||
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["lib"]
|
crate-type = ["lib"]
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
use crate::ConfigKeys;
|
use crate::ConfigKeys;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
|
use solana_program_runtime::{ic_msg, invoke_context::InvokeContext};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{ReadableAccount, WritableAccount},
|
account::{ReadableAccount, WritableAccount},
|
||||||
feature_set, ic_msg,
|
feature_set,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
keyed_account::keyed_account_at_index,
|
keyed_account::keyed_account_at_index,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,8 +19,8 @@ serde_derive = "1.0.103"
|
||||||
solana-frozen-abi = { path = "../../frozen-abi", version = "=1.9.0" }
|
solana-frozen-abi = { path = "../../frozen-abi", version = "=1.9.0" }
|
||||||
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.9.0" }
|
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.9.0" }
|
||||||
solana-metrics = { path = "../../metrics", version = "=1.9.0" }
|
solana-metrics = { path = "../../metrics", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
|
||||||
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
||||||
|
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
||||||
solana-vote-program = { path = "../vote", version = "=1.9.0" }
|
solana-vote-program = { path = "../vote", version = "=1.9.0" }
|
||||||
solana-config-program = { path = "../config", version = "=1.9.0" }
|
solana-config-program = { path = "../config", version = "=1.9.0" }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use {
|
use {
|
||||||
crate::{config, stake_state::StakeAccount},
|
crate::{config, stake_state::StakeAccount},
|
||||||
log::*,
|
log::*,
|
||||||
solana_program_runtime::invoke_context::get_sysvar,
|
solana_program_runtime::invoke_context::{get_sysvar, InvokeContext},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
feature_set,
|
feature_set,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index},
|
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index},
|
||||||
process_instruction::InvokeContext,
|
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
stake::{
|
stake::{
|
||||||
instruction::StakeInstruction,
|
instruction::StakeInstruction,
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
//! * own mining pools
|
//! * own mining pools
|
||||||
|
|
||||||
use {
|
use {
|
||||||
|
solana_program_runtime::{ic_msg, invoke_context::InvokeContext},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
account_utils::{State, StateMut},
|
account_utils::{State, StateMut},
|
||||||
clock::{Clock, Epoch},
|
clock::{Clock, Epoch},
|
||||||
feature_set::stake_merge_with_unmatched_credits_observed,
|
feature_set::stake_merge_with_unmatched_credits_observed,
|
||||||
ic_msg,
|
|
||||||
instruction::{checked_add, InstructionError},
|
instruction::{checked_add, InstructionError},
|
||||||
keyed_account::KeyedAccount,
|
keyed_account::KeyedAccount,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::{Rent, ACCOUNT_STORAGE_OVERHEAD},
|
rent::{Rent, ACCOUNT_STORAGE_OVERHEAD},
|
||||||
stake::{
|
stake::{
|
||||||
|
|
|
@ -20,12 +20,10 @@ solana-frozen-abi = { path = "../../frozen-abi", version = "=1.9.0" }
|
||||||
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.9.0" }
|
solana-frozen-abi-macro = { path = "../../frozen-abi/macro", version = "=1.9.0" }
|
||||||
solana-logger = { path = "../../logger", version = "=1.9.0" }
|
solana-logger = { path = "../../logger", version = "=1.9.0" }
|
||||||
solana-metrics = { path = "../../metrics", version = "=1.9.0" }
|
solana-metrics = { path = "../../metrics", version = "=1.9.0" }
|
||||||
|
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
||||||
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
solana-sdk = { path = "../../sdk", version = "=1.9.0" }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
solana-program-runtime = { path = "../../program-runtime", version = "=1.9.0" }
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
rustc_version = "0.4"
|
rustc_version = "0.4"
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,13 @@ use log::*;
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_metrics::inc_new_counter_info;
|
use solana_metrics::inc_new_counter_info;
|
||||||
|
use solana_program_runtime::invoke_context::InvokeContext;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
decode_error::DecodeError,
|
decode_error::DecodeError,
|
||||||
feature_set,
|
feature_set,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index, KeyedAccount},
|
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index, KeyedAccount},
|
||||||
process_instruction::InvokeContext,
|
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction,
|
system_instruction,
|
||||||
|
|
|
@ -5,16 +5,16 @@ use solana_bpf_loader_program::{
|
||||||
create_vm, serialization::serialize_parameters, syscalls::register_syscalls, BpfError,
|
create_vm, serialization::serialize_parameters, syscalls::register_syscalls, BpfError,
|
||||||
ThisInstructionMeter,
|
ThisInstructionMeter,
|
||||||
};
|
};
|
||||||
use solana_program_runtime::invoke_context::{prepare_mock_invoke_context, ThisInvokeContext};
|
use solana_program_runtime::invoke_context::{
|
||||||
|
prepare_mock_invoke_context, InvokeContext, ThisInvokeContext,
|
||||||
|
};
|
||||||
use solana_rbpf::{
|
use solana_rbpf::{
|
||||||
assembler::assemble,
|
assembler::assemble,
|
||||||
static_analysis::Analysis,
|
static_analysis::Analysis,
|
||||||
verifier::check,
|
verifier::check,
|
||||||
vm::{Config, DynamicAnalysis, Executable},
|
vm::{Config, DynamicAnalysis, Executable},
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{account::AccountSharedData, bpf_loader, pubkey::Pubkey};
|
||||||
account::AccountSharedData, bpf_loader, process_instruction::InvokeContext, pubkey::Pubkey,
|
|
||||||
};
|
|
||||||
use std::{fs::File, io::Read, io::Seek, io::SeekFrom, path::Path};
|
use std::{fs::File, io::Read, io::Seek, io::SeekFrom, path::Path};
|
||||||
use time::Instant;
|
use time::Instant;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use solana_program_runtime::invoke_context::InvokeContext;
|
||||||
use solana_runtime::{bank::*, bank_client::BankClient, loader_utils::create_invoke_instruction};
|
use solana_runtime::{bank::*, bank_client::BankClient, loader_utils::create_invoke_instruction};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
client::AsyncClient,
|
client::AsyncClient,
|
||||||
|
@ -12,7 +13,6 @@ use solana_sdk::{
|
||||||
genesis_config::create_genesis_config,
|
genesis_config::create_genesis_config,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
message::Message,
|
message::Message,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
transaction::Transaction,
|
transaction::Transaction,
|
||||||
|
|
|
@ -70,8 +70,9 @@ use rayon::{
|
||||||
use solana_measure::measure::Measure;
|
use solana_measure::measure::Measure;
|
||||||
use solana_metrics::{inc_new_counter_debug, inc_new_counter_info};
|
use solana_metrics::{inc_new_counter_debug, inc_new_counter_info};
|
||||||
use solana_program_runtime::{
|
use solana_program_runtime::{
|
||||||
instruction_processor::{ExecuteDetailsTimings, Executors, InstructionProcessor},
|
instruction_processor::{ExecuteDetailsTimings, Executor, Executors, InstructionProcessor},
|
||||||
instruction_recorder::InstructionRecorder,
|
instruction_recorder::InstructionRecorder,
|
||||||
|
invoke_context::{ComputeMeter, ProcessInstructionWithContext},
|
||||||
log_collector::LogCollector,
|
log_collector::LogCollector,
|
||||||
};
|
};
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
|
@ -109,7 +110,6 @@ use solana_sdk::{
|
||||||
nonce, nonce_account,
|
nonce, nonce_account,
|
||||||
packet::PACKET_DATA_SIZE,
|
packet::PACKET_DATA_SIZE,
|
||||||
precompiles::get_precompiles,
|
precompiles::get_precompiles,
|
||||||
process_instruction::{ComputeMeter, Executor, ProcessInstructionWithContext},
|
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
secp256k1_program,
|
secp256k1_program,
|
||||||
|
@ -6469,6 +6469,7 @@ pub(crate) mod tests {
|
||||||
status_cache::MAX_CACHE_ENTRIES,
|
status_cache::MAX_CACHE_ENTRIES,
|
||||||
};
|
};
|
||||||
use crossbeam_channel::{bounded, unbounded};
|
use crossbeam_channel::{bounded, unbounded};
|
||||||
|
use solana_program_runtime::invoke_context::InvokeContext;
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
use solana_sdk::sysvar::fees::Fees;
|
use solana_sdk::sysvar::fees::Fees;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
@ -6484,7 +6485,6 @@ pub(crate) mod tests {
|
||||||
message::{Message, MessageHeader},
|
message::{Message, MessageHeader},
|
||||||
nonce,
|
nonce,
|
||||||
poh_config::PohConfig,
|
poh_config::PohConfig,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
signature::{keypair_from_seed, Keypair, Signer},
|
signature::{keypair_from_seed, Keypair, Signer},
|
||||||
stake::{
|
stake::{
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::system_instruction_processor;
|
use crate::system_instruction_processor;
|
||||||
|
use solana_program_runtime::{
|
||||||
|
invoke_context::{InvokeContext, ProcessInstructionWithContext},
|
||||||
|
stable_log,
|
||||||
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
feature_set,
|
feature_set, instruction::InstructionError, pubkey::Pubkey, stake, system_program,
|
||||||
instruction::InstructionError,
|
|
||||||
process_instruction::{stable_log, InvokeContext, ProcessInstructionWithContext},
|
|
||||||
pubkey::Pubkey,
|
|
||||||
stake, system_program,
|
|
||||||
};
|
};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use solana_measure::measure::Measure;
|
||||||
use solana_program_runtime::{
|
use solana_program_runtime::{
|
||||||
instruction_processor::{ExecuteDetailsTimings, Executors, InstructionProcessor},
|
instruction_processor::{ExecuteDetailsTimings, Executors, InstructionProcessor},
|
||||||
instruction_recorder::InstructionRecorder,
|
instruction_recorder::InstructionRecorder,
|
||||||
invoke_context::ThisInvokeContext,
|
invoke_context::{ComputeMeter, InvokeContext, ThisInvokeContext},
|
||||||
log_collector::LogCollector,
|
log_collector::LogCollector,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
@ -13,7 +13,6 @@ use solana_sdk::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
message::Message,
|
message::Message,
|
||||||
precompiles::is_precompile,
|
precompiles::is_precompile,
|
||||||
process_instruction::{ComputeMeter, InvokeContext},
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
sysvar::instructions,
|
sysvar::instructions,
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
use solana_program_runtime::{ic_msg, invoke_context::InvokeContext};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{ReadableAccount, WritableAccount},
|
account::{ReadableAccount, WritableAccount},
|
||||||
account_utils::State as AccountUtilsState,
|
account_utils::State as AccountUtilsState,
|
||||||
feature_set::{self, nonce_must_be_writable},
|
feature_set::{self, nonce_must_be_writable},
|
||||||
ic_msg,
|
|
||||||
instruction::{checked_add, InstructionError},
|
instruction::{checked_add, InstructionError},
|
||||||
keyed_account::KeyedAccount,
|
keyed_account::KeyedAccount,
|
||||||
nonce::{self, state::Versions, State},
|
nonce::{self, state::Versions, State},
|
||||||
process_instruction::InvokeContext,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction::{nonce_to_instruction_error, NonceError},
|
system_instruction::{nonce_to_instruction_error, NonceError},
|
||||||
sysvar::rent::Rent,
|
sysvar::rent::Rent,
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::nonce_keyed_account::NonceKeyedAccount;
|
use crate::nonce_keyed_account::NonceKeyedAccount;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use solana_program_runtime::{ic_msg, invoke_context::InvokeContext};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
feature_set, ic_msg,
|
feature_set,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index, KeyedAccount},
|
keyed_account::{from_keyed_account, get_signers, keyed_account_at_index, KeyedAccount},
|
||||||
nonce,
|
nonce,
|
||||||
process_instruction::InvokeContext,
|
|
||||||
program_utils::limited_deserialize,
|
program_utils::limited_deserialize,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_instruction::{NonceError, SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
system_instruction::{NonceError, SystemError, SystemInstruction, MAX_PERMITTED_DATA_LENGTH},
|
||||||
|
|
|
@ -35,7 +35,6 @@ pub mod nonce_account;
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
pub mod poh_config;
|
pub mod poh_config;
|
||||||
pub mod precompiles;
|
pub mod precompiles;
|
||||||
pub mod process_instruction;
|
|
||||||
pub mod program_utils;
|
pub mod program_utils;
|
||||||
pub mod pubkey;
|
pub mod pubkey;
|
||||||
pub mod recent_blockhashes_account;
|
pub mod recent_blockhashes_account;
|
||||||
|
|
|
@ -1,260 +0,0 @@
|
||||||
#![cfg(feature = "full")]
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
|
||||||
use solana_sdk::{
|
|
||||||
account::AccountSharedData,
|
|
||||||
compute_budget::ComputeBudget,
|
|
||||||
hash::Hash,
|
|
||||||
instruction::{CompiledInstruction, Instruction, InstructionError},
|
|
||||||
keyed_account::KeyedAccount,
|
|
||||||
message::Message,
|
|
||||||
pubkey::Pubkey,
|
|
||||||
};
|
|
||||||
use std::{cell::RefCell, fmt::Debug, rc::Rc, sync::Arc};
|
|
||||||
|
|
||||||
pub type ProcessInstructionWithContext =
|
|
||||||
fn(usize, &[u8], &mut dyn InvokeContext) -> Result<(), InstructionError>;
|
|
||||||
|
|
||||||
/// Invocation context passed to loaders
|
|
||||||
pub trait InvokeContext {
|
|
||||||
/// Push a stack frame onto the invocation stack
|
|
||||||
fn push(
|
|
||||||
&mut self,
|
|
||||||
message: &Message,
|
|
||||||
instruction: &CompiledInstruction,
|
|
||||||
program_indices: &[usize],
|
|
||||||
account_indices: Option<&[usize]>,
|
|
||||||
) -> Result<(), InstructionError>;
|
|
||||||
/// Pop a stack frame from the invocation stack
|
|
||||||
fn pop(&mut self);
|
|
||||||
/// Current depth of the invocation stake
|
|
||||||
fn invoke_depth(&self) -> usize;
|
|
||||||
/// Verify the results of an instruction
|
|
||||||
fn verify(
|
|
||||||
&mut self,
|
|
||||||
message: &Message,
|
|
||||||
instruction: &CompiledInstruction,
|
|
||||||
program_indices: &[usize],
|
|
||||||
) -> Result<(), InstructionError>;
|
|
||||||
/// Verify and update PreAccount state based on program execution
|
|
||||||
fn verify_and_update(
|
|
||||||
&mut self,
|
|
||||||
instruction: &CompiledInstruction,
|
|
||||||
account_indices: &[usize],
|
|
||||||
write_privileges: &[bool],
|
|
||||||
) -> Result<(), InstructionError>;
|
|
||||||
/// Get the program ID of the currently executing program
|
|
||||||
fn get_caller(&self) -> Result<&Pubkey, InstructionError>;
|
|
||||||
/// Removes the first keyed account
|
|
||||||
#[deprecated(
|
|
||||||
since = "1.9.0",
|
|
||||||
note = "To be removed together with remove_native_loader"
|
|
||||||
)]
|
|
||||||
fn remove_first_keyed_account(&mut self) -> Result<(), InstructionError>;
|
|
||||||
/// Get the list of keyed accounts
|
|
||||||
fn get_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError>;
|
|
||||||
/// Get a list of built-in programs
|
|
||||||
fn get_programs(&self) -> &[(Pubkey, ProcessInstructionWithContext)];
|
|
||||||
/// Get this invocation's logger
|
|
||||||
fn get_logger(&self) -> Rc<RefCell<dyn Logger>>;
|
|
||||||
/// Get this invocation's compute meter
|
|
||||||
fn get_compute_meter(&self) -> Rc<RefCell<dyn ComputeMeter>>;
|
|
||||||
/// Loaders may need to do work in order to execute a program. Cache
|
|
||||||
/// the work that can be re-used across executions
|
|
||||||
fn add_executor(&self, pubkey: &Pubkey, executor: Arc<dyn Executor>);
|
|
||||||
/// Get the completed loader work that can be re-used across executions
|
|
||||||
fn get_executor(&self, pubkey: &Pubkey) -> Option<Arc<dyn Executor>>;
|
|
||||||
/// Set which instruction in the message is currently being recorded
|
|
||||||
fn set_instruction_index(&mut self, instruction_index: usize);
|
|
||||||
/// Record invoked instruction
|
|
||||||
fn record_instruction(&self, instruction: &Instruction);
|
|
||||||
/// Get the bank's active feature set
|
|
||||||
fn is_feature_active(&self, feature_id: &Pubkey) -> bool;
|
|
||||||
/// Find an account_index and account by its key
|
|
||||||
fn get_account(&self, pubkey: &Pubkey) -> Option<(usize, Rc<RefCell<AccountSharedData>>)>;
|
|
||||||
/// Update timing
|
|
||||||
fn update_timing(
|
|
||||||
&mut self,
|
|
||||||
serialize_us: u64,
|
|
||||||
create_vm_us: u64,
|
|
||||||
execute_us: u64,
|
|
||||||
deserialize_us: u64,
|
|
||||||
);
|
|
||||||
/// Get sysvars
|
|
||||||
fn get_sysvars(&self) -> &[(Pubkey, Vec<u8>)];
|
|
||||||
/// Get this invocation's compute budget
|
|
||||||
fn get_compute_budget(&self) -> &ComputeBudget;
|
|
||||||
/// Set this invocation's blockhash
|
|
||||||
fn set_blockhash(&mut self, hash: Hash);
|
|
||||||
/// Get this invocation's blockhash
|
|
||||||
fn get_blockhash(&self) -> &Hash;
|
|
||||||
/// Set this invocation's lamports_per_signature value
|
|
||||||
fn set_lamports_per_signature(&mut self, lamports_per_signature: u64);
|
|
||||||
/// Get this invocation's lamports_per_signature value
|
|
||||||
fn get_lamports_per_signature(&self) -> u64;
|
|
||||||
/// Set the return data
|
|
||||||
fn set_return_data(&mut self, data: Vec<u8>) -> Result<(), InstructionError>;
|
|
||||||
/// Get the return data
|
|
||||||
fn get_return_data(&self) -> (Pubkey, &[u8]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convenience macro to log a message with an `Rc<RefCell<dyn Logger>>`
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! ic_logger_msg {
|
|
||||||
($logger:expr, $message:expr) => {
|
|
||||||
if let Ok(logger) = $logger.try_borrow_mut() {
|
|
||||||
if logger.log_enabled() {
|
|
||||||
logger.log($message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
($logger:expr, $fmt:expr, $($arg:tt)*) => {
|
|
||||||
if let Ok(logger) = $logger.try_borrow_mut() {
|
|
||||||
if logger.log_enabled() {
|
|
||||||
logger.log(&format!($fmt, $($arg)*));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convenience macro to log a message with an `InvokeContext`
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! ic_msg {
|
|
||||||
($invoke_context:expr, $message:expr) => {
|
|
||||||
$crate::ic_logger_msg!($invoke_context.get_logger(), $message)
|
|
||||||
};
|
|
||||||
($invoke_context:expr, $fmt:expr, $($arg:tt)*) => {
|
|
||||||
$crate::ic_logger_msg!($invoke_context.get_logger(), $fmt, $($arg)*)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compute meter
|
|
||||||
pub trait ComputeMeter {
|
|
||||||
/// Consume compute units
|
|
||||||
fn consume(&mut self, amount: u64) -> Result<(), InstructionError>;
|
|
||||||
/// Get the number of remaining compute units
|
|
||||||
fn get_remaining(&self) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log messages
|
|
||||||
pub trait Logger {
|
|
||||||
fn log_enabled(&self) -> bool;
|
|
||||||
|
|
||||||
/// Log a message.
|
|
||||||
///
|
|
||||||
/// Unless explicitly stated, log messages are not considered stable and may change in the
|
|
||||||
/// future as necessary
|
|
||||||
fn log(&self, message: &str);
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Stable program log messages
|
|
||||||
///
|
|
||||||
/// The format of these log messages should not be modified to avoid breaking downstream consumers
|
|
||||||
/// of program logging
|
|
||||||
///
|
|
||||||
pub mod stable_log {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
/// Log a program invoke.
|
|
||||||
///
|
|
||||||
/// The general form is:
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// "Program <address> invoke [<depth>]"
|
|
||||||
/// ```
|
|
||||||
pub fn program_invoke(
|
|
||||||
logger: &Rc<RefCell<dyn Logger>>,
|
|
||||||
program_id: &Pubkey,
|
|
||||||
invoke_depth: usize,
|
|
||||||
) {
|
|
||||||
ic_logger_msg!(logger, "Program {} invoke [{}]", program_id, invoke_depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log a message from the program itself.
|
|
||||||
///
|
|
||||||
/// The general form is:
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// "Program log: <program-generated output>"
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// That is, any program-generated output is guaranteed to be prefixed by "Program log: "
|
|
||||||
pub fn program_log(logger: &Rc<RefCell<dyn Logger>>, message: &str) {
|
|
||||||
ic_logger_msg!(logger, "Program log: {}", message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Emit a program data.
|
|
||||||
///
|
|
||||||
/// The general form is:
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// "Program data: <binary-data-in-base64>*"
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// That is, any program-generated output is guaranteed to be prefixed by "Program data: "
|
|
||||||
pub fn program_data(logger: &Rc<RefCell<dyn Logger>>, data: &[&[u8]]) {
|
|
||||||
ic_logger_msg!(
|
|
||||||
logger,
|
|
||||||
"Program data: {}",
|
|
||||||
data.iter().map(base64::encode).join(" ")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log return data as from the program itself. This line will not be present if no return
|
|
||||||
/// data was set, or if the return data was set to zero length.
|
|
||||||
///
|
|
||||||
/// The general form is:
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// "Program return: <program-id> <program-generated-data-in-base64>"
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// That is, any program-generated output is guaranteed to be prefixed by "Program return: "
|
|
||||||
pub fn program_return(logger: &Rc<RefCell<dyn Logger>>, program_id: &Pubkey, data: &[u8]) {
|
|
||||||
ic_logger_msg!(
|
|
||||||
logger,
|
|
||||||
"Program return: {} {}",
|
|
||||||
program_id,
|
|
||||||
base64::encode(data)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log successful program execution.
|
|
||||||
///
|
|
||||||
/// The general form is:
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// "Program <address> success"
|
|
||||||
/// ```
|
|
||||||
pub fn program_success(logger: &Rc<RefCell<dyn Logger>>, program_id: &Pubkey) {
|
|
||||||
ic_logger_msg!(logger, "Program {} success", program_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log program execution failure
|
|
||||||
///
|
|
||||||
/// The general form is:
|
|
||||||
///
|
|
||||||
/// ```notrust
|
|
||||||
/// "Program <address> failed: <program error details>"
|
|
||||||
/// ```
|
|
||||||
pub fn program_failure(
|
|
||||||
logger: &Rc<RefCell<dyn Logger>>,
|
|
||||||
program_id: &Pubkey,
|
|
||||||
err: &InstructionError,
|
|
||||||
) {
|
|
||||||
ic_logger_msg!(logger, "Program {} failed: {}", program_id, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Program executor
|
|
||||||
pub trait Executor: Debug + Send + Sync {
|
|
||||||
/// Execute the program
|
|
||||||
fn execute(
|
|
||||||
&self,
|
|
||||||
first_instruction_account: usize,
|
|
||||||
instruction_data: &[u8],
|
|
||||||
invoke_context: &mut dyn InvokeContext,
|
|
||||||
use_jit: bool,
|
|
||||||
) -> Result<(), InstructionError>;
|
|
||||||
}
|
|
Loading…
Reference in New Issue