@@ -1939,6 +1939,7 @@ enum FlushStateMode {
1939
1939
* or always and in all cases if we're in prune mode and are deleting files.
1940
1940
*/
1941
1941
bool static FlushStateToDisk (CValidationState &state, FlushStateMode mode) {
1942
+ const CChainParams& chainparams = Params ();
1942
1943
LOCK2 (cs_main, cs_LastBlockFile);
1943
1944
static int64_t nLastWrite = 0 ;
1944
1945
static int64_t nLastFlush = 0 ;
@@ -1947,7 +1948,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
1947
1948
bool fFlushForPrune = false ;
1948
1949
try {
1949
1950
if (fPruneMode && fCheckForPruning && !fReindex ) {
1950
- FindFilesToPrune (setFilesToPrune);
1951
+ FindFilesToPrune (setFilesToPrune, chainparams. PruneAfterHeight () );
1951
1952
fCheckForPruning = false ;
1952
1953
if (!setFilesToPrune.empty ()) {
1953
1954
fFlushForPrune = true ;
@@ -2147,8 +2148,8 @@ static int64_t nTimePostConnect = 0;
2147
2148
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
2148
2149
* corresponding to pindexNew, to bypass loading it again from disk.
2149
2150
*/
2150
- bool static ConnectTip (CValidationState & state, CBlockIndex * pindexNew, const CBlock * pblock) {
2151
- const CChainParams& chainparams = Params ();
2151
+ bool static ConnectTip (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock)
2152
+ {
2152
2153
assert (pindexNew->pprev == chainActive.Tip ());
2153
2154
mempool.check (pcoinsTip);
2154
2155
// Read block from disk.
@@ -2280,8 +2281,8 @@ static void PruneBlockIndexCandidates() {
2280
2281
* Try to make some progress towards making pindexMostWork the active block.
2281
2282
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2282
2283
*/
2283
- static bool ActivateBestChainStep (CValidationState & state, CBlockIndex * pindexMostWork, const CBlock * pblock) {
2284
- const CChainParams& chainparams = Params ();
2284
+ static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock)
2285
+ {
2285
2286
AssertLockHeld (cs_main);
2286
2287
bool fInvalidFound = false ;
2287
2288
const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2314,7 +2315,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2314
2315
2315
2316
// Connect new blocks.
2316
2317
BOOST_REVERSE_FOREACH (CBlockIndex *pindexConnect, vpindexToConnect) {
2317
- if (!ConnectTip (state, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
2318
+ if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
2318
2319
if (state.IsInvalid ()) {
2319
2320
// The block violates a consensus rule.
2320
2321
if (!state.CorruptionPossible ())
@@ -2355,10 +2356,10 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2355
2356
* or an activated best chain. pblock is either NULL or a pointer to a block
2356
2357
* that is already loaded (to avoid loading it again from disk).
2357
2358
*/
2358
- bool ActivateBestChain (CValidationState &state, const CBlock *pblock) {
2359
+ bool ActivateBestChain (CValidationState& state, const CChainParams& chainparams, const CBlock* pblock)
2360
+ {
2359
2361
CBlockIndex *pindexNewTip = NULL ;
2360
2362
CBlockIndex *pindexMostWork = NULL ;
2361
- const CChainParams& chainparams = Params ();
2362
2363
do {
2363
2364
boost::this_thread::interruption_point ();
2364
2365
@@ -2371,7 +2372,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
2371
2372
if (pindexMostWork == NULL || pindexMostWork == chainActive.Tip ())
2372
2373
return true ;
2373
2374
2374
- if (!ActivateBestChainStep (state, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
2375
+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
2375
2376
return false ;
2376
2377
2377
2378
pindexNewTip = chainActive.Tip ();
@@ -2850,9 +2851,9 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
2850
2851
return true ;
2851
2852
}
2852
2853
2853
- bool AcceptBlock (const CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested , CDiskBlockPos* dbp)
2854
+ /* * Store block on disk. If dbp is non-NULL, the file is known to already reside on disk */
2855
+ static bool AcceptBlock (const CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested , CDiskBlockPos* dbp)
2854
2856
{
2855
- const CChainParams& chainparams = Params ();
2856
2857
AssertLockHeld (cs_main);
2857
2858
2858
2859
CBlockIndex *&pindex = *ppindex;
@@ -2942,7 +2943,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
2942
2943
2943
2944
// Store to disk
2944
2945
CBlockIndex *pindex = NULL ;
2945
- bool ret = AcceptBlock (*pblock, state, &pindex, fRequested , dbp);
2946
+ bool ret = AcceptBlock (*pblock, state, chainparams, &pindex, fRequested , dbp);
2946
2947
if (pindex && pfrom) {
2947
2948
mapBlockSource[pindex->GetBlockHash ()] = pfrom->GetId ();
2948
2949
}
@@ -2951,7 +2952,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
2951
2952
return error (" %s: AcceptBlock FAILED" , __func__);
2952
2953
}
2953
2954
2954
- if (!ActivateBestChain (state, pblock))
2955
+ if (!ActivateBestChain (state, chainparams, pblock))
2955
2956
return error (" %s: ActivateBestChain failed" , __func__);
2956
2957
2957
2958
return true ;
@@ -3041,13 +3042,13 @@ void UnlinkPrunedFiles(std::set<int>& setFilesToPrune)
3041
3042
}
3042
3043
3043
3044
/* Calculate the block/rev files that should be deleted to remain under target*/
3044
- void FindFilesToPrune (std::set<int >& setFilesToPrune)
3045
+ void FindFilesToPrune (std::set<int >& setFilesToPrune, uint64_t nPruneAfterHeight )
3045
3046
{
3046
3047
LOCK2 (cs_main, cs_LastBlockFile);
3047
3048
if (chainActive.Tip () == NULL || nPruneTarget == 0 ) {
3048
3049
return ;
3049
3050
}
3050
- if (chainActive.Tip ()->nHeight <= Params (). PruneAfterHeight () ) {
3051
+ if (chainActive.Tip ()->nHeight <= nPruneAfterHeight ) {
3051
3052
return ;
3052
3053
}
3053
3054
@@ -3275,9 +3276,8 @@ CVerifyDB::~CVerifyDB()
3275
3276
uiInterface.ShowProgress (" " , 100 );
3276
3277
}
3277
3278
3278
- bool CVerifyDB::VerifyDB (CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
3279
+ bool CVerifyDB::VerifyDB (const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
3279
3280
{
3280
- const CChainParams& chainparams = Params ();
3281
3281
LOCK (cs_main);
3282
3282
if (chainActive.Tip () == NULL || chainActive.Tip ()->pprev == NULL )
3283
3283
return true ;
@@ -3393,9 +3393,8 @@ bool LoadBlockIndex()
3393
3393
return true ;
3394
3394
}
3395
3395
3396
-
3397
- bool InitBlockIndex () {
3398
- const CChainParams& chainparams = Params ();
3396
+ bool InitBlockIndex (const CChainParams& chainparams)
3397
+ {
3399
3398
LOCK (cs_main);
3400
3399
3401
3400
// Initialize global variables that cannot be constructed at startup.
@@ -3413,7 +3412,7 @@ bool InitBlockIndex() {
3413
3412
// Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
3414
3413
if (!fReindex ) {
3415
3414
try {
3416
- CBlock &block = const_cast <CBlock&>(Params () .GenesisBlock ());
3415
+ CBlock &block = const_cast <CBlock&>(chainparams .GenesisBlock ());
3417
3416
// Start new block file
3418
3417
unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION);
3419
3418
CDiskBlockPos blockPos;
@@ -3425,7 +3424,7 @@ bool InitBlockIndex() {
3425
3424
CBlockIndex *pindex = AddToBlockIndex (block);
3426
3425
if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
3427
3426
return error (" LoadBlockIndex(): genesis block not accepted" );
3428
- if (!ActivateBestChain (state, &block))
3427
+ if (!ActivateBestChain (state, chainparams, &block))
3429
3428
return error (" LoadBlockIndex(): genesis block cannot be activated" );
3430
3429
// Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
3431
3430
return FlushStateToDisk (state, FLUSH_STATE_ALWAYS);
@@ -3437,11 +3436,8 @@ bool InitBlockIndex() {
3437
3436
return true ;
3438
3437
}
3439
3438
3440
-
3441
-
3442
- bool LoadExternalBlockFile (FILE* fileIn, CDiskBlockPos *dbp)
3439
+ bool LoadExternalBlockFile (const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp)
3443
3440
{
3444
- const CChainParams& chainparams = Params ();
3445
3441
// Map of disk positions for blocks with unknown parent (only used for reindex)
3446
3442
static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent;
3447
3443
int64_t nStart = GetTimeMillis ();
@@ -3461,10 +3457,10 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
3461
3457
try {
3462
3458
// locate a header
3463
3459
unsigned char buf[MESSAGE_START_SIZE];
3464
- blkdat.FindByte (Params () .MessageStart ()[0 ]);
3460
+ blkdat.FindByte (chainparams .MessageStart ()[0 ]);
3465
3461
nRewind = blkdat.GetPos ()+1 ;
3466
3462
blkdat >> FLATDATA (buf);
3467
- if (memcmp (buf, Params () .MessageStart (), MESSAGE_START_SIZE))
3463
+ if (memcmp (buf, chainparams .MessageStart (), MESSAGE_START_SIZE))
3468
3464
continue ;
3469
3465
// read size
3470
3466
blkdat >> nSize;
@@ -3858,7 +3854,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
3858
3854
// best equivalent proof of work) than the best header chain we know about.
3859
3855
send = mi->second ->IsValid (BLOCK_VALID_SCRIPTS) && (pindexBestHeader != NULL ) &&
3860
3856
(pindexBestHeader->GetBlockTime () - mi->second ->GetBlockTime () < nOneMonth) &&
3861
- (GetBlockProofEquivalentTime (*pindexBestHeader, *mi->second , *pindexBestHeader, Params (). GetConsensus () ) < nOneMonth);
3857
+ (GetBlockProofEquivalentTime (*pindexBestHeader, *mi->second , *pindexBestHeader, consensusParams ) < nOneMonth);
3862
3858
if (!send) {
3863
3859
LogPrintf (" %s: ignoring request from peer=%i for old block that isn't in the main chain\n " , __func__, pfrom->GetId ());
3864
3860
}
@@ -4701,7 +4697,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4701
4697
uint256 alertHash = alert.GetHash ();
4702
4698
if (pfrom->setKnown .count (alertHash) == 0 )
4703
4699
{
4704
- if (alert.ProcessAlert (Params () .AlertKey ()))
4700
+ if (alert.ProcessAlert (chainparams .AlertKey ()))
4705
4701
{
4706
4702
// Relay
4707
4703
pfrom->setKnown .insert (alertHash);
0 commit comments