HomePhabricator

rpc: Add generateblock to mine a custom set of transactions

Description

rpc: Add generateblock to mine a custom set of transactions

Summary:

The existing block generation rpcs for regtest, generatetoaddress and
generatetodescriptor, mine everything in the mempool up to the block
weight limit. This makes it difficult to test a system for several
scenarios where a different set of transactions are mined. For example:

    Testing the common scenario where a transaction is replaced in the
mempool but the replaced transaction is mined instead.
    Testing for a double-spent transaction where a transaction that
conflicts with the mempool is mined.
    Testing for non-standard transactions that are mined.
    Testing the scenario where several blocks are mined without a
specific transaction in the mempool being included in a block.

This PR introduces a new rpc, generateblock, that takes an array of raw
transactions and txids and mines only those and the coinbase. Any txids
must be in the mempool, but the raw txs can be anything conforming to
consensus rules. The coinbase can be specified as either an address or
descriptor.

Backport of core PR17693.

The code has been adapted to remove the Segwit parts. For now the RPC
interface is kept identical to core, but it would be interesting to not
enforce CTOR in the call and sort the txs in the RPC code instead to
make it easier to mix raw txs and txids.

Test Plan:

ninja check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8553

Details

Provenance
Andrew Toth <andrewstoth@gmail.com>Authored on Mar 27 2020, 15:00
FabienCommitted on Dec 1 2020, 15:27
FabienPushed on Dec 1 2020, 15:29
Reviewer
Restricted Project
Differential Revision
D8553: rpc: Add generateblock to mine a custom set of transactions
Parents
rABC4d966bd4b8dd: Do not unpark deep reorg automatically when avalanche is enabled
Branches
Unknown
Tags
Unknown