Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions processor/src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ use accountsdb::AccountLoader;

/// Bridges SVM transaction loading to keeper-backed accounts.
///
/// When `LOAD_OWNED` is set, loaded accounts are copied to owned data; this is
/// used by simulation, which must always operate on owned account copies.
pub(crate) struct LoadCallback<'a, const LOAD_OWNED: bool> {
/// Simulation always loads owned account copies.
pub(crate) struct LoadCallback<'a, const SIMULATION: bool> {
/// Reads accounts from the engine's accounts store.
pub(crate) loader: AccountLoader<'a>,
}

impl<const LOAD_OWNED: bool> TransactionProcessingCallback for LoadCallback<'_, LOAD_OWNED> {
impl<const SIMULATION: bool> TransactionProcessingCallback for LoadCallback<'_, SIMULATION> {
fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<(AccountSharedData, Slot)> {
let account = if LOAD_OWNED {
let account = if SIMULATION {
self.loader.read(pubkey, Clone::clone)
} else {
// SAFETY: execution owns the account until commit/fanout and is
Expand Down
6 changes: 3 additions & 3 deletions processor/src/svm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ impl SvmContext {
}

/// Loads and executes a single transaction through the SVM.
pub(crate) fn execute<const LOAD_OWNED: bool>(
pub(crate) fn execute<const SIMULATION: bool>(
&mut self,
loader: AccountLoader<'_>,
txn: &ResolvedTransaction,
state: &Keeper,
) -> LoadAndExecuteSanitizedTransactionOutput {
let load = LoadCallback::<LOAD_OWNED> { loader };
let load = LoadCallback::<SIMULATION> { loader };
let rent = state.rent();
if self.env.rent != rent {
self.processor.sysvar_cache_mut().set_rent(&rent);
Expand All @@ -113,7 +113,7 @@ impl SvmContext {
}
};
let invoke = InvokeCallback { featureset: features };
self.processor.load_and_execute_sanitized_transaction(
self.processor.load_and_execute_sanitized_transaction::<SIMULATION>(
load,
&invoke,
txn,
Expand Down
5 changes: 3 additions & 2 deletions solana/svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl TransactionBatchProcessor {
///
/// The owned loading callback is dropped as soon as account loading finishes.
/// Invocation then uses the separate borrowed callback.
pub fn load_and_execute_sanitized_transaction(
pub fn load_and_execute_sanitized_transaction<const SIMULATION: bool>(
&self,
load: impl TransactionProcessingCallback,
invoke: &impl InvokeContextCallback,
Expand Down Expand Up @@ -231,7 +231,8 @@ impl TransactionBatchProcessor {
config,
);
balance_collector.collect_post_balances(&executed_tx.loaded_transaction.accounts);
if executed_tx.access_is_valid(tx) {
// Simulation discards account changes, so program changes must stay local too.
if executed_tx.access_is_valid(tx) && !SIMULATION {
let cache = program_cache_for_tx_batch.drain_modified_entries();
self.program_cache.merge(&cache);
}
Expand Down
Loading