Skip to content
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

change(mempool): Refactor the ZIP-317 minimum fee rate calculation to use usize #6585

Merged
merged 2 commits into from
Apr 28, 2023

Conversation

teor2345
Copy link
Contributor

Motivation

@oxarbitrage asked for some help refactoring this.

Specifications

See the links in the code.

Solution

  • Follow the zcashd code, but make it simpler
  • Use usize for all the calculations

This might break the tests, I'll let you update them all at once in whatever way you'd like, to avoid merge issues.

Review

Alfredo asked for this PR.

Feel free to merge or copy-paste.

@teor2345 teor2345 added C-cleanup Category: This is a cleanup P-Medium ⚡ A-compatibility Area: Compatibility with other nodes or wallets, or standard rules A-mempool Area: Memory pool transactions labels Apr 27, 2023
@teor2345 teor2345 self-assigned this Apr 27, 2023
@teor2345 teor2345 requested a review from a team as a code owner April 27, 2023 23:15
@github-actions github-actions bot added the C-enhancement Category: This is an improvement label Apr 27, 2023
Comment on lines +214 to +215
let min_fee = (MIN_MEMPOOL_TX_FEE_RATE * transaction_size / KILOBYTE)
.clamp(MIN_MEMPOOL_TX_FEE_RATE, MEMPOOL_TX_FEE_REQUIREMENT_CAP);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed easier to do this calculation in usize then convert to Amount, which is what zcashd does.

Otherwise every calculation has to be checked for overflow, even though we clamp to [100, 1000] at the end anyway.

@codecov
Copy link

codecov bot commented Apr 28, 2023

Codecov Report

Merging #6585 (ca54611) into issue5336 (a74f12d) will increase coverage by 0.09%.
The diff coverage is 93.75%.

Additional details and impacted files
@@              Coverage Diff              @@
##           issue5336    #6585      +/-   ##
=============================================
+ Coverage      77.90%   77.99%   +0.09%     
=============================================
  Files            308      308              
  Lines          40583    40594      +11     
=============================================
+ Hits           31615    31662      +47     
+ Misses          8968     8932      -36     

Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

Thanks!

@oxarbitrage oxarbitrage merged commit 98f57ed into issue5336 Apr 28, 2023
243 checks passed
@oxarbitrage oxarbitrage deleted the issue5336-fee-rate-refactor branch April 28, 2023 14:07
mergify bot pushed a commit that referenced this pull request May 2, 2023
* add ZIP-317 rules to mempool

* fix some docs

* rustfmt

* fix import

* typo

* fix tests

* fix tests 2

* fix tests 3

* fix tests 4

* fix tests 5

* move constant

* fix constant for feature

* document/quote zip rules

* add Minimum Fee Rate rule

* change(mempool): Refactor the ZIP-317 minimum fee rate calculation to use usize (#6585)

* Refactor the minimum fee rate calculation to use usize

* Check for overflow if constants change

* remove 1 rule check, fix docs

---------

Co-authored-by: teor <teor@riseup.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compatibility Area: Compatibility with other nodes or wallets, or standard rules A-mempool Area: Memory pool transactions C-cleanup Category: This is a cleanup C-enhancement Category: This is an improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants