Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVM: Group transaction processing environment #1650

Merged
merged 5 commits into from
Jun 14, 2024
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
33 changes: 12 additions & 21 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ use {
transaction_processing_callback::TransactionProcessingCallback,
transaction_processor::{
ExecutionRecordingConfig, TransactionBatchProcessor, TransactionLogMessages,
TransactionProcessingConfig,
TransactionProcessingConfig, TransactionProcessingEnvironment,
},
transaction_results::{
TransactionExecutionDetails, TransactionExecutionResult,
Expand Down Expand Up @@ -3712,12 +3712,23 @@ impl Bank {
debug!("check: {}us", check_time.as_us());
timings.saturating_add_in_place(ExecuteTimingType::CheckUs, check_time.as_us());

let (blockhash, lamports_per_signature) = self.last_blockhash_and_lamports_per_signature();
let processing_environment = TransactionProcessingEnvironment {
blockhash,
epoch_total_stake: self.epoch_total_stake(self.epoch()),
epoch_vote_accounts: self.epoch_vote_accounts(self.epoch()),
feature_set: Arc::clone(&self.feature_set),
lamports_per_signature,
rent_collector: Some(&self.rent_collector),
};

let sanitized_output = self
.transaction_processor
.load_and_execute_sanitized_transactions(
self,
sanitized_txs,
check_results,
&processing_environment,
&processing_config,
);

Expand Down Expand Up @@ -6878,26 +6889,6 @@ impl TransactionProcessingCallback for Bank {
.map(|(acc, _)| acc)
}

fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) {
self.last_blockhash_and_lamports_per_signature()
}

fn get_rent_collector(&self) -> &RentCollector {
&self.rent_collector
}

fn get_feature_set(&self) -> Arc<FeatureSet> {
self.feature_set.clone()
}

fn get_epoch_total_stake(&self) -> Option<u64> {
self.epoch_total_stake(self.epoch())
}

fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> {
self.epoch_vote_accounts(self.epoch())
}

fn get_program_match_criteria(&self, program: &Pubkey) -> ProgramCacheMatchCriteria {
if self.check_program_modification_slot {
self.program_modification_slot(program)
Expand Down
79 changes: 42 additions & 37 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub(crate) fn load_accounts<CB: TransactionProcessingCallback>(
validation_results: Vec<TransactionValidationResult>,
error_metrics: &mut TransactionErrorMetrics,
account_overrides: Option<&AccountOverrides>,
feature_set: &FeatureSet,
rent_collector: &RentCollector,
loaded_programs: &ProgramCacheForTxBatch,
) -> Vec<TransactionLoadResult> {
txs.iter()
Expand All @@ -178,6 +180,8 @@ pub(crate) fn load_accounts<CB: TransactionProcessingCallback>(
tx_details,
error_metrics,
account_overrides,
feature_set,
rent_collector,
loaded_programs,
)
}
Expand All @@ -192,15 +196,14 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
tx_details: ValidatedTransactionDetails,
error_metrics: &mut TransactionErrorMetrics,
account_overrides: Option<&AccountOverrides>,
feature_set: &FeatureSet,
rent_collector: &RentCollector,
loaded_programs: &ProgramCacheForTxBatch,
) -> Result<LoadedTransaction> {
let feature_set = callbacks.get_feature_set();

let mut tx_rent: TransactionRent = 0;
let account_keys = message.account_keys();
let mut accounts_found = Vec::with_capacity(account_keys.len());
let mut rent_debits = RentDebits::default();
let rent_collector = callbacks.get_rent_collector();

let requested_loaded_accounts_data_size_limit =
get_requested_loaded_accounts_data_size_limit(message)?;
Expand Down Expand Up @@ -253,7 +256,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
.map(|mut account| {
if message.is_writable(i) {
let rent_due = collect_rent_from_account(
&feature_set,
feature_set,
rent_collector,
key,
&mut account,
Expand Down Expand Up @@ -466,15 +469,12 @@ mod tests {
transaction::{Result, SanitizedTransaction, Transaction, TransactionError},
transaction_context::{TransactionAccount, TransactionContext},
},
solana_vote::vote_account::VoteAccountsHashMap,
std::{borrow::Cow, collections::HashMap, convert::TryFrom, sync::Arc},
};

#[derive(Default)]
struct TestCallbacks {
accounts_map: HashMap<Pubkey, AccountSharedData>,
rent_collector: RentCollector,
feature_set: Arc<FeatureSet>,
}

impl TransactionProcessingCallback for TestCallbacks {
Expand All @@ -485,26 +485,6 @@ mod tests {
fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData> {
self.accounts_map.get(pubkey).cloned()
}

fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) {
(Hash::new_unique(), 0)
}

fn get_rent_collector(&self) -> &RentCollector {
&self.rent_collector
}

fn get_feature_set(&self) -> Arc<FeatureSet> {
self.feature_set.clone()
}

fn get_epoch_total_stake(&self) -> Option<u64> {
None
}

fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> {
None
}
}

fn load_accounts_with_features_and_rent(
Expand All @@ -521,11 +501,7 @@ mod tests {
for (pubkey, account) in accounts {
accounts_map.insert(*pubkey, account.clone());
}
let callbacks = TestCallbacks {
accounts_map,
rent_collector: rent_collector.clone(),
feature_set: Arc::new(feature_set.clone()),
};
let callbacks = TestCallbacks { accounts_map };
load_accounts(
&callbacks,
&[sanitized_tx],
Expand All @@ -535,6 +511,8 @@ mod tests {
})],
error_metrics,
None,
feature_set,
rent_collector,
&ProgramCacheForTxBatch::default(),
)
}
Expand Down Expand Up @@ -811,17 +789,15 @@ mod tests {
for (pubkey, account) in accounts {
accounts_map.insert(*pubkey, account.clone());
}
let callbacks = TestCallbacks {
accounts_map,
rent_collector: RentCollector::default(),
feature_set: Arc::new(FeatureSet::all_enabled()),
};
let callbacks = TestCallbacks { accounts_map };
load_accounts(
&callbacks,
&[tx],
vec![Ok(ValidatedTransactionDetails::default())],
&mut error_metrics,
account_overrides,
&FeatureSet::all_enabled(),
&RentCollector::default(),
&ProgramCacheForTxBatch::default(),
)
}
Expand Down Expand Up @@ -1183,6 +1159,8 @@ mod tests {
},
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1246,6 +1224,8 @@ mod tests {
ValidatedTransactionDetails::default(),
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1288,6 +1268,8 @@ mod tests {
ValidatedTransactionDetails::default(),
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1330,6 +1312,8 @@ mod tests {
ValidatedTransactionDetails::default(),
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1387,6 +1371,8 @@ mod tests {
},
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1452,6 +1438,8 @@ mod tests {
ValidatedTransactionDetails::default(),
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1503,6 +1491,8 @@ mod tests {
ValidatedTransactionDetails::default(),
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1567,6 +1557,8 @@ mod tests {
},
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1660,6 +1652,8 @@ mod tests {
},
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1728,6 +1722,8 @@ mod tests {
vec![Ok(ValidatedTransactionDetails::default())],
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&ProgramCacheForTxBatch::default(),
);

Expand Down Expand Up @@ -1816,6 +1812,8 @@ mod tests {
vec![validation_result],
&mut error_metrics,
None,
&FeatureSet::default(),
&RentCollector::default(),
&loaded_programs,
);

Expand Down Expand Up @@ -1855,6 +1853,9 @@ mod tests {
#[test]
fn test_load_accounts_error() {
let mock_bank = TestCallbacks::default();
let feature_set = FeatureSet::default();
let rent_collector = RentCollector::default();

let message = Message {
account_keys: vec![Pubkey::new_from_array([0; 32])],
header: MessageHeader::default(),
Expand Down Expand Up @@ -1886,6 +1887,8 @@ mod tests {
vec![validation_result.clone()],
&mut TransactionErrorMetrics::default(),
None,
&feature_set,
&rent_collector,
&ProgramCacheForTxBatch::default(),
);

Expand All @@ -1902,6 +1905,8 @@ mod tests {
vec![validation_result],
&mut TransactionErrorMetrics::default(),
None,
&feature_set,
&rent_collector,
&ProgramCacheForTxBatch::default(),
);

Expand Down
28 changes: 1 addition & 27 deletions svm/src/program_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ mod tests {
loaded_programs::{BlockRelation, ForkGraph, ProgramRuntimeEnvironments},
solana_rbpf::program::BuiltinProgram,
},
solana_sdk::{
account::WritableAccount, bpf_loader, bpf_loader_upgradeable, feature_set::FeatureSet,
hash::Hash, rent_collector::RentCollector,
},
solana_vote::vote_account::VoteAccountsHashMap,
solana_sdk::{account::WritableAccount, bpf_loader, bpf_loader_upgradeable},
std::{
cell::RefCell,
collections::HashMap,
Expand All @@ -252,8 +248,6 @@ mod tests {

#[derive(Default, Clone)]
pub struct MockBankCallback {
rent_collector: RentCollector,
feature_set: Arc<FeatureSet>,
pub account_shared_data: RefCell<HashMap<Pubkey, AccountSharedData>>,
}

Expand All @@ -274,26 +268,6 @@ mod tests {
self.account_shared_data.borrow().get(pubkey).cloned()
}

fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64) {
(Hash::new_unique(), 2)
}

fn get_rent_collector(&self) -> &RentCollector {
&self.rent_collector
}

fn get_feature_set(&self) -> Arc<FeatureSet> {
self.feature_set.clone()
}

fn get_epoch_total_stake(&self) -> Option<u64> {
None
}

fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> {
None
}

fn add_builtin_account(&self, name: &str, program_id: &Pubkey) {
let mut account_data = AccountSharedData::default();
account_data.set_data(name.as_bytes().to_vec());
Expand Down
17 changes: 1 addition & 16 deletions svm/src/transaction_processing_callback.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use {
solana_program_runtime::loaded_programs::ProgramCacheMatchCriteria,
solana_sdk::{
account::AccountSharedData, feature_set::FeatureSet, hash::Hash, pubkey::Pubkey,
rent_collector::RentCollector,
},
solana_vote::vote_account::VoteAccountsHashMap,
std::sync::Arc,
solana_sdk::{account::AccountSharedData, pubkey::Pubkey},
};

/// Runtime callbacks for transaction processing.
Expand All @@ -14,16 +9,6 @@ pub trait TransactionProcessingCallback {

fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData>;

fn get_last_blockhash_and_lamports_per_signature(&self) -> (Hash, u64);

fn get_rent_collector(&self) -> &RentCollector;

fn get_feature_set(&self) -> Arc<FeatureSet>;

fn get_epoch_total_stake(&self) -> Option<u64>;

fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap>;

fn get_program_match_criteria(&self, _program: &Pubkey) -> ProgramCacheMatchCriteria {
ProgramCacheMatchCriteria::NoCriteria
}
Expand Down
Loading