Skip to content

Commit

Permalink
SVM: change modified programs result to hash map
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed May 16, 2024
1 parent e01278e commit 242a8ae
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion accounts-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ solana-inline-spl = { workspace = true }
solana-measure = { workspace = true }
solana-metrics = { workspace = true }
solana-nohash-hasher = { workspace = true }
solana-program-runtime = { workspace = true }
solana-rayon-threadlimit = { workspace = true }
solana-sdk = { workspace = true }
solana-stake-program = { workspace = true, optional = true }
Expand Down
3 changes: 1 addition & 2 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ mod tests {
use {
super::*,
assert_matches::assert_matches,
solana_program_runtime::loaded_programs::ProgramCacheForTxBatch,
solana_sdk::{
account::{AccountSharedData, WritableAccount},
address_lookup_table::state::LookupTableMeta,
Expand Down Expand Up @@ -884,7 +883,7 @@ mod tests {
executed_units: 0,
accounts_data_len_delta: 0,
},
programs_modified_by_tx: Box::<ProgramCacheForTxBatch>::default(),
programs_modified_by_tx: HashMap::new(),
}
}

Expand Down
12 changes: 8 additions & 4 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ impl ProgramCacheForTxBatch {
}
}

pub fn entries(&self) -> &HashMap<Pubkey, Arc<ProgramCacheEntry>> {
&self.entries
}

/// Returns the current environments depending on the given epoch
pub fn get_environments_for_epoch(&self, epoch: Epoch) -> &ProgramRuntimeEnvironments {
if epoch != self.latest_root_epoch {
Expand Down Expand Up @@ -761,8 +765,8 @@ impl ProgramCacheForTxBatch {
self.slot = slot;
}

pub fn merge(&mut self, other: &Self) {
other.entries.iter().for_each(|(key, entry)| {
pub fn merge(&mut self, modified_entries: &HashMap<Pubkey, Arc<ProgramCacheEntry>>) {
modified_entries.iter().for_each(|(key, entry)| {
self.merged_modified = true;
self.replenish(*key, entry.clone());
})
Expand Down Expand Up @@ -1153,8 +1157,8 @@ impl<FG: ForkGraph> ProgramCache<FG> {
}
}

pub fn merge(&mut self, tx_batch_cache: &ProgramCacheForTxBatch) {
tx_batch_cache.entries.iter().for_each(|(key, entry)| {
pub fn merge(&mut self, modified_entries: &HashMap<Pubkey, Arc<ProgramCacheEntry>>) {
modified_entries.iter().for_each(|(key, entry)| {
self.assign_program(*key, entry.clone());
})
}
Expand Down
1 change: 0 additions & 1 deletion programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion runtime/src/bank/builtins/core_bpf_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Bank {
.program_cache
.write()
.unwrap()
.merge(&programs_modified);
.merge(programs_modified.entries());

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use {
compute_budget::ComputeBudget,
compute_budget_processor::{self, MAX_COMPUTE_UNIT_LIMIT},
declare_process_instruction,
loaded_programs::{ProgramCacheEntry, ProgramCacheEntryType, ProgramCacheForTxBatch},
loaded_programs::{ProgramCacheEntry, ProgramCacheEntryType},
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
timings::ExecuteTimings,
},
Expand Down Expand Up @@ -242,7 +242,7 @@ fn new_execution_result(
executed_units: 0,
accounts_data_len_delta: 0,
},
programs_modified_by_tx: Box::<ProgramCacheForTxBatch>::default(),
programs_modified_by_tx: HashMap::new(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
executed_units,
accounts_data_len_delta,
},
programs_modified_by_tx: Box::new(programs_modified_by_tx),
programs_modified_by_tx: programs_modified_by_tx.entries().clone(),
}
}

Expand Down
6 changes: 4 additions & 2 deletions svm/src/transaction_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
pub use solana_sdk::inner_instruction::{InnerInstruction, InnerInstructionsList};
use {
crate::nonce_info::{NonceFull, NonceInfo},
solana_program_runtime::loaded_programs::ProgramCacheForTxBatch,
solana_program_runtime::loaded_programs::ProgramCacheEntry,
solana_sdk::{
pubkey::Pubkey,
rent_debits::RentDebits,
transaction::{self, TransactionError},
transaction_context::TransactionReturnData,
},
std::{collections::HashMap, sync::Arc},
};

pub struct TransactionResults {
Expand All @@ -34,7 +36,7 @@ pub struct TransactionResults {
pub enum TransactionExecutionResult {
Executed {
details: TransactionExecutionDetails,
programs_modified_by_tx: Box<ProgramCacheForTxBatch>,
programs_modified_by_tx: HashMap<Pubkey, Arc<ProgramCacheEntry>>,
},
NotExecuted(TransactionError),
}
Expand Down

0 comments on commit 242a8ae

Please sign in to comment.