AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

Merge bitcoin/bitcoin#36908: mining: avoid checkBlock crash when chain has no tip

Public commit record

What the developer wrote

Authored by Ryan Ofsky

100/100 · Strong
Merge bitcoin/bitcoin#36908: mining: avoid checkBlock crash when chain has no tip

8cba4bace8df92afcc9ff46404e36c741d557b64 mining: avoid checkBlock crash when chain has no tip (Turtlecute33)

Pull request description:

**The problem**: `Init.makeMining` returns as soon as the chainstate is loaded. On a first start with an empty datadir, or on a node started with `-reindex`/`-reindex-chainstate`, this is before the genesis block is connected, so the active chain has no tip. A `Mining.checkBlock` call in this window reaches `TestBlockValidity()`, which asserts that the tip exists, and the node aborts.

**The fix**: in `MakeMining`, if `wait_loaded` is set, wait for the chainstate to be present and for the tip to be non-null.

*Alternative fix*: In `Mining.checkBlock`, check if the tip is present, return early with "inconclusive-no-chain-tip" otherwise. (I initially implemented this fix, but decided to go with the `makeMining` one instead, see https://github.com/bitcoin/bitcoin/pull/36908#discussion_r4610682758)

The crash can be reproduced on master using the functional test included in this PR.

This is joint work with Turtlecute33 :)

ACKs for top commit:
Sjors:
ACK 8cba4bace8df92afcc9ff46404e36c741d557b64
w0xlt:
ACK 8cba4bace8df92afcc9ff46404e36c741d557b64
xyzconstant:
tACK 8cba4bace8
ryanofsky:
Code review ACK 8cba4bace8df92afcc9ff46404e36c741d557b64. This extends the #34661 fix to cover a case it missed. #34661 made `makeMining` wait for the chainstate to be loaded, but on a first start or with `-reindex`/`-reindex-chainstate` the chainstate is loaded before genesis is connected, and a `checkBlock` call in between still hits the `Tip()` assert in `TestBlockValidity`. `makeMining` now also waits for a tip using the same condition `AppInitMain` waits for before starting the node.

Tree-SHA512: b9af8bfd43d95ef04a4eca55b269770d562269668e08b7d5a271a05f6c54d4833556333ae22aa282df6a1b0591d507da8401edef6819f16708744b7739d28d9c
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This update fixes a crash in Bitcoin Core that could happen right after starting the node with an empty data directory or during a blockchain reindex. If an external program called the mining interface's checkBlock function in a brief window before the very first genesis block was connected, the node would hit an internal assumption and shut down. The fix makes the mining interface wait until the chain has an actual tip before becoming available.

Recommended action

Apply the patch. It is a targeted, low-risk fix that closes a startup-time crash window. Operators running external mining clients via IPC should upgrade, though the crash requires local access and a well-timed call during startup or reindex.

Security signals we found

01

Denial-of-service vector: external IPC client can crash the node during startup

02

Assertion failure in TestBlockValidity due to null chain tip

03

Race condition between chainstate load and genesis block connection

04

Fix extends prior incomplete mitigation from PR #34661

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.