From 8df9a68b0a96e7eef8579d371dd2359ed3db822d Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Fri, 26 Jul 2024 10:47:52 -0400 Subject: [PATCH 1/3] Generic construct_instructions_account - same impl as SanitizedMessage::decompile_instructions --- svm/src/account_loader.rs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index 20c7dab99f0552..0d4012b0eb1f6e 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -20,10 +20,14 @@ use { rent_collector::{CollectedInfo, RentCollector, RENT_EXEMPT_RENT_EPOCH}, rent_debits::RentDebits, saturating_add_assign, - sysvar::{self, instructions::construct_instructions_data}, + sysvar::{ + self, + instructions::{construct_instructions_data, BorrowedAccountMeta, BorrowedInstruction}, + }, transaction::{Result, SanitizedTransaction, TransactionError}, transaction_context::{IndexOfAccount, TransactionAccount}, }, + solana_svm_transaction::svm_message::SVMMessage, solana_system_program::{get_system_account_kind, SystemAccountKind}, std::num::NonZeroU32, }; @@ -393,9 +397,32 @@ fn accumulate_and_check_loaded_account_data_size( } } -fn construct_instructions_account(message: &SanitizedMessage) -> AccountSharedData { +fn construct_instructions_account(message: &impl SVMMessage) -> AccountSharedData { + let account_keys = message.account_keys(); + let mut decompiled_instructions = Vec::with_capacity(message.num_instructions()); + for (program_id, instruction) in message.program_instructions_iter() { + let accounts = instruction + .accounts + .iter() + .map(|account_index| { + let account_index = usize::from(*account_index); + BorrowedAccountMeta { + is_signer: message.is_signer(account_index), + is_writable: message.is_writable(account_index), + pubkey: account_keys.get(account_index).unwrap(), + } + }) + .collect(); + + decompiled_instructions.push(BorrowedInstruction { + accounts, + data: &instruction.data, + program_id, + }); + } + AccountSharedData::from(Account { - data: construct_instructions_data(&message.decompile_instructions()), + data: construct_instructions_data(&decompiled_instructions), owner: sysvar::id(), ..Account::default() }) From 1b509e6297918d83a22ffb50e670ab7ff2b6e45e Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Fri, 26 Jul 2024 10:58:01 -0400 Subject: [PATCH 2/3] generic load_transaction_accounts --- svm/src/account_loader.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index 0d4012b0eb1f6e..9e5d1f6be72a2d 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -12,7 +12,6 @@ use { account::{Account, AccountSharedData, ReadableAccount, WritableAccount}, feature_set::{self, FeatureSet}, fee::FeeDetails, - message::SanitizedMessage, native_loader, nonce::State as NonceState, pubkey::Pubkey, @@ -192,7 +191,7 @@ pub(crate) fn load_accounts( fn load_transaction_accounts( callbacks: &CB, - message: &SanitizedMessage, + message: &impl SVMMessage, tx_details: ValidatedTransactionDetails, error_metrics: &mut TransactionErrorMetrics, account_overrides: Option<&AccountOverrides>, @@ -207,9 +206,8 @@ fn load_transaction_accounts( let mut accumulated_accounts_data_size: u32 = 0; let instruction_accounts = message - .instructions() - .iter() - .flat_map(|instruction| &instruction.accounts) + .instructions_iter() + .flat_map(|instruction| instruction.accounts) .unique() .collect::>(); @@ -295,8 +293,7 @@ fn load_transaction_accounts( let builtins_start_index = accounts.len(); let program_indices = message - .instructions() - .iter() + .instructions_iter() .map(|instruction| { let mut account_indices = Vec::with_capacity(2); let program_index = instruction.program_id_index as usize; @@ -416,7 +413,7 @@ fn construct_instructions_account(message: &impl SVMMessage) -> AccountSharedDat decompiled_instructions.push(BorrowedInstruction { accounts, - data: &instruction.data, + data: instruction.data, program_id, }); } From 7d33ed787e976d438ff3cc6584cd10f7e618433c Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Fri, 26 Jul 2024 10:59:40 -0400 Subject: [PATCH 3/3] generic load_accounts --- svm/src/account_loader.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/svm/src/account_loader.rs b/svm/src/account_loader.rs index 9e5d1f6be72a2d..4004b6c4d6fb07 100644 --- a/svm/src/account_loader.rs +++ b/svm/src/account_loader.rs @@ -23,7 +23,7 @@ use { self, instructions::{construct_instructions_data, BorrowedAccountMeta, BorrowedInstruction}, }, - transaction::{Result, SanitizedTransaction, TransactionError}, + transaction::{Result, TransactionError}, transaction_context::{IndexOfAccount, TransactionAccount}, }, solana_svm_transaction::svm_message::SVMMessage, @@ -158,7 +158,7 @@ pub fn validate_fee_payer( /// second element. pub(crate) fn load_accounts( callbacks: &CB, - txs: &[SanitizedTransaction], + txs: &[impl SVMMessage], validation_results: Vec, error_metrics: &mut TransactionErrorMetrics, account_overrides: Option<&AccountOverrides>, @@ -170,12 +170,10 @@ pub(crate) fn load_accounts( .zip(validation_results) .map(|etx| match etx { (tx, Ok(tx_details)) => { - let message = tx.message(); - // load transactions load_transaction_accounts( callbacks, - message, + tx, tx_details, error_metrics, account_overrides,