Refactor: Move InstructionRecorder
into TransactionContext
(#22578)
* Moves InstructionRecorder into TransactionContext. * Adds assertions for number_of_instructions_at_transaction_level.
This commit is contained in:
committed by
GitHub
parent
60850d71ce
commit
b448472037
@ -75,7 +75,6 @@ use {
|
||||
solana_metrics::{inc_new_counter_debug, inc_new_counter_info},
|
||||
solana_program_runtime::{
|
||||
compute_budget::ComputeBudget,
|
||||
instruction_recorder::InstructionRecorder,
|
||||
invoke_context::{
|
||||
BuiltinProgram, Executor, Executors, ProcessInstructionWithContext, TransactionExecutor,
|
||||
},
|
||||
@ -3661,19 +3660,12 @@ impl Bank {
|
||||
let mut transaction_context = TransactionContext::new(
|
||||
transaction_accounts,
|
||||
compute_budget.max_invoke_depth.saturating_add(1),
|
||||
tx.message().instructions().len(),
|
||||
);
|
||||
|
||||
let pre_account_state_info =
|
||||
self.get_transaction_account_state_info(&transaction_context, tx.message());
|
||||
|
||||
let instruction_recorder = if enable_cpi_recording {
|
||||
Some(InstructionRecorder::new_ref(
|
||||
tx.message().instructions().len(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let log_collector = if enable_log_recording {
|
||||
Some(LogCollector::new_ref())
|
||||
} else {
|
||||
@ -3691,7 +3683,6 @@ impl Bank {
|
||||
self.rent_collector.rent,
|
||||
log_collector.clone(),
|
||||
executors.clone(),
|
||||
instruction_recorder.clone(),
|
||||
self.feature_set.clone(),
|
||||
compute_budget,
|
||||
timings,
|
||||
@ -3747,16 +3738,17 @@ impl Bank {
|
||||
.ok()
|
||||
});
|
||||
|
||||
let inner_instructions = instruction_recorder
|
||||
.and_then(|instruction_recorder| Rc::try_unwrap(instruction_recorder).ok())
|
||||
.map(|instruction_recorder| instruction_recorder.into_inner().deconstruct());
|
||||
|
||||
loaded_transaction.accounts = transaction_context.deconstruct();
|
||||
let (accounts, instruction_trace) = transaction_context.deconstruct();
|
||||
loaded_transaction.accounts = accounts;
|
||||
|
||||
TransactionExecutionResult::Executed(TransactionExecutionDetails {
|
||||
status,
|
||||
log_messages,
|
||||
inner_instructions,
|
||||
inner_instructions: if enable_cpi_recording {
|
||||
Some(instruction_trace)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
durable_nonce_fee,
|
||||
})
|
||||
}
|
||||
@ -15657,6 +15649,7 @@ pub(crate) mod tests {
|
||||
sol_to_lamports(1.),
|
||||
bank.last_blockhash(),
|
||||
);
|
||||
let number_of_instructions_at_transaction_level = tx.message().instructions.len();
|
||||
let num_accounts = tx.message().account_keys.len();
|
||||
let sanitized_tx = SanitizedTransaction::try_from_legacy_transaction(tx).unwrap();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
@ -15674,6 +15667,7 @@ pub(crate) mod tests {
|
||||
let transaction_context = TransactionContext::new(
|
||||
loaded_txs[0].0.as_ref().unwrap().accounts.clone(),
|
||||
compute_budget.max_invoke_depth.saturating_add(1),
|
||||
number_of_instructions_at_transaction_level,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -3,7 +3,6 @@ use {
|
||||
solana_measure::measure::Measure,
|
||||
solana_program_runtime::{
|
||||
compute_budget::ComputeBudget,
|
||||
instruction_recorder::InstructionRecorder,
|
||||
invoke_context::{BuiltinProgram, Executors, InvokeContext},
|
||||
log_collector::LogCollector,
|
||||
sysvar_cache::SysvarCache,
|
||||
@ -58,7 +57,6 @@ impl MessageProcessor {
|
||||
rent: Rent,
|
||||
log_collector: Option<Rc<RefCell<LogCollector>>>,
|
||||
executors: Rc<RefCell<Executors>>,
|
||||
instruction_recorder: Option<Rc<RefCell<InstructionRecorder>>>,
|
||||
feature_set: Arc<FeatureSet>,
|
||||
compute_budget: ComputeBudget,
|
||||
timings: &mut ExecuteTimings,
|
||||
@ -75,7 +73,6 @@ impl MessageProcessor {
|
||||
log_collector,
|
||||
compute_budget,
|
||||
executors,
|
||||
instruction_recorder,
|
||||
feature_set,
|
||||
blockhash,
|
||||
lamports_per_signature,
|
||||
@ -242,7 +239,7 @@ mod tests {
|
||||
create_loadable_account_for_test("mock_system_program"),
|
||||
),
|
||||
];
|
||||
let mut transaction_context = TransactionContext::new(accounts, 1);
|
||||
let mut transaction_context = TransactionContext::new(accounts, 1, 3);
|
||||
let program_indices = vec![vec![2]];
|
||||
let executors = Rc::new(RefCell::new(Executors::default()));
|
||||
let account_metas = vec![
|
||||
@ -267,7 +264,6 @@ mod tests {
|
||||
rent_collector.rent,
|
||||
None,
|
||||
executors.clone(),
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
@ -308,7 +304,6 @@ mod tests {
|
||||
rent_collector.rent,
|
||||
None,
|
||||
executors.clone(),
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
@ -341,7 +336,6 @@ mod tests {
|
||||
rent_collector.rent,
|
||||
None,
|
||||
executors,
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
@ -441,7 +435,7 @@ mod tests {
|
||||
create_loadable_account_for_test("mock_system_program"),
|
||||
),
|
||||
];
|
||||
let mut transaction_context = TransactionContext::new(accounts, 1);
|
||||
let mut transaction_context = TransactionContext::new(accounts, 1, 3);
|
||||
let program_indices = vec![vec![2]];
|
||||
let executors = Rc::new(RefCell::new(Executors::default()));
|
||||
let account_metas = vec![
|
||||
@ -468,7 +462,6 @@ mod tests {
|
||||
rent_collector.rent,
|
||||
None,
|
||||
executors.clone(),
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
@ -502,7 +495,6 @@ mod tests {
|
||||
rent_collector.rent,
|
||||
None,
|
||||
executors.clone(),
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
@ -533,7 +525,6 @@ mod tests {
|
||||
rent_collector.rent,
|
||||
None,
|
||||
executors,
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
@ -586,7 +577,7 @@ mod tests {
|
||||
(secp256k1_program::id(), secp256k1_account),
|
||||
(mock_program_id, mock_program_account),
|
||||
];
|
||||
let mut transaction_context = TransactionContext::new(accounts, 1);
|
||||
let mut transaction_context = TransactionContext::new(accounts, 1, 1);
|
||||
|
||||
let message = SanitizedMessage::Legacy(Message::new(
|
||||
&[
|
||||
@ -607,7 +598,6 @@ mod tests {
|
||||
RentCollector::default().rent,
|
||||
None,
|
||||
Rc::new(RefCell::new(Executors::default())),
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
&mut ExecuteTimings::default(),
|
||||
|
@ -334,7 +334,7 @@ mod test {
|
||||
where
|
||||
F: FnMut(&mut InvokeContext, &KeyedAccount),
|
||||
{
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let mut invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let pubkey = Pubkey::new_unique();
|
||||
let account = create_account(lamports);
|
||||
|
@ -661,7 +661,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_address_create_with_seed_mismatch() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let from = Pubkey::new_unique();
|
||||
let seed = "dull boy";
|
||||
@ -676,7 +676,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_account_with_seed_missing_sig() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let from = Pubkey::new_unique();
|
||||
@ -707,7 +707,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_with_zero_lamports() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
// create account with zero lamports transferred
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
@ -742,7 +742,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_negative_lamports() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
// Attempt to create account with more lamports than remaining in from_account
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
@ -767,7 +767,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_request_more_than_allowed_data_length() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let from_account = RefCell::new(AccountSharedData::new(100, 0, &system_program::id()));
|
||||
let from = Pubkey::new_unique();
|
||||
@ -815,7 +815,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_already_in_use() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
// Attempt to create system account in account already owned by another program
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
@ -884,7 +884,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_unsigned() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
// Attempt to create an account without signing the transfer
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
@ -940,7 +940,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_sysvar_invalid_id_with_feature() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
// Attempt to create system account in account already owned by another program
|
||||
let from = Pubkey::new_unique();
|
||||
@ -968,7 +968,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_data_populated() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
// Attempt to create system account in account with populated data
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
@ -1002,7 +1002,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_create_from_account_is_nonce_fail() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let nonce = Pubkey::new_unique();
|
||||
let nonce_account = RefCell::new(
|
||||
@ -1041,7 +1041,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_assign() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let new_owner = Pubkey::new(&[9; 32]);
|
||||
let pubkey = Pubkey::new_unique();
|
||||
@ -1084,7 +1084,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_assign_to_sysvar_with_feature() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let new_owner = sysvar::id();
|
||||
let from = Pubkey::new_unique();
|
||||
@ -1135,7 +1135,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_transfer_lamports() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let from = Pubkey::new_unique();
|
||||
let from_account = RefCell::new(AccountSharedData::new(100, 0, &Pubkey::new(&[2; 32]))); // account owner should not matter
|
||||
@ -1174,7 +1174,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_transfer_with_seed() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let base = Pubkey::new_unique();
|
||||
let base_account = RefCell::new(AccountSharedData::new(100, 0, &Pubkey::new(&[2; 32]))); // account owner should not matter
|
||||
@ -1235,7 +1235,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_transfer_lamports_from_nonce_account_fail() {
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1);
|
||||
let mut transaction_context = TransactionContext::new(Vec::new(), 1, 1);
|
||||
let invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
|
||||
let from = Pubkey::new_unique();
|
||||
let from_account = RefCell::new(
|
||||
|
Reference in New Issue
Block a user