@@ -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
@@ -1985,6 +1984,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
1985
1984
assert (*pindex->phashBlock == block_hash);
1986
1985
1987
1986
const auto time_start{SteadyClock::now ()};
1987
+ const CChainParams& params{m_chainman.GetParams ()};
1988
1988
1989
1989
// Check it again in case a previous version let a bad block in
1990
1990
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
@@ -1999,7 +1999,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
1999
1999
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
2000
2000
// re-enforce that rule here (at least until we make it impossible for
2001
2001
// m_adjusted_time_callback() to go backward).
2002
- if (!CheckBlock (block, state, m_params .GetConsensus (), !fJustCheck , !fJustCheck )) {
2002
+ if (!CheckBlock (block, state, params .GetConsensus (), !fJustCheck , !fJustCheck )) {
2003
2003
if (state.GetResult () == BlockValidationResult::BLOCK_MUTATED) {
2004
2004
// We don't write down blocks to disk if they may have been
2005
2005
// corrupted, so this should be impossible unless we're having hardware
@@ -2017,7 +2017,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2017
2017
2018
2018
// Special case for the genesis block, skipping connection of its transactions
2019
2019
// (its coinbase is unspendable)
2020
- if (block_hash == m_params .GetConsensus ().hashGenesisBlock ) {
2020
+ if (block_hash == params .GetConsensus ().hashGenesisBlock ) {
2021
2021
if (!fJustCheck )
2022
2022
view.SetBestBlock (pindex->GetBlockHash ());
2023
2023
return true ;
@@ -2049,7 +2049,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2049
2049
// artificially set the default assumed verified block further back.
2050
2050
// The test against nMinimumChainWork prevents the skipping when denied access to any chain at
2051
2051
// least as good as the expected chain.
2052
- fScriptChecks = (GetBlockProofEquivalentTime (*m_chainman.m_best_header , *pindex, *m_chainman.m_best_header , m_params .GetConsensus ()) <= 60 * 60 * 24 * 7 * 2 );
2052
+ fScriptChecks = (GetBlockProofEquivalentTime (*m_chainman.m_best_header , *pindex, *m_chainman.m_best_header , params .GetConsensus ()) <= 60 * 60 * 24 * 7 * 2 );
2053
2053
}
2054
2054
}
2055
2055
}
@@ -2130,9 +2130,9 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2130
2130
// post BIP34 before approximately height 486,000,000. After block
2131
2131
// 1,983,702 testnet3 starts doing unnecessary BIP30 checking again.
2132
2132
assert (pindex->pprev );
2133
- CBlockIndex* pindexBIP34height = pindex->pprev ->GetAncestor (m_params .GetConsensus ().BIP34Height );
2133
+ CBlockIndex* pindexBIP34height = pindex->pprev ->GetAncestor (params .GetConsensus ().BIP34Height );
2134
2134
// Only continue to enforce if we're below BIP34 activation height or the block hash at that height doesn't correspond.
2135
- fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash () == m_params .GetConsensus ().BIP34Hash ));
2135
+ fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash () == params .GetConsensus ().BIP34Hash ));
2136
2136
2137
2137
// TODO: Remove BIP30 checking from block height 1,983,702 on, once we have a
2138
2138
// consensus change that ensures coinbases at those heights cannot
@@ -2254,7 +2254,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2254
2254
Ticks<SecondsDouble>(time_connect),
2255
2255
Ticks<MillisecondsDouble>(time_connect) / num_blocks_total);
2256
2256
2257
- CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , m_params .GetConsensus ());
2257
+ CAmount blockReward = nFees + GetBlockSubsidy (pindex->nHeight , params .GetConsensus ());
2258
2258
if (block.vtx [0 ]->GetValueOut () > blockReward) {
2259
2259
LogPrintf (" ERROR: ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)\n " , block.vtx [0 ]->GetValueOut (), blockReward);
2260
2260
return state.Invalid (BlockValidationResult::BLOCK_CONSENSUS, " bad-cb-amount" );
@@ -2275,7 +2275,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
2275
2275
if (fJustCheck )
2276
2276
return true ;
2277
2277
2278
- if (!m_blockman.WriteUndoDataForBlock (blockundo, state, pindex, m_params )) {
2278
+ if (!m_blockman.WriteUndoDataForBlock (blockundo, state, pindex, params )) {
2279
2279
return false ;
2280
2280
}
2281
2281
@@ -2394,7 +2394,7 @@ bool Chainstate::FlushStateToDisk(
2394
2394
} else {
2395
2395
LOG_TIME_MILLIS_WITH_CATEGORY (" find files to prune" , BCLog::BENCH);
2396
2396
2397
- m_blockman.FindFilesToPrune (setFilesToPrune, m_params .PruneAfterHeight (), m_chain.Height (), last_prune, IsInitialBlockDownload ());
2397
+ m_blockman.FindFilesToPrune (setFilesToPrune, m_chainman. GetParams () .PruneAfterHeight (), m_chain.Height (), last_prune, IsInitialBlockDownload ());
2398
2398
m_blockman.m_check_for_pruning = false ;
2399
2399
}
2400
2400
if (!setFilesToPrune.empty ()) {
@@ -2548,13 +2548,15 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
2548
2548
AssertLockHeld (::cs_main);
2549
2549
const auto & coins_tip = this ->CoinsTip ();
2550
2550
2551
+ const CChainParams& params{m_chainman.GetParams ()};
2552
+
2551
2553
// The remainder of the function isn't relevant if we are not acting on
2552
2554
// the active chainstate, so return if need be.
2553
2555
if (this != &m_chainman.ActiveChainstate ()) {
2554
2556
// Only log every so often so that we don't bury log messages at the tip.
2555
2557
constexpr int BACKGROUND_LOG_INTERVAL = 2000 ;
2556
2558
if (pindexNew->nHeight % BACKGROUND_LOG_INTERVAL == 0 ) {
2557
- UpdateTipLog (coins_tip, pindexNew, m_params , __func__, " [background validation] " , " " );
2559
+ UpdateTipLog (coins_tip, pindexNew, params , __func__, " [background validation] " , " " );
2558
2560
}
2559
2561
return ;
2560
2562
}
@@ -2575,7 +2577,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
2575
2577
const CBlockIndex* pindex = pindexNew;
2576
2578
for (int bit = 0 ; bit < VERSIONBITS_NUM_BITS; bit++) {
2577
2579
WarningBitsConditionChecker checker (m_chainman, bit);
2578
- ThresholdState state = checker.GetStateFor (pindex, m_params .GetConsensus (), warningcache.at (bit));
2580
+ ThresholdState state = checker.GetStateFor (pindex, params .GetConsensus (), warningcache.at (bit));
2579
2581
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
2580
2582
const bilingual_str warning = strprintf (_ (" Unknown new rules activated (versionbit %i)" ), bit);
2581
2583
if (state == ThresholdState::ACTIVE) {
@@ -2586,7 +2588,7 @@ void Chainstate::UpdateTip(const CBlockIndex* pindexNew)
2586
2588
}
2587
2589
}
2588
2590
}
2589
- UpdateTipLog (coins_tip, pindexNew, m_params , __func__, " " , warning_messages.original );
2591
+ UpdateTipLog (coins_tip, pindexNew, params , __func__, " " , warning_messages.original );
2590
2592
}
2591
2593
2592
2594
/* * Disconnect m_chain's tip.
@@ -2610,7 +2612,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
2610
2612
// Read block from disk.
2611
2613
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
2612
2614
CBlock& block = *pblock;
2613
- if (!ReadBlockFromDisk (block, pindexDelete, m_params .GetConsensus ())) {
2615
+ if (!ReadBlockFromDisk (block, pindexDelete, m_chainman .GetConsensus ())) {
2614
2616
return error (" DisconnectTip(): Failed to read block" );
2615
2617
}
2616
2618
// Apply the block atomically to the chain state.
@@ -2727,7 +2729,7 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
2727
2729
std::shared_ptr<const CBlock> pthisBlock;
2728
2730
if (!pblock) {
2729
2731
std::shared_ptr<CBlock> pblockNew = std::make_shared<CBlock>();
2730
- if (!ReadBlockFromDisk (*pblockNew, pindexNew, m_params .GetConsensus ())) {
2732
+ if (!ReadBlockFromDisk (*pblockNew, pindexNew, m_chainman .GetConsensus ())) {
2731
2733
return AbortNode (state, " Failed to read block" );
2732
2734
}
2733
2735
pthisBlock = pblockNew;
@@ -3835,7 +3837,9 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
3835
3837
if (pindex->nChainWork < nMinimumChainWork) return true ;
3836
3838
}
3837
3839
3838
- if (!CheckBlock (block, state, m_params.GetConsensus ()) ||
3840
+ const CChainParams& params{m_chainman.GetParams ()};
3841
+
3842
+ if (!CheckBlock (block, state, params.GetConsensus ()) ||
3839
3843
!ContextualCheckBlock (block, state, m_chainman, pindex->pprev )) {
3840
3844
if (state.IsInvalid () && state.GetResult () != BlockValidationResult::BLOCK_MUTATED) {
3841
3845
pindex->nStatus |= BLOCK_FAILED_VALID;
@@ -3852,7 +3856,7 @@ bool Chainstate::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockV
3852
3856
// Write block to history file
3853
3857
if (fNewBlock ) *fNewBlock = true ;
3854
3858
try {
3855
- FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, pindex->nHeight , m_chain, m_params , dbp)};
3859
+ FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, pindex->nHeight , m_chain, params , dbp)};
3856
3860
if (blockPos.IsNull ()) {
3857
3861
state.Error (strprintf (" %s: Failed to find position to write new block to disk" , __func__));
3858
3862
return false ;
@@ -3996,7 +4000,7 @@ bool Chainstate::LoadChainTip()
3996
4000
tip->GetBlockHash ().ToString (),
3997
4001
m_chain.Height (),
3998
4002
FormatISO8601DateTime (tip->GetBlockTime ()),
3999
- GuessVerificationProgress (m_params .TxData (), tip));
4003
+ GuessVerificationProgress (m_chainman. GetParams () .TxData (), tip));
4000
4004
return true ;
4001
4005
}
4002
4006
@@ -4132,7 +4136,7 @@ bool Chainstate::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& in
4132
4136
AssertLockHeld (cs_main);
4133
4137
// TODO: merge with ConnectBlock
4134
4138
CBlock block;
4135
- if (!ReadBlockFromDisk (block, pindex, m_params .GetConsensus ())) {
4139
+ if (!ReadBlockFromDisk (block, pindex, m_chainman .GetConsensus ())) {
4136
4140
return error (" ReplayBlock(): ReadBlockFromDisk failed at %d, hash=%s" , pindex->nHeight , pindex->GetBlockHash ().ToString ());
4137
4141
}
4138
4142
@@ -4184,7 +4188,7 @@ bool Chainstate::ReplayBlocks()
4184
4188
while (pindexOld != pindexFork) {
4185
4189
if (pindexOld->nHeight > 0 ) { // Never disconnect the genesis block.
4186
4190
CBlock block;
4187
- if (!ReadBlockFromDisk (block, pindexOld, m_params .GetConsensus ())) {
4191
+ if (!ReadBlockFromDisk (block, pindexOld, m_chainman .GetConsensus ())) {
4188
4192
return error (" RollbackBlock(): ReadBlockFromDisk() failed at %d, hash=%s" , pindexOld->nHeight , pindexOld->GetBlockHash ().ToString ());
4189
4193
}
4190
4194
LogPrintf (" Rolling back %s (%i)\n " , pindexOld->GetBlockHash ().ToString (), pindexOld->nHeight );
@@ -4336,16 +4340,18 @@ bool Chainstate::LoadGenesisBlock()
4336
4340
{
4337
4341
LOCK (cs_main);
4338
4342
4343
+ const CChainParams& params{m_chainman.GetParams ()};
4344
+
4339
4345
// Check whether we're already initialized by checking for genesis in
4340
4346
// m_blockman.m_block_index. Note that we can't use m_chain here, since it is
4341
4347
// set based on the coins db, not the block index db, which is the only
4342
4348
// thing loaded at this point.
4343
- if (m_blockman.m_block_index .count (m_params .GenesisBlock ().GetHash ()))
4349
+ if (m_blockman.m_block_index .count (params .GenesisBlock ().GetHash ()))
4344
4350
return true ;
4345
4351
4346
4352
try {
4347
- const CBlock& block = m_params .GenesisBlock ();
4348
- FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, 0 , m_chain, m_params , nullptr )};
4353
+ const CBlock& block = params .GenesisBlock ();
4354
+ FlatFilePos blockPos{m_blockman.SaveBlockToDisk (block, 0 , m_chain, params , nullptr )};
4349
4355
if (blockPos.IsNull ()) {
4350
4356
return error (" %s: writing genesis block to disk failed" , __func__);
4351
4357
}
@@ -4369,6 +4375,7 @@ void Chainstate::LoadExternalBlockFile(
4369
4375
assert (!dbp == !blocks_with_unknown_parent);
4370
4376
4371
4377
const auto start{SteadyClock::now ()};
4378
+ const CChainParams& params{m_chainman.GetParams ()};
4372
4379
4373
4380
int nLoaded = 0 ;
4374
4381
try {
@@ -4385,10 +4392,10 @@ void Chainstate::LoadExternalBlockFile(
4385
4392
try {
4386
4393
// locate a header
4387
4394
unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
4388
- blkdat.FindByte (m_params .MessageStart ()[0 ]);
4395
+ blkdat.FindByte (params .MessageStart ()[0 ]);
4389
4396
nRewind = blkdat.GetPos () + 1 ;
4390
4397
blkdat >> buf;
4391
- if (memcmp (buf, m_params .MessageStart (), CMessageHeader::MESSAGE_START_SIZE)) {
4398
+ if (memcmp (buf, params .MessageStart (), CMessageHeader::MESSAGE_START_SIZE)) {
4392
4399
continue ;
4393
4400
}
4394
4401
// read size
@@ -4414,7 +4421,7 @@ void Chainstate::LoadExternalBlockFile(
4414
4421
{
4415
4422
LOCK (cs_main);
4416
4423
// detect out of order blocks, and store them for later
4417
- if (hash != m_params .GetConsensus ().hashGenesisBlock && !m_blockman.LookupBlockIndex (block.hashPrevBlock )) {
4424
+ if (hash != params .GetConsensus ().hashGenesisBlock && !m_blockman.LookupBlockIndex (block.hashPrevBlock )) {
4418
4425
LogPrint (BCLog::REINDEX, " %s: Out of order block %s, parent %s not known\n " , __func__, hash.ToString (),
4419
4426
block.hashPrevBlock .ToString ());
4420
4427
if (dbp && blocks_with_unknown_parent) {
@@ -4433,13 +4440,13 @@ void Chainstate::LoadExternalBlockFile(
4433
4440
if (state.IsError ()) {
4434
4441
break ;
4435
4442
}
4436
- } else if (hash != m_params .GetConsensus ().hashGenesisBlock && pindex->nHeight % 1000 == 0 ) {
4443
+ } else if (hash != params .GetConsensus ().hashGenesisBlock && pindex->nHeight % 1000 == 0 ) {
4437
4444
LogPrint (BCLog::REINDEX, " Block Import: already had block %s at height %d\n " , hash.ToString (), pindex->nHeight );
4438
4445
}
4439
4446
}
4440
4447
4441
4448
// Activate the genesis block so normal node progress can continue
4442
- if (hash == m_params .GetConsensus ().hashGenesisBlock ) {
4449
+ if (hash == params .GetConsensus ().hashGenesisBlock ) {
4443
4450
BlockValidationState state;
4444
4451
if (!ActivateBestChain (state, nullptr )) {
4445
4452
break ;
@@ -4460,7 +4467,7 @@ void Chainstate::LoadExternalBlockFile(
4460
4467
while (range.first != range.second ) {
4461
4468
std::multimap<uint256, FlatFilePos>::iterator it = range.first ;
4462
4469
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
4463
- if (ReadBlockFromDisk (*pblockrecursive, it->second , m_params .GetConsensus ())) {
4470
+ if (ReadBlockFromDisk (*pblockrecursive, it->second , params .GetConsensus ())) {
4464
4471
LogPrint (BCLog::REINDEX, " %s: Processing out of order child %s of %s\n " , __func__, pblockrecursive->GetHash ().ToString (),
4465
4472
head.ToString ());
4466
4473
LOCK (cs_main);
@@ -4560,7 +4567,7 @@ void Chainstate::CheckBlockIndex()
4560
4567
// Begin: actual consistency checks.
4561
4568
if (pindex->pprev == nullptr ) {
4562
4569
// Genesis block checks.
4563
- assert (pindex->GetBlockHash () == m_params .GetConsensus ().hashGenesisBlock ); // Genesis block's hash must match.
4570
+ assert (pindex->GetBlockHash () == m_chainman .GetConsensus ().hashGenesisBlock ); // Genesis block's hash must match.
4564
4571
assert (pindex == m_chain.Genesis ()); // The current active chain's genesis block must be this block.
4565
4572
}
4566
4573
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