WIP: mining: use a steady clock for the getblocktemplate rebuild interval

bitcoin/bitcoin: PR #36922

1 minor finding · 1 suggestion

Findings

Link

[minor] · Unmocked cache clock aborts the rpc fuzz target

The rpc fuzz target now aborts on inputs rebuilding the getblocktemplate cache because it mocks only NodeClock; this follows from source inspection, not execution, and existing-corpus triggers remain unconfirmed.

Location: src/node/block_template_manager.cpp:74 (head).

Details and suggested fix

The argument generator can supply {"rules":["segwit"]} without a longpollid, and the regtest fixture skips the connection and IBD checks. With an empty cache, this path reads MockableSteadyClock::now() before building the template. CheckGlobals clears steady mock time before each input, but FUZZ_TARGET(rpc) installs only FakeNodeClock, so the new read sets g_used_system_time and the per-input cleanup calls std::abort(). The same path previously used GetTime() through the mocked NodeClock. Add FakeSteadyClock steady_clock; beside FakeNodeClock in the fuzz target in the clock-switch commit.


Optional improvements

Link

[suggestion] · Longpoll tests discard the returned template

Although the RPC currently produces consistent fields, the longpoll test discards its responses, leaving this PR's cached-template wiring unchecked after tip changes.

Location: src/rpc/mining.cpp:1007 (head).

Details and suggested fix

LongpollThread.run() in mining_getblocktemplate_longpoll.py ignores the response, and both block-change cases only assert thread termination. A successful longpoll response containing stale tip fields would therefore escape these checks; the new manager unit tests also bypass RPC serialization. Store the response and, after each block-change join, assert that previousblockhash equals node 0's getbestblockhash(), longpollid[:64] equals previousblockhash, and height equals getblockcount() + 1. This directly covers the removal of the post-wait tip refresh and the switch to the cached template for pindexPrev and longpollid. The existing self.generate() synchronizes both nodes, so no additional timed wait is needed.


Coverage details