Repository navigation
refactor: Make CFeeRate constructor architecture-independent - #21848
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. |
jonatack
left a comment
There was a problem hiding this comment.
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 |
promag
left a comment
There was a problem hiding this comment.
Code review ACK fa776331cf21c554c41292c323740601d1a12307.
fa8cd28 to
fa748a6
Compare
promag
left a comment
There was a problem hiding this comment.
Code review ACK fa748a6fb20486e1a839151f13284d719c25ad18.
theStack
left a comment
There was a problem hiding this comment.
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))?
theStack
left a comment
There was a problem hiding this comment.
Code-review ACK fa12128869b2c96709420ddc862bce299f5d1e97
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 |
| #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.
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.
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_tis not neededFix all issues by making it arch-independent. Also, fix
{}style according to dev notes.