diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 18aafe957d01ef..ce24da3b71431e 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -600,6 +600,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. @@ -885,6 +886,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 { @@ -1002,6 +1006,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 = @@ -1247,6 +1252,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!({ @@ -1638,6 +1644,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 = @@ -3714,6 +3721,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), }; @@ -6825,7 +6833,7 @@ impl Bank { } pub fn fee_structure(&self) -> &FeeStructure { - &self.transaction_processor.fee_structure + &self.fee_structure } pub fn compute_budget(&self) -> Option { @@ -7147,7 +7155,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 06174fdf6bac10..e212cb4f943941 100644 --- a/svm/src/transaction_processor.rs +++ b/svm/src/transaction_processor.rs @@ -131,6 +131,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. @@ -145,9 +147,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. @@ -165,7 +164,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() @@ -177,7 +175,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(), @@ -193,7 +190,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), @@ -204,7 +200,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()), @@ -239,6 +234,9 @@ impl TransactionBatchProcessor { sanitized_txs, check_results, &environment.feature_set, + environment + .fee_structure + .unwrap_or(&FeeStructure::default()), environment .rent_collector .unwrap_or(&RentCollector::default()), @@ -402,6 +400,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 { @@ -420,6 +419,7 @@ impl TransactionBatchProcessor { callbacks, message, feature_set, + fee_structure, lamports_per_signature, rent_collector, error_counters, @@ -456,6 +456,7 @@ impl TransactionBatchProcessor { callbacks: &CB, message: &SanitizedMessage, feature_set: &FeatureSet, + fee_structure: &FeeStructure, lamports_per_signature: u64, rent_collector: &RentCollector, error_counters: &mut TransactionErrorMetrics, @@ -475,7 +476,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()) @@ -1972,6 +1973,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2030,6 +2032,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2065,6 +2068,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &RentCollector::default(), &mut error_counters, @@ -2093,6 +2097,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &RentCollector::default(), &mut error_counters, @@ -2125,6 +2130,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2155,6 +2161,7 @@ mod tests { &mock_bank, &message, &FeatureSet::default(), + &FeeStructure::default(), lamports_per_signature, &RentCollector::default(), &mut error_counters, @@ -2206,6 +2213,7 @@ mod tests { &mock_bank, &message, &feature_set, + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters, @@ -2251,6 +2259,7 @@ mod tests { &mock_bank, &message, &feature_set, + &FeeStructure::default(), lamports_per_signature, &rent_collector, &mut error_counters,