mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
Merge bitcoin/bitcoin#25168: refactor: Avoid passing params where not needed
fa1b76aeb0Do not call global Params() when chainman is in scope (MacroFake)fa30234be8Do not pass CChainParams& to PeerManager::make (MacroFake)fafe5c0ca2Do not pass CChainParams& to BlockAssembler constructor (MacroFake)faf012b438Do not pass Consensus::Params& to Chainstate helpers (MacroFake)fa4ee53dcaDo not pass time getter to Chainstate helpers (MacroFake) Pull request description: It seems confusing to pass chain params, consensus params, or a time function around when it is not needed. Fix this by: * Inlining the passed time getter function. I don't see a use case why this should be mockable. * Using `chainman.GetConsensus()` or `chainman.GetParams()`, where possible. ACKs for top commit: promag: Code review ACKfa1b76aeb0. vincenzopalazzo: ACKfa1b76aeb0Tree-SHA512: 1abff5cba4b4871d97f17dbcdf67bc9255ff21fa4150a79a74e39b28f0610eab3e7dee24d56872dd6e111f003b55e288958cdd467e6218368d896f191e4ec9cd
This commit is contained in:
13
src/init.cpp
13
src/init.cpp
@@ -1435,7 +1435,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
chainman,
|
||||
Assert(node.mempool.get()),
|
||||
fPruneMode,
|
||||
chainparams.GetConsensus(),
|
||||
fReindexChainState,
|
||||
cache_sizes.block_tree_db,
|
||||
cache_sizes.coins_db,
|
||||
@@ -1482,7 +1481,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_BLOCKS_WITNESS_INSUFFICIENTLY_VALIDATED:
|
||||
strLoadError = strprintf(_("Witness data for blocks after height %d requires validation. Please restart with -reindex."),
|
||||
chainparams.GetConsensus().SegwitHeight);
|
||||
chainman.GetConsensus().SegwitHeight);
|
||||
break;
|
||||
case ChainstateLoadingError::SHUTDOWN_PROBED:
|
||||
break;
|
||||
@@ -1499,10 +1498,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
maybe_verify_error = VerifyLoadedChainstate(chainman,
|
||||
fReset,
|
||||
fReindexChainState,
|
||||
chainparams.GetConsensus(),
|
||||
check_blocks,
|
||||
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
|
||||
/*get_unix_time_seconds=*/static_cast<int64_t(*)()>(GetTime));
|
||||
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL));
|
||||
} catch (const std::exception& e) {
|
||||
LogPrintf("%s\n", e.what());
|
||||
maybe_verify_error = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
|
||||
@@ -1558,7 +1555,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
ChainstateManager& chainman = *Assert(node.chainman);
|
||||
|
||||
assert(!node.peerman);
|
||||
node.peerman = PeerManager::make(chainparams, *node.connman, *node.addrman, node.banman.get(),
|
||||
node.peerman = PeerManager::make(*node.connman, *node.addrman, node.banman.get(),
|
||||
chainman, *node.mempool, ignores_incoming_txs);
|
||||
RegisterValidationInterface(node.peerman.get());
|
||||
|
||||
@@ -1680,8 +1677,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
chain_active_height = chainman.ActiveChain().Height();
|
||||
if (tip_info) {
|
||||
tip_info->block_height = chain_active_height;
|
||||
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
|
||||
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
|
||||
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : chainman.GetParams().GenesisBlock().GetBlockTime();
|
||||
tip_info->verification_progress = GuessVerificationProgress(chainman.GetParams().TxData(), chainman.ActiveChain().Tip());
|
||||
}
|
||||
if (tip_info && chainman.m_best_header) {
|
||||
tip_info->header_height = chainman.m_best_header->nHeight;
|
||||
|
||||
Reference in New Issue
Block a user