Refactor: CPI Instruction Recording (#22111)

* Unifies all InstructionRecorders of a transaction into one.

* Stops explicitly compiling CPI instructions for recording,
uses the indices gathered from instruction_accounts instead.
This commit is contained in:
Alexander Meißner
2021-12-25 13:35:43 +01:00
committed by GitHub
parent 60ddd93d09
commit cc947cad03
6 changed files with 64 additions and 51 deletions

View File

@ -3576,11 +3576,10 @@ impl Bank {
let account_refcells =
Self::accounts_to_refcells(&mut loaded_transaction.accounts);
let instruction_recorders = if enable_cpi_recording {
let ix_count = tx.message().instructions().len();
let mut recorders = Vec::with_capacity(ix_count);
recorders.resize_with(ix_count, InstructionRecorder::default);
Some(recorders)
let instruction_recorder = if enable_cpi_recording {
Some(InstructionRecorder::new_ref(
tx.message().instructions().len(),
))
} else {
None
};
@ -3603,7 +3602,7 @@ impl Bank {
self.rent_collector.rent,
log_collector.clone(),
executors.clone(),
instruction_recorders.as_deref(),
instruction_recorder.clone(),
feature_set,
compute_budget,
&mut timings.details,
@ -3628,14 +3627,15 @@ impl Bank {
.ok()
});
transaction_log_messages.push(log_messages);
let inner_instruction_list: Option<InnerInstructionsList> =
instruction_recorders.and_then(|instruction_recorders| {
instruction_recorders
.into_iter()
.map(|r| r.compile_instructions(tx.message()))
.collect()
});
inner_instructions.push(inner_instruction_list);
inner_instructions.push(
instruction_recorder
.and_then(|instruction_recorder| {
Rc::try_unwrap(instruction_recorder).ok()
})
.map(|instruction_recorder| {
instruction_recorder.into_inner().deconstruct()
}),
);
Self::refcells_to_accounts(
&mut loaded_transaction.accounts,

View File

@ -58,7 +58,7 @@ impl MessageProcessor {
rent: Rent,
log_collector: Option<Rc<RefCell<LogCollector>>>,
executors: Rc<RefCell<Executors>>,
instruction_recorders: Option<&[InstructionRecorder]>,
instruction_recorder: Option<Rc<RefCell<InstructionRecorder>>>,
feature_set: Arc<FeatureSet>,
compute_budget: ComputeBudget,
timings: &mut ExecuteDetailsTimings,
@ -74,6 +74,7 @@ impl MessageProcessor {
log_collector,
compute_budget,
executors,
instruction_recorder,
feature_set,
blockhash,
lamports_per_signature,
@ -109,10 +110,6 @@ impl MessageProcessor {
}
}
if let Some(instruction_recorders) = instruction_recorders {
invoke_context.instruction_recorder =
Some(&instruction_recorders[instruction_index]);
}
let instruction_accounts = instruction
.accounts
.iter()