Repository navigation
fix: node crashes at first AuxPoW block (header serialization, block read, index load) - #4
colneech-dev wants to merge 2 commits into
Conversation
…s / loading the index
|
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:
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 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 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. |
#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>
Problem
Once the chain passes the AuxPoW activation height (80,000) and the first merge-mined block is accepted, the node aborts:
It then restarts into the same state (we saw >25,000 restarts). There are three related defects, all caused by
CBlockIndexnot storing the AuxPoW proof:CBlockIndex::GetBlockHeader()returns a header whose version has the AuxPoW flag but whoseauxpowis null. Serializing it asserts. Hit when announcing/serving headers to peers (net_processing.cpp), and bygetblockheader <hash> falseand/rest/headers.BlockManager::ReadBlockre-checks PoW withCheckProofOfWork(block.GetHash(), ...). For an AuxPoW block the work is in the parent header, so every merge-mined block fails to read from disk.BlockManager::LoadBlockIndexGutsdoes 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
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.ReadBlockuses the header-awareCheckProofOfWork(const CBlockHeader&, ...).LoadBlockIndexGutsskips 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
getblockheaderreturns the correct header for AuxPoW blocks. No unit tests added; there is no existing harness for serializing index headers.