rpc: generateblock to allow multiple outputs with custom payouts

bitcoin/bitcoin: PR #32468

2 minor findings · 4 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Findings

Link

[minor] · Mempool selection does not reserve resources for requested payouts

With a deliberately block-filling regtest mempool, many payouts can make generateblock fail final validation; this is source-inferred, and no current caller producing that workload was found.

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

Details and suggested fix

When transactions is omitted, the assembler selects transactions using the existing reservations, which default to 8,000 WU for the header and coinbase and 400 sigop cost. The RPC installs the requested payouts only afterward. If eligible transactions fill the template closely enough, payouts exceeding the remaining slack cause TestBlockValidity to reject the result with bad-blk-weight or bad-blk-sigops, before submission. Retrying the unchanged request does not reduce selection. A smaller explicit transaction list avoids this; increasing -blockreservedweight can also avoid the weight case.

Before assembly, compute adequate reservations for the header and final coinbase, including payout weight and legacy sigop cost. Pass them through block_reserved_weight and coinbase_output_max_additional_sigops, retaining any larger configured weight reservation. Add a regression test with a block-filling mempool and many payouts.


Link

[minor] · OpenRPC's output schema excludes accepted input forms

The hidden schema from getopenrpcinfo(true) excludes accepted strings and reward-object entries while permitting rejected top-level objects; no affected schema-driven consumer was identified.

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

Details and suggested fix

With this unchecked ARR and its single inner STR, OpenRPCArgSchema emits oneOf: [{type: array, items: {type: string}}, {type: object}]. The handler instead accepts a bare address or descriptor string, or an array containing strings and single-key reward objects. A schema-validating client would reject those supported forms and allow a top-level object that the RPC rejects. Use an appropriate type_str override to emit a permissive annotated schema rather than these false constraints, and add an assertion for this parameter in rpc_openrpc.py using getopenrpcinfo(True).


Optional improvements

Link

[suggestion] · Mode-dependent fee payouts are no longer documented

Omitting transactions pays subsidy plus selected fees, while an explicit list retains the pre-existing subsidy-only behavior, but the updated help removes its fee warning.

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

Details and suggested fix

Explicit arrays, including arrays of mempool txids, set use_mempool=false and append transactions after the subsidy-only coinbase has been created. RegenerateCommitments does not credit their fees, and total_reward retains that template value. This also changes the custom-allocation budget: amounts covering subsidy plus fees can succeed with automatic selection but fail with an explicit list of the same transactions. Add a mode-specific note to the help and release note explaining that automatic selection distributes the selected fees, whereas explicit lists leave those fees unclaimed.


Link

[suggestion] · Multi-recipient payout fixtures reuse the same address

address, address2 and address3 come from the same non-mutating getter, so the custom-reward tests cannot detect a payout or amount associated with the wrong recipient.

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

Details and suggested fix

MiniWallet.get_address() returns the stored address rather than generating a new one. The address-list, addr(...)-list and custom-reward cases therefore compare every output against the same destination, although their amount assertions still check the arithmetic. The witness-prefix case checks distinct raw scripts, but only through string entries, not reward objects. Use distinct deterministic destinations from differently tagged MiniWallet instances, keeping the original wallet for funding. Assert that the addresses differ and retain the per-output address and amount checks.


Link

[suggestion] · Mempool-mode test does not check fee-inclusive payouts

The new mempool-mode test checks transaction inclusion but would not catch payouts that omit the selected fees.

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

Details and suggested fix

This case creates ten fee-paying MiniWallet transfers and asserts only len(block['tx']) == 11. The exact multi-output and custom-amount checks use transactions=[], so they do not exercise fee distribution. Paying less than subsidy plus fees remains consensus-valid, so block acceptance does not close the gap. Add a mempool-mode case with several distinct recipients, record the selected fees, and assert the payout total against the subsidy at the mined height plus those fees. Check the expected quotient and remainder distribution as well.


Link

[suggestion] · Over-allocation test misses the cumulative budget check

The rejection fixture uses one amount that is too large on its own, so it does not distinguish cumulative validation from per-entry checks.

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

Details and suggested fix

[{address: 51*COIN}] is rejected whether the guard compares the running total or each individual allocation. Beside the earlier 25 BTC fixtures, two 15 BTC allocations would distinguish them. With only a per-entry check, extra would become -5 BTC and each output would receive 15 - 2.5 = 12.5 BTC, so the block could still validate. Before the parallel-mining step changes the subsidy, assert that [{address: 15*COIN}, {address2: 15*COIN}] fails with -8 and Sum of custom rewards exceeds the total block reward.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.