-
Notifications
You must be signed in to change notification settings - Fork 291
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
secp256r1 signature fees #4472
base: master
Are you sure you want to change the base?
secp256r1 signature fees #4472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,47 @@ | ||
use {solana_fee_structure::FeeDetails, solana_svm_transaction::svm_message::SVMMessage}; | ||
use { | ||
solana_feature_set::{ | ||
enable_secp256r1_precompile, 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. | ||
// DEVELOPER NOTE: | ||
// This struct may become empty at some point. It is preferable to keep it | ||
// instead of removing, since fees will naturally be changed via feature-gates | ||
// in the future. Keeping this struct will help keep things organized. | ||
#[derive(Copy, Clone)] | ||
pub struct FeeFeatures { | ||
pub remove_rounding_in_fee_calculation: bool, | ||
pub enable_secp256r1_precompile: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do these need to be public, since only this model needs to know which feature(s) matter to fee calculation? |
||
} | ||
|
||
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), | ||
enable_secp256r1_precompile: feature_set.is_active(&enable_secp256r1_precompile::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() | ||
} | ||
|
@@ -23,16 +51,20 @@ 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(); | ||
} | ||
|
||
FeeDetails::new( | ||
calculate_signature_fee(SignatureCounts::from(message), lamports_per_signature), | ||
calculate_signature_fee( | ||
SignatureCounts::from(message), | ||
lamports_per_signature, | ||
fee_features.enable_secp256r1_precompile, | ||
), | ||
prioritization_fee, | ||
remove_rounding_in_fee_calculation, | ||
fee_features.remove_rounding_in_fee_calculation, | ||
) | ||
} | ||
|
||
|
@@ -42,20 +74,25 @@ fn calculate_signature_fee( | |
num_transaction_signatures, | ||
num_ed25519_signatures, | ||
num_secp256k1_signatures, | ||
num_secp256r1_signatures, | ||
}: SignatureCounts, | ||
lamports_per_signature: u64, | ||
enable_secp256r1_precompile: bool, | ||
) -> u64 { | ||
let signature_count = num_transaction_signatures | ||
.saturating_add(num_ed25519_signatures) | ||
.saturating_add(num_secp256k1_signatures); | ||
|
||
.saturating_add(num_secp256k1_signatures) | ||
.saturating_add( | ||
u64::from(enable_secp256r1_precompile).wrapping_mul(num_secp256r1_signatures), | ||
); | ||
signature_count.saturating_mul(lamports_per_signature) | ||
} | ||
|
||
struct SignatureCounts { | ||
pub num_transaction_signatures: u64, | ||
pub num_ed25519_signatures: u64, | ||
pub num_secp256k1_signatures: u64, | ||
pub num_secp256r1_signatures: u64, | ||
} | ||
|
||
impl<Tx: SVMMessage> From<&Tx> for SignatureCounts { | ||
|
@@ -64,6 +101,7 @@ impl<Tx: SVMMessage> From<&Tx> for SignatureCounts { | |
num_transaction_signatures: message.num_transaction_signatures(), | ||
num_ed25519_signatures: message.num_ed25519_signatures(), | ||
num_secp256k1_signatures: message.num_secp256k1_signatures(), | ||
num_secp256r1_signatures: message.num_secp256r1_signatures(), | ||
} | ||
} | ||
} | ||
|
@@ -83,8 +121,10 @@ mod tests { | |
num_transaction_signatures: 0, | ||
num_ed25519_signatures: 0, | ||
num_secp256k1_signatures: 0, | ||
num_secp256r1_signatures: 0, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
true, | ||
), | ||
0 | ||
); | ||
|
@@ -96,8 +136,10 @@ mod tests { | |
num_transaction_signatures: 1, | ||
num_ed25519_signatures: 0, | ||
num_secp256k1_signatures: 0, | ||
num_secp256r1_signatures: 0, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
true, | ||
), | ||
LAMPORTS_PER_SIGNATURE | ||
); | ||
|
@@ -109,8 +151,25 @@ mod tests { | |
num_transaction_signatures: 1, | ||
num_ed25519_signatures: 2, | ||
num_secp256k1_signatures: 3, | ||
num_secp256r1_signatures: 4, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
true, | ||
), | ||
10 * LAMPORTS_PER_SIGNATURE | ||
); | ||
|
||
// Pre-compile signatures (no secp256r1) | ||
assert_eq!( | ||
calculate_signature_fee( | ||
SignatureCounts { | ||
num_transaction_signatures: 1, | ||
num_ed25519_signatures: 2, | ||
num_secp256k1_signatures: 3, | ||
num_secp256r1_signatures: 4, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
false, | ||
), | ||
6 * LAMPORTS_PER_SIGNATURE | ||
); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goal of this structure is so that we do not have a bunch of bool arguments that we always need, but also to not introduce the entire feature set which.
Keeping this makes it extremely obvious exactly which features affect the fee-calculation; and the
FeeFeatures
could even be re-used to avoid re-looking up in the feature-set!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since needed features come and go, there will be a time
FeeFeatures
becomes an empty struct. I would think to keep it empty then (perhaps with a note or something to prevent innocent "cleanup"), so to keepcalculate_fee()
signature unchanged. wdyt?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I agree with keeping it with a note, so that the design idea is not lost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9b75b1c