forked from solana-labs/solana
-
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
separate functions for different signature types #4354
Merged
apfitzge
merged 4 commits into
anza-xyz:master
from
apfitzge:separate_signature_functions
Jan 16, 2025
+136
−55
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,91 @@ pub fn calculate_fee_details( | |
if zero_fees_for_test { | ||
return FeeDetails::default(); | ||
} | ||
let signature_fee = message | ||
.num_total_signatures() | ||
.saturating_mul(lamports_per_signature); | ||
|
||
FeeDetails::new( | ||
signature_fee, | ||
calculate_signature_fee(SignatureCounts::from(message), lamports_per_signature), | ||
prioritization_fee, | ||
remove_rounding_in_fee_calculation, | ||
) | ||
} | ||
|
||
/// Calculate fees from signatures. | ||
fn calculate_signature_fee( | ||
SignatureCounts { | ||
num_transaction_signatures, | ||
num_ed25519_signatures, | ||
num_secp256k1_signatures, | ||
}: SignatureCounts, | ||
lamports_per_signature: u64, | ||
) -> u64 { | ||
let signature_count = num_transaction_signatures | ||
.saturating_add(num_ed25519_signatures) | ||
.saturating_add(num_secp256k1_signatures); | ||
|
||
signature_count.saturating_mul(lamports_per_signature) | ||
} | ||
|
||
struct SignatureCounts { | ||
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. see follow-up PR in #4472 which adds the secpr1 signature count behind a feature-gate. |
||
pub num_transaction_signatures: u64, | ||
pub num_ed25519_signatures: u64, | ||
pub num_secp256k1_signatures: u64, | ||
} | ||
|
||
impl<Tx: SVMMessage> From<&Tx> for SignatureCounts { | ||
fn from(message: &Tx) -> Self { | ||
Self { | ||
num_transaction_signatures: message.num_transaction_signatures(), | ||
num_ed25519_signatures: message.num_ed25519_signatures(), | ||
num_secp256k1_signatures: message.num_secp256k1_signatures(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_calculate_signature_fee() { | ||
const LAMPORTS_PER_SIGNATURE: u64 = 5_000; | ||
|
||
// Impossible case - 0 signatures. | ||
assert_eq!( | ||
calculate_signature_fee( | ||
SignatureCounts { | ||
num_transaction_signatures: 0, | ||
num_ed25519_signatures: 0, | ||
num_secp256k1_signatures: 0, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
), | ||
0 | ||
); | ||
|
||
// Simple signature | ||
assert_eq!( | ||
calculate_signature_fee( | ||
SignatureCounts { | ||
num_transaction_signatures: 1, | ||
num_ed25519_signatures: 0, | ||
num_secp256k1_signatures: 0, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
), | ||
LAMPORTS_PER_SIGNATURE | ||
); | ||
|
||
// Pre-compile signatures. | ||
assert_eq!( | ||
calculate_signature_fee( | ||
SignatureCounts { | ||
num_transaction_signatures: 1, | ||
num_ed25519_signatures: 2, | ||
num_secp256k1_signatures: 3, | ||
}, | ||
LAMPORTS_PER_SIGNATURE, | ||
), | ||
6 * LAMPORTS_PER_SIGNATURE | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@jstarry thinking to make the fee functions above take something where
SignatureCounts: From<&T>
.This gives the functions a bit more flexibility, since we should be able to use this function for types that do not implement
SVMMessage
. Ideally we'd use this same function for estimating priority before we resolve ALTs (which SVMMessage requires from us); and could just implement the correctFrom
here.If fee model changed and we needed additional information from the type, this also gives a bit more flexibility than just taking
SignatureCounts
as the argument directly, as we can just add additional bounds:I think the alternative is basically just us doing this a few times for different types we want to calculate fees for, which seems worse to me than using
From
traits. let me know what you think of the approach.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.
Maybe in a follow up? I'm happy with the current PR. I'm just not sure how useful it is to have priority before we resolve ALTs in the scheduler..
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.
It's useful because if below the current minimum priority, I won't resolve at all.
Less useful in scheduler, more useful in forwarding stage (wip) where the buffer is significantly smaller
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.
also just to expand on this, the medium-term plan is to move prioritization into sigverify stage. but we don't want SV reaching into accounts-db at all, obviously. so we'd want a way to calculate fees just from an unresolved view (essentially to what i mentioned for forwarding stage now).