Bitcoin Core  29.1.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
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 
21 namespace node {
22 struct NodeContext;
23 } // namespace node
24 
26 class CScript;
27 
28 namespace interfaces {
29 
32 {
33 public:
34  virtual ~BlockTemplate() = default;
35 
36  virtual CBlockHeader getBlockHeader() = 0;
37  virtual CBlock getBlock() = 0;
38 
39  virtual std::vector<CAmount> getTxFees() = 0;
40  virtual std::vector<int64_t> getTxSigops() = 0;
41 
42  virtual CTransactionRef getCoinbaseTx() = 0;
43  virtual std::vector<unsigned char> getCoinbaseCommitment() = 0;
44  virtual int getWitnessCommitmentIndex() = 0;
45 
51  virtual std::vector<uint256> getCoinbaseMerklePath() = 0;
52 
58  virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) = 0;
59 };
60 
63 class Mining
64 {
65 public:
66  virtual ~Mining() = default;
67 
69  virtual bool isTestChain() = 0;
70 
72  virtual bool isInitialBlockDownload() = 0;
73 
75  virtual std::optional<BlockRef> getTip() = 0;
76 
86  virtual BlockRef waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
87 
94  virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0;
95 
98  virtual node::NodeContext* context() { return nullptr; }
99 };
100 
102 std::unique_ptr<Mining> MakeMining(node::NodeContext& node);
103 
104 } // namespace interfaces
105 
106 #endif // BITCOIN_INTERFACES_MINING_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
virtual int getWitnessCommitmentIndex()=0
Block template interface.
Definition: mining.h:31
virtual CBlockHeader getBlockHeader()=0
unsigned int nonce
Definition: miner_tests.cpp:75
Definition: block.h:68
virtual ~Mining()=default
Hash/height pair to help track and identify blocks.
Definition: types.h:13
virtual CTransactionRef getCoinbaseTx()=0
NodeContext struct containing references to chain state and connection state.
Definition: context.h:56
Interface giving clients (RPC, Stratum v2 Template Provider in the future) ability to create block te...
Definition: mining.h:63
virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase)=0
Construct and broadcast the block.
std::chrono::duration< double, std::chrono::milliseconds::period > MillisecondsDouble
Definition: time.h:87
virtual std::vector< CAmount > getTxFees()=0
virtual std::vector< uint256 > getCoinbaseMerklePath()=0
Compute merkle path to the coinbase transaction.
virtual std::vector< unsigned char > getCoinbaseCommitment()=0
virtual 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.
Definition: messages.h:20
256-bit opaque blob.
Definition: uint256.h:201
virtual node::NodeContext * context()
Get internal node context.
Definition: mining.h:98
virtual ~BlockTemplate()=default
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:414
virtual std::optional< BlockRef > getTip()=0
Returns the hash and height for the tip of this chain.
virtual std::vector< int64_t > getTxSigops()=0
std::unique_ptr< Mining > MakeMining(node::NodeContext &node)
Return implementation of Mining interface.
virtual CBlock getBlock()=0
is a home for public enum and struct type definitions that are used internally by node code...
virtual bool isTestChain()=0
If this chain is exclusively used for testing.
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:21