Skip to content

fix: node crashes at first AuxPoW block (header serialization, block read, index load) - #4

Closed
colneech-dev wants to merge 2 commits into
Blocklechain:masterfrom
colneech-dev:fix/auxpow-header-relay
Closed

colneech-dev wants to merge 2 commits into
Blocklechain:masterfrom
colneech-dev:fix/auxpow-header-relay

Conversation

@colneech-dev

Copy link
Copy Markdown

Problem

Once the chain passes the AuxPoW activation height (80,000) and the first merge-mined block is accepted, the node aborts:

perbugd: ./primitives/block.h:43: ... CBlockHeader::SerializationOps ... Assertion `obj.auxpow != nullptr' failed.

It then restarts into the same state (we saw >25,000 restarts). There are three related defects, all caused by CBlockIndex not storing the AuxPoW proof:

  1. Header serialization. CBlockIndex::GetBlockHeader() returns a header whose version has the AuxPoW flag but whose auxpow is null. Serializing it asserts. Hit when announcing/serving headers to peers (net_processing.cpp), and by getblockheader <hash> false and /rest/headers.
  2. Reading blocks back. BlockManager::ReadBlock re-checks PoW with CheckProofOfWork(block.GetHash(), ...). For an AuxPoW block the work is in the parent header, so every merge-mined block fails to read from disk.
  3. Restart. BlockManager::LoadBlockIndexGuts does the same plain check, so after an AuxPoW block has been persisted the node refuses to load its block index on the next start. (Not visible while defect 1 crashes the node before anything is persisted.)

Fix

  • Add BlockManager::ReadBlockHeader(const CBlockIndex&), which returns the stored block's header (with proof) when the AuxPoW flag is set, and use it at the six places that serialize an index entry's header.
  • ReadBlock uses the header-aware CheckProofOfWork(const CBlockHeader&, ...).
  • LoadBlockIndexGuts skips the plain PoW re-check for AuxPoW-flagged versions (it was verified when the block was accepted).

Testing

Built v30.4.2 + this patch and ran it on the live chain (height 80,008, crash-looping before). It passed the old crash point and stayed up while merge-mined blocks accumulated. A graceful restart reloaded the best chain with AuxPoW blocks in the index, and getblockheader returns the correct header for AuxPoW blocks. No unit tests added; there is no existing harness for serializing index headers.

@Blocklechain

Copy link
Copy Markdown
Owner

Thank you, and an apology: this PR was correct, it was first, and it sat here for three days without being looked at.

GitHub holds workflow runs for first-time contributors pending maintainer approval, so CI never ran and nothing surfaced it. In the meantime our own mainnet node crash-looped 20,034 times on exactly the bug you fixed here. The fix was sitting in this PR the whole time.

A second report of the same two bugs came in today, we treated it as unsolved, and shipped our own fix in 5639c84 / v30.4.3 before finding this. That was our process failure, not yours — the first thing to check on a bug report is whether someone has already sent a patch, and we did not.

Your version is better than what shipped, in three specific ways, and we are adopting all three:

  • LoadBlockIndexGuts — you build a CPureBlockHeader version_probe, copy nVersion in and call IsAuxpow(). We hand-rolled the bit test nVersion & CPureBlockHeader::VERSION_AUXPOW. Yours reuses the real predicate instead of duplicating bit logic in a second place.
  • ReadBlockHeader — you return CBlockHeader{block}, slicing the stored block. We assigned header.auxpow = block.auxpow field by field. Both are correct; yours is right by construction and shorter.
  • The name. ReadBlockHeader sits alongside the existing ReadBlock / ReadRawBlock. Ours was GetSerialisableHeader, which matches nothing.

Your diff is +60/-10 against our +94/-9, and the extra is mostly our comments.

We also agree with every call-site decision you made independently: stop on the getheaders reply because headers must be contiguous, fall back to an inv on the announcement paths, and std::optional rather than trying to repair the header — which is right, because the AuxPoW flag is in nVersion and therefore in the block hash, so clearing it would produce a different block.

Closing this as superseded by 5639c84 only because master has already moved and the tag is out — not because anything here was wrong. A follow-up is landing that takes your three constructs with Co-Authored-By, so the attribution is in the history where it belongs.

Two process changes on our side as a result: workflow approval for first-time contributors will not be left sitting again, and we will check open PRs before writing a fix for a reported bug.

Blocklechain pushed a commit that referenced this pull request Nov 30, 2026
#4 arrived three days before the bug report that prompted 5639c84 and was the
better patch. It went unreviewed because GitHub gates workflow runs for
first-time contributors, so CI never ran and nothing surfaced it. Taking its
three improvements here so the attribution sits in the history rather than
only in a closed PR.

  * LoadBlockIndexGuts builds a CPureBlockHeader and calls IsAuxpow() instead
    of hand-rolling `nVersion & CPureBlockHeader::VERSION_AUXPOW`. Reuses the
    real predicate rather than duplicating the bit logic in a second place.

  * ReadBlockHeader returns CBlockHeader{block}, slicing the stored block,
    instead of copying auxpow across field by field. Right by construction.

  * Renamed GetSerialisableHeader -> ReadBlockHeader, which sits alongside the
    existing ReadBlock / ReadRawBlock. The old name matched nothing.

No behaviour change: same six call sites, same failure handling, same
std::optional contract. Builds clean.

Co-Authored-By: colneech-dev <256970689+colneech-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants