This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
64 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
use { | ||
solana_sdk::{ | ||
instruction::{CompiledInstruction, Instruction}, | ||
message::SanitizedMessage, | ||
}, | ||
solana_sdk::instruction::CompiledInstruction, | ||
std::{cell::RefCell, rc::Rc}, | ||
}; | ||
|
||
/// Records and compiles cross-program invoked instructions | ||
#[derive(Clone, Default)] | ||
#[derive(Clone)] | ||
pub struct InstructionRecorder { | ||
inner: Rc<RefCell<Vec<Instruction>>>, | ||
records: Vec<Vec<CompiledInstruction>>, | ||
} | ||
|
||
impl InstructionRecorder { | ||
pub fn compile_instructions( | ||
&self, | ||
message: &SanitizedMessage, | ||
) -> Option<Vec<CompiledInstruction>> { | ||
self.inner | ||
.borrow() | ||
.iter() | ||
.map(|ix| message.try_compile_instruction(ix)) | ||
.collect() | ||
pub fn new_ref(instructions_in_message: usize) -> Rc<RefCell<Self>> { | ||
Rc::new(RefCell::new(Self { | ||
records: Vec::with_capacity(instructions_in_message), | ||
})) | ||
} | ||
|
||
pub fn record_instruction(&self, instruction: Instruction) { | ||
self.inner.borrow_mut().push(instruction); | ||
pub fn deconstruct(self) -> Vec<Vec<CompiledInstruction>> { | ||
self.records | ||
} | ||
|
||
pub fn begin_next_recording(&mut self) { | ||
self.records.push(Vec::new()); | ||
} | ||
|
||
pub fn record_compiled_instruction(&mut self, instruction: CompiledInstruction) { | ||
if let Some(records) = self.records.last_mut() { | ||
records.push(instruction); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters