From a0041cec970bcabd8a288dad9523a01aeb8b0375 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Tue, 2 Apr 2019 09:35:38 -0600 Subject: [PATCH] Rename Runtime to MessageProcessor --- .../{runtime.rs => message_processor.rs} | 2 +- runtime/src/accounts.rs | 2 +- runtime/src/bank.rs | 32 +++++++++---------- runtime/src/lib.rs | 2 +- .../src/{runtime.rs => message_processor.rs} | 8 ++--- 5 files changed, 23 insertions(+), 23 deletions(-) rename runtime/benches/{runtime.rs => message_processor.rs} (84%) rename runtime/src/{runtime.rs => message_processor.rs} (98%) diff --git a/runtime/benches/runtime.rs b/runtime/benches/message_processor.rs similarity index 84% rename from runtime/benches/runtime.rs rename to runtime/benches/message_processor.rs index 26bfd9f514..494929b34d 100644 --- a/runtime/benches/runtime.rs +++ b/runtime/benches/message_processor.rs @@ -2,7 +2,7 @@ extern crate test; -use solana_runtime::runtime::*; +use solana_runtime::message_processor::*; use test::Bencher; #[bench] diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index c7224deee3..24ed8caf32 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -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::*; diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e83d77430b..747ef43846 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -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> = 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> = + 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. diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a1db8ab3ed..b41d5c92c7 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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; diff --git a/runtime/src/runtime.rs b/runtime/src/message_processor.rs similarity index 98% rename from runtime/src/runtime.rs rename to runtime/src/message_processor.rs index 94f27f6fd1..b9153ab64a 100644 --- a/runtime/src/runtime.rs +++ b/runtime/src/message_processor.rs @@ -10,7 +10,7 @@ use solana_sdk::transaction::TransactionError; /// Return true if the slice has any duplicate elements pub fn has_duplicates(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,