@@ -2091,8 +2091,8 @@ static int64_t nTimePostConnect = 0;
20912091 * Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
20922092 * corresponding to pindexNew, to bypass loading it again from disk.
20932093 */
2094- bool static ConnectTip (CValidationState &state, CBlockIndex *pindexNew, CBlock *pblock) {
2095- const CChainParams& chainparams = Params ();
2094+ bool static ConnectTip (CValidationState &state, const CChainParams& chainparams, CBlockIndex *pindexNew, CBlock *pblock)
2095+ {
20962096 assert (pindexNew->pprev == chainActive.Tip ());
20972097 mempool.check (pcoinsTip);
20982098 // Read block from disk.
@@ -2225,8 +2225,8 @@ static void PruneBlockIndexCandidates() {
22252225 * Try to make some progress towards making pindexMostWork the active block.
22262226 * pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
22272227 */
2228- static bool ActivateBestChainStep (CValidationState &state, CBlockIndex *pindexMostWork, CBlock *pblock) {
2229- const CChainParams& chainparams = Params ();
2228+ static bool ActivateBestChainStep (CValidationState &state, const CChainParams& chainparams, CBlockIndex *pindexMostWork, CBlock *pblock)
2229+ {
22302230 AssertLockHeld (cs_main);
22312231 bool fInvalidFound = false ;
22322232 const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2257,7 +2257,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
22572257
22582258 // Connect new blocks.
22592259 BOOST_REVERSE_FOREACH (CBlockIndex *pindexConnect, vpindexToConnect) {
2260- if (!ConnectTip (state, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
2260+ if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
22612261 if (state.IsInvalid ()) {
22622262 // The block violates a consensus rule.
22632263 if (!state.CorruptionPossible ())
@@ -2295,8 +2295,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
22952295 * or an activated best chain. pblock is either NULL or a pointer to a block
22962296 * that is already loaded (to avoid loading it again from disk).
22972297 */
2298- bool ActivateBestChain (CValidationState &state, CBlock *pblock) {
2299- const CChainParams& chainparams = Params ();
2298+ bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, CBlock *pblock)
2299+ {
23002300 CBlockIndex *pindexNewTip = NULL ;
23012301 CBlockIndex *pindexMostWork = NULL ;
23022302 const CChainParams& chainParams = Params ();
@@ -2312,7 +2312,7 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) {
23122312 if (pindexMostWork == NULL || pindexMostWork == chainActive.Tip ())
23132313 return true ;
23142314
2315- if (!ActivateBestChainStep (state, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
2315+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
23162316 return false ;
23172317
23182318 pindexNewTip = chainActive.Tip ();
@@ -2726,9 +2726,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
27262726 return true ;
27272727}
27282728
2729- bool AcceptBlockHeader (const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex)
2729+ bool AcceptBlockHeader (const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex)
27302730{
2731- const CChainParams& chainparams = Params ();
27322731 AssertLockHeld (cs_main);
27332732 // Check for duplicate
27342733 uint256 hash = block.GetHash ();
@@ -2770,14 +2769,13 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
27702769 return true ;
27712770}
27722771
2773- bool AcceptBlock (CBlock& block, CValidationState& state, CBlockIndex** ppindex, CDiskBlockPos* dbp)
2772+ bool AcceptBlock (CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, CDiskBlockPos* dbp)
27742773{
2775- const CChainParams& chainparams = Params ();
27762774 AssertLockHeld (cs_main);
27772775
27782776 CBlockIndex *&pindex = *ppindex;
27792777
2780- if (!AcceptBlockHeader (block, state, &pindex))
2778+ if (!AcceptBlockHeader (block, state, chainparams, &pindex))
27812779 return false ;
27822780
27832781 // If we're pruning, ensure that we don't allow a peer to dump a copy
@@ -2850,7 +2848,7 @@ bool ProcessNewBlock(CValidationState &state, const CChainParams& chainparams, C
28502848
28512849 // Store to disk
28522850 CBlockIndex *pindex = NULL ;
2853- bool ret = AcceptBlock (*pblock, state, &pindex, dbp);
2851+ bool ret = AcceptBlock (*pblock, state, chainparams, &pindex, dbp);
28542852 if (pindex && pfrom) {
28552853 mapBlockSource[pindex->GetBlockHash ()] = pfrom->GetId ();
28562854 }
@@ -2859,7 +2857,7 @@ bool ProcessNewBlock(CValidationState &state, const CChainParams& chainparams, C
28592857 return error (" %s: AcceptBlock FAILED" , __func__);
28602858 }
28612859
2862- if (!ActivateBestChain (state, pblock))
2860+ if (!ActivateBestChain (state, chainparams, pblock))
28632861 return error (" %s: ActivateBestChain failed" , __func__);
28642862
28652863 return true ;
@@ -3181,9 +3179,8 @@ CVerifyDB::~CVerifyDB()
31813179 uiInterface.ShowProgress (" " , 100 );
31823180}
31833181
3184- bool CVerifyDB::VerifyDB (CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
3182+ bool CVerifyDB::VerifyDB (const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
31853183{
3186- const CChainParams& chainparams = Params ();
31873184 LOCK (cs_main);
31883185 if (chainActive.Tip () == NULL || chainActive.Tip ()->pprev == NULL )
31893186 return true ;
@@ -3298,9 +3295,8 @@ bool LoadBlockIndex()
32983295 return true ;
32993296}
33003297
3301-
3302- bool InitBlockIndex () {
3303- const CChainParams& chainparams = Params ();
3298+ bool InitBlockIndex (const CChainParams& chainparams)
3299+ {
33043300 LOCK (cs_main);
33053301 // Check whether we're already initialized
33063302 if (chainActive.Genesis () != NULL )
@@ -3314,7 +3310,7 @@ bool InitBlockIndex() {
33143310 // Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
33153311 if (!fReindex ) {
33163312 try {
3317- CBlock &block = const_cast <CBlock&>(Params () .GenesisBlock ());
3313+ CBlock &block = const_cast <CBlock&>(chainparams .GenesisBlock ());
33183314 // Start new block file
33193315 unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION);
33203316 CDiskBlockPos blockPos;
@@ -3326,7 +3322,7 @@ bool InitBlockIndex() {
33263322 CBlockIndex *pindex = AddToBlockIndex (block);
33273323 if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
33283324 return error (" LoadBlockIndex(): genesis block not accepted" );
3329- if (!ActivateBestChain (state, &block))
3325+ if (!ActivateBestChain (state, chainparams, &block))
33303326 return error (" LoadBlockIndex(): genesis block cannot be activated" );
33313327 // Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
33323328 return FlushStateToDisk (state, FLUSH_STATE_ALWAYS);
@@ -3338,11 +3334,8 @@ bool InitBlockIndex() {
33383334 return true ;
33393335}
33403336
3341-
3342-
3343- bool LoadExternalBlockFile (FILE* fileIn, CDiskBlockPos *dbp)
3337+ bool LoadExternalBlockFile (const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp)
33443338{
3345- const CChainParams& chainparams = Params ();
33463339 // Map of disk positions for blocks with unknown parent (only used for reindex)
33473340 static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent;
33483341 int64_t nStart = GetTimeMillis ();
@@ -3362,10 +3355,10 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
33623355 try {
33633356 // locate a header
33643357 unsigned char buf[MESSAGE_START_SIZE];
3365- blkdat.FindByte (Params () .MessageStart ()[0 ]);
3358+ blkdat.FindByte (chainparams .MessageStart ()[0 ]);
33663359 nRewind = blkdat.GetPos ()+1 ;
33673360 blkdat >> FLATDATA (buf);
3368- if (memcmp (buf, Params () .MessageStart (), MESSAGE_START_SIZE))
3361+ if (memcmp (buf, chainparams .MessageStart (), MESSAGE_START_SIZE))
33693362 continue ;
33703363 // read size
33713364 blkdat >> nSize;
@@ -4368,7 +4361,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
43684361 Misbehaving (pfrom->GetId (), 20 );
43694362 return error (" non-continuous headers sequence" );
43704363 }
4371- if (!AcceptBlockHeader (header, state, &pindexLast)) {
4364+ if (!AcceptBlockHeader (header, state, chainparams, &pindexLast)) {
43724365 int nDoS;
43734366 if (state.IsInvalid (nDoS)) {
43744367 if (nDoS > 0 )
0 commit comments