Skip to content
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
11 changes: 11 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ members = [
"download-utils",
"entry",
"faucet",
"fee",
"frozen-abi",
"frozen-abi/macro",
"genesis",
Expand Down Expand Up @@ -360,6 +361,7 @@ solana-define-syscall = { path = "define-syscall", version = "=2.1.0" }
solana-download-utils = { path = "download-utils", version = "=2.1.0" }
solana-entry = { path = "entry", version = "=2.1.0" }
solana-faucet = { path = "faucet", version = "=2.1.0" }
solana-fee = { path = "fee", version = "=2.1.0" }
solana-frozen-abi = { path = "frozen-abi", version = "=2.1.0" }
solana-frozen-abi-macro = { path = "frozen-abi/macro", version = "=2.1.0" }
solana-tps-client = { path = "tps-client", version = "=2.1.0" }
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ solana-compute-budget = { workspace = true }
solana-connection-cache = { workspace = true }
solana-cost-model = { workspace = true }
solana-entry = { workspace = true }
solana-fee = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-geyser-plugin-manager = { workspace = true }
Expand Down
16 changes: 8 additions & 8 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use {
solana_sdk::{
clock::{Slot, FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, MAX_PROCESSING_AGE},
feature_set,
fee::FeeBudgetLimits,
message::SanitizedMessage,
saturating_add_assign,
timing::timestamp,
Expand Down Expand Up @@ -741,15 +742,14 @@ impl Consumer {
error_counters: &mut TransactionErrorMetrics,
) -> Result<(), TransactionError> {
let fee_payer = message.fee_payer();
let budget_limits =
process_compute_budget_instructions(message.program_instructions_iter())?.into();
let fee = bank.fee_structure().calculate_fee(
let fee_budget_limits = FeeBudgetLimits::from(process_compute_budget_instructions(
message.program_instructions_iter(),
)?);
let fee = solana_fee::calculate_fee(
Comment thread
tao-stones marked this conversation as resolved.
message,
bank.get_lamports_per_signature(),
&budget_limits,
bank.feature_set.is_active(
&feature_set::include_loaded_accounts_data_size_in_fee_calculation::id(),
),
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()),
);
Expand Down
14 changes: 14 additions & 0 deletions fee/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "solana-fee"
description = "Solana fee calculation"
documentation = "https://docs.rs/solana-fee"
version = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[dependencies]
solana-sdk = { workspace = true }
solana-svm-transaction = { workspace = true }
40 changes: 40 additions & 0 deletions fee/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use {solana_sdk::fee::FeeDetails, solana_svm_transaction::svm_message::SVMMessage};

/// 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,
) -> u64 {
calculate_fee_details(
message,
zero_fees_for_test,
lamports_per_signature,
prioritization_fee,
remove_rounding_in_fee_calculation,
)
.total_fee()
}

pub fn calculate_fee_details(
Comment thread
tao-stones marked this conversation as resolved.
message: &impl SVMMessage,
Comment thread
tao-stones marked this conversation as resolved.
zero_fees_for_test: bool,
lamports_per_signature: u64,
Comment thread
tao-stones marked this conversation as resolved.
prioritization_fee: u64,
remove_rounding_in_fee_calculation: bool,
) -> FeeDetails {
if zero_fees_for_test {
return FeeDetails::default();
}
let signature_fee = message
.num_total_signatures()
.saturating_mul(lamports_per_signature);

FeeDetails::new(
signature_fee,
prioritization_fee,
remove_rounding_in_fee_calculation,
)
}
19 changes: 19 additions & 0 deletions programs/sbf/Cargo.lock

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

6 changes: 4 additions & 2 deletions programs/sbf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ net2 = "0.2.37"
num-derive = "0.4.2"
num-traits = "0.2"
rand = "0.8"
serde = "1.0.112" # must match the serde_derive version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde_derive = "1.0.112" # must match the serde version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde = "1.0.112" # must match the serde_derive version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
serde_derive = "1.0.112" # must match the serde version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251
Comment on lines +25 to +26
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI yelled at me. I think because I edited file and we must have added formatting requirement since last edit 🤷‍♂️

serde_json = "1.0.56"
solana-account-decoder = { path = "../../account-decoder", version = "=2.1.0" }
solana-accounts-db = { path = "../../accounts-db", version = "=2.1.0" }
Expand All @@ -33,6 +33,7 @@ solana-cli-output = { path = "../../cli-output", version = "=2.1.0" }
solana-compute-budget = { path = "../../compute-budget", version = "=2.1.0" }
solana-curve25519 = { path = "../../curves/curve25519", version = "=2.1.0" }
solana-decode-error = { path = "../../sdk/decode-error", version = "=2.1.0" }
solana-fee = { path = "../../fee", version = "=2.1.0" }
solana-ledger = { path = "../../ledger", version = "=2.1.0" }
solana-log-collector = { path = "../../log-collector", version = "=2.1.0" }
solana-logger = { path = "../../logger", version = "=2.1.0" }
Expand Down Expand Up @@ -99,6 +100,7 @@ solana-accounts-db = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-cli-output = { workspace = true }
solana-compute-budget = { workspace = true }
solana-fee = { workspace = true }
solana-ledger = { workspace = true }
solana-log-collector = { workspace = true }
solana-logger = { workspace = true }
Expand Down
30 changes: 17 additions & 13 deletions programs/sbf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use {
compute_budget::ComputeBudgetInstruction,
entrypoint::MAX_PERMITTED_DATA_INCREASE,
feature_set::{self, FeatureSet},
fee::FeeStructure,
fee::{FeeBudgetLimits, FeeStructure},
fee_calculator::FeeRateGovernor,
genesis_config::ClusterType,
hash::Hash,
Expand Down Expand Up @@ -3890,13 +3890,15 @@ fn test_program_fees() {
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let expected_normal_fee = fee_structure.calculate_fee(
let fee_budget_limits = FeeBudgetLimits::from(
process_compute_budget_instructions(sanitized_message.program_instructions_iter())
.unwrap_or_default(),
);
let expected_normal_fee = solana_fee::calculate_fee(
&sanitized_message,
congestion_multiplier,
&process_compute_budget_instructions(sanitized_message.program_instructions_iter())
.unwrap_or_default()
.into(),
false,
congestion_multiplier == 0,
fee_structure.lamports_per_signature,
fee_budget_limits.prioritization_fee,
true,
);
bank_client
Expand All @@ -3918,13 +3920,15 @@ fn test_program_fees() {
&ReservedAccountKeys::empty_key_set(),
)
.unwrap();
let expected_prioritized_fee = fee_structure.calculate_fee(
let fee_budget_limits = FeeBudgetLimits::from(
process_compute_budget_instructions(sanitized_message.program_instructions_iter())
.unwrap_or_default(),
);
let expected_prioritized_fee = solana_fee::calculate_fee(
&sanitized_message,
congestion_multiplier,
&process_compute_budget_instructions(sanitized_message.program_instructions_iter())
.unwrap_or_default()
.into(),
false,
congestion_multiplier == 0,
fee_structure.lamports_per_signature,
fee_budget_limits.prioritization_fee,
true,
);
assert!(expected_normal_fee < expected_prioritized_fee);
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ solana-compute-budget = { workspace = true }
solana-compute-budget-program = { workspace = true }
solana-config-program = { workspace = true }
solana-cost-model = { workspace = true }
solana-fee = { workspace = true }
solana-frozen-abi = { workspace = true, optional = true }
solana-frozen-abi-macro = { workspace = true, optional = true }
solana-inline-spl = { workspace = true }
Expand Down
20 changes: 10 additions & 10 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ use {
epoch_schedule::EpochSchedule,
feature,
feature_set::{
self, include_loaded_accounts_data_size_in_fee_calculation,
remove_rounding_in_fee_calculation, reward_full_priority_fee, FeatureSet,
self, remove_rounding_in_fee_calculation, reward_full_priority_fee, FeatureSet,
},
fee::{FeeDetails, FeeStructure},
fee::{FeeBudgetLimits, FeeDetails, FeeStructure},
fee_calculator::FeeRateGovernor,
genesis_config::{ClusterType, GenesisConfig},
hard_forks::HardForks,
Expand Down Expand Up @@ -3048,14 +3047,15 @@ impl Bank {
message: &SanitizedMessage,
lamports_per_signature: u64,
) -> u64 {
self.fee_structure().calculate_fee(
let fee_budget_limits = FeeBudgetLimits::from(
process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default(),
);
solana_fee::calculate_fee(
Comment thread
tao-stones marked this conversation as resolved.
message,
lamports_per_signature,
&process_compute_budget_instructions(message.program_instructions_iter())
.unwrap_or_default()
.into(),
self.feature_set
.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()),
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()),
)
Expand Down
16 changes: 6 additions & 10 deletions runtime/src/bank/fee_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use {
log::{debug, warn},
solana_sdk::{
account::{ReadableAccount, WritableAccount},
feature_set::{
include_loaded_accounts_data_size_in_fee_calculation,
remove_rounding_in_fee_calculation, reward_full_priority_fee,
},
feature_set::{remove_rounding_in_fee_calculation, reward_full_priority_fee},
fee::FeeBudgetLimits,
pubkey::Pubkey,
reward_info::RewardInfo,
Expand Down Expand Up @@ -85,12 +82,11 @@ impl Bank {
transaction: &SanitizedTransaction,
fee_budget_limits: &FeeBudgetLimits,
) -> u64 {
let fee_details = self.fee_structure().calculate_fee_details(
transaction.message(),
self.get_lamports_per_signature(),
fee_budget_limits,
self.feature_set
.is_active(&include_loaded_accounts_data_size_in_fee_calculation::id()),
let fee_details = solana_fee::calculate_fee_details(
transaction,
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()),
);
Expand Down
Loading