@@ -3226,7 +3226,7 @@ void CChainState::ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pi
3226
3226
}
3227
3227
}
3228
3228
3229
- static bool FindBlockPos (FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false )
3229
+ static bool FindBlockPos (FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, CChain& active_chain, uint64_t nTime, bool fKnown = false )
3230
3230
{
3231
3231
LOCK (cs_LastBlockFile);
3232
3232
@@ -3241,7 +3241,8 @@ static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int n
3241
3241
// when the undo file is keeping up with the block file, we want to flush it explicitly
3242
3242
// when it is lagging behind (more blocks arrive than are being connected), we let the
3243
3243
// undo block write case handle it
3244
- finalize_undo = (vinfoBlockFile[nFile].nHeightLast == (unsigned int )ChainActive ().Tip ()->nHeight );
3244
+ assert (std::addressof (::ChainActive ()) == std::addressof (active_chain));
3245
+ finalize_undo = (vinfoBlockFile[nFile].nHeightLast == (unsigned int )active_chain.Tip ()->nHeight );
3245
3246
nFile++;
3246
3247
if (vinfoBlockFile.size () <= nFile) {
3247
3248
vinfoBlockFile.resize (nFile + 1 );
@@ -3703,12 +3704,12 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
3703
3704
}
3704
3705
3705
3706
/* * Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
3706
- static FlatFilePos SaveBlockToDisk (const CBlock& block, int nHeight, const CChainParams& chainparams, const FlatFilePos* dbp) {
3707
+ static FlatFilePos SaveBlockToDisk (const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp) {
3707
3708
unsigned int nBlockSize = ::GetSerializeSize (block, CLIENT_VERSION);
3708
3709
FlatFilePos blockPos;
3709
3710
if (dbp != nullptr )
3710
3711
blockPos = *dbp;
3711
- if (!FindBlockPos (blockPos, nBlockSize+8 , nHeight, block.GetBlockTime (), dbp != nullptr )) {
3712
+ if (!FindBlockPos (blockPos, nBlockSize+8 , nHeight, active_chain, block.GetBlockTime (), dbp != nullptr )) {
3712
3713
error (" %s: FindBlockPos failed" , __func__);
3713
3714
return FlatFilePos ();
3714
3715
}
@@ -3787,7 +3788,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
3787
3788
// Write block to history file
3788
3789
if (fNewBlock ) *fNewBlock = true ;
3789
3790
try {
3790
- FlatFilePos blockPos = SaveBlockToDisk (block, pindex->nHeight , chainparams, dbp);
3791
+ FlatFilePos blockPos = SaveBlockToDisk (block, pindex->nHeight , :: ChainActive (), chainparams, dbp);
3791
3792
if (blockPos.IsNull ()) {
3792
3793
state.Error (strprintf (" %s: Failed to find position to write new block to disk" , __func__));
3793
3794
return false ;
@@ -4629,7 +4630,7 @@ bool CChainState::LoadGenesisBlock(const CChainParams& chainparams)
4629
4630
4630
4631
try {
4631
4632
const CBlock& block = chainparams.GenesisBlock ();
4632
- FlatFilePos blockPos = SaveBlockToDisk (block, 0 , chainparams, nullptr );
4633
+ FlatFilePos blockPos = SaveBlockToDisk (block, 0 , :: ChainActive (), chainparams, nullptr );
4633
4634
if (blockPos.IsNull ())
4634
4635
return error (" %s: writing genesis block to disk failed" , __func__);
4635
4636
CBlockIndex *pindex = m_blockman.AddToBlockIndex (block);
0 commit comments