rpc: generateblock to allow multiple outputs with custom payouts

bitcoin/bitcoin: PR #32468

1 minor finding · 6 suggestions

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

Findings

Link

[minor] · OpenRPC misdescribes generateblock payout arguments

With show_hidden=true, getopenrpcinfo misdescribes valid generateblock payout forms and permits rejected objects; no in-tree consumer validating these calls against the schema was found.

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

Details and suggested fix

The unchecked ARR fallback produces oneOf containing an array of strings and a top-level object. The handler accepts a top-level string or an array of strings and single-pair custom-reward objects, but rejects a top-level object. Tooling using this schema would therefore reject supported calls and permit unsupported ones. Add metadata for object array entries and generator support for the actual string-or-array union, without the unconditional top-level object alternative. An arbitrary type_str label alone is insufficient because ApplyTypeStrOverride only emits an extension annotation for unrecognized labels. Add a hidden-command schema assertion in rpc_openrpc.py.


Optional improvements

Link

[suggestion] · Custom amounts are base allocations, not fixed payouts

Explicit amounts deliberately receive a share of the leftover reward, so the help's “fixed amount” wording does not describe the final payout, especially when mempool fees change the total.

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

Details and suggested fix

The loop adds an equal share of total_reward - total_value to every output, including entries with an explicit amount. The mixed-entry test consequently expects an 8 BTC allocation to receive 13.66666667 BTC. Exhausting a known reward can produce exact payments, but the API has no independently fixed entry with another recipient absorbing an unknown remainder. To preserve the deliberately tested behavior, describe these amounts as base allocations plus an equal share of the remainder in both the help and release notes, and include a worked mixed-entry example.


Link

[suggestion] · Help no longer explains mode-dependent fee collection

The help drops the pre-existing explicit-list fee caveat even though only the new omitted-transactions mode includes selected fees in coinbase payouts.

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

Details and suggested fix

With an explicit transaction list, generateblock appends transactions to a .use_mempool = false template and regenerates commitments without increasing its subsidy-only reward. Omitting transactions instead selects a fee-bearing template. The same fee-paying transactions therefore produce different payout budgets, and an explicit-list custom allocation above the subsidy is rejected even if transaction fees cover it. Add a scoped sentence to the help and release notes: “Fees of explicitly provided transactions are not collected; when transactions is omitted, the selected mempool transactions' fees are included in the reward.” This preserves both modes.


Link

[suggestion] · Custom-payout tests use the same recipient for every output

The custom-payout tests obtain address, address2, and address3 from one fixed-address MiniWallet, so recipient-script mix-ups confined to object entries can pass the existing assertions.

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

Details and suggested fix

MiniWallet.get_address() returns self._address; it does not derive a new destination. The value assertions distinguish amounts by position, but reusing the first custom object's recipient script for later objects would remain invisible. The witness-prefix loop uses distinct scripts only as string entries, so it does not close this gap. Obtain address2 and address3 from differently tagged MiniWallet instances, assert that the recipients differ, and retain the existing per-index address and value checks. Keep the default MiniWallet as the transaction funder.


Link

[suggestion] · Mempool-mining tests do not check fee-inclusive payouts

The new mempool-mode tests check transaction selection but not coinbase values, so a subsidy-only payout regression would leave these assertions passing.

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

Details and suggested fix

The exact-value payout cases all pass transactions=[], while the ten-transaction mempool case checks only the transaction count. Successful block validation cannot substitute for a reward assertion because leaving fees unclaimed is consensus-valid. Give the mempool transactions known fees, omit transactions, and request multiple payouts. Assert each payout and that their sum equals the subsidy at the generated height plus the included fees. Choosing an odd total would also exercise remainder distribution with a fee-bearing reward.


Link

[suggestion] · Weight coverage misses the CompactSize output-count boundary

Both payout counts in test_generateblock_weight stay below the CompactSize boundary, so removing the new output-count reservation term would not affect either assertion set.

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

Details and suggested fix

The dummy payout and witness commitment give the template two outputs. Replacing the dummy with 64 or 100 payouts produces 65 or 101 outputs, so output_count_increase remains zero. Add a case with 252 raw(51) payouts: the final count becomes 253 and requires another eight weight units. Measure the coinbase-only weight using submit=False, transactions=[], then configure -blockmaxweight with the minimum reserve so omitting those eight units would admit both of two independent known-weight transactions, while correct accounting admits only the higher-feerate one. Retain the selection, remaining-mempool, and final-weight assertions to detect exceeding the configured mining limit.


Link

[suggestion] · Multi-output commit descriptions omit reservation and commitment handling

The multi-output commit adds weight/sigops reservation and commitment ordering without describing them, while the following test commit mixes their targeted assertions with cross-file cleanup.

Location: src/rpc/mining.cpp:440 at ade479c5c73d (commit) (commit).

Details and suggested fix

After 63c12e44944ec162019de8cee809ea762bd01596 adds optional-transaction mempool mining, ade479c5c73db05e4432d30e60a05e6917679926 adds multi-output payouts together with two-pass weight/sigops reservation and commitment regeneration before payout insertion. Its message describes splitting but omits those additional changes. ab1484c306665cc7072925c74e11769e1b6c2dd5 then adds the witness-prefix, sigops, and weight assertions alongside raw-output removals across other functional tests. Expand ade479c's message and separate the cross-file cleanup into its own mechanical commit, leaving the complete rpc_generate.py additions in a dedicated test commit immediately after ade479c. This lets reviewers validate the reservation logic and its assertions separately from cleanup. Keep reservation and commitment handling with multi-output support so the rearrangement preserves safe intermediate behavior; the tests do not depend on the later custom-reward commits.


Coverage details

Earlier concerns

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