[glm-grade=B] fix(reindex): set phashBlock before GetStakeModifierChecksum in FastImportBlockFile
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.
This commit is contained in:
+8
-4
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user