Rename Runtime to MessageProcessor

This commit is contained in:
Greg Fitzgerald 2019-04-02 09:35:38 -06:00
parent 77bb9e7ffc
commit a0041cec97
5 changed files with 23 additions and 23 deletions

View File

@ -2,7 +2,7 @@
extern crate test;
use solana_runtime::runtime::*;
use solana_runtime::message_processor::*;
use test::Bencher;
#[bench]

View File

@ -1,6 +1,6 @@
use crate::append_vec::AppendVec;
use crate::bank::Result;
use crate::runtime::has_duplicates;
use crate::message_processor::has_duplicates;
use bincode::serialize;
use hashbrown::{HashMap, HashSet};
use log::*;

View File

@ -6,7 +6,7 @@
use crate::accounts::{Accounts, ErrorCounters, InstructionAccounts, InstructionLoaders};
use crate::blockhash_queue::BlockhashQueue;
use crate::locked_accounts_results::LockedAccountsResults;
use crate::runtime::{ProcessInstruction, Runtime};
use crate::message_processor::{MessageProcessor, ProcessInstruction};
use crate::status_cache::StatusCache;
use bincode::serialize;
use hashbrown::HashMap;
@ -160,8 +160,8 @@ pub struct Bank {
/// stream for the slot == self.slot
is_delta: AtomicBool,
/// The runtime executation environment
runtime: Runtime,
/// The Message processor
message_processor: MessageProcessor,
}
impl Default for BlockhashQueue {
@ -346,7 +346,7 @@ impl Bank {
genesis_block.epoch_warmup,
);
// Add native programs mandatory for the runtime to function
// Add native programs mandatory for the MessageProcessor to function
self.register_native_instruction_processor(
"solana_system_program",
&solana_sdk::system_program::id(),
@ -609,17 +609,17 @@ impl Bank {
let load_elapsed = now.elapsed();
let now = Instant::now();
let executed: Vec<Result<()>> = loaded_accounts
.iter_mut()
.zip(txs.iter())
.map(|(accs, tx)| match accs {
Err(e) => Err(e.clone()),
Ok((ref mut accounts, ref mut loaders)) => {
self.runtime
.process_message(tx.message(), loaders, accounts, tick_height)
}
})
.collect();
let executed: Vec<Result<()>> =
loaded_accounts
.iter_mut()
.zip(txs.iter())
.map(|(accs, tx)| match accs {
Err(e) => Err(e.clone()),
Ok((ref mut accounts, ref mut loaders)) => self
.message_processor
.process_message(tx.message(), loaders, accounts, tick_height),
})
.collect();
let execution_elapsed = now.elapsed();
@ -934,7 +934,7 @@ impl Bank {
program_id: Pubkey,
process_instruction: ProcessInstruction,
) {
self.runtime
self.message_processor
.add_instruction_processor(program_id, process_instruction);
// Register a bogus executable account, which will be loaded and ignored.

View File

@ -6,8 +6,8 @@ mod blockhash_queue;
pub mod bloom;
pub mod loader_utils;
pub mod locked_accounts_results;
pub mod message_processor;
mod native_loader;
pub mod runtime;
mod status_cache;
mod system_instruction_processor;

View File

@ -10,7 +10,7 @@ use solana_sdk::transaction::TransactionError;
/// Return true if the slice has any duplicate elements
pub fn has_duplicates<T: PartialEq>(xs: &[T]) -> bool {
// Note: This is an O(n^2) algorithm, but requires no heap allocations. The benchmark
// `bench_has_duplicates` in benches/runtime.rs shows that this implementation is
// `bench_has_duplicates` in benches/message_processor.rs shows that this implementation is
// ~50 times faster than using HashSet for very short slices.
for i in 1..xs.len() {
if xs[i..].contains(&xs[i - 1]) {
@ -85,11 +85,11 @@ fn verify_error(err: InstructionError) -> InstructionError {
pub type ProcessInstruction =
fn(&Pubkey, &mut [KeyedAccount], &[u8], u64) -> Result<(), InstructionError>;
pub struct Runtime {
pub struct MessageProcessor {
instruction_processors: Vec<(Pubkey, ProcessInstruction)>,
}
impl Default for Runtime {
impl Default for MessageProcessor {
fn default() -> Self {
let instruction_processors: Vec<(Pubkey, ProcessInstruction)> = vec![(
system_program::id(),
@ -102,7 +102,7 @@ impl Default for Runtime {
}
}
impl Runtime {
impl MessageProcessor {
/// Add a static entrypoint to intercept intructions before the dynamic loader.
pub fn add_instruction_processor(
&mut self,