rpc: generateblock to allow multiple outputs with custom payouts

bitcoin/bitcoin: PR #32468

1 minor finding · 7 suggestions

Findings

Link

[minor] · The removed fee caveat still applies to explicit transaction lists

Removing the caveat hides the pre-existing subsidy-only payout for explicit transactions, while omitted or null transactions now include selected fees.

Location: src/rpc/mining.cpp:338 (base).

Details and suggested fix

The explicit-list branch appends transactions to a template created with .use_mempool = false. RegenerateCommitments updates commitments and the merkle root, not the payout value, so total_reward remains the subsidy even when the listed transactions are mempool txids. That value also caps custom allocations: amounts relying on those transaction fees are rejected. Restore a mode-specific explanation in the RPC help and release note: omitted or null transactions includes fees from assembler-selected transactions, whereas an explicit array leaves fees uncollected and excludes them from the custom-reward budget.


Optional improvements

Link

[suggestion] · Custom rewards are documented as fixed final payouts

The tested allocation adds a share of the remaining reward to custom-amount outputs too, so describing their amounts as fixed can mislead callers about the final payout.

Location: src/rpc/mining.cpp:343 (head).

Details and suggested fix

When custom amounts leave some reward unallocated, the loop adds reward_parted and any remainder satoshi to every payout, including explicitly valued entries. Thus [{A: X}, B] does not generally mean exactly X to A and the rest to B. The value tests intentionally require this additive behavior. Describe the object value as a base allocation in the help and release note, explicitly state that custom allocations also share the remaining reward, and limit the unconditional equal-split wording to that remaining reward.


Link

[suggestion] · Mempool-mode tests leave fee-inclusive payouts unchecked

The new functional tests would still accept a mempool-mode block that pays only the subsidy, even though the implementation currently collects selected transaction fees.

Location: test/functional/rpc_generate.py:150 (head).

Details and suggested fix

The ten self-transfers use a positive default fee rate, but the resulting block is checked only for eleven transactions. All exact payout-value assertions use transactions=[]; the weight and sigops tests also leave amounts unchecked. Dropping fees only from the distributed mempool-mode reward would remain consensus-valid because validation permits underclaiming. After this block, assert that the sum of coinbase output values, converted to satoshis, equals the block's getblockstats values for subsidy plus totalfee.


Link

[suggestion] · Payout correctness tests are mixed with unrelated call-site cleanup

The series separates payout-reservation and commitment-ordering logic from its focused tests, then mixes those tests with mechanical cleanup, making the correctness changes harder to validate.

Location: src/rpc/mining.cpp:438 at 170edfbe9312 (commit) (commit).

Details and suggested fix

The mempool-selection commit 567a42ca9efe5fcc20abc95ee24ee55f112895e2 uses a single template build. 170edfbe9312296deb9fcca937872e311ac3c2e7 replaces it with two-pass payout weight/sigops reservation, including both CompactSize margins, and constructs the commitment before inserting payouts. Its message explains only the equal split. 9baeea743f7ca75f94d6991cc6c1e2710bf1c283 adds the weight, sigops and witness-prefix tests alongside unrelated removals of explicit output= arguments.

Move those focused tests and their imports into 170edfbe9312296deb9fcca937872e311ac3c2e7, explain the reservation and commitment ordering in its message, and leave the mechanical call-site sweep separate. Keep the production correctness changes with payout replacement: moving reservation or commitment reordering later would temporarily allow configured-weight overshoots or mishandle commitment-prefix payouts. This rearrangement leaves the final tree unchanged.


Link

[suggestion] · Custom-reward tests reuse one recipient

address2 and address3 equal address, so the functional tests cannot detect a custom amount being paired with the wrong recipient.

Location: test/functional/rpc_generate.py:72 (head).

Details and suggested fix

MiniWallet.get_address() returns the address stored during construction rather than generating another one. Consequently, the per-index address assertions all compare the same destination, while the value assertions protect only the allocation arithmetic. The witness-prefix loop checks distinct scripts but supplies no custom amounts. Obtain address2 and address3 from MiniWallet instances with distinct tag_name values, assert that the recipients differ, and retain the existing per-index address and value checks. These wallets only supply recipient addresses, so they need no funding.


Link

[suggestion] · Generated output types omit accepted input forms

Generated output types omit the accepted plain-string and object-entry forms, while OpenRPC advertises a top-level object that the handler rejects.

Location: src/rpc/mining.cpp:339 (head).

Details and suggested fix

output declares an ARR containing only STR, with skip_type_check. This renders array-of-string help and makes OpenRPC infer oneOf: [array<string>, object], although the handler accepts a string or an array of strings/single-key payout objects and rejects a top-level object. The prose describes these alternatives, but the generated types contradict it. Set type_str to describe the string-or-array form and add an OBJ_USER_KEYS alternative for array entries, documenting satoshi units. This corrects the help metadata; at this revision that type_str label becomes only x-bitcoin-type-override, not a fully generated OpenRPC union.


Link

[suggestion] · Over-allocation tests do not exercise the cumulative limit

The single-entry rejection cannot distinguish a per-output check from the required cumulative check, allowing a weakened-guard regression to escape the functional tests.

Location: test/functional/rpc_generate.py:248 (head).

Details and suggested fix

The only over-allocation rejection uses one 51 BTC entry, which a per-entry comparison would also reject. The successful 10+15 BTC case tests equality, not a cumulative overrun. With a 25 BTC reward, a weakened per-entry guard would accept 15+15 BTC, then distribute the negative extra by reducing both outputs to 12.5 BTC. That block would remain valid. Next to the existing 25 BTC fixtures, before parallel mining, add two 15 BTC allocations and expect RPC error -8, Sum of custom rewards exceeds the total block reward.


Link

[suggestion] · Weight tests miss the coinbase output-count boundary

The current reservation handles the boundary, but the 64- and 100-payout fixtures cannot detect losing the extra 8 WU at 253 coinbase outputs.

Location: test/functional/rpc_generate.py:289 (head).

Details and suggested fix

Including the witness commitment, these fixtures have 65 and 101 outputs, so their output-count CompactSize remains one byte and output_count_increase is zero. Add 252 payouts plus the commitment to reach 253 outputs, where the count gains two bytes, or 8 WU. Raise -blockmaxweight and choose a cap where a transaction of known weight fits only if those 8 WU are omitted. Keep max_tx_count below 253 so tx_count_weight cannot mask the omission, and account for the strict >= selection check. Assert that the transaction stays in the mempool and the block remains within the configured cap; final consensus validation would not catch a small configured-cap overshoot.


Coverage details