aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2022-08-22 13:19:15 -0400
committerRyan Ofsky <ryan@ofsky.org>2022-08-22 13:19:15 -0400
commit7bc33a88f7817c7ff9cb5f9dcc751c2d2937ead0 (patch)
tree6a8fc74db3026a075fa88b4400169dc32559bd19 /src
parent2bd9aa5a44b88c866c4d98f8a7bf7154049cba31 (diff)
refactor: Move ChainstateManager options into m_options struct
Move ChainstateManager options into m_options struct to simplify class initialization, organize class members, and to name external option variables differently than internal state variables. This change was originally in #25862, but it was suggested to split off in https://github.com/bitcoin/bitcoin/pull/25862#discussion_r951459817 so it could be merged earlier and reduce conflicts with other PRs.
Diffstat (limited to 'src')
-rw-r--r--src/validation.cpp2
-rw-r--r--src/validation.h16
2 files changed, 8 insertions, 10 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index f4cae07b9e..0834dbe5a4 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3608,7 +3608,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
}
- if (!ContextualCheckBlockHeader(block, state, m_blockman, *this, pindexPrev, m_adjusted_time_callback())) {
+ if (!ContextualCheckBlockHeader(block, state, m_blockman, *this, pindexPrev, m_options.adjusted_time_callback())) {
LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
return false;
}
diff --git a/src/validation.h b/src/validation.h
index b1b6689c46..19241caeb9 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -838,10 +838,6 @@ private:
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
- const CChainParams m_chainparams;
-
- const std::function<NodeClock::time_point()> m_adjusted_time_callback;
-
//! Internal helper for ActivateSnapshot().
[[nodiscard]] bool PopulateAndValidateSnapshot(
CChainState& snapshot_chainstate,
@@ -861,12 +857,13 @@ private:
public:
using Options = kernel::ChainstateManagerOpts;
- explicit ChainstateManager(const Options& opts)
- : m_chainparams{opts.chainparams},
- m_adjusted_time_callback{Assert(opts.adjusted_time_callback)} {};
+ explicit ChainstateManager(Options options) : m_options{std::move(options)}
+ {
+ Assert(m_options.adjusted_time_callback);
+ }
- const CChainParams& GetParams() const { return m_chainparams; }
- const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }
+ const CChainParams& GetParams() const { return m_options.chainparams; }
+ const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
/**
* Alias for ::cs_main.
@@ -881,6 +878,7 @@ public:
*/
RecursiveMutex& GetMutex() const LOCK_RETURNED(::cs_main) { return ::cs_main; }
+ const Options m_options;
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.