bitcoin/src/interfaces
Ava Chow 99a4ddf5ab
Merge bitcoin/bitcoin#31785: Have createNewBlock() wait for tip, make rpc handle shutdown during long poll and wait methods
05117e6e17f9a2d9a18a5b32570808c8907febb3 rpc: clarify longpoll behavior (Sjors Provoost)
5315278e7c7fb961fd749cd8e991d5c5c66dde11 Have createNewBlock() wait for a tip (Sjors Provoost)
64a2795fd4fe223a55564c31e9fa36264e79ac22 rpc: handle shutdown during long poll and wait methods (Sjors Provoost)
a3bf43343f0d88ec9ff847a55fd48745aeebb429 rpc: drop unneeded IsRPCRunning() guards (Sjors Provoost)
f9cf8bd0ab77cdf125d78384197a5c466577fd8f Handle 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:
    ACK 05117e6e17f9a2d9a18a5b32570808c8907febb3
  ryanofsky:
    Code review ACK 05117e6e17f9a2d9a18a5b32570808c8907febb3, just updated a commit message since last review
  TheCharlatan:
    ACK 05117e6e17f9a2d9a18a5b32570808c8907febb3
  vasild:
    ACK 05117e6e17f9a2d9a18a5b32570808c8907febb3

Tree-SHA512: 277c285a6e73dfff88fd379298190b264254996f98b93c91c062986ab35c2aa5e1fbfec4cd71d7b29dc2d68e33f252b5cfc501345f54939d6bd78599b71fec04
2025-04-14 14:39:57 -07:00
..
2024-07-08 11:12:01 +02:00
2024-07-08 11:12:01 +02:00
2024-10-29 11:58:51 -04:00
2024-09-17 09:14:15 +02:00

Internal c++ interfaces

The following interfaces are defined here:

  • Chain — used by wallet to access blockchain and mempool state. Added in #14437, #14711, #15288, and #10973.

  • ChainClient — used by node to start & stop Chain clients. Added in #14437.

  • Node — used by GUI to start & stop bitcoin node. Added in #10244.

  • Wallet — used by GUI to access wallets. Added in #10244.

  • Handler — returned by handleEvent methods on interfaces above and used to manage lifetimes of event handlers.

  • Init — used by multiprocess code to access interfaces above on startup. Added in #19160.

  • Ipc — used by multiprocess code to access Init interface across processes. Added in #19160.

The interfaces above define boundaries between major components of bitcoin code (node, wallet, and gui), making it possible for them to run in different processes, and be tested, developed, and understood independently. These interfaces are not currently designed to be stable or to be used externally.