Repository navigation
RFC: consensus: Make CAmount a class - #35511
hodlinator wants to merge 12 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste 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. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-11-24 19:35:39 |
|
Concept ACK |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
c14d67a to
6b8a616
Compare
This is enables later commit which changes CAmount to no longer be an integer, so it cannot be used directly through ConsumeIntegralInRange<CAmount>().
Co-authored-by: janb84 <[email protected]>
This allows for later banning of multiplying amount with floating point types. Uses a "unit type" to multiply with along the lines of the mp_units library http://wg21.link/p3045, instead of a _BTC user-defined literal.
c8ebdc5 to
5d4dbb0
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
5d4dbb0 to
a0e1107
Compare
No longer allows implicit conversions from non-integer types such as floats or bools. Would prevent issues such as the one fixed by 0026b33.
…ization becomes required
-BEGIN VERIFY SCRIPT-
sed -i -E "s/(^\s+CAmount )(\w+);/\1\2{0};/g" $( git grep -lE "^\s+CAmount \w+;" -- src/ ':!src/primitives/transaction.h' )
-END VERIFY SCRIPT-
…mpoolInfo Preparation for CAmount not having default ctor.
-BEGIN VERIFY SCRIPT-
sed -i -E "s/(\s+CAmount )(\w+) = (-?[0-9]+);/\1\2{\3};/g" $( git grep -lE "CAmount \w+ = -?[0-9]+;" src/ )
sed -i -E "s/CFeeRate([\(\{])((-?[0-9\'])+)([\)\}])/CFeeRate\1CAmount{\2}\4/g" $( git grep -lE "CFeeRate[\(\{]-?[0-9\']+[\)\}]" src/ )
sed -i -E "s/\.nValue = ([a-zA-Z_]+ - )?([0-9]+[0-9L]*([ \-]*[0-9]+(LL)?)*)([^\*0-9])/.nValue = \1CAmount{\2}\5/g" src/test/miner_tests.cpp src/test/transaction_tests.cpp src/test/script_p2sh_tests.cpp
sed -i -E "s/([\(\{])(-?(0x)?[0-9a-f]+), (-?\w+)([\)\}])/\1CAmount{\2}, \4\5/g" src/test/feefrac_tests.cpp src/test/rbf_tests.cpp
sed -i -E "s/(\bCTxOut\{)(([0-9]{1,9})LL|([0-9L\ \-]+))(, .*)/\1CAmount{\3\4}\5/g" $( git grep -lE "CTxOut\{[0-9]+" src/ )
-END VERIFY SCRIPT-
-BEGIN VERIFY SCRIPT-
sed -i -E "s/CAmount[\{\(](-?[0-9\']+)[\}\)]/\1*sats/g" $( git grep -lE "CAmount[\{\(]-?[0-9\']+[\}\)]" src/ )
-END VERIFY SCRIPT-
a0e1107 to
b889efb
Compare
|
🐙 This pull request conflicts with the target branch and needs rebase. |

We should treat people's money with care across node and wallet.
Having our
CAmountbe atypedeffor rawint64_tas on master has the following drawbacks:bools, leading to the issues like the one previously fixed by 0026b33.CAmount fee;).CAmount target = 49.5L * COINin src/wallet/test/coinselector_tests.cpp.CAmounts with each other, which does not make sense.Beyond fixing the above, this PR also makes amounts stick out more in code - either by the
CAmounttype itself or by using thesatsunit specifier.This work is also a stepping stone for possible future work introducing an even safer amount type which only allows values in the range
[0, MAX_MONEY].Already merged PRs spawned out of this work: #35456, #35372
Prior attempts in similar directions: #5430, #4067