mining: handle negative and NaN wait timeouts

bitcoin/bitcoin: PR #36940

2 suggestions

Optional improvements

Link

[suggestion] · Infinite-timeout tests discard interrupt errors and lack a failure deadline

The new infinite-timeout tests discard the interrupt promises and can hang instead of reporting an ineffective interrupt promptly.

Location: test/functional/interface_ipc_mining.py:171 (head).

Details and suggested fix

The new calls pass mining.interrupt and template6.interruptWait as callables, but wait_and_do invokes do_fn() without awaiting its result. Their IPC errors therefore cannot propagate through asyncio.gather. If an interrupt has no effect, waitTipChanged can wait for its 100-year clamped timeout, while waitNext has no finite deadline and depends on another event, such as a tip change or the minimum-difficulty path. The check_order assertion cannot help because it runs only after both tasks finish, and the test runner waits for the subprocess without a per-test deadline.

Keep the delayed callable invocation, but capture its result and await it when inspect.isawaitable returns true. Also wrap each infinite-timeout wait_and_do call in asyncio.wait_for, using a bound derived from long_ipc_timeout / 1000. This preserves the ordering check while making interrupt errors and ineffective interrupts fail promptly. Whether discarding a pycapnp promise can itself drop the request is unverified; the missing deadline matters regardless of what prevents the interrupt from taking effect.


Link

[suggestion] · The new timeout errors are missing from release notes

Mining.waitTipChanged and BlockTemplate.waitNext now reject negative and NaN timeouts, but no release note describes the client-visible change; no current client sending these values was identified.

Location: src/node/interfaces.cpp:929 (head).

Details and suggested fix

Both methods now throw before delegating to the template manager. Previously, a negative finite timeout made waitNext perform one immediate iteration, while waitTipChanged clamped it to zero in builds where Assume did not abort. The header comments document the new errors, but clients consulting release notes will miss the change. Add a release-note fragment stating that both methods now return an error for negative or NaN timeouts. The existing mining notes already document the analogous switch from clamping out-of-range template options to rejecting them.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Ralph's inferences

The pre-existing contract describes the default as “forever,” but represents it with the largest finite MillisecondsDouble value, not positive infinity. This supports interpreting “forever” as an effectively unbounded, interruptible wait rather than a promise about a particular floating-point representation.

Both wait methods retain their finite maximum defaults. The new interface checks also accept positive infinity, so they do not restrict valid timeouts to finite values. However, the inspected evidence establishes compatibility with existing behavior, not an independently documented historical guarantee that clients may supply infinity.

Positive infinity and the default finite maximum reach different timeout mechanisms. WaitTipChanged bounds either value to 100 years, explicitly to avoid undefined behavior in std::chrono. WaitAndCreateNewBlock instead waits in at-most-one-second increments and checks its overall deadline between iterations; positive infinity supplies no finite timeout expiry there.

Rejecting only negative and unordered values at the interface leaves these existing large-timeout mechanisms intact. Accepting infinity therefore does not mean passing an infinite deadline directly to WaitTipChanged’s condition-variable wait, nor does it remove interruption or event-driven completion. The two methods provide effectively indefinite waits through different mechanisms.

The code distinguishes a caller-domain error from an internal programming assumption: the interface rejects negative and NaN timeouts with an exception before delegation, while the manager’s existing Assume explicitly says internal callers should not supply negative timeouts.

Placing rejection in the interface preserves that separation: external values are checked before reaching the manager, and direct internal manager callers remain subject to its assumption. The same comparison permits zero, positive finite values, and positive infinity. This is a code-supported interpretation of the boundary, not a verified historical resolution of IPC error-handling policy.