mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 13:49:35 +02:00
mining: add new getCoinbaseTx() returning a struct
Introduce a new method intended to replace getCoinbaseRawTx(), which provides a struct with everything clients need to construct a coinbase. This is safer than providing a raw dummy coinbase that clients then have to manipulate. The CoinbaseTx data is populated during the dummy transaction generation and stored in struct CBlockTemplate. Expand the interface_ipc.py functional test to document its usage and ensure equivalence.
This commit is contained in:
@@ -16,10 +16,13 @@
|
||||
#include <consensus/amount.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <policy/policy.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <script/script.h>
|
||||
#include <uint256.h>
|
||||
#include <util/time.h>
|
||||
#include <vector>
|
||||
|
||||
namespace node {
|
||||
enum class TransactionError {
|
||||
@@ -99,6 +102,53 @@ struct BlockCheckOptions {
|
||||
bool check_pow{true};
|
||||
};
|
||||
|
||||
/**
|
||||
* Template containing all coinbase transaction fields that are set by our
|
||||
* miner code. Clients are expected to add their own outputs and typically
|
||||
* also expand the scriptSig.
|
||||
*/
|
||||
struct CoinbaseTx {
|
||||
/* nVersion */
|
||||
uint32_t version;
|
||||
/* nSequence for the only coinbase transaction input */
|
||||
uint32_t sequence;
|
||||
/**
|
||||
* Prefix which needs to be placed at the beginning of the scriptSig.
|
||||
* Clients may append extra data to this as long as the overall scriptSig
|
||||
* size is 100 bytes or less, to avoid the block being rejected with
|
||||
* "bad-cb-length" error.
|
||||
*
|
||||
* Currently with BIP 34, the prefix is guaranteed to be less than 8 bytes,
|
||||
* but future soft forks could require longer prefixes.
|
||||
*/
|
||||
CScript script_sig_prefix;
|
||||
/**
|
||||
* The first (and only) witness stack element of the coinbase input.
|
||||
*
|
||||
* Omitted for block templates without witness data.
|
||||
*
|
||||
* This is currently the BIP 141 witness reserved value, and can be chosen
|
||||
* arbitrarily by the node, but future soft forks may constrain it.
|
||||
*/
|
||||
std::optional<uint256> witness;
|
||||
/**
|
||||
* Block subsidy plus fees, minus any non-zero required_outputs.
|
||||
*
|
||||
* Currently there are no non-zero required_outputs, so block_reward_remaining
|
||||
* is the entire block reward. See also required_outputs.
|
||||
*/
|
||||
CAmount block_reward_remaining;
|
||||
/*
|
||||
* To be included as the last outputs in the coinbase transaction.
|
||||
* Currently this is only the witness commitment OP_RETURN, but future
|
||||
* softforks or a custom mining patch could add more.
|
||||
*
|
||||
* The dummy output that spends the full reward is excluded.
|
||||
*/
|
||||
std::vector<CTxOut> required_outputs;
|
||||
uint32_t lock_time;
|
||||
};
|
||||
|
||||
/**
|
||||
* How to broadcast a local transaction.
|
||||
* Used to influence `BroadcastTransaction()` and its callers.
|
||||
|
||||
Reference in New Issue
Block a user