Bitcoin Core 28.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
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 virtual CBlock getBlock() = 0;
38
39 virtual std::vector<CAmount> getTxFees() = 0;
40 virtual std::vector<int64_t> getTxSigops() = 0;
41
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
63class Mining
64{
65public:
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
102std::unique_ptr<Mining> MakeMining(node::NodeContext& node);
103
104} // namespace interfaces
105
106#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::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:64
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:98
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:190
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 by 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:62