mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-21 11:25:46 +02:00
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