From da9548fd12077a8d5cac8245b408572adbc72962 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 29 Oct 2020 23:43:10 -0700 Subject: [PATCH] de-mut some InvokeContext methods --- programs/bpf_loader/src/lib.rs | 4 ++-- programs/bpf_loader/src/syscalls.rs | 8 ++++---- runtime/src/message_processor.rs | 6 +++--- sdk/src/process_instruction.rs | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index b4bbb614ab..877d97a14d 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -64,14 +64,14 @@ impl UserDefinedError for BPFError {} /// Point all log messages to the log collector macro_rules! log{ ($logger:ident, $message:expr) => { - if let Ok(mut logger) = $logger.try_borrow_mut() { + if let Ok(logger) = $logger.try_borrow_mut() { if logger.log_enabled() { logger.log($message); } } }; ($logger:ident, $fmt:expr, $($arg:tt)*) => { - if let Ok(mut logger) = $logger.try_borrow_mut() { + if let Ok(logger) = $logger.try_borrow_mut() { if logger.log_enabled() { logger.log(&format!($fmt, $($arg)*)); } diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index 50b39f3b60..52f37a1701 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -371,7 +371,7 @@ impl<'a> SyscallObject for SyscallLog<'a> { _rw_regions: &[MemoryRegion], ) -> Result> { self.compute_meter.consume(self.cost)?; - let mut logger = self + let logger = self .logger .try_borrow_mut() .map_err(|_| SyscallError::InvokeContextBorrowFailed)?; @@ -409,7 +409,7 @@ impl SyscallObject for SyscallLogU64 { _rw_regions: &[MemoryRegion], ) -> Result> { self.compute_meter.consume(self.cost)?; - let mut logger = self + let logger = self .logger .try_borrow_mut() .map_err(|_| SyscallError::InvokeContextBorrowFailed)?; @@ -441,7 +441,7 @@ impl SyscallObject for SyscallLogBpfComputeUnits { _rw_regions: &[MemoryRegion], ) -> Result> { self.compute_meter.consume(self.cost)?; - let mut logger = self + let logger = self .logger .try_borrow_mut() .map_err(|_| SyscallError::InvokeContextBorrowFailed)?; @@ -474,7 +474,7 @@ impl<'a> SyscallObject for SyscallLogPubkey<'a> { _rw_regions: &[MemoryRegion], ) -> Result> { self.compute_meter.consume(self.cost)?; - let mut logger = self + let logger = self .logger .try_borrow_mut() .map_err(|_| SyscallError::InvokeContextBorrowFailed)?; diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index b9570d8ea7..86fc2b9a57 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -293,10 +293,10 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> { fn get_compute_meter(&self) -> Rc> { self.compute_meter.clone() } - fn add_executor(&mut self, pubkey: &Pubkey, executor: Arc) { + fn add_executor(&self, pubkey: &Pubkey, executor: Arc) { self.executors.borrow_mut().insert(*pubkey, executor); } - fn get_executor(&mut self, pubkey: &Pubkey) -> Option> { + fn get_executor(&self, pubkey: &Pubkey) -> Option> { self.executors.borrow().get(&pubkey) } fn record_instruction(&self, instruction: &Instruction) { @@ -315,7 +315,7 @@ impl Logger for ThisLogger { fn log_enabled(&self) -> bool { log_enabled!(log::Level::Info) || self.log_collector.is_some() } - fn log(&mut self, message: &str) { + fn log(&self, message: &str) { info!("{}", message); if let Some(log_collector) = &self.log_collector { log_collector.log(message); diff --git a/sdk/src/process_instruction.rs b/sdk/src/process_instruction.rs index 62647fbad8..6b15f021f1 100644 --- a/sdk/src/process_instruction.rs +++ b/sdk/src/process_instruction.rs @@ -52,9 +52,9 @@ pub trait InvokeContext { fn get_compute_meter(&self) -> Rc>; /// 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); + fn add_executor(&self, pubkey: &Pubkey, executor: Arc); /// Get the completed loader work that can be re-used across executions - fn get_executor(&mut self, pubkey: &Pubkey) -> Option>; + fn get_executor(&self, pubkey: &Pubkey) -> Option>; /// Record invoked instruction fn record_instruction(&self, instruction: &Instruction); /// Get the bank's active feature set @@ -156,7 +156,7 @@ pub trait ComputeMeter { pub trait Logger { fn log_enabled(&self) -> bool; /// Log a message - fn log(&mut self, message: &str); + fn log(&self, message: &str); } /// Program executor @@ -197,7 +197,7 @@ impl Logger for MockLogger { fn log_enabled(&self) -> bool { true } - fn log(&mut self, message: &str) { + fn log(&self, message: &str) { self.log.borrow_mut().push(message.to_string()); } } @@ -249,8 +249,8 @@ impl InvokeContext for MockInvokeContext { fn get_compute_meter(&self) -> Rc> { Rc::new(RefCell::new(self.compute_meter.clone())) } - fn add_executor(&mut self, _pubkey: &Pubkey, _executor: Arc) {} - fn get_executor(&mut self, _pubkey: &Pubkey) -> Option> { + fn add_executor(&self, _pubkey: &Pubkey, _executor: Arc) {} + fn get_executor(&self, _pubkey: &Pubkey) -> Option> { None } fn record_instruction(&self, _instruction: &Instruction) {}