Bitcoin Core 31.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/mining_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 <string>
20#include <vector>
21
22namespace node {
23struct NodeContext;
24} // namespace node
25
26namespace interfaces {
27
30{
31public:
32 virtual ~BlockTemplate() = default;
33
35 // Block contains a dummy coinbase transaction that should not be used and
36 // it may not match a transaction constructed from getCoinbaseTx().
37 virtual CBlock getBlock() = 0;
38
39 // Fees per transaction, not including coinbase transaction.
40 virtual std::vector<CAmount> getTxFees() = 0;
41 // Sigop cost per transaction, not including coinbase transaction.
42 virtual std::vector<int64_t> getTxSigops() = 0;
43
46
52 virtual std::vector<uint256> getCoinbaseMerklePath() = 0;
53
78 virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) = 0;
79
91 virtual std::unique_ptr<BlockTemplate> waitNext(node::BlockWaitOptions options = {}) = 0;
92
96 virtual void interruptWait() = 0;
97};
98
102{
103public:
104 virtual ~Mining() = default;
105
107 virtual bool isTestChain() = 0;
108
110 virtual bool isInitialBlockDownload() = 0;
111
113 virtual std::optional<BlockRef> getTip() = 0;
114
126 virtual std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
127
140 virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}, bool cooldown = true) = 0;
141
145 virtual void interrupt() = 0;
146
160 virtual bool checkBlock(const CBlock& block, const node::BlockCheckOptions& options, std::string& reason, std::string& debug) = 0;
161
181 virtual bool submitBlock(const CBlock& block, std::string& reason, std::string& debug) = 0;
182
185 virtual const node::NodeContext* context() { return nullptr; }
186};
187
193std::unique_ptr<Mining> MakeMining(const node::NodeContext& node, bool wait_loaded=true);
194
195} // namespace interfaces
196
197#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:27
Definition: block.h:74
Block template interface.
Definition: mining.h:30
virtual std::vector< int64_t > getTxSigops()=0
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 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:102
virtual ~Mining()=default
virtual bool submitBlock(const CBlock &block, std::string &reason, std::string &debug)=0
Process a fully assembled block.
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 const node::NodeContext * context()
Get internal node context.
Definition: mining.h:185
virtual void interrupt()=0
Interrupts createNewBlock and waitTipChanged.
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 std::unique_ptr< BlockTemplate > createNewBlock(const node::BlockCreateOptions &options={}, bool cooldown=true)=0
Construct a new block template.
256-bit opaque blob.
Definition: uint256.h:196
unsigned int nonce
Definition: miner_tests.cpp:99
is used externally by mining IPC clients, so it should only declare simple data definitions.
std::unique_ptr< Mining > MakeMining(const node::NodeContext &node, bool wait_loaded=true)
Return implementation of Mining interface.
Definition: messages.h:21
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
Block template creation options.
Definition: mining_types.h:33
Template containing all coinbase transaction fields that are set by our miner code.
Definition: mining_types.h:132
NodeContext struct containing references to chain state and connection state.
Definition: context.h:59
std::chrono::duration< double, std::chrono::milliseconds::period > MillisecondsDouble
Definition: time.h:103