@@ -92,7 +92,7 @@ void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
92
92
* in the last Consensus::Params::nMajorityWindow blocks, starting at pstart and going backwards.
93
93
*/
94
94
static bool IsSuperMajority (int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams);
95
- static void CheckBlockIndex ();
95
+ static void CheckBlockIndex (const Consensus::Params& consensusParams );
96
96
97
97
/* * Constant stuff for coinbase transactions we create: */
98
98
CScript COINBASE_FLAGS;
@@ -998,7 +998,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
998
998
}
999
999
1000
1000
/* * Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock */
1001
- bool GetTransaction (const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow )
1001
+ bool GetTransaction (const uint256 &hash, CTransaction &txOut, const Consensus::Params& consensusParams, uint256 &hashBlock, bool fAllowSlow )
1002
1002
{
1003
1003
CBlockIndex *pindexSlow = NULL ;
1004
1004
@@ -1044,7 +1044,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
1044
1044
1045
1045
if (pindexSlow) {
1046
1046
CBlock block;
1047
- if (ReadBlockFromDisk (block, pindexSlow)) {
1047
+ if (ReadBlockFromDisk (block, pindexSlow, consensusParams )) {
1048
1048
BOOST_FOREACH (const CTransaction &tx, block.vtx ) {
1049
1049
if (tx.GetHash () == hash) {
1050
1050
txOut = tx;
@@ -1089,7 +1089,7 @@ bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHea
1089
1089
return true ;
1090
1090
}
1091
1091
1092
- bool ReadBlockFromDisk (CBlock& block, const CDiskBlockPos& pos)
1092
+ bool ReadBlockFromDisk (CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams )
1093
1093
{
1094
1094
block.SetNull ();
1095
1095
@@ -1107,15 +1107,15 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
1107
1107
}
1108
1108
1109
1109
// Check the header
1110
- if (!CheckProofOfWork (block.GetHash (), block.nBits , Params (). GetConsensus () ))
1110
+ if (!CheckProofOfWork (block.GetHash (), block.nBits , consensusParams ))
1111
1111
return error (" ReadBlockFromDisk: Errors in block header at %s" , pos.ToString ());
1112
1112
1113
1113
return true ;
1114
1114
}
1115
1115
1116
- bool ReadBlockFromDisk (CBlock& block, const CBlockIndex* pindex)
1116
+ bool ReadBlockFromDisk (CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams )
1117
1117
{
1118
- if (!ReadBlockFromDisk (block, pindex->GetBlockPos ()))
1118
+ if (!ReadBlockFromDisk (block, pindex->GetBlockPos (), consensusParams ))
1119
1119
return false ;
1120
1120
if (block.GetHash () != pindex->GetBlockHash ())
1121
1121
return error (" ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s" ,
@@ -2064,13 +2064,14 @@ void static UpdateTip(CBlockIndex *pindexNew) {
2064
2064
}
2065
2065
2066
2066
/* * Disconnect chainActive's tip. You want to manually re-limit mempool size after this */
2067
- bool static DisconnectTip (CValidationState &state) {
2067
+ bool static DisconnectTip (CValidationState& state, const Consensus::Params& consensusParams)
2068
+ {
2068
2069
CBlockIndex *pindexDelete = chainActive.Tip ();
2069
2070
assert (pindexDelete);
2070
2071
mempool.check (pcoinsTip);
2071
2072
// Read block from disk.
2072
2073
CBlock block;
2073
- if (!ReadBlockFromDisk (block, pindexDelete))
2074
+ if (!ReadBlockFromDisk (block, pindexDelete, consensusParams ))
2074
2075
return AbortNode (state, " Failed to read block" );
2075
2076
// Apply the block atomically to the chain state.
2076
2077
int64_t nStart = GetTimeMicros ();
@@ -2125,13 +2126,14 @@ static int64_t nTimePostConnect = 0;
2125
2126
* corresponding to pindexNew, to bypass loading it again from disk.
2126
2127
*/
2127
2128
bool static ConnectTip (CValidationState &state, CBlockIndex *pindexNew, const CBlock *pblock) {
2129
+ const CChainParams& chainparams = Params ();
2128
2130
assert (pindexNew->pprev == chainActive.Tip ());
2129
2131
mempool.check (pcoinsTip);
2130
2132
// Read block from disk.
2131
2133
int64_t nTime1 = GetTimeMicros ();
2132
2134
CBlock block;
2133
2135
if (!pblock) {
2134
- if (!ReadBlockFromDisk (block, pindexNew))
2136
+ if (!ReadBlockFromDisk (block, pindexNew, chainparams. GetConsensus () ))
2135
2137
return AbortNode (state, " Failed to read block" );
2136
2138
pblock = █
2137
2139
}
@@ -2257,6 +2259,7 @@ static void PruneBlockIndexCandidates() {
2257
2259
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2258
2260
*/
2259
2261
static bool ActivateBestChainStep (CValidationState &state, CBlockIndex *pindexMostWork, const CBlock *pblock) {
2262
+ const CChainParams& chainparams = Params ();
2260
2263
AssertLockHeld (cs_main);
2261
2264
bool fInvalidFound = false ;
2262
2265
const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2265,7 +2268,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2265
2268
// Disconnect active blocks which are no longer in the best chain.
2266
2269
bool fBlocksDisconnected = false ;
2267
2270
while (chainActive.Tip () && chainActive.Tip () != pindexFork) {
2268
- if (!DisconnectTip (state))
2271
+ if (!DisconnectTip (state, chainparams. GetConsensus () ))
2269
2272
return false ;
2270
2273
fBlocksDisconnected = true ;
2271
2274
}
@@ -2333,7 +2336,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
2333
2336
bool ActivateBestChain (CValidationState &state, const CBlock *pblock) {
2334
2337
CBlockIndex *pindexNewTip = NULL ;
2335
2338
CBlockIndex *pindexMostWork = NULL ;
2336
- const CChainParams& chainParams = Params ();
2339
+ const CChainParams& chainparams = Params ();
2337
2340
do {
2338
2341
boost::this_thread::interruption_point ();
2339
2342
@@ -2360,7 +2363,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
2360
2363
// Relay inventory, but don't relay old inventory during initial block download.
2361
2364
int nBlockEstimate = 0 ;
2362
2365
if (fCheckpointsEnabled )
2363
- nBlockEstimate = Checkpoints::GetTotalBlocksEstimate (chainParams .Checkpoints ());
2366
+ nBlockEstimate = Checkpoints::GetTotalBlocksEstimate (chainparams .Checkpoints ());
2364
2367
{
2365
2368
LOCK (cs_vNodes);
2366
2369
BOOST_FOREACH (CNode* pnode, vNodes)
@@ -2372,7 +2375,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
2372
2375
uiInterface.NotifyBlockTip (hashNewTip);
2373
2376
}
2374
2377
} while (pindexMostWork != chainActive.Tip ());
2375
- CheckBlockIndex ();
2378
+ CheckBlockIndex (chainparams. GetConsensus () );
2376
2379
2377
2380
// Write changes periodically to disk, after relay.
2378
2381
if (!FlushStateToDisk (state, FLUSH_STATE_PERIODIC)) {
@@ -2382,7 +2385,8 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
2382
2385
return true ;
2383
2386
}
2384
2387
2385
- bool InvalidateBlock (CValidationState& state, CBlockIndex *pindex) {
2388
+ bool InvalidateBlock (CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex *pindex)
2389
+ {
2386
2390
AssertLockHeld (cs_main);
2387
2391
2388
2392
// Mark the block itself as invalid.
@@ -2397,7 +2401,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
2397
2401
setBlockIndexCandidates.erase (pindexWalk);
2398
2402
// ActivateBestChain considers blocks already in chainActive
2399
2403
// unconditionally valid already, so force disconnect away from it.
2400
- if (!DisconnectTip (state)) {
2404
+ if (!DisconnectTip (state, consensusParams )) {
2401
2405
return false ;
2402
2406
}
2403
2407
}
@@ -2899,6 +2903,7 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned
2899
2903
2900
2904
bool ProcessNewBlock (CValidationState &state, const CNode* pfrom, const CBlock* pblock, bool fForceProcessing , CDiskBlockPos *dbp)
2901
2905
{
2906
+ const CChainParams& chainparams = Params ();
2902
2907
// Preliminary checks
2903
2908
bool checked = CheckBlock (*pblock, state);
2904
2909
@@ -2916,7 +2921,7 @@ bool ProcessNewBlock(CValidationState &state, const CNode* pfrom, const CBlock*
2916
2921
if (pindex && pfrom) {
2917
2922
mapBlockSource[pindex->GetBlockHash ()] = pfrom->GetId ();
2918
2923
}
2919
- CheckBlockIndex ();
2924
+ CheckBlockIndex (chainparams. GetConsensus () );
2920
2925
if (!ret)
2921
2926
return error (" %s: AcceptBlock FAILED" , __func__);
2922
2927
}
@@ -3248,6 +3253,7 @@ CVerifyDB::~CVerifyDB()
3248
3253
3249
3254
bool CVerifyDB::VerifyDB (CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
3250
3255
{
3256
+ const CChainParams& chainparams = Params ();
3251
3257
LOCK (cs_main);
3252
3258
if (chainActive.Tip () == NULL || chainActive.Tip ()->pprev == NULL )
3253
3259
return true ;
@@ -3272,7 +3278,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
3272
3278
break ;
3273
3279
CBlock block;
3274
3280
// check level 0: read from disk
3275
- if (!ReadBlockFromDisk (block, pindex))
3281
+ if (!ReadBlockFromDisk (block, pindex, chainparams. GetConsensus () ))
3276
3282
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3277
3283
// check level 1: verify block validity
3278
3284
if (nCheckLevel >= 1 && !CheckBlock (block, state))
@@ -3312,7 +3318,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
3312
3318
uiInterface.ShowProgress (_ (" Verifying blocks..." ), std::max (1 , std::min (99 , 100 - (int )(((double )(chainActive.Height () - pindex->nHeight )) / (double )nCheckDepth * 50 ))));
3313
3319
pindex = chainActive.Next (pindex);
3314
3320
CBlock block;
3315
- if (!ReadBlockFromDisk (block, pindex))
3321
+ if (!ReadBlockFromDisk (block, pindex, chainparams. GetConsensus () ))
3316
3322
return error (" VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
3317
3323
if (!ConnectBlock (block, state, pindex, coins))
3318
3324
return error (" VerifyDB(): *** found unconnectable block at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
@@ -3485,7 +3491,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
3485
3491
std::pair<std::multimap<uint256, CDiskBlockPos>::iterator, std::multimap<uint256, CDiskBlockPos>::iterator> range = mapBlocksUnknownParent.equal_range (head);
3486
3492
while (range.first != range.second ) {
3487
3493
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first ;
3488
- if (ReadBlockFromDisk (block, it->second ))
3494
+ if (ReadBlockFromDisk (block, it->second , chainparams. GetConsensus () ))
3489
3495
{
3490
3496
LogPrintf (" %s: Processing out of order child %s of %s\n " , __func__, block.GetHash ().ToString (),
3491
3497
head.ToString ());
@@ -3512,9 +3518,8 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
3512
3518
return nLoaded > 0 ;
3513
3519
}
3514
3520
3515
- void static CheckBlockIndex ()
3521
+ void static CheckBlockIndex (const Consensus::Params& consensusParams )
3516
3522
{
3517
- const Consensus::Params& consensusParams = Params ().GetConsensus ();
3518
3523
if (!fCheckBlockIndex ) {
3519
3524
return ;
3520
3525
}
@@ -3796,7 +3801,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
3796
3801
return true ;
3797
3802
}
3798
3803
3799
- void static ProcessGetData (CNode* pfrom)
3804
+ void static ProcessGetData (CNode* pfrom, const Consensus::Params& consensusParams )
3800
3805
{
3801
3806
std::deque<CInv>::iterator it = pfrom->vRecvGetData .begin ();
3802
3807
@@ -3851,7 +3856,7 @@ void static ProcessGetData(CNode* pfrom)
3851
3856
{
3852
3857
// Send block from disk
3853
3858
CBlock block;
3854
- if (!ReadBlockFromDisk (block, (*mi).second ))
3859
+ if (!ReadBlockFromDisk (block, (*mi).second , consensusParams ))
3855
3860
assert (!" cannot load block from disk" );
3856
3861
if (inv.type == MSG_BLOCK)
3857
3862
pfrom->PushMessage (" block" , block);
@@ -4243,7 +4248,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4243
4248
LogPrint (" net" , " received getdata for: %s peer=%d\n " , vInv[0 ].ToString (), pfrom->id );
4244
4249
4245
4250
pfrom->vRecvGetData .insert (pfrom->vRecvGetData .end (), vInv.begin (), vInv.end ());
4246
- ProcessGetData (pfrom);
4251
+ ProcessGetData (pfrom, chainparams. GetConsensus () );
4247
4252
}
4248
4253
4249
4254
@@ -4509,7 +4514,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4509
4514
pfrom->PushMessage (" getheaders" , chainActive.GetLocator (pindexLast), uint256 ());
4510
4515
}
4511
4516
4512
- CheckBlockIndex ();
4517
+ CheckBlockIndex (chainparams. GetConsensus () );
4513
4518
}
4514
4519
4515
4520
else if (strCommand == " block" && !fImporting && !fReindex ) // Ignore blocks received while importing
@@ -4793,6 +4798,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
4793
4798
// requires LOCK(cs_vRecvMsg)
4794
4799
bool ProcessMessages (CNode* pfrom)
4795
4800
{
4801
+ const CChainParams& chainparams = Params ();
4796
4802
// if (fDebug)
4797
4803
// LogPrintf("%s(%u messages)\n", __func__, pfrom->vRecvMsg.size());
4798
4804
@@ -4807,7 +4813,7 @@ bool ProcessMessages(CNode* pfrom)
4807
4813
bool fOk = true ;
4808
4814
4809
4815
if (!pfrom->vRecvGetData .empty ())
4810
- ProcessGetData (pfrom);
4816
+ ProcessGetData (pfrom, chainparams. GetConsensus () );
4811
4817
4812
4818
// this maintains the order of responses
4813
4819
if (!pfrom->vRecvGetData .empty ()) return fOk ;
@@ -4834,15 +4840,15 @@ bool ProcessMessages(CNode* pfrom)
4834
4840
it++;
4835
4841
4836
4842
// Scan for message start
4837
- if (memcmp (msg.hdr .pchMessageStart , Params () .MessageStart (), MESSAGE_START_SIZE) != 0 ) {
4843
+ if (memcmp (msg.hdr .pchMessageStart , chainparams .MessageStart (), MESSAGE_START_SIZE) != 0 ) {
4838
4844
LogPrintf (" PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n " , SanitizeString (msg.hdr .GetCommand ()), pfrom->id );
4839
4845
fOk = false ;
4840
4846
break ;
4841
4847
}
4842
4848
4843
4849
// Read header
4844
4850
CMessageHeader& hdr = msg.hdr ;
4845
- if (!hdr.IsValid (Params () .MessageStart ()))
4851
+ if (!hdr.IsValid (chainparams .MessageStart ()))
4846
4852
{
4847
4853
LogPrintf (" PROCESSMESSAGE: ERRORS IN HEADER %s peer=%d\n " , SanitizeString (hdr.GetCommand ()), pfrom->id );
4848
4854
continue ;
0 commit comments