Skip to content

Commit fa0d921

Browse files
author
MarcoFalke
committed
refactor: Remove chainparams arg from CChainState member functions
Passing this is confusing and redundant with the m_params member.
1 parent fa38947 commit fa0d921

10 files changed

+142
-140
lines changed

src/init.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13721372
// block file from disk.
13731373
// Note that it also sets fReindex based on the disk flag!
13741374
// From here on out fReindex and fReset mean something different!
1375-
if (!chainman.LoadBlockIndex(chainparams)) {
1375+
if (!chainman.LoadBlockIndex()) {
13761376
if (ShutdownRequested()) break;
13771377
strLoadError = _("Error loading block database");
13781378
break;
@@ -1396,7 +1396,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13961396
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
13971397
// (otherwise we use the one already on disk).
13981398
// This is called again in ThreadImport after the reindex completes.
1399-
if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock(chainparams)) {
1399+
if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock()) {
14001400
strLoadError = _("Error initializing block database");
14011401
break;
14021402
}
@@ -1427,7 +1427,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14271427
}
14281428

14291429
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
1430-
if (!chainstate->ReplayBlocks(chainparams)) {
1430+
if (!chainstate->ReplayBlocks()) {
14311431
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
14321432
failed_chainstate_init = true;
14331433
break;
@@ -1439,7 +1439,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14391439

14401440
if (!is_coinsview_empty(chainstate)) {
14411441
// LoadChainTip initializes the chain based on CoinsTip()'s best block
1442-
if (!chainstate->LoadChainTip(chainparams)) {
1442+
if (!chainstate->LoadChainTip()) {
14431443
strLoadError = _("Error initializing block database");
14441444
failed_chainstate_init = true;
14451445
break; // out of the per-chainstate loop
@@ -1461,7 +1461,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14611461
LOCK(cs_main);
14621462
auto chainstates{chainman.GetAll()};
14631463
if (std::any_of(chainstates.begin(), chainstates.end(),
1464-
[&chainparams](const CChainState* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(chainparams); })) {
1464+
[](const CChainState* cs) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return cs->NeedsRedownload(); })) {
14651465
strLoadError = strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
14661466
chainparams.GetConsensus().SegwitHeight);
14671467
break;

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
16941694
} // release cs_main before calling ActivateBestChain
16951695
if (need_activate_chain) {
16961696
BlockValidationState state;
1697-
if (!m_chainman.ActiveChainstate().ActivateBestChain(state, m_chainparams, a_recent_block)) {
1697+
if (!m_chainman.ActiveChainstate().ActivateBestChain(state, a_recent_block)) {
16981698
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString());
16991699
}
17001700
}
@@ -2920,7 +2920,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
29202920
a_recent_block = most_recent_block;
29212921
}
29222922
BlockValidationState state;
2923-
if (!m_chainman.ActiveChainstate().ActivateBestChain(state, m_chainparams, a_recent_block)) {
2923+
if (!m_chainman.ActiveChainstate().ActivateBestChain(state, a_recent_block)) {
29242924
LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString());
29252925
}
29262926
}

src/node/blockstorage.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ struct CImportingNow {
493493

494494
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
495495
{
496-
const CChainParams& chainparams = Params();
497496
ScheduleBatchPriority();
498497

499498
{
@@ -512,7 +511,7 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
512511
break; // This error is logged in OpenBlockFile
513512
}
514513
LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
515-
chainman.ActiveChainstate().LoadExternalBlockFile(chainparams, file, &pos);
514+
chainman.ActiveChainstate().LoadExternalBlockFile(file, &pos);
516515
if (ShutdownRequested()) {
517516
LogPrintf("Shutdown requested. Exit %s\n", __func__);
518517
return;
@@ -523,15 +522,15 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
523522
fReindex = false;
524523
LogPrintf("Reindexing finished\n");
525524
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
526-
chainman.ActiveChainstate().LoadGenesisBlock(chainparams);
525+
chainman.ActiveChainstate().LoadGenesisBlock();
527526
}
528527

529528
// -loadblock=
530529
for (const fs::path& path : vImportFiles) {
531530
FILE* file = fsbridge::fopen(path, "rb");
532531
if (file) {
533532
LogPrintf("Importing blocks file %s...\n", path.string());
534-
chainman.ActiveChainstate().LoadExternalBlockFile(chainparams, file);
533+
chainman.ActiveChainstate().LoadExternalBlockFile(file);
535534
if (ShutdownRequested()) {
536535
LogPrintf("Shutdown requested. Exit %s\n", __func__);
537536
return;
@@ -548,7 +547,7 @@ void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFile
548547
// the relevant pointers before the ABC call.
549548
for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
550549
BlockValidationState state;
551-
if (!chainstate->ActivateBestChain(state, chainparams, nullptr)) {
550+
if (!chainstate->ActivateBestChain(state, nullptr)) {
552551
LogPrintf("Failed to connect best block (%s)\n", state.ToString());
553552
StartShutdown();
554553
return;

src/rpc/blockchain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ static RPCHelpMan preciousblock()
17061706
}
17071707

17081708
BlockValidationState state;
1709-
chainman.ActiveChainstate().PreciousBlock(state, Params(), pblockindex);
1709+
chainman.ActiveChainstate().PreciousBlock(state, pblockindex);
17101710

17111711
if (!state.IsValid()) {
17121712
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());
@@ -1743,10 +1743,10 @@ static RPCHelpMan invalidateblock()
17431743
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
17441744
}
17451745
}
1746-
chainman.ActiveChainstate().InvalidateBlock(state, Params(), pblockindex);
1746+
chainman.ActiveChainstate().InvalidateBlock(state, pblockindex);
17471747

17481748
if (state.IsValid()) {
1749-
chainman.ActiveChainstate().ActivateBestChain(state, Params());
1749+
chainman.ActiveChainstate().ActivateBestChain(state);
17501750
}
17511751

17521752
if (!state.IsValid()) {
@@ -1787,7 +1787,7 @@ static RPCHelpMan reconsiderblock()
17871787
}
17881788

17891789
BlockValidationState state;
1790-
chainman.ActiveChainstate().ActivateBestChain(state, Params());
1790+
chainman.ActiveChainstate().ActivateBestChain(state);
17911791

17921792
if (!state.IsValid()) {
17931793
throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString());

src/test/fuzz/load_external_block_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
3232
return;
3333
}
3434
FlatFilePos flat_file_pos;
35-
g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
35+
g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile(fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
3636
}

src/test/interfaces_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(findCommonAncestor)
9898
auto* orig_tip = active.Tip();
9999
for (int i = 0; i < 10; ++i) {
100100
BlockValidationState state;
101-
m_node.chainman->ActiveChainstate().InvalidateBlock(state, Params(), active.Tip());
101+
m_node.chainman->ActiveChainstate().InvalidateBlock(state, active.Tip());
102102
}
103103
BOOST_CHECK_EQUAL(active.Height(), orig_tip->nHeight - 10);
104104
coinbaseKey.MakeNewKey(true);

src/test/util/setup_common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
186186
assert(!m_node.chainman->ActiveChainstate().CanFlushToDisk());
187187
m_node.chainman->ActiveChainstate().InitCoinsCache(1 << 23);
188188
assert(m_node.chainman->ActiveChainstate().CanFlushToDisk());
189-
if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock(chainparams)) {
189+
if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock()) {
190190
throw std::runtime_error("LoadGenesisBlock failed.");
191191
}
192192

193193
BlockValidationState state;
194-
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state, chainparams)) {
194+
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
195195
throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString()));
196196
}
197197

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
3131
CTxMemPool& mempool = *m_node.mempool;
3232

3333
std::vector<CChainState*> chainstates;
34-
const CChainParams& chainparams = Params();
3534

3635
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
3736

@@ -76,9 +75,9 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
7675
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
7776
WITH_LOCK(::cs_main, c2.InitCoinsCache(1 << 23));
7877
// Unlike c1, which doesn't have any blocks. Gets us different tip, height.
79-
c2.LoadGenesisBlock(chainparams);
78+
c2.LoadGenesisBlock();
8079
BlockValidationState _;
81-
BOOST_CHECK(c2.ActivateBestChain(_, chainparams, nullptr));
80+
BOOST_CHECK(c2.ActivateBestChain(_, nullptr));
8281

8382
BOOST_CHECK(manager.IsSnapshotActive());
8483
BOOST_CHECK(!manager.IsSnapshotValidated());
@@ -138,7 +137,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches)
138137
{
139138
LOCK(::cs_main);
140139
c1.InitCoinsCache(1 << 23);
141-
BOOST_REQUIRE(c1.LoadGenesisBlock(Params()));
140+
BOOST_REQUIRE(c1.LoadGenesisBlock());
142141
c1.CoinsTip().SetBestBlock(InsecureRand256());
143142
manager.MaybeRebalanceCaches();
144143
}
@@ -156,7 +155,7 @@ BOOST_AUTO_TEST_CASE(chainstatemanager_rebalance_caches)
156155
{
157156
LOCK(::cs_main);
158157
c2.InitCoinsCache(1 << 23);
159-
BOOST_REQUIRE(c2.LoadGenesisBlock(Params()));
158+
BOOST_REQUIRE(c2.LoadGenesisBlock());
160159
c2.CoinsTip().SetBestBlock(InsecureRand256());
161160
manager.MaybeRebalanceCaches();
162161
}

0 commit comments

Comments
 (0)