Review report

bitcoin/bitcoin: PR #35511

1 major finding · 6 suggestions

Findings

Link

[major] · Four fee-rate test calls no longer compile

Four integer-fee calls in amount_tests.cpp require an implicit CAmount conversion that is now forbidden, preventing test_bitcoin from compiling.

Location: src/test/amount_tests.cpp:31 (head).

Details and suggested fix

The two-argument CFeeRate constructor takes const CAmount&, so its first argument cannot use the now-explicit CAmount(T) constructor implicitly. This leaves CFeeRate(0, 0) at line 31, CFeeRate empty_rate(0, 0) at line 99, and both CFeeRate(1, 1) calls at lines 100–101 ill-formed. The zero-vsize handling does not avoid compile-time argument conversion. Use 0*sats or 1*sats as the first argument in all four calls, as the adjacent migrated tests already do.


Optional improvements

Link

[suggestion] · The Qt amount-field API exposes the property conversion

BitcoinAmountField exposes implicit qint64 conversion and a numeric setter, so GUI callers retain boolean and floating-point amount operations despite the new type restrictions.

Location: src/qt/bitcoinamountfield.h:35 (head).

Details and suggested fix

QAmount lets expressions such as field.value() * 0.5, field.value() * field.value() and if (field.value()) use built-in numeric operations. The public setValue(qint64) also accepts true and 1.5, truncating the latter before constructing an amount. No current caller misusing these conversions was identified, and parsing still checks the money range. Keep the conversion in dedicated qintValue() and setQintValue(qint64) property adapters, then return CAmount from value() and remove QAmount and the numeric setValue overload. This preserves the property's name, qint64 type, notification and USER flag. It costs explicit CAmount{...} or .Int() conversions at the settings callers and GUI test identified above. The base alias already allowed numeric operations, so this is an exception to the new protections, not a regression in payment behavior.


Link

[suggestion] · Braced CAmount construction loses unsigned narrowing checks

CAmount{u} converts uint64_t values above INT64_MAX to negative amounts without the alias's braced-narrowing diagnostic; no current caller producing such an input was identified.

Location: src/consensus/amount.h:36 (head).

Details and suggested fix

non_bool_integral accepts unsigned 64-bit types, and m_sats(sats) performs an unchecked conversion to int64_t even when the caller writes CAmount{u}. The scalar / and % templates also accept these types, retaining the base's unsigned-promotion behavior for negative amounts. CreateTransaction rejects negative recipients before recipients_sum / vecSend.size(), so that call does not establish a negative-input defect. Constrain these templates to integral types whose whole range fits in int64_t, making wider unsigned sources require deliberate casts. This would require explicit conversions at affected unsigned callers, including the wallet division and the uint64_t results in FeeFrac::EvaluateFee.


Link

[suggestion] · CAmount's compile-time restrictions lack regression coverage

The tests never require forbidden CAmount expressions to stay ill-formed, so later relaxation of its compile-time restrictions can go unnoticed.

Location: src/consensus/amount.h:36 (head).

Details and suggested fix

The amount tests check runtime MoneyRange and CFeeRate behavior, but those positive uses do not pin the deleted default constructor, explicit integer construction, rejection of bool and floating-point construction, or prohibited multiplication. Add static assertions in amount_tests.cpp for !std::is_default_constructible_v<CAmount>, rejection of construction from bool and double, and explicit but not implicit construction from int64_t. For operators, use a dependent concept such as template<class A, class B> concept Multipliable = requires(A a, B b) { a * b; };. Assert that CAmount multiplied by CAmount or double is unavailable and that multiplication by int remains supported.


Link

[suggestion] · Fractional CoinGrinder test targets lose a satoshi on some platforms

With extended-precision long double, the converted 1.9 and 25.33 BTC test targets lose one satoshi relative to base, making the fixtures platform-dependent.

Location: src/wallet/test/coinselector_tests.cpp:42 (head).

Details and suggested fix

BTCUnit receives an already-rounded double literal, widens it to long double, multiplies by 100,000,000 and truncates. Widening cannot recover the literal's lost precision. On extended-long-double platforms, 1.9 * BTC becomes 189,999,999 sats and 25.33 * BTC becomes 2,532,999,999 sats. Where long double equals double, the products round back to the intended integers. CoinGrinder cases 3, 4 and 7 therefore use different targets across platforms, whereas the base's L-suffixed expressions produced the intended values. Retain the suffixes as 1.9L * BTC and 25.33L * BTC. No changed selection or attempt count has been established.


Link

[suggestion] · The CAmount IPC writer skips the integer-width check

The new CAmount IPC writer bypasses BuildPrimitive's range assertions, so a future Int32 amount field could silently truncate values; current amount fields use Int64.

Location: src/ipc/capnp/common-types.h:150 (head).

Details and suggested fix

The typedef previously followed the default CustomBuildField path through BuildPrimitive, which asserts that the schema field can represent the C++ integer's full range. The new Priority<1> hook calls output.set(value.Int()) directly, allowing an implicit int64-to-int32 conversion if an amount field is declared Int32. Reading that field back into int64 only widens the truncated value. Preserve the existing check by forwarding the extracted integer through it: output.set(BuildPrimitive(invoke_context, value.Int(), TypeList<decltype(output.get())>()));.


Link

[suggestion] · The new fee-delta insertion lambda repeats the map lookup

try_emplace can preserve PrioritiseTransaction's explicit zero and returned reference while removing the new lambda and its second lookup on insertion.

Location: src/txmempool.cpp:682 (head).

Details and suggested fix

Replacing mapDeltas[hash] is necessary because CAmount has no default constructor, but the new lambda performs find() and then another tree lookup in emplace() on a miss. Use CAmount& delta{mapDeltas.try_emplace(hash, 0*sats).first->second}; instead. It returns the existing delta on a hit and explicitly constructs zero on a miss. The stable reference, following SaturatingAdd update, zero-delta erase and existing LOCK(cs) scope remain unchanged, without the lambda or its lock annotation.


Coverage details