Bitcoin Core 29.99.0
P2P Digital Currency
mining.h
Go to the documentation of this file.
1// Copyright (c) 2024 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> // for CAmount
9#include <interfaces/types.h> // for BlockRef
10#include <node/types.h> // for BlockCreateOptions, BlockWaitOptions
11#include <primitives/block.h> // for CBlock, CBlockHeader
12#include <primitives/transaction.h> // for CTransactionRef
13#include <stdint.h> // for int64_t
14#include <uint256.h> // for uint256
15#include <util/time.h> // for MillisecondsDouble
16
17#include <memory> // for unique_ptr, shared_ptr
18#include <optional> // for optional
19#include <vector> // for 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
46 virtual std::vector<unsigned char> getCoinbaseCommitment() = 0;
47 virtual int getWitnessCommitmentIndex() = 0;
48
54 virtual std::vector<uint256> getCoinbaseMerklePath() = 0;
55
61 virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) = 0;
62
74 virtual std::unique_ptr<BlockTemplate> waitNext(const node::BlockWaitOptions options = {}) = 0;
75};
76
79class Mining
80{
81public:
82 virtual ~Mining() = default;
83
85 virtual bool isTestChain() = 0;
86
88 virtual bool isInitialBlockDownload() = 0;
89
91 virtual std::optional<BlockRef> getTip() = 0;
92
102 virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
103
110 virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0;
111
114 virtual node::NodeContext* context() { return nullptr; }
115};
116
118std::unique_ptr<Mining> MakeMining(node::NodeContext& node);
119
120} // namespace interfaces
121
122#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:415
Block template interface.
Definition: mining.h:32
virtual std::vector< int64_t > getTxSigops()=0
virtual int getWitnessCommitmentIndex()=0
virtual std::vector< unsigned char > getCoinbaseCommitment()=0
virtual std::unique_ptr< BlockTemplate > waitNext(const node::BlockWaitOptions options={})=0
Waits for fees in the next block to rise, a new tip or the timeout.
virtual std::vector< CAmount > getTxFees()=0
virtual std::vector< uint256 > getCoinbaseMerklePath()=0
Compute merkle path to the coinbase transaction.
virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase)=0
Construct and broadcast the block.
virtual CBlock getBlock()=0
virtual CBlockHeader getBlockHeader()=0
virtual ~BlockTemplate()=default
virtual CTransactionRef getCoinbaseTx()=0
Interface giving clients (RPC, Stratum v2 Template Provider in the future) ability to create block te...
Definition: mining.h:80
virtual ~Mining()=default
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:114
virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout=MillisecondsDouble::max())=0
Waits for the connected tip to change.
256-bit opaque blob.
Definition: uint256.h:201
unsigned int nonce
Definition: miner_tests.cpp:74
std::unique_ptr< Mining > MakeMining(node::NodeContext &node)
Return implementation of Mining interface.
Definition: messages.h:20
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:423
Hash/height pair to help track and identify blocks.
Definition: types.h:13
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:87