-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Add multiplication operator to CFeeRate #29037
Add multiplication operator to CFeeRate #29037
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
src/policy/feerate.h
Outdated
@@ -71,6 +71,8 @@ class CFeeRate | |||
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; } | |||
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; } | |||
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const; | |||
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); } | |||
friend CFeeRate operator*(int a, const CFeeRate& f) { return f * a; } |
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.
nit: To me it confused me for a moment cause I didn't realize that f was using the operator defined on the line above, I think it would make more sense for a reader to just see the same thing above defined backwards like so
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(f.nSatoshisPerK * a); }
feel free to ignore this suggestion though
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.
Sure, I updated it to use the same formula in both lines, so that only the parameters appear in either order
7dacc17
to
1553c80
Compare
ACK 1553c80 |
tACK 1553c80 I compiled from source, ran the test suite, and added some additional BOOST_CHECK tests on my local machine that all passed |
Thanks both of you! @kashifs: If you open a PR against my PR or send me a patch by email, I’d be happy to add your commit with the additional tests to the PR. |
Hi @murchandamus, |
9a6dd54
to
1553c80
Compare
Thanks @kashifs, I’ve merged your pull request into my pull request and pushed it. |
Okay, great! I'm slowly working my way through #27877 |
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.
ACK 1757452 ; lgtm
@@ -71,6 +71,8 @@ class CFeeRate | |||
friend bool operator!=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK != b.nSatoshisPerK; } | |||
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; } | |||
std::string ToString(const FeeEstimateMode& fee_estimate_mode = FeeEstimateMode::BTC_KVB) const; | |||
friend CFeeRate operator*(const CFeeRate& f, int a) { return CFeeRate(a * f.nSatoshisPerK); } | |||
friend CFeeRate operator*(int a, const CFeeRate& f) { return CFeeRate(a * f.nSatoshisPerK); } |
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.
Seems strange to have operator+=
and operator*
but no operator*=
or operator+
.
reACK 1757452 |
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.
ACK 1757452
@@ -87,10 +87,30 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) | |||
CFeeRate(MAX_MONEY, std::numeric_limits<uint32_t>::max()).GetFeePerK(); |
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.
nit: will be nice to squashed this 1757452 to the first commit
ACK 1757452 |
Allows us to use
coin_selection_params.m_long_term_feerate * 3
or
3 * coin_selection_params.m_long_term_feerate
instead of
CFeeRate{coin_selection_params.m_long_term_feerate.GetFee(3000)}
inspired by #27877 (comment)