Skip to content

Separate fee-calculation from SDK#2120

Merged
apfitzge merged 7 commits intoanza-xyz:masterfrom
apfitzge:issue2116
Jul 26, 2024
Merged

Separate fee-calculation from SDK#2120
apfitzge merged 7 commits intoanza-xyz:masterfrom
apfitzge:issue2116

Conversation

@apfitzge
Copy link
Copy Markdown

Problem

  • SVM is becoming generic over transaction/message traits.
  • The FeeStructure's calculate_fee and calculate_fee_details cannot be abstracted over traits if they live in SDK.
  • Fee calculation was moved from runtime to sdk recently, this was not an ideal move, and better if we just put it in a separate crate.

Summary of Changes

  • duplicate functionality in separate crate
  • make new crate generic over SVMMessage
  • deprecate SDK functions

Fixes #2116

@apfitzge
Copy link
Copy Markdown
Author

An alternative, following @t-nelson's comment/idea, is that we could deprecate the entire FeeStructure in SDK, and move it into this new crate, leaving the calculate_fee_* as member functions on this new FeeStructure.

@tao-stones
Copy link
Copy Markdown

Is FeeStructure absolutely necessary at the moment, or even for near future? Didn't think through this yet, but gut feeling is calculate_fee() might be better off without binding to FeeStructure

@apfitzge
Copy link
Copy Markdown
Author

apfitzge commented Jul 12, 2024

Is FeeStructure absolutely necessary at the moment, or even for near future? Didn't think through this yet, but gut feeling is calculate_fee() might be better off without binding to FeeStructure

We do not use compute_fee_bins anywhere. You'd know better than I if there are plans to ever use them - but I think not.

nor is lamports_per_write_lock non-zero anywhere. We could just pass lamports_per_signature.

@tao-stones
Copy link
Copy Markdown

nor is lamports_per_write_lock non-zero anywhere.

the tests uses that to set transaction fees to zero. So still need a version of "calculate zero fee for tests"

@apfitzge
Copy link
Copy Markdown
Author

nor is lamports_per_write_lock non-zero anywhere.

the tests uses that to set transaction fees to zero. So still need a version of "calculate zero fee for tests"

That's lamports_per_signature right? There's another unused field for having a fee per write-lock

@tao-stones
Copy link
Copy Markdown

nor is lamports_per_write_lock non-zero anywhere.

the tests uses that to set transaction fees to zero. So still need a version of "calculate zero fee for tests"

That's lamports_per_signature right? There's another unused field for having a fee per write-lock

right! sorry, i misread it.

@apfitzge apfitzge marked this pull request as ready for review July 23, 2024 13:16
@apfitzge apfitzge requested a review from jstarry July 23, 2024 13:17
Comment thread fee/src/lib.rs
Copy link
Copy Markdown

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

Would like to sync up on lamports_per_signature == 0 case more, two versions of same-name-variable could have diff
values add confusion. One is from bank.fee_rate_governor (often as parameter to calculate_fee()), the other from bank.fee_structure (used in calculating signature fee).

Comment thread fee/src/lib.rs
Comment thread fee/src/lib.rs
Comment thread core/src/banking_stage/consumer.rs Outdated
let fee = bank.fee_structure().calculate_fee(
let fee = solana_fee::calculate_fee(
message,
bank.get_lamports_per_signature(),
Copy link
Copy Markdown

@tao-stones tao-stones Jul 24, 2024

Choose a reason for hiding this comment

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

To keep inline with sdk version, the parameter should be bank.fee_structure().lamports_per_signature, which could be different from bank.get_lamports_per_signature() { bank.fee_rate_governor.lamports_per_signature }. iirc, fee_rate_governor's lamports_per_signature can change based on block utilization, but fee_structure's sig rate is static (need to verify it)

(also wondering how does this not break CI tests?)

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.

I don't think it actually changes, was just "future proofed" in order to allow it to change.

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.

but yeah I'll revert t using the fee_structure one; and will need some manual fix for all the tests that breaks.

Comment thread runtime/src/bank.rs
@apfitzge
Copy link
Copy Markdown
Author

two versions of same-name-variable could have diff values add confusion.

LOL it's even worse, there's at least 3! Since we also have get_lamports_per_signature_for_blockhash which could be different from both of the others! 🫠

Comment thread core/src/banking_stage/consumer.rs
Comment thread programs/sbf/Cargo.toml
Comment on lines +25 to +26
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
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 🤷‍♂️

@apfitzge apfitzge requested a review from tao-stones July 25, 2024 20:43
Comment thread core/src/banking_stage/consumer.rs Outdated
Comment thread fee/src/lib.rs
Comment thread runtime/src/bank/tests.rs Outdated
Comment thread sdk/src/fee.rs Outdated
Copy link
Copy Markdown

@tao-stones tao-stones left a comment

Choose a reason for hiding this comment

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

lgtm

@apfitzge apfitzge merged commit 5604a4d into anza-xyz:master Jul 26, 2024
@apfitzge apfitzge deleted the issue2116 branch July 26, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FeeStructure: deprecate SDK calculations. Abstract over SVMMessage.

2 participants