MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / createNewBlock

Method createNewBlock

src/node/interfaces.cpp:981–1010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

979 }
980
981 std::unique_ptr<BlockTemplate> createNewBlock(const BlockCreateOptions& options, bool cooldown) override
982 {
983 // Ensure m_tip_block is set so consumers of BlockTemplate can rely on that.
984 std::optional<BlockRef> maybe_tip{waitTipChanged(uint256::ZERO, MillisecondsDouble::max())};
985
986 if (!maybe_tip) return {};
987
988 if (cooldown) {
989 // Do not return a template during IBD, because it can have long
990 // pauses and sometimes takes a while to get started. Although this
991 // is useful in general, it's gated behind the cooldown argument,
992 // because on regtest and single miner signets this would wait
993 // forever if no block was mined in the past day.
994 while (chainman().IsInitialBlockDownload()) {
995 maybe_tip = waitTipChanged(maybe_tip->hash, MillisecondsDouble{1000});
996 if (!maybe_tip || chainman().m_interrupt || WITH_LOCK(notifications().m_tip_block_mutex, return m_interrupt_mining)) return {};
997 }
998
999 // Also wait during the final catch-up moments after IBD.
1000 if (!CooldownIfHeadersAhead(chainman(), notifications(), *maybe_tip, m_interrupt_mining)) return {};
1001 }
1002 const BlockCreateOptions create_options{MergeMiningOptions(options, m_node.mining_args)};
1003 return std::make_unique<BlockTemplateImpl>(create_options,
1004 BlockAssembler{
1005 chainman().ActiveChainstate(),
1006 m_node.mempool.get(),
1007 create_options,
1008 }.CreateNewBlock(),
1009 m_node);
1010 }
1011
1012 void interrupt() override
1013 {

Callers 15

async_routineMethod · 0.80
wait_fnMethod · 0.80
create_blockMethod · 0.80
async_routineMethod · 0.80
CreateBlockMethod · 0.80
mineBlockFunction · 0.80
TestPackageSelectionMethod · 0.80
TestBasicMiningMethod · 0.80
TestPrioritisedMiningMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 5

CooldownIfHeadersAheadFunction · 0.85
MergeMiningOptionsFunction · 0.85
CreateNewBlockMethod · 0.80
getMethod · 0.45

Tested by 11

CreateBlockMethod · 0.64
mineBlockFunction · 0.64
TestPackageSelectionMethod · 0.64
TestBasicMiningMethod · 0.64
TestPrioritisedMiningMethod · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
BlockMethod · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
PrepareBlockFunction · 0.64
CreateBlockMethod · 0.64