Skip to content

Have createNewBlock() wait for tip, make rpc handle shutdown during long poll and wait methods

The Mining interface waitTipChanged() method now returns nullopt if the node is shutting down.

Previously it would return the last known tip during shutdown, but this could cause a crash in the scenario where the node is started and quickly shutdown, before notifications().TipBlock() is set.

This allows the proposed waitNext() method in https://github.com/bitcoin/bitcoin/pull/31283 to safely assume TipBlock() isn't null, not even during a scenario of early shutdown.

The behavior is now easier to understand for callers: waitTipChanged() either eventually returns a tip, or nullptr if the timeout is reached or the node shuts down.

Another possibility was that TipBlock() wasn't set yet at timeout. To keep the interface simple, waitTipChanged() will ignore timeout in that case a wait longer.

They no longer have to worry about a case where a tip is returned, but it's unchanged and the node is shutting down.

The getblocktemplate, waitfornewblock and waitforblockheight RPC calls now explicitly handle the shutdown scenario.

Finally this PR clarifies long poll behaviour, mostly by adding code comments, but also through an early break.

Merge request reports

Loading