Bitcoin Core 32.99.0
P2P Digital Currency
block_template_manager.h
Go to the documentation of this file.
1// Copyright (c) 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_NODE_BLOCK_TEMPLATE_MANAGER_H
6#define BITCOIN_NODE_BLOCK_TEMPLATE_MANAGER_H
7
8#include <node/mining_types.h>
9#include <util/time.h>
10
11#include <memory>
12#include <optional>
13#include <string>
14
15class CBlock;
17class CTxMemPool;
18class uint256;
19
20namespace interfaces {
21struct BlockRef;
22} // namespace interfaces
23
24namespace node {
25class KernelNotifications;
26struct CBlockTemplate;
27
33{
34private:
39
40public:
41 explicit BlockTemplateManager(CTxMemPool& mempool,
42 ChainstateManager& chainman,
43 KernelNotifications& notifications,
44 BlockCreateOptions block_create_args = {});
45
48
50 std::unique_ptr<CBlockTemplate> CreateNewTemplate(const BlockCreateOptions& options);
51
54 bool SubmitBlock(const std::shared_ptr<const CBlock>& block, std::string& reason, std::string& debug);
55
58 std::optional<interfaces::BlockRef> GetTip();
59
64 std::optional<interfaces::BlockRef> WaitTipChanged(const uint256& current_tip, MillisecondsDouble& timeout, bool& interrupt);
65
69 std::optional<interfaces::BlockRef> WaitTipChanged(const uint256& current_tip, MillisecondsDouble timeout = MillisecondsDouble::max());
70
91 bool CooldownIfHeadersAhead(const interfaces::BlockRef& last_tip, bool& interrupt_mining);
92
94 void InterruptWait(bool& interrupt_wait);
95
98 std::unique_ptr<CBlockTemplate> WaitAndCreateNewBlock(
99 const std::unique_ptr<CBlockTemplate>& block_template,
100 const BlockWaitOptions& wait_options,
101 const BlockCreateOptions& create_options,
102 bool& interrupt_wait);
103};
104} // namespace node
105
106#endif // BITCOIN_NODE_BLOCK_TEMPLATE_MANAGER_H
Definition: block.h:74
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:187
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
Definition: validation.h:950
Creates block templates, submits solved blocks, and provides tip-waiting helpers for mining code.
BlockTemplateManager(CTxMemPool &mempool, ChainstateManager &chainman, KernelNotifications &notifications, BlockCreateOptions block_create_args={})
std::optional< interfaces::BlockRef > WaitTipChanged(const uint256 &current_tip, MillisecondsDouble &timeout, bool &interrupt)
Wait for the tip to differ from current_tip or timeout.
std::unique_ptr< CBlockTemplate > CreateNewTemplate(const BlockCreateOptions &options)
Create a fresh block template, applying init-time defaults to any unset options.
const BlockCreateOptions & BlockCreateArgs() const
bool SubmitBlock(const std::shared_ptr< const CBlock > &block, std::string &reason, std::string &debug)
Submit a block via ProcessNewBlock and capture validation state.
std::optional< interfaces::BlockRef > GetTip()
Locks cs_main.
const BlockCreateOptions m_block_create_args
KernelNotifications & m_notifications
void InterruptWait(bool &interrupt_wait)
Interrupt a blocking wait.
std::unique_ptr< CBlockTemplate > WaitAndCreateNewBlock(const std::unique_ptr< CBlockTemplate > &block_template, const BlockWaitOptions &wait_options, const BlockCreateOptions &create_options, bool &interrupt_wait)
Return a new block template when fees rise to a certain threshold or after a new tip; return nullptr ...
bool CooldownIfHeadersAhead(const interfaces::BlockRef &last_tip, bool &interrupt_mining)
Wait while the best known header extends the current chain tip AND at least one block is being added ...
256-bit opaque blob.
Definition: uint256.h:196
is used externally by mining IPC clients, so it should only declare simple data definitions.
Definition: messages.h:21
Hash/height pair to help track and identify blocks.
Definition: types.h:13
Block template creation options.
Definition: mining_types.h:33
std::chrono::duration< double, std::chrono::milliseconds::period > MillisecondsDouble
Definition: time.h:103