From 2dc95087ae736a22d7380e14a125f5196fc81b68 Mon Sep 17 00:00:00 2001 From: Joe C Date: Tue, 18 Jun 2024 10:07:22 -0500 Subject: [PATCH] SVM: Move `fee_structure` to environment input (#1771) * SVM: add `fee_structure` to environment arg * runtime: add `fee_structure` to bank * SVM: drop `fee_structure` from global configs --- runtime/src/bank.rs | 12 ++++++++++-- svm/src/transaction_processor.rs | 25 +++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 551474c168d00a..428feb94006f61 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -602,6 +602,7 @@ impl PartialEq for Bank { collector_fee_details: _, compute_budget: _, transaction_account_lock_limit: _, + fee_structure: _, // Ignore new fields explicitly if they do not impact PartialEq. // Adding ".." will remove compile-time checks that if a new field // is added to the struct, this PartialEq is accordingly updated. @@ -887,6 +888,9 @@ pub struct Bank { /// The max number of accounts that a transaction may lock. transaction_account_lock_limit: Option, + + /// Fee structure to use for assessing transaction fees. + fee_structure: FeeStructure, } struct VoteWithStakeDelegations { @@ -1004,6 +1008,7 @@ impl Bank { collector_fee_details: RwLock::new(CollectorFeeDetails::default()), compute_budget: None, transaction_account_lock_limit: None, + fee_structure: FeeStructure::default(), }; bank.transaction_processor = @@ -1249,6 +1254,7 @@ impl Bank { collector_fee_details: RwLock::new(CollectorFeeDetails::default()), compute_budget: parent.compute_budget, transaction_account_lock_limit: parent.transaction_account_lock_limit, + fee_structure: parent.fee_structure.clone(), }; let (_, ancestors_time_us) = measure_us!({ @@ -1640,6 +1646,7 @@ impl Bank { collector_fee_details: RwLock::new(CollectorFeeDetails::default()), compute_budget: runtime_config.compute_budget, transaction_account_lock_limit: runtime_config.transaction_account_lock_limit, + fee_structure: FeeStructure::default(), }; bank.transaction_processor = @@ -3716,6 +3723,7 @@ impl Bank { 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), + fee_structure: Some(&self.fee_structure), lamports_per_signature, rent_collector: Some(&self.rent_collector), }; @@ -6827,7 +6835,7 @@ impl Bank { } pub fn fee_structure(&self) -> &FeeStructure { - &self.transaction_processor.fee_structure + &self.fee_structure } pub fn compute_budget(&self) -> Option { @@ -7149,7 +7157,7 @@ impl Bank { } pub fn set_fee_structure(&mut self, fee_structure: &FeeStructure) { - self.transaction_processor.fee_structure = fee_structure.clone(); + self.fee_structure = fee_structure.clone(); } pub fn load_program( diff --git a/svm/src/transaction_processor.rs b/svm/src/transaction_processor.rs index a1946061ec8b25..0c3557bc8970ba 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -128,6 +128,8 @@ pub struct TransactionProcessingEnvironment<'a> { pub epoch_vote_accounts: Option<&'a VoteAccountsHashMap>, /// Runtime feature set to use for the transaction batch. pub feature_set: Arc, + /// Fee structure to use for assessing transaction fees. + pub fee_structure: Option<&'a FeeStructure>, /// Lamports per signature to charge per transaction. pub lamports_per_signature: u64, /// Rent collector to use for the transaction batch. @@ -142,9 +144,6 @@ pub struct TransactionBatchProcessor { /// Bank epoch epoch: Epoch, - /// Transaction fee structure - pub fee_structure: FeeStructure, - /// SysvarCache is a collection of system variables that are /// accessible from on chain programs. It is passed to SVM from /// client code (e.g. Bank) and forwarded to the MessageProcessor. @@ -162,7 +161,6 @@ impl Debug for TransactionBatchProcessor { f.debug_struct("TransactionBatchProcessor") .field("slot", &self.slot) .field("epoch", &self.epoch) - .field("fee_structure", &self.fee_structure) .field("sysvar_cache", &self.sysvar_cache) .field("program_cache", &self.program_cache) .finish() @@ -174,7 +172,6 @@ impl Default for TransactionBatchProcessor { Self { slot: Slot::default(), epoch: Epoch::default(), - fee_structure: FeeStructure::default(), sysvar_cache: RwLock::::default(), program_cache: Arc::new(RwLock::new(ProgramCache::new( Slot::default(), @@ -190,7 +187,6 @@ impl TransactionBatchProcessor { Self { slot, epoch, - fee_structure: FeeStructure::default(), sysvar_cache: RwLock::::default(), program_cache: Arc::new(RwLock::new(ProgramCache::new(slot, epoch))), builtin_program_ids: RwLock::new(builtin_program_ids), @@ -201,7 +197,6 @@ impl TransactionBatchProcessor { Self { slot, epoch, - fee_structure: self.fee_structure.clone(), sysvar_cache: RwLock::::default(), program_cache: self.program_cache.clone(), builtin_program_ids: RwLock::new(self.builtin_program_ids.read().unwrap().clone()), @@ -236,6 +231,9 @@ impl TransactionBatchProcessor { sanitized_txs, check_results, &environment.feature_set, + environment + .fee_structure + .unwrap_or(&FeeStructure::default()), environment .rent_collector .unwrap_or(&RentCollector::default()), @@ -399,6 +397,7 @@ impl TransactionBatchProcessor { sanitized_txs: &[impl core::borrow::Borrow], check_results: Vec, feature_set: &FeatureSet, + fee_structure: &FeeStructure, rent_collector: &RentCollector, error_counters: &mut TransactionErrorMetrics, ) -> Vec { @@ -417,6 +416,7 @@ impl TransactionBatchProcessor { callbacks, message, feature_set, + fee_structure, lamports_per_signature, rent_collector, error_counters, @@ -453,6 +453,7 @@ impl TransactionBatchProcessor { callbacks: &CB, message: &SanitizedMessage, feature_set: &FeatureSet, + fee_structure: &FeeStructure, lamports_per_signature: u64, rent_collector: &RentCollector, error_counters: &mut TransactionErrorMetrics, @@ -472,7 +473,7 @@ impl TransactionBatchProcessor { ) .rent_amount; - let fee_details = self.fee_structure.calculate_fee_details( + let fee_details = fee_structure.calculate_fee_details( message, lamports_per_signature, &process_compute_budget_instructions(message.program_instructions_iter()) @@ -1975,6 +1976,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2033,6 +2035,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2068,6 +2071,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &RentCollector::default(), &mut error_counters, @@ -2096,6 +2100,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &RentCollector::default(), &mut error_counters, @@ -2128,6 +2133,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2158,6 +2164,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &RentCollector::default(), &mut error_counters, @@ -2209,6 +2216,7 @@ mod tests { &mock_bank, &message, &feature_set, + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2254,6 +2262,7 @@ mod tests { &mock_bank, &message, &feature_set, + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters,