From 6b2293ad1ac95e73bb2720e0a4234995855a2e07 Mon Sep 17 00:00:00 2001 From: Krystie Date: Sat, 8 Aug 2026 02:55:45 -0700 Subject: [PATCH] [glm-grade=B] fix(reindex): set phashBlock before GetStakeModifierChecksum in FastImportBlockFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FastImportBlockFile() was calling GetStakeModifierChecksum(pindexNew) which calls GetBlockHash() which dereferences *phashBlock — but phashBlock was still null because the mapBlockIndex.insert that sets it happened 10 lines later. This caused a segfault (exit 139) on every fresh -reindex with no existing chainstate. Fix: move the mapBlockIndex.insert + phashBlock assignment before the GetStakeModifierChecksum call. Pure ordering fix, no logic change. --- src/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b412ec8..9722461 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4424,16 +4424,20 @@ bool FastImportBlockFile() hash.ToString().c_str()); } pindexNew->SetStakeModifier(nStakeModifier, fGeneratedStakeModifier); + + // Insert into mapBlockIndex and set phashBlock BEFORE calling + // GetStakeModifierChecksum, which calls GetBlockHash() which + // dereferences phashBlock. Without this ordering, phashBlock is + // null and the checksum call segfaults. + auto mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; + pindexNew->phashBlock = &mi->first; + pindexNew->nStakeModifierChecksum = GetStakeModifierChecksum(pindexNew); // PoS stake seen set if (pindexNew->IsProofOfStake()) setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime)); - // Insert into mapBlockIndex - auto mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; - pindexNew->phashBlock = &mi->first; - // pnext is rebuilt after best-chain selection. File order also // contains side branches, so assigning it here would let the last // imported child hijack stake-modifier forward walks.