Cleanup: `record_instruction_in_transaction_context_push` (#26658)
Cleanup feature gate of record_instruction_in_transaction_context_push.
This commit is contained in:
parent
73129cadc2
commit
cbb74a190f
|
@ -16,8 +16,7 @@ use {
|
||||||
account::{AccountSharedData, ReadableAccount},
|
account::{AccountSharedData, ReadableAccount},
|
||||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||||
feature_set::{
|
feature_set::{
|
||||||
cap_accounts_data_len, enable_early_verification_of_account_modifications,
|
cap_accounts_data_len, enable_early_verification_of_account_modifications, FeatureSet,
|
||||||
record_instruction_in_transaction_context_push, FeatureSet,
|
|
||||||
},
|
},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
|
@ -25,9 +24,7 @@ use {
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
saturating_add_assign,
|
saturating_add_assign,
|
||||||
transaction_context::{
|
transaction_context::{InstructionAccount, TransactionAccount, TransactionContext},
|
||||||
InstructionAccount, InstructionContext, TransactionAccount, TransactionContext,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
alloc::Layout,
|
alloc::Layout,
|
||||||
|
@ -322,17 +319,6 @@ impl<'a> InvokeContext<'a> {
|
||||||
program_indices: &[usize],
|
program_indices: &[usize],
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
if !self
|
|
||||||
.feature_set
|
|
||||||
.is_active(&record_instruction_in_transaction_context_push::id())
|
|
||||||
&& self
|
|
||||||
.transaction_context
|
|
||||||
.get_instruction_context_stack_height()
|
|
||||||
> self.compute_budget.max_invoke_depth
|
|
||||||
{
|
|
||||||
return Err(InstructionError::CallDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
let program_id = self.transaction_context.get_key_of_account_at_index(
|
let program_id = self.transaction_context.get_key_of_account_at_index(
|
||||||
*program_indices
|
*program_indices
|
||||||
.last()
|
.last()
|
||||||
|
@ -437,13 +423,8 @@ impl<'a> InvokeContext<'a> {
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
self.syscall_context.push(None);
|
self.syscall_context.push(None);
|
||||||
self.transaction_context.push(
|
self.transaction_context
|
||||||
program_indices,
|
.push(program_indices, instruction_accounts, instruction_data)
|
||||||
instruction_accounts,
|
|
||||||
instruction_data,
|
|
||||||
self.feature_set
|
|
||||||
.is_active(&record_instruction_in_transaction_context_push::id()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pop a stack frame from the invocation stack
|
/// Pop a stack frame from the invocation stack
|
||||||
|
@ -836,41 +817,23 @@ impl<'a> InvokeContext<'a> {
|
||||||
.transaction_context
|
.transaction_context
|
||||||
.get_instruction_context_stack_height();
|
.get_instruction_context_stack_height();
|
||||||
let is_top_level_instruction = nesting_level == 0;
|
let is_top_level_instruction = nesting_level == 0;
|
||||||
if !is_top_level_instruction {
|
if !is_top_level_instruction
|
||||||
if !self
|
&& !self
|
||||||
.feature_set
|
.feature_set
|
||||||
.is_active(&enable_early_verification_of_account_modifications::id())
|
.is_active(&enable_early_verification_of_account_modifications::id())
|
||||||
{
|
{
|
||||||
// Verify the calling program hasn't misbehaved
|
// Verify the calling program hasn't misbehaved
|
||||||
let mut verify_caller_time = Measure::start("verify_caller_time");
|
let mut verify_caller_time = Measure::start("verify_caller_time");
|
||||||
let verify_caller_result = self.verify_and_update(instruction_accounts, true);
|
let verify_caller_result = self.verify_and_update(instruction_accounts, true);
|
||||||
verify_caller_time.stop();
|
verify_caller_time.stop();
|
||||||
saturating_add_assign!(
|
saturating_add_assign!(
|
||||||
timings
|
timings
|
||||||
.execute_accessories
|
.execute_accessories
|
||||||
.process_instructions
|
.process_instructions
|
||||||
.verify_caller_us,
|
.verify_caller_us,
|
||||||
verify_caller_time.as_us()
|
verify_caller_time.as_us()
|
||||||
);
|
);
|
||||||
verify_caller_result?;
|
verify_caller_result?;
|
||||||
}
|
|
||||||
|
|
||||||
if !self
|
|
||||||
.feature_set
|
|
||||||
.is_active(&record_instruction_in_transaction_context_push::id())
|
|
||||||
{
|
|
||||||
let instruction_accounts_lamport_sum = self
|
|
||||||
.transaction_context
|
|
||||||
.instruction_accounts_lamport_sum(instruction_accounts)?;
|
|
||||||
self.transaction_context
|
|
||||||
.record_instruction(InstructionContext::new(
|
|
||||||
nesting_level,
|
|
||||||
instruction_accounts_lamport_sum,
|
|
||||||
program_indices,
|
|
||||||
instruction_accounts,
|
|
||||||
instruction_data,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.push(instruction_accounts, program_indices, instruction_data)?;
|
self.push(instruction_accounts, program_indices, instruction_data)?;
|
||||||
|
|
|
@ -106,7 +106,7 @@ fn create_inputs() -> TransactionContext {
|
||||||
TransactionContext::new(transaction_accounts, Some(Rent::default()), 1, 1);
|
TransactionContext::new(transaction_accounts, Some(Rent::default()), 1, 1);
|
||||||
let instruction_data = vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
let instruction_data = vec![1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
||||||
transaction_context
|
transaction_context
|
||||||
.push(&[0], &instruction_accounts, &instruction_data, true)
|
.push(&[0], &instruction_accounts, &instruction_data)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
transaction_context
|
transaction_context
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,7 @@ use {
|
||||||
},
|
},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::WritableAccount,
|
account::WritableAccount,
|
||||||
feature_set::{
|
feature_set::{prevent_calling_precompiles_as_programs, FeatureSet},
|
||||||
prevent_calling_precompiles_as_programs,
|
|
||||||
record_instruction_in_transaction_context_push, FeatureSet,
|
|
||||||
},
|
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
message::SanitizedMessage,
|
message::SanitizedMessage,
|
||||||
precompiles::is_precompile,
|
precompiles::is_precompile,
|
||||||
|
@ -93,14 +90,6 @@ impl MessageProcessor {
|
||||||
.feature_set
|
.feature_set
|
||||||
.is_active(&prevent_calling_precompiles_as_programs::id())
|
.is_active(&prevent_calling_precompiles_as_programs::id())
|
||||||
&& is_precompile(program_id, |id| invoke_context.feature_set.is_active(id));
|
&& is_precompile(program_id, |id| invoke_context.feature_set.is_active(id));
|
||||||
if is_precompile
|
|
||||||
&& !invoke_context
|
|
||||||
.feature_set
|
|
||||||
.is_active(&record_instruction_in_transaction_context_push::id())
|
|
||||||
{
|
|
||||||
// Precompiled programs don't have an instruction processor
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fixup the special instructions key if present
|
// Fixup the special instructions key if present
|
||||||
// before the account pre-values are taken care of
|
// before the account pre-values are taken care of
|
||||||
|
@ -140,19 +129,10 @@ impl MessageProcessor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = if is_precompile
|
let result = if is_precompile {
|
||||||
&& invoke_context
|
|
||||||
.feature_set
|
|
||||||
.is_active(&record_instruction_in_transaction_context_push::id())
|
|
||||||
{
|
|
||||||
invoke_context
|
invoke_context
|
||||||
.transaction_context
|
.transaction_context
|
||||||
.push(
|
.push(program_indices, &instruction_accounts, &instruction.data)
|
||||||
program_indices,
|
|
||||||
&instruction_accounts,
|
|
||||||
&instruction.data,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
.and_then(|_| invoke_context.transaction_context.pop())
|
.and_then(|_| invoke_context.transaction_context.pop())
|
||||||
} else {
|
} else {
|
||||||
let mut time = Measure::start("execute_instruction");
|
let mut time = Measure::start("execute_instruction");
|
||||||
|
|
|
@ -191,7 +191,6 @@ impl TransactionContext {
|
||||||
program_accounts: &[usize],
|
program_accounts: &[usize],
|
||||||
instruction_accounts: &[InstructionAccount],
|
instruction_accounts: &[InstructionAccount],
|
||||||
instruction_data: &[u8],
|
instruction_data: &[u8],
|
||||||
record_instruction_in_transaction_context_push: bool,
|
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let callee_instruction_accounts_lamport_sum =
|
let callee_instruction_accounts_lamport_sum =
|
||||||
self.instruction_accounts_lamport_sum(instruction_accounts)?;
|
self.instruction_accounts_lamport_sum(instruction_accounts)?;
|
||||||
|
@ -224,16 +223,14 @@ impl TransactionContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(instruction_trace) = self.instruction_trace.last_mut() {
|
if let Some(instruction_trace) = self.instruction_trace.last_mut() {
|
||||||
if record_instruction_in_transaction_context_push {
|
let instruction_context = InstructionContext {
|
||||||
let instruction_context = InstructionContext {
|
nesting_level: self.instruction_stack.len(),
|
||||||
nesting_level: self.instruction_stack.len(),
|
instruction_accounts_lamport_sum: callee_instruction_accounts_lamport_sum,
|
||||||
instruction_accounts_lamport_sum: callee_instruction_accounts_lamport_sum,
|
program_accounts: program_accounts.to_vec(),
|
||||||
program_accounts: program_accounts.to_vec(),
|
instruction_accounts: instruction_accounts.to_vec(),
|
||||||
instruction_accounts: instruction_accounts.to_vec(),
|
instruction_data: instruction_data.to_vec(),
|
||||||
instruction_data: instruction_data.to_vec(),
|
};
|
||||||
};
|
instruction_trace.push(instruction_context);
|
||||||
instruction_trace.push(instruction_context);
|
|
||||||
}
|
|
||||||
instruction_trace.len().saturating_sub(1)
|
instruction_trace.len().saturating_sub(1)
|
||||||
} else {
|
} else {
|
||||||
return Err(InstructionError::CallDepth);
|
return Err(InstructionError::CallDepth);
|
||||||
|
@ -296,23 +293,13 @@ impl TransactionContext {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used by the runtime when a new CPI instruction begins
|
|
||||||
///
|
|
||||||
/// Deprecated, automatically done in push()
|
|
||||||
/// once record_instruction_in_transaction_context_push is activated.
|
|
||||||
pub fn record_instruction(&mut self, instruction: InstructionContext) {
|
|
||||||
if let Some(records) = self.instruction_trace.last_mut() {
|
|
||||||
records.push(instruction);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns instruction trace
|
/// Returns instruction trace
|
||||||
pub fn get_instruction_trace(&self) -> &InstructionTrace {
|
pub fn get_instruction_trace(&self) -> &InstructionTrace {
|
||||||
&self.instruction_trace
|
&self.instruction_trace
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculates the sum of all lamports within an instruction
|
/// Calculates the sum of all lamports within an instruction
|
||||||
pub fn instruction_accounts_lamport_sum(
|
fn instruction_accounts_lamport_sum(
|
||||||
&self,
|
&self,
|
||||||
instruction_accounts: &[InstructionAccount],
|
instruction_accounts: &[InstructionAccount],
|
||||||
) -> Result<u128, InstructionError> {
|
) -> Result<u128, InstructionError> {
|
||||||
|
|
Loading…
Reference in New Issue