-
Notifications
You must be signed in to change notification settings - Fork 38k
refactor: Make CFeeRate constructor architecture-independent #21848
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
Conversation
Strong concept ACK I've always found the now cleaned up code confusing. Thanks for making the code easier to reason about. |
I wrote the assert in #7796, so it might be partially my fault |
Good! Important note which may not be immediately clear for all reviewers:
Thus the choice of
Safer how? Live demo:
Note the silent narrowing from That is why the See also C++ Core Guidelines: ES.23: Prefer the {}-initializer syntax. |
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.
Approach ACK
Maybe write "architecture" instead of "arch" (I first thought this was about arch linux 😄)
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Our automated reviewer friend
|
Thanks, fixed |
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.
Code review ACK fa77633.
fa8cd28
to
fa748a6
Compare
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.
Code review ACK fa748a6.
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.
Concept ACK
Right now the initialization of nSize
from num_bytes
is slightly different in the ctor CFeeRate::CFeeRate(...)
and the method CFeeRate::GetFee(...)
. Both could use const int64_t nSize{num_bytes}
, as also suggested at one place by promag (#21848 (comment))?
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.
Code-review ACK fa12128
nit: Doesn't matter much in those short methods, but if for any reason you need to retouch, you could add a const
in front of int64_t nSize{num_bytes};
(both instances).
Added |
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.
re-ACK fafd121
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.
Code review ACK fafd121.
#include <tinyformat.h> | ||
|
||
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_) | ||
CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) |
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
CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes)
: nSatoshisPerK(num_bytes > 0 ? nFeePaid * 1000 / int64_t{num_bytes} : 0)
{
}
And make const CAmount 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.
Nice, but adding const
can be done in a follow-up
This PR effectively fixes the bug from #19735. 👍 |
Currently the constructor is architecture dependent. This is confusing for several reasons:
uint32_t
, so a 64-bitsize_t
is not neededFix all issues by making it arch-independent. Also, fix
{}
style according to dev notes.