@@ -2139,6 +2139,7 @@ enum FlushStateMode {
2139
2139
* or always and in all cases if we're in prune mode and are deleting files.
2140
2140
*/
2141
2141
bool static FlushStateToDisk (CValidationState &state, FlushStateMode mode) {
2142
+ const CChainParams& chainparams = Params ();
2142
2143
LOCK2 (cs_main, cs_LastBlockFile);
2143
2144
static int64_t nLastWrite = 0 ;
2144
2145
static int64_t nLastFlush = 0 ;
@@ -2147,7 +2148,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
2147
2148
bool fFlushForPrune = false ;
2148
2149
try {
2149
2150
if (fPruneMode && fCheckForPruning && !fReindex ) {
2150
- FindFilesToPrune (setFilesToPrune);
2151
+ FindFilesToPrune (setFilesToPrune, chainparams. PruneAfterHeight () );
2151
2152
fCheckForPruning = false ;
2152
2153
if (!setFilesToPrune.empty ()) {
2153
2154
fFlushForPrune = true ;
@@ -2347,8 +2348,8 @@ static int64_t nTimePostConnect = 0;
2347
2348
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
2348
2349
* corresponding to pindexNew, to bypass loading it again from disk.
2349
2350
*/
2350
- bool static ConnectTip (CValidationState & state, CBlockIndex * pindexNew, const CBlock * pblock) {
2351
- const CChainParams& chainparams = Params ();
2351
+ bool static ConnectTip (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock)
2352
+ {
2352
2353
assert (pindexNew->pprev == chainActive.Tip ());
2353
2354
mempool.check (pcoinsTip);
2354
2355
// Read block from disk.
@@ -2480,8 +2481,8 @@ static void PruneBlockIndexCandidates() {
2480
2481
* Try to make some progress towards making pindexMostWork the active block.
2481
2482
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2482
2483
*/
2483
- static bool ActivateBestChainStep (CValidationState & state, CBlockIndex * pindexMostWork, const CBlock * pblock) {
2484
- const CChainParams& chainparams = Params ();
2484
+ static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock)
2485
+ {
2485
2486
AssertLockHeld (cs_main);
2486
2487
bool fInvalidFound = false ;
2487
2488
const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2514,7 +2515,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2514
2515
2515
2516
// Connect new blocks.
2516
2517
BOOST_REVERSE_FOREACH (CBlockIndex *pindexConnect, vpindexToConnect) {
2517
- if (!ConnectTip (state, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
2518
+ if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL )) {
2518
2519
if (state.IsInvalid ()) {
2519
2520
// The block violates a consensus rule.
2520
2521
if (!state.CorruptionPossible ())
@@ -2555,10 +2556,10 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2555
2556
* or an activated best chain. pblock is either NULL or a pointer to a block
2556
2557
* that is already loaded (to avoid loading it again from disk).
2557
2558
*/
2558
- bool ActivateBestChain (CValidationState &state, const CBlock *pblock) {
2559
+ bool ActivateBestChain (CValidationState& state, const CChainParams& chainparams, const CBlock* pblock)
2560
+ {
2559
2561
CBlockIndex *pindexNewTip = NULL ;
2560
2562
CBlockIndex *pindexMostWork = NULL ;
2561
- const CChainParams& chainparams = Params ();
2562
2563
do {
2563
2564
boost::this_thread::interruption_point ();
2564
2565
@@ -2571,7 +2572,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
2571
2572
if (pindexMostWork == NULL || pindexMostWork == chainActive.Tip ())
2572
2573
return true ;
2573
2574
2574
- if (!ActivateBestChainStep (state, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
2575
+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL ))
2575
2576
return false ;
2576
2577
2577
2578
pindexNewTip = chainActive.Tip ();
@@ -3050,9 +3051,9 @@ static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state
3050
3051
return true ;
3051
3052
}
3052
3053
3053
- bool AcceptBlock (const CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested , CDiskBlockPos* dbp)
3054
+ /* * Store block on disk. If dbp is non-NULL, the file is known to already reside on disk */
3055
+ static bool AcceptBlock (const CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested , CDiskBlockPos* dbp)
3054
3056
{
3055
- const CChainParams& chainparams = Params ();
3056
3057
AssertLockHeld (cs_main);
3057
3058
3058
3059
CBlockIndex *&pindex = *ppindex;
@@ -3142,7 +3143,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
3142
3143
3143
3144
// Store to disk
3144
3145
CBlockIndex *pindex = NULL ;
3145
- bool ret = AcceptBlock (*pblock, state, &pindex, fRequested , dbp);
3146
+ bool ret = AcceptBlock (*pblock, state, chainparams, &pindex, fRequested , dbp);
3146
3147
if (pindex && pfrom) {
3147
3148
mapBlockSource[pindex->GetBlockHash ()] = pfrom->GetId ();
3148
3149
}
@@ -3151,7 +3152,7 @@ bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, c
3151
3152
return error (" %s: AcceptBlock FAILED" , __func__);
3152
3153
}
3153
3154
3154
- if (!ActivateBestChain (state, pblock))
3155
+ if (!ActivateBestChain (state, chainparams, pblock))
3155
3156
return error (" %s: ActivateBestChain failed" , __func__);
3156
3157
3157
3158
return true ;
@@ -3241,13 +3242,13 @@ void UnlinkPrunedFiles(std::set<int>& setFilesToPrune)
3241
3242
}
3242
3243
3243
3244
/* Calculate the block/rev files that should be deleted to remain under target*/
3244
- void FindFilesToPrune (std::set<int >& setFilesToPrune)
3245
+ void FindFilesToPrune (std::set<int >& setFilesToPrune, uint64_t nPruneAfterHeight )
3245
3246
{
3246
3247
LOCK2 (cs_main, cs_LastBlockFile);
3247
3248
if (chainActive.Tip () == NULL || nPruneTarget == 0 ) {
3248
3249
return ;
3249
3250
}
3250
- if (chainActive.Tip ()->nHeight <= Params (). PruneAfterHeight () ) {
3251
+ if (chainActive.Tip ()->nHeight <= nPruneAfterHeight ) {
3251
3252
return ;
3252
3253
}
3253
3254
@@ -3475,9 +3476,8 @@ CVerifyDB::~CVerifyDB()
3475
3476
uiInterface.ShowProgress (" " , 100 );
3476
3477
}
3477
3478
3478
- bool CVerifyDB::VerifyDB (CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
3479
+ bool CVerifyDB::VerifyDB (const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
3479
3480
{
3480
- const CChainParams& chainparams = Params ();
3481
3481
LOCK (cs_main);
3482
3482
if (chainActive.Tip () == NULL || chainActive.Tip ()->pprev == NULL )
3483
3483
return true ;
@@ -3593,9 +3593,8 @@ bool LoadBlockIndex()
3593
3593
return true ;
3594
3594
}
3595
3595
3596
-
3597
- bool InitBlockIndex () {
3598
- const CChainParams& chainparams = Params ();
3596
+ bool InitBlockIndex (const CChainParams& chainparams)
3597
+ {
3599
3598
LOCK (cs_main);
3600
3599
3601
3600
// Initialize global variables that cannot be constructed at startup.
@@ -3613,7 +3612,7 @@ bool InitBlockIndex() {
3613
3612
// Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
3614
3613
if (!fReindex ) {
3615
3614
try {
3616
- CBlock &block = const_cast <CBlock&>(Params () .GenesisBlock ());
3615
+ CBlock &block = const_cast <CBlock&>(chainparams .GenesisBlock ());
3617
3616
// Start new block file
3618
3617
unsigned int nBlockSize = ::GetSerializeSize (block, SER_DISK, CLIENT_VERSION);
3619
3618
CDiskBlockPos blockPos;
@@ -3625,7 +3624,7 @@ bool InitBlockIndex() {
3625
3624
CBlockIndex *pindex = AddToBlockIndex (block);
3626
3625
if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
3627
3626
return error (" LoadBlockIndex(): genesis block not accepted" );
3628
- if (!ActivateBestChain (state, &block))
3627
+ if (!ActivateBestChain (state, chainparams, &block))
3629
3628
return error (" LoadBlockIndex(): genesis block cannot be activated" );
3630
3629
// Force a chainstate write so that when we VerifyDB in a moment, it doesn't check stale data
3631
3630
return FlushStateToDisk (state, FLUSH_STATE_ALWAYS);
@@ -3637,11 +3636,8 @@ bool InitBlockIndex() {
3637
3636
return true ;
3638
3637
}
3639
3638
3640
-
3641
-
3642
- bool LoadExternalBlockFile (FILE* fileIn, CDiskBlockPos *dbp)
3639
+ bool LoadExternalBlockFile (const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp)
3643
3640
{
3644
- const CChainParams& chainparams = Params ();
3645
3641
// Map of disk positions for blocks with unknown parent (only used for reindex)
3646
3642
static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent;
3647
3643
int64_t nStart = GetTimeMillis ();
@@ -3661,10 +3657,10 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
3661
3657
try {
3662
3658
// locate a header
3663
3659
unsigned char buf[MESSAGE_START_SIZE];
3664
- blkdat.FindByte (Params () .MessageStart ()[0 ]);
3660
+ blkdat.FindByte (chainparams .MessageStart ()[0 ]);
3665
3661
nRewind = blkdat.GetPos ()+1 ;
3666
3662
blkdat >> FLATDATA (buf);
3667
- if (memcmp (buf, Params () .MessageStart (), MESSAGE_START_SIZE))
3663
+ if (memcmp (buf, chainparams .MessageStart (), MESSAGE_START_SIZE))
3668
3664
continue ;
3669
3665
// read size
3670
3666
blkdat >> nSize;
@@ -4058,7 +4054,7 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
4058
4054
// best equivalent proof of work) than the best header chain we know about.
4059
4055
send = mi->second ->IsValid (BLOCK_VALID_SCRIPTS) && (pindexBestHeader != NULL ) &&
4060
4056
(pindexBestHeader->GetBlockTime () - mi->second ->GetBlockTime () < nOneMonth) &&
4061
- (GetBlockProofEquivalentTime (*pindexBestHeader, *mi->second , *pindexBestHeader, Params (). GetConsensus () ) < nOneMonth);
4057
+ (GetBlockProofEquivalentTime (*pindexBestHeader, *mi->second , *pindexBestHeader, consensusParams ) < nOneMonth);
4062
4058
if (!send) {
4063
4059
LogPrintf (" %s: ignoring request from peer=%i for old block that isn't in the main chain\n " , __func__, pfrom->GetId ());
4064
4060
}
@@ -4932,7 +4928,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4932
4928
uint256 alertHash = alert.GetHash ();
4933
4929
if (pfrom->setKnown .count (alertHash) == 0 )
4934
4930
{
4935
- if (alert.ProcessAlert (Params () .AlertKey ()))
4931
+ if (alert.ProcessAlert (chainparams .AlertKey ()))
4936
4932
{
4937
4933
// Relay
4938
4934
pfrom->setKnown .insert (alertHash);
0 commit comments