Cache re-usable work performed by the loader (bp #12135) (#12216)

* Cache re-usable work performed by the loader (#12135)

(cherry picked from commit 3278d78f08)

# Conflicts:
#	programs/bpf/Cargo.toml
#	programs/bpf/tests/programs.rs
#	programs/bpf_loader/Cargo.toml

* resolve conflicts

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2020-09-15 21:25:32 +00:00
committed by GitHub
parent 7267257073
commit 11ff80c64b
11 changed files with 697 additions and 247 deletions

View File

@@ -1,10 +1,12 @@
//! @brief Solana Native program entry point
#[cfg(RUSTC_WITH_SPECIALIZATION)]
use crate::abi_example::AbiExample;
use crate::{
account::Account, account::KeyedAccount, instruction::CompiledInstruction,
instruction::InstructionError, message::Message, pubkey::Pubkey,
};
use std::{cell::RefCell, rc::Rc};
use std::{cell::RefCell, rc::Rc, sync::Arc};
// Prototype of a native program entry point
///
@@ -217,6 +219,11 @@ pub trait InvokeContext {
fn get_compute_budget(&self) -> ComputeBudget;
/// 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(&mut self, pubkey: &Pubkey, executor: Arc<dyn Executor>);
/// Get the completed loader work that can be re-used across executions
fn get_executor(&mut self, pubkey: &Pubkey) -> Option<Arc<dyn Executor>>;
}
#[derive(Clone, Copy, Debug)]
@@ -264,3 +271,33 @@ pub trait Logger {
/// Log a message
fn log(&mut self, message: &str);
}
/// Program executor
pub trait Executor: Send + Sync {
/// Execute the program
fn execute(
&self,
program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
instruction_data: &[u8],
invoke_context: &mut dyn InvokeContext,
) -> Result<(), InstructionError>;
}
#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl AbiExample for Arc<dyn Executor> {
fn example() -> Self {
struct ExampleExecutor {}
impl Executor for ExampleExecutor {
fn execute(
&self,
_program_id: &Pubkey,
_keyed_accounts: &[KeyedAccount],
_instruction_data: &[u8],
_invoke_context: &mut dyn InvokeContext,
) -> std::result::Result<(), InstructionError> {
Ok(())
}
}
Arc::new(ExampleExecutor {})
}
}