migrate memberes from deprecated structs (#24263)
This commit is contained in:
parent
2d4d639635
commit
b035991c35
|
@ -177,8 +177,6 @@ pub struct StackFrame<'a> {
|
||||||
pub number_of_program_accounts: usize,
|
pub number_of_program_accounts: usize,
|
||||||
pub keyed_accounts: Vec<KeyedAccount<'a>>,
|
pub keyed_accounts: Vec<KeyedAccount<'a>>,
|
||||||
pub keyed_accounts_range: std::ops::Range<usize>,
|
pub keyed_accounts_range: std::ops::Range<usize>,
|
||||||
pub orig_account_lengths: Option<Vec<usize>>,
|
|
||||||
pub allocator: Option<Rc<RefCell<dyn Alloc>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> StackFrame<'a> {
|
impl<'a> StackFrame<'a> {
|
||||||
|
@ -191,8 +189,6 @@ impl<'a> StackFrame<'a> {
|
||||||
number_of_program_accounts,
|
number_of_program_accounts,
|
||||||
keyed_accounts,
|
keyed_accounts,
|
||||||
keyed_accounts_range,
|
keyed_accounts_range,
|
||||||
orig_account_lengths: None,
|
|
||||||
allocator: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +216,10 @@ pub struct InvokeContext<'a> {
|
||||||
pub timings: ExecuteDetailsTimings,
|
pub timings: ExecuteDetailsTimings,
|
||||||
pub blockhash: Hash,
|
pub blockhash: Hash,
|
||||||
pub lamports_per_signature: u64,
|
pub lamports_per_signature: u64,
|
||||||
pub check_aligned: bool,
|
check_aligned: bool,
|
||||||
pub check_size: bool,
|
check_size: bool,
|
||||||
|
orig_account_lengths: Vec<Option<Vec<usize>>>,
|
||||||
|
allocators: Vec<Option<Rc<RefCell<dyn Alloc>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InvokeContext<'a> {
|
impl<'a> InvokeContext<'a> {
|
||||||
|
@ -258,6 +256,8 @@ impl<'a> InvokeContext<'a> {
|
||||||
lamports_per_signature,
|
lamports_per_signature,
|
||||||
check_aligned: true,
|
check_aligned: true,
|
||||||
check_size: true,
|
check_size: true,
|
||||||
|
orig_account_lengths: Vec::new(),
|
||||||
|
allocators: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,6 +443,8 @@ impl<'a> InvokeContext<'a> {
|
||||||
std::mem::transmute(keyed_accounts.as_slice())
|
std::mem::transmute(keyed_accounts.as_slice())
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
self.orig_account_lengths.push(None);
|
||||||
|
self.allocators.push(None);
|
||||||
self.transaction_context.push(
|
self.transaction_context.push(
|
||||||
program_indices,
|
program_indices,
|
||||||
instruction_accounts,
|
instruction_accounts,
|
||||||
|
@ -454,6 +456,8 @@ impl<'a> InvokeContext<'a> {
|
||||||
|
|
||||||
/// Pop a stack frame from the invocation stack
|
/// Pop a stack frame from the invocation stack
|
||||||
pub fn pop(&mut self) -> Result<(), InstructionError> {
|
pub fn pop(&mut self) -> Result<(), InstructionError> {
|
||||||
|
self.orig_account_lengths.pop();
|
||||||
|
self.allocators.pop();
|
||||||
self.invoke_stack.pop();
|
self.invoke_stack.pop();
|
||||||
self.transaction_context.pop()
|
self.transaction_context.pop()
|
||||||
}
|
}
|
||||||
|
@ -1085,57 +1089,61 @@ impl<'a> InvokeContext<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
orig_account_lengths: Vec<usize>,
|
orig_account_lengths: Vec<usize>,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let stack_frame = &mut self
|
*self
|
||||||
.invoke_stack
|
.orig_account_lengths
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.ok_or(InstructionError::CallDepth)?;
|
.ok_or(InstructionError::CallDepth)? = Some(orig_account_lengths);
|
||||||
stack_frame.orig_account_lengths = Some(orig_account_lengths);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the original account lengths
|
/// Get the original account lengths
|
||||||
pub fn get_orig_account_lengths(&self) -> Result<&[usize], InstructionError> {
|
pub fn get_orig_account_lengths(&self) -> Result<&[usize], InstructionError> {
|
||||||
self.invoke_stack
|
self.orig_account_lengths
|
||||||
.last()
|
.last()
|
||||||
.and_then(|frame| frame.orig_account_lengths.as_ref())
|
.and_then(|orig_account_lengths| orig_account_lengths.as_ref())
|
||||||
.ok_or(InstructionError::CallDepth)
|
|
||||||
.map(|orig_account_lengths| orig_account_lengths.as_slice())
|
.map(|orig_account_lengths| orig_account_lengths.as_slice())
|
||||||
|
.ok_or(InstructionError::CallDepth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set should alignment be enforced during user pointer translation
|
||||||
pub fn set_check_aligned(&mut self, check_aligned: bool) {
|
pub fn set_check_aligned(&mut self, check_aligned: bool) {
|
||||||
self.check_aligned = check_aligned;
|
self.check_aligned = check_aligned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sshould alignment be enforced during user pointer translation
|
||||||
pub fn get_check_aligned(&self) -> bool {
|
pub fn get_check_aligned(&self) -> bool {
|
||||||
self.check_aligned
|
self.check_aligned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set should type size be checked during user pointer translation
|
||||||
pub fn set_check_size(&mut self, check_size: bool) {
|
pub fn set_check_size(&mut self, check_size: bool) {
|
||||||
self.check_size = check_size;
|
self.check_size = check_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set should type size be checked during user pointer translation
|
||||||
pub fn get_check_size(&self) -> bool {
|
pub fn get_check_size(&self) -> bool {
|
||||||
self.check_size
|
self.check_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get this instruction's memory allocator
|
||||||
|
pub fn get_allocator(&self) -> Result<Rc<RefCell<dyn Alloc>>, InstructionError> {
|
||||||
|
self.allocators
|
||||||
|
.last()
|
||||||
|
.and_then(|allocator| allocator.clone())
|
||||||
|
.ok_or(InstructionError::CallDepth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set this instruction's memory allocator
|
||||||
pub fn set_allocator(
|
pub fn set_allocator(
|
||||||
&mut self,
|
&mut self,
|
||||||
allocator: Rc<RefCell<dyn Alloc>>,
|
allocator: Rc<RefCell<dyn Alloc>>,
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let stack_frame = &mut self
|
*self
|
||||||
.invoke_stack
|
.allocators
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.ok_or(InstructionError::CallDepth)?;
|
.ok_or(InstructionError::CallDepth)? = Some(allocator);
|
||||||
stack_frame.allocator = Some(allocator);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_allocator(&self) -> Result<Rc<RefCell<dyn Alloc>>, InstructionError> {
|
|
||||||
self.invoke_stack
|
|
||||||
.last()
|
|
||||||
.and_then(|frame| frame.allocator.clone())
|
|
||||||
.ok_or(InstructionError::CallDepth)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MockInvokeContextPreparation {
|
pub struct MockInvokeContextPreparation {
|
||||||
|
|
|
@ -112,11 +112,10 @@ impl TransactionContext {
|
||||||
self.account_keys.iter().rposition(|key| key == pubkey)
|
self.account_keys.iter().rposition(|key| key == pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets an InstructionContext by its nesting level in the stack
|
pub fn get_instruction_context_indicies(
|
||||||
pub fn get_instruction_context_at(
|
|
||||||
&self,
|
&self,
|
||||||
level: usize,
|
level: usize,
|
||||||
) -> Result<&InstructionContext, InstructionError> {
|
) -> Result<(usize, usize), InstructionError> {
|
||||||
let top_level_index = *self
|
let top_level_index = *self
|
||||||
.instruction_stack
|
.instruction_stack
|
||||||
.get(0)
|
.get(0)
|
||||||
|
@ -129,6 +128,15 @@ impl TransactionContext {
|
||||||
.get(level)
|
.get(level)
|
||||||
.ok_or(InstructionError::CallDepth)?
|
.ok_or(InstructionError::CallDepth)?
|
||||||
};
|
};
|
||||||
|
Ok((top_level_index, cpi_index))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an InstructionContext by its nesting level in the stack
|
||||||
|
pub fn get_instruction_context_at(
|
||||||
|
&self,
|
||||||
|
level: usize,
|
||||||
|
) -> Result<&InstructionContext, InstructionError> {
|
||||||
|
let (top_level_index, cpi_index) = self.get_instruction_context_indicies(level)?;
|
||||||
let instruction_context = self
|
let instruction_context = self
|
||||||
.instruction_trace
|
.instruction_trace
|
||||||
.get(top_level_index)
|
.get(top_level_index)
|
||||||
|
@ -138,6 +146,21 @@ impl TransactionContext {
|
||||||
Ok(instruction_context)
|
Ok(instruction_context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets an InstructionContext by its nesting level in the stack
|
||||||
|
pub fn get_instruction_context_mut_at(
|
||||||
|
&mut self,
|
||||||
|
level: usize,
|
||||||
|
) -> Result<&mut InstructionContext, InstructionError> {
|
||||||
|
let (top_level_index, cpi_index) = self.get_instruction_context_indicies(level)?;
|
||||||
|
let instruction_context = self
|
||||||
|
.instruction_trace
|
||||||
|
.get_mut(top_level_index)
|
||||||
|
.and_then(|instruction_trace| instruction_trace.get_mut(cpi_index))
|
||||||
|
.ok_or(InstructionError::CallDepth)?;
|
||||||
|
debug_assert_eq!(instruction_context.nesting_level, level);
|
||||||
|
Ok(instruction_context)
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets the max height of the InstructionContext stack
|
/// Gets the max height of the InstructionContext stack
|
||||||
pub fn get_instruction_context_capacity(&self) -> usize {
|
pub fn get_instruction_context_capacity(&self) -> usize {
|
||||||
self.instruction_context_capacity
|
self.instruction_context_capacity
|
||||||
|
@ -158,6 +181,17 @@ impl TransactionContext {
|
||||||
self.get_instruction_context_at(level)
|
self.get_instruction_context_at(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the current InstructionContext
|
||||||
|
pub fn get_current_instruction_context_mut(
|
||||||
|
&mut self,
|
||||||
|
) -> Result<&mut InstructionContext, InstructionError> {
|
||||||
|
let level = self
|
||||||
|
.get_instruction_context_stack_height()
|
||||||
|
.checked_sub(1)
|
||||||
|
.ok_or(InstructionError::CallDepth)?;
|
||||||
|
self.get_instruction_context_mut_at(level)
|
||||||
|
}
|
||||||
|
|
||||||
/// Pushes a new InstructionContext
|
/// Pushes a new InstructionContext
|
||||||
pub fn push(
|
pub fn push(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -237,6 +271,26 @@ impl TransactionContext {
|
||||||
pub fn get_instruction_trace(&self) -> &InstructionTrace {
|
pub fn get_instruction_trace(&self) -> &InstructionTrace {
|
||||||
&self.instruction_trace
|
&self.instruction_trace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /// Set the original account lengths
|
||||||
|
// pub fn set_orig_account_lengths(
|
||||||
|
// &mut self,
|
||||||
|
// orig_account_lengths: Vec<usize>,
|
||||||
|
// ) -> Result<(), InstructionError> {
|
||||||
|
// let level = self
|
||||||
|
// .get_instruction_context_stack_height()
|
||||||
|
// .checked_sub(1)
|
||||||
|
// .ok_or(InstructionError::CallDepth)?;
|
||||||
|
// let (top_level_index, cpi_index) = self.get_instruction_context_indicies(level)?;
|
||||||
|
// let instruction_context = self
|
||||||
|
// .instruction_trace
|
||||||
|
// .get_mut(top_level_index)
|
||||||
|
// .and_then(|instruction_trace| instruction_trace.get_mut(cpi_index))
|
||||||
|
// .ok_or(InstructionError::CallDepth)?;
|
||||||
|
// debug_assert_eq!(instruction_context.nesting_level, level);
|
||||||
|
// instruction_context.orig_account_lengths = Some(orig_account_lengths);
|
||||||
|
// Ok(())
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return data at the end of a transaction
|
/// Return data at the end of a transaction
|
||||||
|
|
Loading…
Reference in New Issue