Skip to content

Commit fa38947

Browse files
author
MarcoFalke
committed
refactor: Remove ::Params() global from inside CChainState member functions
It is confusing and verbose to repeatedly access the global when a member variable can simply refer to it.
1 parent 9c1ec68 commit fa38947

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/validation.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ void CoinsViews::InitCache()
12101210

12111211
CChainState::CChainState(CTxMemPool& mempool, BlockManager& blockman, std::optional<uint256> from_snapshot_blockhash)
12121212
: m_mempool(mempool),
1213+
m_params(::Params()),
12131214
m_blockman(blockman),
12141215
m_from_snapshot_blockhash(from_snapshot_blockhash) {}
12151216

@@ -2196,20 +2197,19 @@ bool CChainState::FlushStateToDisk(
21962197
return true;
21972198
}
21982199

2199-
void CChainState::ForceFlushStateToDisk() {
2200+
void CChainState::ForceFlushStateToDisk()
2201+
{
22002202
BlockValidationState state;
2201-
const CChainParams& chainparams = Params();
2202-
if (!this->FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS)) {
2203+
if (!this->FlushStateToDisk(m_params, state, FlushStateMode::ALWAYS)) {
22032204
LogPrintf("%s: failed to flush state (%s)\n", __func__, state.ToString());
22042205
}
22052206
}
22062207

2207-
void CChainState::PruneAndFlush() {
2208+
void CChainState::PruneAndFlush()
2209+
{
22082210
BlockValidationState state;
22092211
fCheckForPruning = true;
2210-
const CChainParams& chainparams = Params();
2211-
2212-
if (!this->FlushStateToDisk(chainparams, state, FlushStateMode::NONE)) {
2212+
if (!this->FlushStateToDisk(m_params, state, FlushStateMode::NONE)) {
22132213
LogPrintf("%s: failed to flush state (%s)\n", __func__, state.ToString());
22142214
}
22152215
}
@@ -4507,16 +4507,14 @@ bool CChainState::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
45074507
this->ToString(), coinstip_size * (1.0 / 1024 / 1024));
45084508

45094509
BlockValidationState state;
4510-
const CChainParams& chainparams = Params();
4511-
45124510
bool ret;
45134511

45144512
if (coinstip_size > old_coinstip_size) {
45154513
// Likely no need to flush if cache sizes have grown.
4516-
ret = FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED);
4514+
ret = FlushStateToDisk(m_params, state, FlushStateMode::IF_NEEDED);
45174515
} else {
45184516
// Otherwise, flush state to disk and deallocate the in-memory coins map.
4519-
ret = FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS);
4517+
ret = FlushStateToDisk(m_params, state, FlushStateMode::ALWAYS);
45204518
CoinsTip().ReallocateCache();
45214519
}
45224520
return ret;

src/validation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ class CChainState
595595
//! mempool that is kept in sync with the chain
596596
CTxMemPool& m_mempool;
597597

598+
const CChainParams& m_params;
599+
598600
//! Manages the UTXO set, which is a reflection of the contents of `m_chain`.
599601
std::unique_ptr<CoinsViews> m_coins_views;
600602

0 commit comments

Comments
 (0)