Skip to content

Commit ffc7df4

Browse files
committed
merge bitcoin#25830: Replace m_params with chainman.GetParams()
1 parent 1c00d0a commit ffc7df4

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

src/test/fuzz/tx_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, con
9898
options.nBlockMaxSize = fuzzed_data_provider.ConsumeIntegralInRange(0U, MaxBlockSize(true));
9999
options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
100100

101-
auto assembler = BlockAssembler{chainstate, node, static_cast<CTxMemPool*>(&tx_pool), chainstate.m_params, options};
101+
auto assembler = BlockAssembler{chainstate, node, static_cast<CTxMemPool*>(&tx_pool), chainstate.m_chainman.GetParams(), options};
102102
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
103103
Assert(block_template->block.vtx.size() >= 1);
104104
}

src/validation.cpp

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, const CTr
13311331
int64_t accept_time, bool bypass_limits, bool test_accept)
13321332
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
13331333
{
1334-
const CChainParams& chainparams{active_chainstate.m_params};
1334+
const CChainParams& chainparams{active_chainstate.m_chainman.GetParams()};
13351335
assert(active_chainstate.GetMempool() != nullptr);
13361336
CTxMemPool& pool{*active_chainstate.GetMempool()};
13371337

@@ -1365,7 +1365,7 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
13651365
assert(std::all_of(package.cbegin(), package.cend(), [](const auto& tx){return tx != nullptr;}));
13661366

13671367
std::vector<COutPoint> coins_to_uncache;
1368-
const CChainParams& chainparams = active_chainstate.m_params;
1368+
const CChainParams& chainparams = active_chainstate.m_chainman.GetParams();
13691369
const auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
13701370
AssertLockHeld(cs_main);
13711371
if (test_accept) {
@@ -1590,7 +1590,6 @@ CChainState::CChainState(CTxMemPool* mempool,
15901590
m_chain_helper(chain_helper),
15911591
m_evoDb(evoDb),
15921592
m_blockman(blockman),
1593-
m_params(chainman.GetParams()),
15941593
m_chainman(chainman),
15951594
m_from_snapshot_blockhash(from_snapshot_blockhash) {}
15961595

@@ -2220,6 +2219,8 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
22202219

22212220
assert(m_chain_helper);
22222221

2222+
const CChainParams& params{m_chainman.GetParams()};
2223+
22232224
// Check it again in case a previous version let a bad block in
22242225
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
22252226
// ContextualCheckBlockHeader() here. This means that if we add a new
@@ -2233,7 +2234,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
22332234
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
22342235
// re-enforce that rule here (at least until we make it impossible for
22352236
// GetAdjustedTime() to go backward).
2236-
if (!CheckBlock(block, state, m_params.GetConsensus(), !fJustCheck, !fJustCheck)) {
2237+
if (!CheckBlock(block, state, params.GetConsensus(), !fJustCheck, !fJustCheck)) {
22372238
if (state.GetResult() == BlockValidationResult::BLOCK_MUTATED) {
22382239
// We don't write down blocks to disk if they may have been
22392240
// corrupted, so this should be impossible unless we're having hardware
@@ -2253,7 +2254,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
22532254
assert(hashPrevBlock == view.GetBestBlock());
22542255

22552256
if (pindex->pprev) {
2256-
bool fDIP0003Active = pindex->nHeight >= m_params.GetConsensus().DIP0003Height;
2257+
bool fDIP0003Active = pindex->nHeight >= params.GetConsensus().DIP0003Height;
22572258
if (fDIP0003Active && !m_evoDb.VerifyBestBlock(pindex->pprev->GetBlockHash())) {
22582259
// Nodes that upgraded after DIP3 activation will have to reindex to ensure evodb consistency
22592260
return AbortNode(state, "Found EvoDB inconsistency, you must reindex to continue");
@@ -2263,7 +2264,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
22632264

22642265
// Special case for the genesis block, skipping connection of its transactions
22652266
// (its coinbase is unspendable)
2266-
if (block_hash == m_params.GetConsensus().hashGenesisBlock) {
2267+
if (block_hash == params.GetConsensus().hashGenesisBlock) {
22672268
if (!fJustCheck)
22682269
view.SetBestBlock(pindex->GetBlockHash());
22692270
return true;
@@ -2295,7 +2296,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
22952296
// artificially set the default assumed verified block further back.
22962297
// The test against nMinimumChainWork prevents the skipping when denied access to any chain at
22972298
// least as good as the expected chain.
2298-
fScriptChecks = (GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, m_params.GetConsensus()) <= 60 * 60 * 24 * 7 * 2);
2299+
fScriptChecks = (GetBlockProofEquivalentTime(*m_chainman.m_best_header, *pindex, *m_chainman.m_best_header, params.GetConsensus()) <= 60 * 60 * 24 * 7 * 2);
22992300
}
23002301
}
23012302
}
@@ -2322,9 +2323,9 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
23222323
// duplicate transactions descending from the known pairs either.
23232324
// If we're on the known chain at height greater than where BIP34 activated, we can save the db accesses needed for the BIP30 check.
23242325
assert(pindex->pprev);
2325-
CBlockIndex* pindexBIP34height = pindex->pprev->GetAncestor(m_params.GetConsensus().BIP34Height);
2326+
CBlockIndex* pindexBIP34height = pindex->pprev->GetAncestor(params.GetConsensus().BIP34Height);
23262327
//Only continue to enforce if we're below BIP34 activation height or the block hash at that height doesn't correspond.
2327-
fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash() == m_params.GetConsensus().BIP34Hash));
2328+
fEnforceBIP30 = fEnforceBIP30 && (!pindexBIP34height || !(pindexBIP34height->GetBlockHash() == params.GetConsensus().BIP34Hash));
23282329

23292330
if (fEnforceBIP30) {
23302331
for (const auto& tx : block.vtx) {
@@ -2340,9 +2341,9 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
23402341
/// DASH: Check superblock start
23412342

23422343
// make sure old budget is the real one
2343-
if (pindex->nHeight == m_params.GetConsensus().nSuperblockStartBlock &&
2344-
m_params.GetConsensus().nSuperblockStartHash != uint256() &&
2345-
block_hash != m_params.GetConsensus().nSuperblockStartHash) {
2344+
if (pindex->nHeight == params.GetConsensus().nSuperblockStartBlock &&
2345+
params.GetConsensus().nSuperblockStartHash != uint256() &&
2346+
block_hash != params.GetConsensus().nSuperblockStartHash) {
23462347
LogPrintf("ERROR: ConnectBlock(): invalid superblock start\n");
23472348
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-sb-start");
23482349
}
@@ -2604,7 +2605,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
26042605

26052606
int64_t nTime6 = GetTimeMicros();
26062607

2607-
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, m_params)) {
2608+
if (!m_blockman.WriteUndoDataForBlock(blockundo, state, pindex, params)) {
26082609
return false;
26092610
}
26102611

@@ -2740,7 +2741,7 @@ bool CChainState::FlushStateToDisk(
27402741
} else {
27412742
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCHMARK);
27422743

2743-
m_blockman.FindFilesToPrune(setFilesToPrune, m_params.PruneAfterHeight(), m_chain.Height(), last_prune, IsInitialBlockDownload());
2744+
m_blockman.FindFilesToPrune(setFilesToPrune, m_chainman.GetParams().PruneAfterHeight(), m_chain.Height(), last_prune, IsInitialBlockDownload());
27442745
m_blockman.m_check_for_pruning = false;
27452746
}
27462747
if (!setFilesToPrune.empty()) {
@@ -2907,13 +2908,15 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
29072908
AssertLockHeld(::cs_main);
29082909
const auto& coins_tip = this->CoinsTip();
29092910

2911+
const CChainParams& params{m_chainman.GetParams()};
2912+
29102913
// The remainder of the function isn't relevant if we are not acting on
29112914
// the active chainstate, so return if need be.
29122915
if (this != &m_chainman.ActiveChainstate()) {
29132916
// Only log every so often so that we don't bury log messages at the tip.
29142917
constexpr int BACKGROUND_LOG_INTERVAL = 2000;
29152918
if (pindexNew->nHeight % BACKGROUND_LOG_INTERVAL == 0) {
2916-
UpdateTipLog(coins_tip, pindexNew, m_params, m_evoDb, __func__, "[background validation] ", "");
2919+
UpdateTipLog(coins_tip, pindexNew, params, m_evoDb, __func__, "[background validation] ", "");
29172920
}
29182921
return;
29192922
}
@@ -2935,7 +2938,7 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
29352938
const CBlockIndex* pindex = pindexNew;
29362939
for (int bit = 0; bit < VERSIONBITS_NUM_BITS; bit++) {
29372940
WarningBitsConditionChecker checker(m_chainman, bit);
2938-
ThresholdState state = checker.GetStateFor(pindex, m_params.GetConsensus(), warningcache.at(bit));
2941+
ThresholdState state = checker.GetStateFor(pindex, params.GetConsensus(), warningcache.at(bit));
29392942
if (state == ThresholdState::ACTIVE || state == ThresholdState::LOCKED_IN) {
29402943
const bilingual_str warning = strprintf(_("Unknown new rules activated (versionbit %i)"), bit);
29412944
if (state == ThresholdState::ACTIVE) {
@@ -2946,7 +2949,7 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
29462949
}
29472950
}
29482951
}
2949-
UpdateTipLog(coins_tip, pindexNew, m_params, m_evoDb, __func__, "", warning_messages.original);
2952+
UpdateTipLog(coins_tip, pindexNew, params, m_evoDb, __func__, "", warning_messages.original);
29502953
}
29512954

29522955
/** Disconnect m_chain's tip.
@@ -2972,7 +2975,7 @@ bool CChainState::DisconnectTip(BlockValidationState& state, DisconnectedBlockTr
29722975
// Read block from disk.
29732976
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
29742977
CBlock& block = *pblock;
2975-
if (!ReadBlockFromDisk(block, pindexDelete, m_params.GetConsensus())) {
2978+
if (!ReadBlockFromDisk(block, pindexDelete, m_chainman.GetConsensus())) {
29762979
return error("DisconnectTip(): Failed to read block");
29772980
}
29782981
// Apply the block atomically to the chain state.
@@ -3104,7 +3107,7 @@ bool CChainState::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew
31043107
std::shared_ptr<const CBlock> pthisBlock;
31053108
if (!pblock) {
31063109
std::shared_ptr<CBlock> pblockNew = std::make_shared<CBlock>();
3107-
if (!ReadBlockFromDisk(*pblockNew, pindexNew, m_params.GetConsensus())) {
3110+
if (!ReadBlockFromDisk(*pblockNew, pindexNew, m_chainman.GetConsensus())) {
31083111
return AbortNode(state, "Failed to read block");
31093112
}
31103113
pthisBlock = pblockNew;
@@ -4330,7 +4333,9 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
43304333
if (pindex->nChainWork < nMinimumChainWork) return true;
43314334
}
43324335

4333-
if (!CheckBlock(block, state, m_params.GetConsensus()) ||
4336+
const CChainParams& params{m_chainman.GetParams()};
4337+
4338+
if (!CheckBlock(block, state, params.GetConsensus()) ||
43344339
!ContextualCheckBlock(block, state, m_chainman, pindex->pprev)) {
43354340
if (state.IsInvalid() && state.GetResult() != BlockValidationResult::BLOCK_MUTATED) {
43364341
pindex->nStatus |= BLOCK_FAILED_VALID;
@@ -4347,7 +4352,7 @@ bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, Block
43474352
// Write block to history file
43484353
if (fNewBlock) *fNewBlock = true;
43494354
try {
4350-
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, m_chain, m_params, dbp)};
4355+
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, pindex->nHeight, m_chain, params, dbp)};
43514356
if (blockPos.IsNull()) {
43524357
state.Error(strprintf("%s: Failed to find position to write new block to disk", __func__));
43534358
return false;
@@ -4519,7 +4524,7 @@ bool CChainState::LoadChainTip()
45194524
tip->GetBlockHash().ToString(),
45204525
m_chain.Height(),
45214526
FormatISO8601DateTime(tip->GetBlockTime()),
4522-
GuessVerificationProgress(m_params.TxData(), tip));
4527+
GuessVerificationProgress(m_chainman.GetParams().TxData(), tip));
45234528
return true;
45244529
}
45254530

@@ -4667,7 +4672,7 @@ bool CChainState::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& i
46674672

46684673
// TODO: merge with ConnectBlock
46694674
CBlock block;
4670-
if (!ReadBlockFromDisk(block, pindex, m_params.GetConsensus())) {
4675+
if (!ReadBlockFromDisk(block, pindex, m_chainman.GetConsensus())) {
46714676
return error("RollforwardBlock(): ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
46724677
}
46734678

@@ -4796,7 +4801,7 @@ bool CChainState::ReplayBlocks()
47964801
pindexOld = &(m_blockman.m_block_index[hashHeads[1]]);
47974802
pindexFork = LastCommonAncestor(pindexOld, pindexNew);
47984803
assert(pindexFork != nullptr);
4799-
const bool fDIP0003Active = pindexOld->nHeight >= m_params.GetConsensus().DIP0003Height;
4804+
const bool fDIP0003Active = pindexOld->nHeight >= m_chainman.GetConsensus().DIP0003Height;
48004805
if (fDIP0003Active && !m_evoDb.VerifyBestBlock(pindexOld->GetBlockHash())) {
48014806
return error("ReplayBlocks(DASH): Found EvoDB inconsistency");
48024807
}
@@ -4808,7 +4813,7 @@ bool CChainState::ReplayBlocks()
48084813
while (pindexOld != pindexFork) {
48094814
if (pindexOld->nHeight > 0) { // Never disconnect the genesis block.
48104815
CBlock block;
4811-
if (!ReadBlockFromDisk(block, pindexOld, m_params.GetConsensus())) {
4816+
if (!ReadBlockFromDisk(block, pindexOld, m_chainman.GetConsensus())) {
48124817
return error("ReplayBlocks(): ReadBlockFromDisk() failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString());
48134818
}
48144819
LogPrintf("Rolling back %s (%i)\n", pindexOld->GetBlockHash().ToString(), pindexOld->nHeight);
@@ -4960,7 +4965,7 @@ void ChainstateManager::InitAdditionalIndexes()
49604965

49614966
bool CChainState::AddGenesisBlock(const CBlock& block, BlockValidationState& state)
49624967
{
4963-
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, m_params, nullptr)};
4968+
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, m_chain, m_chainman.GetParams(), nullptr)};
49644969
if (blockPos.IsNull()) {
49654970
return error("%s: writing genesis block to disk failed (%s)", __func__, state.ToString());
49664971
}
@@ -4973,24 +4978,26 @@ bool CChainState::LoadGenesisBlock()
49734978
{
49744979
LOCK(cs_main);
49754980

4981+
const CChainParams& params{m_chainman.GetParams()};
4982+
49764983
// Check whether we're already initialized by checking for genesis in
49774984
// m_blockman.m_block_index. Note that we can't use m_chain here, since it is
49784985
// set based on the coins db, not the block index db, which is the only
49794986
// thing loaded at this point.
4980-
if (m_blockman.m_block_index.count(m_params.GenesisBlock().GetHash()))
4987+
if (m_blockman.m_block_index.count(params.GenesisBlock().GetHash()))
49814988
return true;
49824989

49834990
try {
49844991
BlockValidationState state;
49854992

4986-
if (!AddGenesisBlock(m_params.GenesisBlock(), state))
4993+
if (!AddGenesisBlock(params.GenesisBlock(), state))
49874994
return false;
49884995

4989-
if (m_params.NetworkIDString() == CBaseChainParams::DEVNET) {
4996+
if (params.NetworkIDString() == CBaseChainParams::DEVNET) {
49904997
// We can't continue if devnet genesis block is invalid
49914998
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(
4992-
m_params.DevNetGenesisBlock());
4993-
bool fCheckBlock = CheckBlock(*shared_pblock, state, m_params.GetConsensus());
4999+
params.DevNetGenesisBlock());
5000+
bool fCheckBlock = CheckBlock(*shared_pblock, state, params.GetConsensus());
49945001
assert(fCheckBlock);
49955002
if (!AcceptBlock(shared_pblock, state, nullptr, true, nullptr, nullptr))
49965003
return false;
@@ -5013,6 +5020,7 @@ void CChainState::LoadExternalBlockFile(
50135020
assert(!dbp == !blocks_with_unknown_parent);
50145021

50155022
const auto start{SteadyClock::now()};
5023+
const CChainParams& params{m_chainman.GetParams()};
50165024

50175025
int nLoaded = 0;
50185026
try {
@@ -5032,10 +5040,10 @@ void CChainState::LoadExternalBlockFile(
50325040
try {
50335041
// locate a header
50345042
unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
5035-
blkdat.FindByte(m_params.MessageStart()[0]);
5043+
blkdat.FindByte(params.MessageStart()[0]);
50365044
nRewind = blkdat.GetPos() + 1;
50375045
blkdat >> buf;
5038-
if (memcmp(buf, m_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE)) {
5046+
if (memcmp(buf, params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE)) {
50395047
continue;
50405048
}
50415049
// read size
@@ -5063,7 +5071,7 @@ void CChainState::LoadExternalBlockFile(
50635071
{
50645072
LOCK(cs_main);
50655073
// detect out of order blocks, and store them for later
5066-
if (hash != m_params.GetConsensus().hashGenesisBlock && !m_blockman.LookupBlockIndex(header.hashPrevBlock)) {
5074+
if (hash != params.GetConsensus().hashGenesisBlock && !m_blockman.LookupBlockIndex(header.hashPrevBlock)) {
50675075
LogPrint(BCLog::REINDEX, "%s: Out of order block %s, parent %s not known\n", __func__, hash.ToString(),
50685076
header.hashPrevBlock.ToString());
50695077
if (dbp && blocks_with_unknown_parent) {
@@ -5088,13 +5096,13 @@ void CChainState::LoadExternalBlockFile(
50885096
if (state.IsError()) {
50895097
break;
50905098
}
5091-
} else if (hash != m_params.GetConsensus().hashGenesisBlock && pindex->nHeight % 1000 == 0) {
5099+
} else if (hash != params.GetConsensus().hashGenesisBlock && pindex->nHeight % 1000 == 0) {
50925100
LogPrint(BCLog::REINDEX, "Block Import: already had block %s at height %d\n", hash.ToString(), pindex->nHeight);
50935101
}
50945102
}
50955103

50965104
// Activate the genesis block so normal node progress can continue
5097-
if (hash == m_params.GetConsensus().hashGenesisBlock) {
5105+
if (hash == params.GetConsensus().hashGenesisBlock) {
50985106
BlockValidationState state;
50995107
if (!ActivateBestChain(state, nullptr)) {
51005108
break;
@@ -5115,7 +5123,7 @@ void CChainState::LoadExternalBlockFile(
51155123
while (range.first != range.second) {
51165124
std::multimap<uint256, FlatFilePos>::iterator it = range.first;
51175125
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
5118-
if (ReadBlockFromDisk(*pblockrecursive, it->second, m_params.GetConsensus())) {
5126+
if (ReadBlockFromDisk(*pblockrecursive, it->second, params.GetConsensus())) {
51195127
LogPrint(BCLog::REINDEX, "%s: Processing out of order child %s of %s\n", __func__, pblockrecursive->GetHash().ToString(),
51205128
head.ToString());
51215129
LOCK(cs_main);
@@ -5228,7 +5236,7 @@ void CChainState::CheckBlockIndex()
52285236
// Begin: actual consistency checks.
52295237
if (pindex->pprev == nullptr) {
52305238
// Genesis block checks.
5231-
assert(pindex->GetBlockHash() == m_params.GetConsensus().hashGenesisBlock); // Genesis block's hash must match.
5239+
assert(pindex->GetBlockHash() == m_chainman.GetConsensus().hashGenesisBlock); // Genesis block's hash must match.
52325240
assert(pindex == m_chain.Genesis()); // The current active chain's genesis block must be this block.
52335241
}
52345242
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

Comments
 (0)