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: Move fee_structure to environment input #1771

Merged
merged 3 commits into from
Jun 18, 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
12 changes: 10 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -885,6 +886,9 @@ pub struct Bank {

/// The max number of accounts that a transaction may lock.
transaction_account_lock_limit: Option<usize>,

/// Fee structure to use for assessing transaction fees.
fee_structure: FeeStructure,
}

struct VoteWithStakeDelegations {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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!({
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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),
};
Expand Down Expand Up @@ -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<ComputeBudget> {
Expand Down Expand Up @@ -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(
Expand Down
25 changes: 17 additions & 8 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FeatureSet>,
/// 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.
Expand All @@ -145,9 +147,6 @@ pub struct TransactionBatchProcessor<FG: ForkGraph> {
/// 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.
Expand All @@ -165,7 +164,6 @@ impl<FG: ForkGraph> Debug for TransactionBatchProcessor<FG> {
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()
Expand All @@ -177,7 +175,6 @@ impl<FG: ForkGraph> Default for TransactionBatchProcessor<FG> {
Self {
slot: Slot::default(),
epoch: Epoch::default(),
fee_structure: FeeStructure::default(),
sysvar_cache: RwLock::<SysvarCache>::default(),
program_cache: Arc::new(RwLock::new(ProgramCache::new(
Slot::default(),
Expand All @@ -193,7 +190,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
Self {
slot,
epoch,
fee_structure: FeeStructure::default(),
sysvar_cache: RwLock::<SysvarCache>::default(),
program_cache: Arc::new(RwLock::new(ProgramCache::new(slot, epoch))),
builtin_program_ids: RwLock::new(builtin_program_ids),
Expand All @@ -204,7 +200,6 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
Self {
slot,
epoch,
fee_structure: self.fee_structure.clone(),
sysvar_cache: RwLock::<SysvarCache>::default(),
program_cache: self.program_cache.clone(),
builtin_program_ids: RwLock::new(self.builtin_program_ids.read().unwrap().clone()),
Expand Down Expand Up @@ -239,6 +234,9 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
sanitized_txs,
check_results,
&environment.feature_set,
environment
.fee_structure
.unwrap_or(&FeeStructure::default()),
environment
.rent_collector
.unwrap_or(&RentCollector::default()),
Expand Down Expand Up @@ -402,6 +400,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
sanitized_txs: &[impl core::borrow::Borrow<SanitizedTransaction>],
check_results: Vec<TransactionCheckResult>,
feature_set: &FeatureSet,
fee_structure: &FeeStructure,
rent_collector: &RentCollector,
error_counters: &mut TransactionErrorMetrics,
) -> Vec<TransactionValidationResult> {
Expand All @@ -420,6 +419,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
callbacks,
message,
feature_set,
fee_structure,
lamports_per_signature,
rent_collector,
error_counters,
Expand Down Expand Up @@ -456,6 +456,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
callbacks: &CB,
message: &SanitizedMessage,
feature_set: &FeatureSet,
fee_structure: &FeeStructure,
lamports_per_signature: u64,
rent_collector: &RentCollector,
error_counters: &mut TransactionErrorMetrics,
Expand All @@ -475,7 +476,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
)
.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())
Expand Down Expand Up @@ -1972,6 +1973,7 @@ mod tests {
&mock_bank,
&message,
&FeatureSet::default(),
&FeeStructure::default(),
lamports_per_signature,
&rent_collector,
&mut error_counters,
Expand Down Expand Up @@ -2030,6 +2032,7 @@ mod tests {
&mock_bank,
&message,
&FeatureSet::default(),
&FeeStructure::default(),
lamports_per_signature,
&rent_collector,
&mut error_counters,
Expand Down Expand Up @@ -2065,6 +2068,7 @@ mod tests {
&mock_bank,
&message,
&FeatureSet::default(),
&FeeStructure::default(),
lamports_per_signature,
&RentCollector::default(),
&mut error_counters,
Expand Down Expand Up @@ -2093,6 +2097,7 @@ mod tests {
&mock_bank,
&message,
&FeatureSet::default(),
&FeeStructure::default(),
lamports_per_signature,
&RentCollector::default(),
&mut error_counters,
Expand Down Expand Up @@ -2125,6 +2130,7 @@ mod tests {
&mock_bank,
&message,
&FeatureSet::default(),
&FeeStructure::default(),
lamports_per_signature,
&rent_collector,
&mut error_counters,
Expand Down Expand Up @@ -2155,6 +2161,7 @@ mod tests {
&mock_bank,
&message,
&FeatureSet::default(),
&FeeStructure::default(),
lamports_per_signature,
&RentCollector::default(),
&mut error_counters,
Expand Down Expand Up @@ -2206,6 +2213,7 @@ mod tests {
&mock_bank,
&message,
&feature_set,
&FeeStructure::default(),
lamports_per_signature,
&rent_collector,
&mut error_counters,
Expand Down Expand Up @@ -2251,6 +2259,7 @@ mod tests {
&mock_bank,
&message,
&feature_set,
&FeeStructure::default(),
lamports_per_signature,
&rent_collector,
&mut error_counters,
Expand Down