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 Jun 4, 2024
1 parent 039c62b commit 2407074
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 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.

2 changes: 0 additions & 2 deletions 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 Expand Up @@ -84,7 +83,6 @@ dev-context-only-utils = ["dep:qualifier_attr", "dep:solana-stake-program", "dep
frozen-abi = [
"dep:solana-frozen-abi",
"dep:solana-frozen-abi-macro",
"solana-program-runtime/frozen-abi",
"solana-sdk/frozen-abi",
"solana-svm/frozen-abi",
"solana-vote-program/frozen-abi",
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 @@ -831,7 +831,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 @@ -883,7 +882,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 @@ -223,7 +223,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 @@ -42,7 +42,7 @@ use {
solana_logger,
solana_program_runtime::{
declare_process_instruction,
loaded_programs::{ProgramCacheEntry, ProgramCacheEntryType, ProgramCacheForTxBatch},
loaded_programs::{ProgramCacheEntry, ProgramCacheEntryType},
timings::ExecuteTimings,
},
solana_sdk::{
Expand Down Expand Up @@ -246,7 +246,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 @@ -726,7 +726,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 @@ -5,13 +5,15 @@
)]
pub use solana_sdk::inner_instruction::{InnerInstruction, InnerInstructionsList};
use {
solana_program_runtime::loaded_programs::ProgramCacheForTxBatch,
solana_program_runtime::loaded_programs::ProgramCacheEntry,
solana_sdk::{
fee::FeeDetails,
pubkey::Pubkey,
rent_debits::RentDebits,
transaction::{self, TransactionError},
transaction_context::TransactionReturnData,
},
std::{collections::HashMap, sync::Arc},
};

pub struct TransactionResults {
Expand Down Expand Up @@ -41,7 +43,7 @@ pub struct TransactionLoadedAccountsStats {
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 2407074

Please sign in to comment.