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

Add multiplication operator to CFeeRate #29037

Merged

Conversation

murchandamus
Copy link
Contributor

@murchandamus murchandamus commented Dec 8, 2023

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)

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 8, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ajtowns, kevkevinpal, ismaelsadeeq, achow101
Stale ACK kashifs

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@murchandamus murchandamus marked this pull request as ready for review December 8, 2023 19:00
@@ -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; }
Copy link
Contributor

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

Copy link
Contributor Author

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

@murchandamus murchandamus force-pushed the 2023-12-multiply-operator-CFeeRate branch from 7dacc17 to 1553c80 Compare December 9, 2023 14:34
@kevkevinpal
Copy link
Contributor

ACK 1553c80

@kashifs
Copy link
Contributor

kashifs commented Dec 10, 2023

tACK 1553c80

I compiled from source, ran the test suite, and added some additional BOOST_CHECK tests on my local machine that all passed

@murchandamus
Copy link
Contributor Author

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.

@kashifs
Copy link
Contributor

kashifs commented Dec 11, 2023

Hi @murchandamus,
I believe that I correctly opened a PR against this PR. Please let me know if this is the correct etiquette or if there is anything more that I should do.

@murchandamus murchandamus force-pushed the 2023-12-multiply-operator-CFeeRate branch 2 times, most recently from 9a6dd54 to 1553c80 Compare December 14, 2023 21:11
@murchandamus
Copy link
Contributor Author

Thanks @kashifs, I’ve merged your pull request into my pull request and pushed it.

@kashifs
Copy link
Contributor

kashifs commented Dec 14, 2023

Okay, great! I'm slowly working my way through #27877

Copy link
Contributor

@ajtowns ajtowns left a 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); }
Copy link
Contributor

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+.

@DrahtBot DrahtBot requested review from kevkevinpal and removed request for kevkevinpal December 18, 2023 16:35
@kevkevinpal
Copy link
Contributor

reACK 1757452

@DrahtBot DrahtBot removed the request for review from kevkevinpal December 18, 2023 17:34
Copy link
Member

@ismaelsadeeq ismaelsadeeq left a 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();
Copy link
Member

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

@achow101
Copy link
Member

ACK 1757452

@achow101 achow101 merged commit e3847f7 into bitcoin:master Dec 20, 2023
16 checks passed
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.

None yet

7 participants