Bitcoin Core 30.99.0
P2P Digital Currency
mining.h
Go to the documentation of this file.
1// Copyright (c) 2024-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_INTERFACES_MINING_H
6#define BITCOIN_INTERFACES_MINING_H
7
8#include <consensus/amount.h>
9#include <interfaces/types.h>
10#include <node/types.h>
11#include <primitives/block.h>
13#include <uint256.h>
14#include <util/time.h>
15
16#include <cstdint>
17#include <memory>
18#include <optional>
19#include <vector>
20
21namespace node {
22struct NodeContext;
23} // namespace node
24
26class CScript;
27
28namespace interfaces {
29
32{
33public:
34 virtual ~BlockTemplate() = default;
35
37 // Block contains a dummy coinbase transaction that should not be used.
38 virtual CBlock getBlock() = 0;
39
40 // Fees per transaction, not including coinbase transaction.
41 virtual std::vector<CAmount> getTxFees() = 0;
42 // Sigop cost per transaction, not including coinbase transaction.
43 virtual std::vector<int64_t> getTxSigops() = 0;
44
51
54
60 virtual std::vector<unsigned char> getCoinbaseCommitment() = 0;
61
68 virtual int getWitnessCommitmentIndex() = 0;
69
75 virtual std::vector<uint256> getCoinbaseMerklePath() = 0;
76
95 virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) = 0;
96
108 virtual std::unique_ptr<BlockTemplate> waitNext(node::BlockWaitOptions options = {}) = 0;
109
113 virtual void interruptWait() = 0;
114};
115
119{
120public:
121 virtual ~Mining() = default;
122
124 virtual bool isTestChain() = 0;
125
127 virtual bool isInitialBlockDownload() = 0;
128
130 virtual std::optional<BlockRef> getTip() = 0;
131
143 virtual std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
144
154 virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0;
155
169 virtual bool checkBlock(const CBlock& block, const node::BlockCheckOptions& options, std::string& reason, std::string& debug) = 0;
170
173 virtual node::NodeContext* context() { return nullptr; }
174};
175
177std::unique_ptr<Mining> MakeMining(node::NodeContext& node);
178
179} // namespace interfaces
180
181#endif // BITCOIN_INTERFACES_MINING_H
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:22
Definition: block.h:69
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
Block template interface.
Definition: mining.h:32
virtual std::vector< int64_t > getTxSigops()=0
virtual int getWitnessCommitmentIndex()=0
Return which output in the dummy coinbase contains the SegWit OP_RETURN.
virtual std::vector< unsigned char > getCoinbaseCommitment()=0
Return scriptPubKey with SegWit OP_RETURN.
virtual std::vector< CAmount > getTxFees()=0
virtual node::CoinbaseTx getCoinbaseTx()=0
Return fields needed to construct a coinbase transaction.
virtual std::vector< uint256 > getCoinbaseMerklePath()=0
Compute merkle path to the coinbase transaction.
virtual CTransactionRef getCoinbaseRawTx()=0
Return serialized dummy coinbase transaction.
virtual std::unique_ptr< BlockTemplate > waitNext(node::BlockWaitOptions options={})=0
Waits for fees in the next block to rise, a new tip or the timeout.
virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase)=0
Construct and broadcast the block.
virtual void interruptWait()=0
Interrupts the current wait for the next block template.
virtual CBlock getBlock()=0
virtual CBlockHeader getBlockHeader()=0
virtual ~BlockTemplate()=default
Interface giving clients (RPC, Stratum v2 Template Provider in the future) ability to create block te...
Definition: mining.h:119
virtual ~Mining()=default
virtual bool checkBlock(const CBlock &block, const node::BlockCheckOptions &options, std::string &reason, std::string &debug)=0
Checks if a given block is valid.
virtual std::optional< BlockRef > waitTipChanged(uint256 current_tip, MillisecondsDouble timeout=MillisecondsDouble::max())=0
Waits for the connected tip to change.
virtual bool isInitialBlockDownload()=0
Returns whether IBD is still in progress.
virtual std::unique_ptr< BlockTemplate > createNewBlock(const node::BlockCreateOptions &options={})=0
Construct a new block template.
virtual std::optional< BlockRef > getTip()=0
Returns the hash and height for the tip of this chain.
virtual bool isTestChain()=0
If this chain is exclusively used for testing.
virtual node::NodeContext * context()
Get internal node context.
Definition: mining.h:173
256-bit opaque blob.
Definition: uint256.h:195
unsigned int nonce
Definition: miner_tests.cpp:81
std::unique_ptr< Mining > MakeMining(node::NodeContext &node)
Return implementation of Mining interface.
Definition: messages.h:21
is a home for public enum and struct type definitions that are used internally by node code,...
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
Template containing all coinbase transaction fields that are set by our miner code.
Definition: types.h:110
NodeContext struct containing references to chain state and connection state.
Definition: context.h:56
std::chrono::duration< double, std::chrono::milliseconds::period > MillisecondsDouble
Definition: time.h:88