2 suggestions
Optional improvements
[suggestion] · An oversized total is reported as an invalid output amount
When individually in-range outputs total more than MAX_MONEY, fundrawtransaction reports an invalid output amount rather than explaining that the total exceeds the limit.
Location: src/wallet/spend.cpp:1094 (head).
Details and suggested fix
The combined condition uses the same error for negative amounts, individual amounts above MAX_MONEY, and an excessive total. In the new [MAX_MONEY, 1] test, both amounts satisfy MoneyRange. The second output fails the total check before its dust check, and the RPC forwards "Transaction output amount must be valid" unchanged. Negative amounts also lose the previous negative-specific diagnostic. Split the individual-amount and total checks and give the total failure a message such as "Total transaction output amount exceeds the maximum allowed", then update the expected test strings. Keep individual validation before the addition so the overflow protection remains intact. This improves diagnostics without changing which requests are rejected.
[suggestion] · The overflow test does not cover amount-check ordering
The first 2**62 output is rejected immediately, so this functional test would still pass if the running-sum expression were evaluated before validating the individual amount.
Location: test/functional/wallet_fundrawtransaction.py:180 (head).
Details and suggested fix
Each 2**62 output exceeds MAX_MONEY. The current condition short-circuits on the first output, while reversing its operands would also reject that output because 0 + 2**62 is representable but outside MoneyRange. The case remains useful against the former unchecked loop, but adds no ordering coverage beyond the single oversized-output case. Use tx.vout = [CTxOut(COIN, spk), CTxOut(2**63 - 1, spk)] here. COIN passes the dust check and is accumulated, so addition-first ordering would evaluate COIN + INT64_MAX and trigger signed-overflow detection under the ASan/UBSan CI configuration. This distinction relies on the sanitizer; the expected RPC error alone need not distinguish the orderings in an ordinary build. Do not use one satoshi for the first output, because the dust check would reject it before accumulation.