From 250d2ba74ab902c5262632a144a96b6d1a957f91 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 26 Sep 2020 00:40:32 +0000 Subject: [PATCH] Pre-construct cpi instruction recorders before message processing (#12467) (#12504) (cherry picked from commit 1c970bb39f63c0ba9616687b5321128b6c4f64dd) Co-authored-by: Justin Starry --- runtime/src/bank.rs | 10 +++++++--- runtime/src/message_processor.rs | 10 ++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 20faceb2ab..5e7a2c04e3 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2010,11 +2010,15 @@ impl Bank { let (account_refcells, loader_refcells) = Self::accounts_to_refcells(accounts, loaders); - let mut instruction_recorders = if enable_cpi_recording { - Some(Vec::new()) + let instruction_recorders = if enable_cpi_recording { + Some(vec![ + InstructionRecorder::default(); + tx.message.instructions.len() + ]) } else { None }; + let process_result = self.message_processor.process_message( tx.message(), &loader_refcells, @@ -2022,7 +2026,7 @@ impl Bank { &self.rent_collector, log_collector.clone(), executors.clone(), - instruction_recorders.as_mut(), + instruction_recorders.as_deref(), self.cluster_type(), self.epoch(), ); diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 7c8c3db351..8dd67e1e3a 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -735,16 +735,14 @@ impl MessageProcessor { rent_collector: &RentCollector, log_collector: Option>, executors: Rc>, - mut instruction_recorders: Option<&mut Vec>, + instruction_recorders: Option<&[InstructionRecorder]>, cluster_type: ClusterType, epoch: Epoch, ) -> Result<(), TransactionError> { for (instruction_index, instruction) in message.instructions.iter().enumerate() { - let instruction_recorder = instruction_recorders.as_mut().map(|recorders| { - let instruction_recorder = InstructionRecorder::default(); - recorders.push(instruction_recorder.clone()); - instruction_recorder - }); + let instruction_recorder = instruction_recorders + .as_ref() + .map(|recorders| recorders[instruction_index].clone()); self.execute_instruction( message, instruction,