rpc: generateblock to allow multiple outputs with custom payouts

bitcoin/bitcoin: PR #32468

2 minor findings · 6 suggestions

Findings

Link

[minor] · Help omits the fee difference between transactions modes

The revised generateblock help omits the existing subsidy-only behavior for explicit transaction arrays and does not distinguish it from fee-inclusive mining when transactions is omitted or null.

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

Details and suggested fix

Explicit arrays still use a use_mempool=false template whose reward contains only the subsidy. Appending fee-paying transactions and calling RegenerateCommitments does not update that value. The omitted/null branch instead rebuilds the template with mempool selection, which adds selected fees to the reward. Consequently, a custom allocation sized to subsidy plus fees can succeed in mempool mode but fail with an explicit list containing the same transactions. Otherwise, the explicit-list fees remain unclaimed, which is consensus-valid. Replace the deleted warning with conditional wording in the help and release-notes-32468.md: fees are included only when transactions is omitted or null, not when transactions are explicitly listed.


Link

[minor] · The output schema excludes supported call forms

By source inspection, hidden generateblock metadata in getopenrpcinfo(true) excludes bare strings and custom-reward array items while allowing top-level objects that the handler rejects.

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

Details and suggested fix

Declaring output as ARR with skip_type_check and one inner STR makes OpenRPCArgSchema emit an array-of-strings-or-object union. The handler instead accepts a bare string or an array containing strings and single-key custom-reward objects. The help signature also renders only string items. Use a type_str override describing the top-level string-or-array union to avoid the misleading fallback schema, and declare an OBJ_USER_KEYS inner alternative for the object form. Add an assertion for this hidden parameter in rpc_openrpc.py. The schema result here is derived from the generator, not an observed live RPC response.


Optional improvements

Link

[suggestion] · Custom amounts described as fixed also receive a remainder share

The help states remainder sharing, but calls custom allocations “fixed” even though generateblock adds a share to them, unlike sendall.

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

Details and suggested fix

With a 25 BTC reward, assigning 100,000,000 satoshis to one recipient and leaving a second unspecified pays 13 BTC and 12 BTC. The loop subtracts custom allocations, divides the leftover among all entries, and adds that share to custom entries too. The new assertions deliberately encode this behavior. Unlike sendall, these are base allocations rather than exact final payouts, which matters when the fee-inclusive reward is not known in advance. Keep the tested formula, but use that terminology in the help and release note, qualify the unconditional equal-split sentence as the no-custom-allocation case, and include a mixed example.


Link

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

The rpc_generate.py custom-payout tests reuse one MiniWallet address, so swapping recipient scripts between entries could leave all their address/value assertions passing.

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

Details and suggested fix

MiniWallet.get_address() returns the stored self._address; it does not derive a new destination. Thus address, address2 and address3 are identical despite the per-output destination checks. The witness-prefix loop uses distinct raw scripts, but does not exercise custom-amount objects. Create the extra recipients from differently tagged MiniWallet instances, assert that all three addresses differ, and retain the existing per-output address and value checks.


Link

[suggestion] · Mempool payout tests do not check transaction fees

The new rpc_generate.py cases assert transaction inclusion but would not catch subsidy-only payouts in mempool mode.

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

Details and suggested fix

Every exact payout-value assertion uses transactions=[]. The mempool case checks only that eleven transactions were mined, while the sigops and weight cases check selection and limits. Using the initial use_mempool=false template's reward instead of the rebuilt template's reward could preserve these assertions because underclaiming fees is consensus-valid. Mine a known-fee MiniWallet transaction in mempool mode to two payouts, then assert their total equals the subsidy plus the included fee and check the split and remainder.


Link

[suggestion] · 170edfbe's message omits the reservation and commitment-ordering changes

The series adds two-pass reservation and commitment-ordering logic without explaining it in the implementation message, then mixes its focused tests with mechanical caller cleanup.

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

Details and suggested fix

170edfbe9312296deb9fcca937872e311ac3c2e7 introduces the weight/sigops reservation and commitment-before-payout ordering, not just the multiple outputs and equal split described in its message. Explain both there. In the immediately following 9baeea743f7ca75f94d6991cc6c1e2710bf1c283, keep the sigops, weight and witness-prefix tests together, and move the mechanical caller removals, such as those in wallet_bumpfee.py and p2p_outbound_eviction.py, into a separate later commit. That separates validation of the new accounting contract from caller cleanup. Keep the accounting with the multi-output implementation and keep cleanup after that commit, where output becomes optional; the final tree remains unchanged.


Link

[suggestion] · The rejection test does not cover cumulative over-allocation

The custom-reward rejection test only covers one oversized entry, so it cannot distinguish the cumulative guard from a check against each entry separately.

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

Details and suggested fix

The single 51*COIN entry fails under either guard. With only a per-entry check, two 15 BTC allocations against a 25 BTC subsidy would leave a negative 5 BTC remainder; splitting it would reduce each payout to 12.5 BTC and still produce a valid coinbase total. Add [{address: 15*COIN}, {address2: 15*COIN}] alongside the early custom-payout cases, while the subsidy is 25 BTC and before parallel mining changes it. Expect RPC error -8 with Sum of custom rewards exceeds the total block reward.


Link

[suggestion] · The weight test misses the CompactSize output-count boundary

The new weight test never crosses the CompactSize output-count boundary, so it cannot detect removal of the currently correct 8-WU reservation for 252 payouts.

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

Details and suggested fix

The template has a dummy payout and a witness commitment, so 252 replacement payouts create 253 outputs and require two extra count bytes. Both existing cases, with 64 and 100 payouts, leave output_count_increase at zero. Omitting this term would reserve 8 WU too little and could let selection exceed the configured -blockmaxweight by a few WU. Add a 252-payout mempool-mode case with a larger cap chosen so a known-weight transaction fits only if the term is omitted. Keep max_tx_count < 253 so tx_count_weight does not mask the omission, then assert transaction exclusion and actual block weight.


Coverage details