7 suggestions
Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.
Optional improvements
[suggestion] · CAmount restrictions lack compile-time regression tests
The amount tests exercise supported expressions, so they would not detect removal of the constructor restrictions that provide the PR's main guarantees.
Location: src/consensus/amount.h:38 (head).
Details and suggested fix
The existing MoneyRange and CFeeRate tests use permitted forms such as N*sats and CAmount{...}. Add static_asserts checking non-default-constructibility, rejection of bool and double, and the absence of implicit conversions in either direction with int64_t. Also use dependent requires helpers with parameters such as requires(T a) { a * a; } and requires(T a) { a < 5; } to check the forbidden operators. Pair these with positive assertions for direct integer construction, amount * 3, and 5*sats. Using parameters rather than CAmount{} ensures the deleted default constructor does not mask an accidentally enabled operator.
[suggestion] · The Qt property bridge bypasses CAmount restrictions for C++ callers
No current caller misusing these conversions was found, but QAmount and the public setValue(qint64) overload expose integer, boolean and floating-point conversions outside the Qt property bridge.
Location: src/qt/bitcoinamountfield.h:35 (head).
Details and suggested fix
QAmount::operator qint64() permits expressions such as if (field.value()) and field.value() * 1.5, while setValue(qint64) accepts true and floating-point arguments through standard conversions. Return CAmount from the ordinary C++ getters and retain setValue(const CAmount&) for normal calls. Point Q_PROPERTY at separately named private bridge functions that return qint64 through .Int() and construct CAmount when setting the value. This preserves the property's name, type, notification and USER semantics without the converting subclass. Keep the settings boundary explicit, for example with static_cast<qint64>(ui->customFee->value().Int()).
[suggestion] · The new BTC helper changes two coin-selection targets by one satoshi
The two 1.9 * BTC targets evaluate to 189999999 sats with 80-bit long double, versus 190000000 with binary64 long double; no assertion failure was established.
Location: src/wallet/test/coinselector_tests.cpp:39 (head).
Details and suggested fix
Scenarios 4 and 7 replace 1.9L * COIN with 1.9 * BTC. The unsuffixed literal is rounded to a binary64 value slightly below 1.9 before promotion to the helper's long double parameter. With 80-bit long double, multiplying by 100000000 remains below 190000000 and the integer cast truncates to 189999999. With binary64 long double, the product rounds to 190000000. The previous long-double literal produced 190000000 in both cases. The assertions compare selected coin values and attempt counts, not the constructed target. Write both targets as 190'000'000*sats to preserve their intended value independently of floating-point format.
[suggestion] · CAmount{...} no longer rejects narrowing integer inputs
Unlike the base typedef's brace initialization, CAmount{u64} can now wrap values above INT64_MAX; no current caller supplying such a value was found.
Location: src/consensus/amount.h:39 (head).
Details and suggested fix
The constructor deduces any non_bool_integral type and converts it through m_sats(sats). For a nonconstant uint64_t input, the base typedef's list-initialization diagnosed narrowing, but the new constructor accepts it without checking representability. Base copy-initialization already allowed this conversion, so the newly lost protection is specifically the brace form. FeeFrac::EvaluateFee now constructs amounts from unsigned expressions whose safety depends on its documented result bound. Constrain the constructor to integral types whose full range fits int64_t, requiring explicit, reviewable casts where callers already establish that a wider or unsigned result fits.
[suggestion] · CAmount IPC building bypasses existing integer-range checks
All current amount fields are Int64, but the new IPC build hook bypasses BuildPrimitive's compile-time checks that the wire type covers the full int64_t range.
Location: src/ipc/capnp/common-types.h:150 (head).
Details and suggested fix
The old alias reached the default CustomBuildField, which calls BuildPrimitive and checks both ends of the destination integer range with static_asserts. The new hook calls output.set(value.Int()) directly, so an Int32 or UInt64 schema mismatch no longer receives those checks. Route the underlying integer through the same checked conversion: output.set(BuildPrimitive(invoke_context, value.Int(), TypeList<decltype(output.get())>()));. This preserves the existing wire values while retaining the boundary validation that applied before the wrapper was introduced.
[suggestion] · Orphanage resource ratios acquire monetary types
Eviction ordering is unchanged, but GetDosScore() now represents latency counts and memory usage as CAmount, making non-monetary resource ratios look like satoshi values.
Location: src/node/txorphanage.cpp:166 (head).
Details and suggested fix
FeeFrac(CAmount, int32_t) forces GetDosScore() to wrap m_total_latency_score and m_total_usage as monetary amounts, and LimitOrphans() now expresses its unitless ratio-one threshold as FeeFrac{1*sats, 1}. These quantities are not fees, so this weakens the semantic distinction the wrapper introduces. Keep the ratio core integer-based and apply amount typing at monetary boundaries instead. Retain the overflow-safe cross multiplication, reversed-size ordering and peer-ID tie-breaks when separating the representations.
[suggestion] · Amount-map initialization adds avoidable insertion lookups
The replacement for mapDeltas[hash] adds a lock-annotated lambda and separate searches on insertion; try_emplace supplies the required explicit zero value without that machinery.
Location: src/txmempool.cpp:682 (head).
Details and suggested fix
Under the existing LOCK(cs), use CAmount& delta{mapDeltas.try_emplace(hash, 0).first->second};. try_emplace directly constructs the mapped amount, so the explicit constructor is supported without restoring default construction. The subsequent saturation, graph update and zero-delta erase remain unchanged. The analogous balance accumulation can use balances.try_emplace(addr, 0).first->second += n;, preserving both existing-value accumulation and insertion of zero-valued destinations. These replacements remove the find/emplace branches and their extra insertion lookup.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: USDT amount arguments no longer have their documented scalar type (earlier report)
- [suggestion]:
mempool.dat's mixed amount encodings lack a direct compatibility test (earlier report)
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The typedef was a deliberate low-risk compromise, not an assertion that a primitive integer provides strong type safety. Earlier reviewers prioritized verifying unchanged arithmetic behavior and conserving scarce consensus-review capacity.
The base defines CAmount as int64_t; the head replaces it with an explicit class and overloaded operators. In #4067, Wladimir van der Laan required exactly the existing integer behavior, including division and rounding semantics. Pieter Wuille distinguished architectural improvement from the separate burden of proving consensus equivalence. The historical concern was economically consequential: an accidental fork could impose losses on miners and damage confidence in upgrades.
Source 1 · Source 2 · Source 3 · Source 4
The historical case for a distinct monetary type was to expose hidden assumptions and make permitted arithmetic and conversions explicit, rather than merely rename int64_t.
Mark Friedenbach argued that a typedef leaves integer-specific dependencies undetected, whereas a restricted, type-checked API prevents new dependencies from appearing silently. The original proposal also sought easier patch sharing with codebases using different monetary representations. Later #5430 discussion specifically identified implicit boolean conversion as undesirable for a future amount class and cited improved analyzability as a Bitcoin-side benefit. These are direct antecedents to the head's explicit constructor, exclusion of bool and floating-point operands, and restricted operator set; they do not establish that every present operator choice follows from the earlier proposal.
Source 1 · Source 2 · Source 3 · Source 4 · Source 5
An amount abstraction was intended to encapsulate arithmetic and protocol serialization without making core data structures depend on human-facing formatting or speculative conversion machinery.
In #4067, Pieter Wuille described a dependency-light core-data-structures library containing protocol structures and serialization, while leaving human-readable conversion at a higher layer. He also proposed serializing the monetary wrapper directly as int64_t. The head similarly serializes CAmount's underlying integer, while FormatMoney and ParseMoney remain in util/moneystr.cpp. This history explains why type encapsulation, wire representation, and display formatting are distinct design concerns.
Source 1 · Source 2 · Source 3
Avoiding floating-point conversion of monetary values is an established precision constraint, including at RPC boundaries where amounts are expressed in decimal BTC.
The 2015 #6239 proposal explicitly attributed monetary deviations to double conversions and used UniValue's string representation to switch to fixed-point parsing and formatting. The pinned head's AmountFromValue still parses textual numbers into an integer and then checks MoneyRange. The class's refusal of implicit floating-point construction extends the same precision concern to C++ expressions, but it does not replace boundary parsing and validation.
Negative monetary quantities have legitimate internal policy uses even though negative transaction outputs and fees are not valid consensus values.
Discussion #7796 defended negative modified feerates because prioritisation deltas can precede transaction acceptance, applying -X followed by X should restore the original state, and flooring at zero would erase the ordering of transactions an operator currently does not want to mine. The head therefore retains a signed underlying representation and unary negation. This history distinguishes local transaction-selection adjustments from permission to create transactions with negative actual fees.
Ralph's inferences
The existing design separates representable amounts from valid transaction amounts; making the representation a class is distinct from enforcing the interval [0, MAX_MONEY].
Both base and head retain MoneyRange as a separate check. Validation rejects negative outputs, oversized individual outputs, and out-of-range aggregate values, and separately checks input totals and fees. CTxOut also uses -1 as an internal null sentinel. These uses explain why the affected type currently represents more than valid spendable balances and why a future range-restricted type would have a different scope from this wrapper.
MAX_MONEY is a consensus-critical overflow sanity bound, not merely a descriptive statement of eventual supply.
The pinned amount header explicitly makes this distinction and warns that changing the bound could create a fork in unusual overflow circumstances. Transaction validation links its negative and overflow checks to CVE-2010-5139. Consequently, compile-time type restrictions and adversarial runtime monetary-range checks address different hazards; the wrapper's existence alone says nothing about the necessity or semantics of those checks.
Unresolved disagreements
The inspected history does not resolve how to weigh a strong amount API's preventive safety benefits against the immediate review burden and risk of altering consensus arithmetic.
Proponents argued that semantic explicitness prevents future consensus-risk logic errors and reduces maintenance divergence. Opponents questioned whether those benefits justified the verification cost for Bitcoin, while another position supported encapsulation only when its responsibilities and unchanged behavior were convincingly established. The typedef was the practical historical outcome, not a general resolution for later class proposals. These positions frame the affected behavior without determining the merits of the current PR.