mining: add interrupt()

Both waitTipChanged() and createNewBlock() can take a long time to
return. Add a way for clients to interrupt them.

The new m_interrupt_mining is safely accessed with a lock on
m_tip_block_mutex, but it has no guard annotation. A more thorough
solution is discussed here:
https://github.com/bitcoin/bitcoin/pull/34184#discussion_r2743566474
This commit is contained in:
Sjors Provoost
2026-02-07 12:34:22 +01:00
parent a11297a904
commit 1e82fa498c
6 changed files with 58 additions and 17 deletions

View File

@@ -116,7 +116,7 @@ public:
* @param[in] timeout how long to wait for a new tip (default is forever)
*
* @retval BlockRef hash and height of the current chain tip after this call.
* @retval std::nullopt if the node is shut down.
* @retval std::nullopt if the node is shut down or interrupt() is called.
*/
virtual std::optional<BlockRef> waitTipChanged(uint256 current_tip, MillisecondsDouble timeout = MillisecondsDouble::max()) = 0;
@@ -130,10 +130,15 @@ public:
* 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.
* @retval std::nullptr if the node is shut down or interrupt() is called.
*/
virtual std::unique_ptr<BlockTemplate> createNewBlock(const node::BlockCreateOptions& options = {}, bool cooldown = true) = 0;
/**
* Interrupts createNewBlock and waitTipChanged.
*/
virtual void interrupt() = 0;
/**
* Checks if a given block is valid.
*