Skip to content

Commit

Permalink
SVM: change modified programs result to hash map (anza-xyz#1391)
Browse files Browse the repository at this point in the history
* SVM: change modified programs result to hash map

* take entries
  • Loading branch information
buffalojoec authored and samkim-crypto committed Jul 31, 2024
1 parent aeb5f88 commit f084303
Show file tree
Hide file tree
Showing 9 changed files with 21 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 @@ -826,7 +826,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 @@ -878,7 +877,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
16 changes: 12 additions & 4 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,14 @@ impl ProgramCacheForTxBatch {
}
}

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

pub fn take_entries(&mut self) -> HashMap<Pubkey, Arc<ProgramCacheEntry>> {
std::mem::take(&mut 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 @@ -764,8 +772,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 @@ -1156,8 +1164,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 @@ -232,7 +232,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 @@ -43,7 +43,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 @@ -247,7 +247,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 @@ -868,7 +868,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.take_entries(),
}
}

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,13 +6,15 @@
pub use solana_sdk::inner_instruction::{InnerInstruction, InnerInstructionsList};
use {
serde::{Deserialize, Serialize},
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 @@ -42,7 +44,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 f084303

Please sign in to comment.