@@ -1414,7 +1414,7 @@ MempoolAcceptResult AcceptToMemoryPool(Chainstate& active_chainstate, const CTra
1414
1414
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
1415
1415
{
1416
1416
AssertLockHeld (::cs_main);
1417
- const CChainParams& chainparams{active_chainstate.m_params };
1417
+ const CChainParams& chainparams{active_chainstate.m_chainman . GetParams () };
1418
1418
assert (active_chainstate.GetMempool () != nullptr );
1419
1419
CTxMemPool& pool{*active_chainstate.GetMempool ()};
1420
1420
@@ -1444,7 +1444,7 @@ PackageMempoolAcceptResult ProcessNewPackage(Chainstate& active_chainstate, CTxM
1444
1444
assert (std::all_of (package.cbegin (), package.cend (), [](const auto & tx){return tx != nullptr ;}));
1445
1445
1446
1446
std::vector<COutPoint> coins_to_uncache;
1447
- const CChainParams& chainparams = active_chainstate.m_params ;
1447
+ const CChainParams& chainparams = active_chainstate.m_chainman . GetParams () ;
1448
1448
const auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED (cs_main) {
1449
1449
AssertLockHeld (cs_main);
1450
1450
if (test_accept) {
@@ -1502,7 +1502,6 @@ Chainstate::Chainstate(
1502
1502
std::optional<uint256> from_snapshot_blockhash)
1503
1503
: m_mempool(mempool),
1504
1504
m_blockman(blockman),
1505
- m_params(chainman.GetParams()),
1506
1505
m_chainman(chainman),
1507
1506
m_from_snapshot_blockhash(from_snapshot_blockhash) {}
1508
1507
@@ -1997,6 +1996,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
1997
1996
assert (*pindex->phashBlock == block_hash);
1998
1997
1999
1998
const auto time_start{SteadyClock::now ()};
1999
+ const CChainParams& params{m_chainman.GetParams ()};
2000
2000
2001
2001
// Check it again in case a previous version let a bad block in
2002
2002
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
@@ -2011,7 +2011,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2011
2011
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
2012
2012
// re-enforce that rule here (at least until we make it impossible for
2013
2013
// m_adjusted_time_callback() to go backward).
2014
- if (!CheckBlock (block, state, m_params .GetConsensus (), !fJustCheck , !fJustCheck )) {
2014
+ if (!CheckBlock (block, state, params .GetConsensus (), !fJustCheck , !fJustCheck )) {
2015
2015
if (state.GetResult () == BlockValidationResult::BLOCK_MUTATED) {
2016
2016
// We don't write down blocks to disk if they may have been
2017
2017
// corrupted, so this should be impossible unless we're having hardware
@@ -2029,7 +2029,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2029
2029
2030
2030
// Special case for the genesis block, skipping connection of its transactions
2031
2031
// (its coinbase is unspendable)
2032
- if (block_hash == m_params .GetConsensus ().hashGenesisBlock ) {
2032
+ if (block_hash == params .GetConsensus ().hashGenesisBlock ) {
2033
2033
if (!fJustCheck )
2034
2034
view.SetBestBlock (pindex->GetBlockHash ());
2035
2035
return true ;
@@ -2061,7 +2061,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2061
2061
// artificially set the default assumed verified block further back.
2062
2062
// The test against nMinimumChainWork prevents the skipping when denied access to any chain at
2063
2063
// least as good as the expected chain.
2064
- fScriptChecks = (GetBlockProofEquivalentTime (*m_chainman.m_best_header , *pindex, *m_chainman.m_best_header , m_params .GetConsensus ()) <= 60 * 60 * 24 * 7 * 2 );
2064
+ fScriptChecks = (GetBlockProofEquivalentTime (*m_chainman.m_best_header , *pindex, *m_chainman.m_best_header , params .GetConsensus ()) <= 60 * 60 * 24 * 7 * 2 );
2065
2065
}
2066
2066
}
2067
2067
}
@@ -2142,9 +2142,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2142
2142
// post BIP34 before approximately height 486,000,000. After block
2143
2143
// 1,983,702 testnet3 starts doing unnecessary BIP30 checking again.
2144
2144
assert (pindex->pprev );
2145
- CBlockIndex* pindexBIP34height = pindex->pprev ->GetAncestor (m_params .GetConsensus ().BIP34Height );
2145
+ CBlockIndex* pindexBIP34height = pindex->pprev ->GetAncestor (params .GetConsensus ().BIP34Height );
2146
2146
// Only continue to enforce if we're below BIP34 activation height or the block hash at that height doesn't correspond.
2147
- fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash () == m_params .GetConsensus ().BIP34Hash ));
2147
+ fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash () == params .GetConsensus ().BIP34Hash ));
2148
2148
2149
2149
// TODO: Remove BIP30 checking from block height 1,983,702 on, once we have a
2150
2150
// consensus change that ensures coinbases at those heights cannot
@@ -2266,7 +2266,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2266
2266
Ticks<SecondsDouble>(time_connect),
2267
2267
Ticks<MillisecondsDouble>(time_connect) / num_blocks_total);
2268
2268
2269
- CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , m_params .GetConsensus ());
2269
+ CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , params .GetConsensus ());
2270
2270
if (block.vtx [0 ]->GetValueOut () > blockReward) {
2271
2271
LogPrintf (" ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n " , block.vtx [0 ]->GetValueOut (), blockReward);
2272
2272
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cb-amount" );
@@ -2287,7 +2287,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2287
2287
if (fJustCheck )
2288
2288
return true ;
2289
2289
2290
- if (!m_blockman.WriteUndoDataForBlock (blockundo, state, pindex, m_params )) {
2290
+ if (!m_blockman.WriteUndoDataForBlock (blockundo, state, pindex, params )) {
2291
2291
return false ;
2292
2292
}
2293
2293
@@ -2406,7 +2406,7 @@ bool Chainstate::FlushStateToDisk(
2406
2406
} else {
2407
2407
LOG_TIME_MILLIS_WITH_CATEGORY (" find files to prune" , BCLog::BENCH);
2408
2408
2409
- m_blockman.FindFilesToPrune (setFilesToPrune, m_params .PruneAfterHeight (), m_chain.Height (), last_prune, IsInitialBlockDownload ());
2409
+ m_blockman.FindFilesToPrune (setFilesToPrune, m_chainman. GetParams () .PruneAfterHeight (), m_chain.Height (), last_prune, IsInitialBlockDownload ());
2410
2410
m_blockman.m_check_for_pruning = false ;
2411
2411
}
2412
2412
if (!setFilesToPrune.empty ()) {
@@ -2560,13 +2560,15 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
2560
2560
AssertLockHeld (::cs_main);
2561
2561
const auto & coins_tip = this ->CoinsTip ();
2562
2562
2563
+ const CChainParams& params{m_chainman.GetParams ()};
2564
+
2563
2565
// The remainder of the function isn't relevant if we are not acting on
2564
2566
// the active chainstate, so return if need be.
2565
2567
if (this != &m_chainman.ActiveChainstate ()) {
2566
2568
// Only log every so often so that we don't bury log messages at the tip.
2567
2569
constexpr int BACKGROUND_LOG_INTERVAL = 2000 ;
2568
2570
if (pindexNew->nHeight % BACKGROUND_LOG_INTERVAL == 0 ) {
2569
- UpdateTipLog (coins_tip, pindexNew, m_params , __func__, " [background validation] " , " " );
2571
+ UpdateTipLog (coins_tip, pindexNew, params , __func__, " [background validation] " , " " );
2570
2572
}
2571
2573
return ;
2572
2574
}
@@ -2587,7 +2589,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
2587
2589
const CBlockIndex* pindex = pindexNew;
2588
2590
for (int bit = 0 ; bit < VERSIONBITS_NUM_BITS; bit++) {
2589
2591
WarningBitsConditionChecker checker (m_chainman, bit);
2590
- ThresholdState state = checker.GetStateFor (pindex, m_params .GetConsensus (), warningcache.at (bit));
2592
+ ThresholdState state = checker.GetStateFor (pindex, params .GetConsensus (), warningcache.at (bit));
2591
2593
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
2592
2594
const bilingual_str warning = strprintf (_ (" Unknown new rules activated (versionbit %i)" ), bit);
2593
2595
if (state == ThresholdState::ACTIVE) {
@@ -2598,7 +2600,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
2598
2600
}
2599
2601
}
2600
2602
}
2601
- UpdateTipLog (coins_tip, pindexNew, m_params , __func__, " " , warning_messages.original );
2603
+ UpdateTipLog (coins_tip, pindexNew, params , __func__, " " , warning_messages.original );
2602
2604
}
2603
2605
2604
2606
/* * Disconnect m_chain's tip.
@@ -2622,7 +2624,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
2622
2624
// Read block from disk.
2623
2625
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
2624
2626
CBlock& block = *pblock;
2625
- if (!ReadBlockFromDisk (block, pindexDelete, m_params .GetConsensus ())) {
2627
+ if (!ReadBlockFromDisk (block, pindexDelete, m_chainman .GetConsensus ())) {
2626
2628
return error (" DisconnectTip(): Failed to read block" );
2627
2629
}
2628
2630
// Apply the block atomically to the chain state.
@@ -2739,7 +2741,7 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
2739
2741
std::shared_ptr<const CBlock> pthisBlock;
2740
2742
if (!pblock) {
2741
2743
std::shared_ptr<CBlock> pblockNew = std::make_shared<CBlock>();
2742
- if (!ReadBlockFromDisk (*pblockNew, pindexNew, m_params .GetConsensus ())) {
2744
+ if (!ReadBlockFromDisk (*pblockNew, pindexNew, m_chainman .GetConsensus ())) {
2743
2745
return AbortNode (state, " Failed to read block" );
2744
2746
}
2745
2747
pthisBlock = pblockNew;
@@ -3847,7 +3849,9 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
3847
3849
if (pindex->nChainWork < nMinimumChainWork) return true ;
3848
3850
}
3849
3851
3850
- if (!CheckBlock (block, state, m_params.GetConsensus ()) ||
3852
+ const CChainParams& params{m_chainman.GetParams ()};
3853
+
3854
+ if (!CheckBlock (block, state, params.GetConsensus ()) ||
3851
3855
!ContextualCheckBlock (block, state, m_chainman, pindex->pprev )) {
3852
3856
if (state.IsInvalid () && state.GetResult () != BlockValidationResult::BLOCK_MUTATED) {
3853
3857
pindex->nStatus |= BLOCK_FAILED_VALID;
@@ -3864,7 +3868,7 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
3864
3868
// Write block to history file
3865
3869
if (fNewBlock ) *fNewBlock = true ;
3866
3870
try {
3867
- FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, pindex->nHeight , m_chain, m_params , dbp)};
3871
+ FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, pindex->nHeight , m_chain, params , dbp)};
3868
3872
if (blockPos.IsNull ()) {
3869
3873
state.Error (strprintf (" %s: Failed to find position to write new block to disk" , __func__));
3870
3874
return false ;
@@ -4008,7 +4012,7 @@ bool Chainstate::LoadChainTip()
4008
4012
tip->GetBlockHash ().ToString (),
4009
4013
m_chain.Height (),
4010
4014
FormatISO8601DateTime (tip->GetBlockTime ()),
4011
- GuessVerificationProgress (m_params .TxData (), tip));
4015
+ GuessVerificationProgress (m_chainman. GetParams () .TxData (), tip));
4012
4016
return true ;
4013
4017
}
4014
4018
@@ -4144,7 +4148,7 @@ bool Chainstate::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& in
4144
4148
AssertLockHeld (cs_main);
4145
4149
// TODO: merge with ConnectBlock
4146
4150
CBlock block;
4147
- if (!ReadBlockFromDisk (block, pindex, m_params .GetConsensus ())) {
4151
+ if (!ReadBlockFromDisk (block, pindex, m_chainman .GetConsensus ())) {
4148
4152
return error (" ReplayBlock(): ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4149
4153
}
4150
4154
@@ -4196,7 +4200,7 @@ bool Chainstate::ReplayBlocks()
4196
4200
while (pindexOld != pindexFork) {
4197
4201
if (pindexOld->nHeight > 0 ) { // Never disconnect the genesis block.
4198
4202
CBlock block;
4199
- if (!ReadBlockFromDisk (block, pindexOld, m_params .GetConsensus ())) {
4203
+ if (!ReadBlockFromDisk (block, pindexOld, m_chainman .GetConsensus ())) {
4200
4204
return error (" RollbackBlock(): ReadBlockFromDisk() failed at %d, hash=%s" , pindexOld->nHeight , pindexOld->GetBlockHash ().ToString ());
4201
4205
}
4202
4206
LogPrintf (" Rolling back %s (%i)\n " , pindexOld->GetBlockHash ().ToString (), pindexOld->nHeight );
@@ -4348,16 +4352,18 @@ bool Chainstate::LoadGenesisBlock()
4348
4352
{
4349
4353
LOCK (cs_main);
4350
4354
4355
+ const CChainParams& params{m_chainman.GetParams ()};
4356
+
4351
4357
// Check whether we're already initialized by checking for genesis in
4352
4358
// m_blockman.m_block_index. Note that we can't use m_chain here, since it is
4353
4359
// set based on the coins db, not the block index db, which is the only
4354
4360
// thing loaded at this point.
4355
- if (m_blockman.m_block_index .count (m_params .GenesisBlock ().GetHash ()))
4361
+ if (m_blockman.m_block_index .count (params .GenesisBlock ().GetHash ()))
4356
4362
return true ;
4357
4363
4358
4364
try {
4359
- const CBlock& block = m_params .GenesisBlock ();
4360
- FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, 0 , m_chain, m_params , nullptr )};
4365
+ const CBlock& block = params .GenesisBlock ();
4366
+ FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, 0 , m_chain, params , nullptr )};
4361
4367
if (blockPos.IsNull ()) {
4362
4368
return error (" %s: writing genesis block to disk failed" , __func__);
4363
4369
}
@@ -4381,6 +4387,7 @@ void Chainstate::LoadExternalBlockFile(
4381
4387
assert (!dbp == !blocks_with_unknown_parent);
4382
4388
4383
4389
const auto start{SteadyClock::now ()};
4390
+ const CChainParams& params{m_chainman.GetParams ()};
4384
4391
4385
4392
int nLoaded = 0 ;
4386
4393
try {
@@ -4397,10 +4404,10 @@ void Chainstate::LoadExternalBlockFile(
4397
4404
try {
4398
4405
// locate a header
4399
4406
unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
4400
- blkdat.FindByte (m_params .MessageStart ()[0 ]);
4407
+ blkdat.FindByte (params .MessageStart ()[0 ]);
4401
4408
nRewind = blkdat.GetPos () + 1 ;
4402
4409
blkdat >> buf;
4403
- if (memcmp (buf, m_params .MessageStart (), CMessageHeader::MESSAGE_START_SIZE)) {
4410
+ if (memcmp (buf, params .MessageStart (), CMessageHeader::MESSAGE_START_SIZE)) {
4404
4411
continue ;
4405
4412
}
4406
4413
// read size
@@ -4426,7 +4433,7 @@ void Chainstate::LoadExternalBlockFile(
4426
4433
{
4427
4434
LOCK (cs_main);
4428
4435
// detect out of order blocks, and store them for later
4429
- if (hash != m_params .GetConsensus ().hashGenesisBlock && !m_blockman.LookupBlockIndex (block.hashPrevBlock )) {
4436
+ if (hash != params .GetConsensus ().hashGenesisBlock && !m_blockman.LookupBlockIndex (block.hashPrevBlock )) {
4430
4437
LogPrint (BCLog::REINDEX, " %s: Out of order block %s, parent %s not known\n " , __func__, hash.ToString (),
4431
4438
block.hashPrevBlock .ToString ());
4432
4439
if (dbp && blocks_with_unknown_parent) {
@@ -4445,13 +4452,13 @@ void Chainstate::LoadExternalBlockFile(
4445
4452
if (state.IsError ()) {
4446
4453
break ;
4447
4454
}
4448
- } else if (hash != m_params .GetConsensus ().hashGenesisBlock && pindex->nHeight % 1000 == 0 ) {
4455
+ } else if (hash != params .GetConsensus ().hashGenesisBlock && pindex->nHeight % 1000 == 0 ) {
4449
4456
LogPrint (BCLog::REINDEX, " Block Import: already had block %s at height %d\n " , hash.ToString (), pindex->nHeight );
4450
4457
}
4451
4458
}
4452
4459
4453
4460
// Activate the genesis block so normal node progress can continue
4454
- if (hash == m_params .GetConsensus ().hashGenesisBlock ) {
4461
+ if (hash == params .GetConsensus ().hashGenesisBlock ) {
4455
4462
BlockValidationState state;
4456
4463
if (!ActivateBestChain (state, nullptr )) {
4457
4464
break ;
@@ -4472,7 +4479,7 @@ void Chainstate::LoadExternalBlockFile(
4472
4479
while (range.first != range.second ) {
4473
4480
std::multimap<uint256, FlatFilePos>::iterator it = range.first ;
4474
4481
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
4475
- if (ReadBlockFromDisk (*pblockrecursive, it->second , m_params .GetConsensus ())) {
4482
+ if (ReadBlockFromDisk (*pblockrecursive, it->second , params .GetConsensus ())) {
4476
4483
LogPrint (BCLog::REINDEX, " %s: Processing out of order child %s of %s\n " , __func__, pblockrecursive->GetHash ().ToString (),
4477
4484
head.ToString ());
4478
4485
LOCK (cs_main);
@@ -4583,7 +4590,7 @@ void Chainstate::CheckBlockIndex()
4583
4590
// Begin: actual consistency checks.
4584
4591
if (pindex->pprev == nullptr ) {
4585
4592
// Genesis block checks.
4586
- assert (pindex->GetBlockHash () == m_params .GetConsensus ().hashGenesisBlock ); // Genesis block's hash must match.
4593
+ assert (pindex->GetBlockHash () == m_chainman .GetConsensus ().hashGenesisBlock ); // Genesis block's hash must match.
4587
4594
assert (pindex == m_chain.Genesis ()); // The current active chain's genesis block must be this block.
4588
4595
}
4589
4596
if (!pindex->HaveTxsDownloaded ()) assert (pindex->nSequenceId <= 0 ); // nSequenceId can't be set positive for blocks that aren't linked (negative is used for preciousblock)
0 commit comments