Have createNewBlock() wait for a tip
- return null on shutdown instead of the last tip - ignore timeout value node initialization This allows consumers of BlockTemplate to safely assume that a tip is connected, instead of having to account for startup and early shutdown scenarios.
This commit is contained in:
2 files changed
+8
-2
No files matched your search
@@ -101,10 +101,13 @@ public:
|
|||||||
virtual std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
|
virtual std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new block template
|
* Construct a new block template.
|
||||||
|
*
|
||||||
|
* During node initialization, this will wait until the tip is connected.
|
||||||
*
|
*
|
||||||
* @param[in] options options for creating the block
|
* @param[in] options options for creating the block
|
||||||
* @returns a block template
|
* @retval BlockTemplate a block template.
|
||||||
|
* @retval std::nullptr if the node is shut down.
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0;
|
virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -1102,6 +1102,9 @@ public:
|
|||||||
|
|
||||||
std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options) override
|
std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options) override
|
||||||
{
|
{
|
||||||
|
// Ensure m_tip_block is set so consumers of BlockTemplate can rely on that.
|
||||||
|
if (!waitTipChanged(uint256::ZERO, MillisecondsDouble::max())) return {};
|
||||||
|
|
||||||
BlockAssembler::Options assemble_options{options};
|
BlockAssembler::Options assemble_options{options};
|
||||||
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
|
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
|
||||||
return std::make_unique<BlockTemplateImpl>(assemble_options, BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(), m_node);
|
return std::make_unique<BlockTemplateImpl>(assemble_options, BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(), m_node);
|
||||||
|
|||||||
Reference in new issue
Block a user