mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-25 05:20:01 +01:00
Merge bitcoin/bitcoin#31785: Have createNewBlock() wait for tip, make rpc handle shutdown during long poll and wait methods
05117e6e17rpc: clarify longpoll behavior (Sjors Provoost)5315278e7cHave createNewBlock() wait for a tip (Sjors Provoost)64a2795fd4rpc: handle shutdown during long poll and wait methods (Sjors Provoost)a3bf43343frpc: drop unneeded IsRPCRunning() guards (Sjors Provoost)f9cf8bd0abHandle negative timeout for waitTipChanged() (Sjors Provoost) Pull request description: This PR prevents Mining interface methods from sometimes crashing when called during startup before a tip is connected. It also makes other improvements like making more RPC methods usable from the GUI. Specifically this PR: - Adds an `Assume` check to disallow passing negative timeout values to `Mining::waitTipChanged` - Makes `waitfornewblock`, `waitforblock` and `waitforblockheight` RPC methods usable from the GUI when `-server=1` is not set. - Changes `Mining::waitTipChanged` to return `optional<BlockRef>` instead of `BlockRef` and return `nullopt` instead of crashing if there is a timeout or if the node is shut down before a tip is connected. - Changes `Mining::waitTipChanged` to not time out before a tip is connected, so it is convenient and safe to call during startup, and only returns `nullopt` on early shutdowns. - Changes `Mining::createNewBlock` to block and wait for a tip to be connected if it is called on startup instead of crashing. Also documents that it will return null on early shutdowns. This allows `waitNext()` (added in https://github.com/bitcoin/bitcoin/pull/31283) to safely assume `TipBlock()` isn't `null`, not even during a scenario of early shutdown. Finally this PR clarifies long poll behaviour, mostly by adding code comments, but also through an early `break`. ACKs for top commit: achow101: ACK05117e6e17ryanofsky: Code review ACK05117e6e17, just updated a commit message since last review TheCharlatan: ACK05117e6e17vasild: ACK05117e6e17Tree-SHA512: 277c285a6e73dfff88fd379298190b264254996f98b93c91c062986ab35c2aa5e1fbfec4cd71d7b29dc2d68e33f252b5cfc501345f54939d6bd78599b71fec04
This commit is contained in:
@@ -92,20 +92,25 @@ public:
|
||||
|
||||
/**
|
||||
* Waits for the connected tip to change. During node initialization, this will
|
||||
* wait until the tip is connected.
|
||||
* wait until the tip is connected (regardless of `timeout`).
|
||||
*
|
||||
* @param[in] current_tip block hash of the current chain tip. Function waits
|
||||
* for the chain tip to differ from this.
|
||||
* @param[in] timeout how long to wait for a new tip
|
||||
* @returns Hash and height of the current chain tip after this call.
|
||||
* @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.
|
||||
*/
|
||||
virtual 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
|
||||
* @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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user