Skip to content

Commit

Permalink
FeeFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Jan 16, 2025
1 parent 91d0d0c commit fc43cc3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use {
},
itertools::Itertools,
solana_feature_set as feature_set,
solana_fee::FeeFeatures,
solana_ledger::token_balances::collect_token_balances,
solana_measure::{measure::Measure, measure_us},
solana_poh::poh_recorder::{
Expand Down Expand Up @@ -767,8 +768,7 @@ impl Consumer {
bank.get_lamports_per_signature() == 0,
bank.fee_structure().lamports_per_signature,
fee_budget_limits.prioritization_fee,
bank.feature_set
.is_active(&feature_set::remove_rounding_in_fee_calculation::id()),
FeeFeatures::from(bank.feature_set.as_ref()),
);
let (mut fee_payer_account, _slot) = bank
.rc
Expand Down
1 change: 1 addition & 0 deletions fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ license = { workspace = true }
edition = { workspace = true }

[dependencies]
solana-feature-set = { workspace = true }
solana-fee-structure = { workspace = true }
solana-svm-transaction = { workspace = true }
30 changes: 25 additions & 5 deletions fee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
use {solana_fee_structure::FeeDetails, solana_svm_transaction::svm_message::SVMMessage};
use {
solana_feature_set::{remove_rounding_in_fee_calculation, FeatureSet},
solana_fee_structure::FeeDetails,
solana_svm_transaction::svm_message::SVMMessage,
};

/// Bools indicating the activation of features relevant
/// to the fee calculation.
#[derive(Copy, Clone)]
pub struct FeeFeatures {
pub remove_rounding_in_fee_calculation: bool,
}

impl From<&FeatureSet> for FeeFeatures {
fn from(feature_set: &FeatureSet) -> Self {
Self {
remove_rounding_in_fee_calculation: feature_set
.is_active(&remove_rounding_in_fee_calculation::ID),
}
}
}

/// Calculate fee for `SanitizedMessage`
pub fn calculate_fee(
message: &impl SVMMessage,
zero_fees_for_test: bool,
lamports_per_signature: u64,
prioritization_fee: u64,
remove_rounding_in_fee_calculation: bool,
fee_features: FeeFeatures,
) -> u64 {
calculate_fee_details(
message,
zero_fees_for_test,
lamports_per_signature,
prioritization_fee,
remove_rounding_in_fee_calculation,
fee_features,
)
.total_fee()
}
Expand All @@ -23,7 +43,7 @@ pub fn calculate_fee_details(
zero_fees_for_test: bool,
lamports_per_signature: u64,
prioritization_fee: u64,
remove_rounding_in_fee_calculation: bool,
fee_features: FeeFeatures,
) -> FeeDetails {
if zero_fees_for_test {
return FeeDetails::default();
Expand All @@ -32,7 +52,7 @@ pub fn calculate_fee_details(
FeeDetails::new(
calculate_signature_fee(SignatureCounts::from(message), lamports_per_signature),
prioritization_fee,
remove_rounding_in_fee_calculation,
fee_features.remove_rounding_in_fee_calculation,
)
}

Expand Down
9 changes: 3 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ use {
solana_compute_budget::compute_budget::ComputeBudget,
solana_compute_budget_instruction::instructions_processor::process_compute_budget_instructions,
solana_cost_model::{block_cost_limits::simd_0207_block_limits, cost_tracker::CostTracker},
solana_feature_set::{
self as feature_set, remove_rounding_in_fee_calculation, reward_full_priority_fee,
FeatureSet,
},
solana_feature_set::{self as feature_set, reward_full_priority_fee, FeatureSet},
solana_fee::FeeFeatures,
solana_lattice_hash::lt_hash::LtHash,
solana_measure::{meas_dur, measure::Measure, measure_time, measure_us},
solana_program_runtime::{
Expand Down Expand Up @@ -2920,8 +2918,7 @@ impl Bank {
lamports_per_signature == 0,
self.fee_structure().lamports_per_signature,
fee_budget_limits.prioritization_fee,
self.feature_set
.is_active(&remove_rounding_in_fee_calculation::id()),
FeeFeatures::from(self.feature_set.as_ref()),
)
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/src/bank/fee_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use {
super::Bank,
crate::bank::CollectorFeeDetails,
log::{debug, warn},
solana_feature_set::{remove_rounding_in_fee_calculation, reward_full_priority_fee},
solana_feature_set::reward_full_priority_fee,
solana_fee::FeeFeatures,
solana_runtime_transaction::transaction_with_meta::TransactionWithMeta,
solana_sdk::{
account::{ReadableAccount, WritableAccount},
Expand Down Expand Up @@ -81,8 +82,7 @@ impl Bank {
self.get_lamports_per_signature() == 0,
self.fee_structure().lamports_per_signature,
fee_budget_limits.prioritization_fee,
self.feature_set
.is_active(&remove_rounding_in_fee_calculation::id()),
FeeFeatures::from(self.feature_set.as_ref()),
);
let (reward, _burn) = if self.feature_set.is_active(&reward_full_priority_fee::id()) {
self.calculate_reward_and_burn_fee_details(&CollectorFeeDetails::from(fee_details))
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10388,7 +10388,9 @@ fn calculate_test_fee(
lamports_per_signature == 0,
fee_structure.lamports_per_signature,
fee_budget_limits.prioritization_fee,
true,
FeeFeatures {
remove_rounding_in_fee_calculation: true,
},
)
}

Expand Down
8 changes: 3 additions & 5 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use {
solana_compute_budget::compute_budget::ComputeBudget,
solana_compute_budget_instruction::instructions_processor::process_compute_budget_instructions,
solana_feature_set::{
enable_transaction_loading_failure_fees, remove_accounts_executable_flag_checks,
remove_rounding_in_fee_calculation, FeatureSet,
enable_transaction_loading_failure_fees, remove_accounts_executable_flag_checks, FeatureSet,
},
solana_fee::FeeFeatures,
solana_fee_structure::{FeeBudgetLimits, FeeStructure},
solana_hash::Hash,
solana_instruction::TRANSACTION_LEVEL_STACK_HEIGHT,
Expand Down Expand Up @@ -606,9 +606,7 @@ impl<FG: ForkGraph> TransactionBatchProcessor<FG> {
lamports_per_signature == 0,
fee_lamports_per_signature,
fee_budget_limits.prioritization_fee,
account_loader
.feature_set
.is_active(&remove_rounding_in_fee_calculation::id()),
FeeFeatures::from(account_loader.feature_set.as_ref()),
);

let fee_payer_index = 0;
Expand Down

0 comments on commit fc43cc3

Please sign in to comment.