mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
mining: add cooldown argument to createNewBlock()
At startup, if the needs to catch up, connected mining clients will receive a flood of new templates as new blocks are connected. Fix this by adding a cooldown argument to createNewBlock(). When set to true, block template creation is briefly paused while the best header chain is ahead of the tip. This wait only happens when the best header extends the current tip, to ignore competing branches. Additionally, cooldown waits for isInitialBlockDownload() to latch to false, which happens when there is less than a day of blocks left to sync. When cooldown is false createNewBlock() returns immediately. The argument is optional, because many tests are negatively impacted by this mechanism, and single miner signets could end up stuck if no block was mined for a day. The getblocktemplate RPC also opts out, because it would add a delay to each call. Fixes #33994
This commit is contained in:
@@ -123,13 +123,16 @@ public:
|
||||
/**
|
||||
* 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] cooldown wait for tip to be connected and IBD to complete.
|
||||
* If the best header is ahead of the tip, wait for the
|
||||
* tip to catch up. It's recommended to disable this on
|
||||
* regtest and signets with only one miner, as these
|
||||
* could stall.
|
||||
* @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 = {}, bool cooldown = true) = 0;
|
||||
|
||||
/**
|
||||
* Checks if a given block is valid.
|
||||
|
||||
Reference in New Issue
Block a user