Skip to content

Commit

Permalink
refactor: Move ChainstateManager options into m_options struct
Browse files Browse the repository at this point in the history
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 bitcoin#25862, but it was suggested to split off in
bitcoin#25862 (comment) so it could
be merged earlier and reduce conflicts with other PRs.
  • Loading branch information
ryanofsky committed Aug 22, 2022
1 parent 2bd9aa5 commit 6db2c00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 7 additions & 9 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,6 @@ class ChainstateManager

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,
Expand All @@ -861,12 +857,13 @@ class ChainstateManager
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.
Expand All @@ -881,6 +878,7 @@ class ChainstateManager
*/
RecursiveMutex& GetMutex() const LOCK_RETURNED(::cs_main) { return ::cs_main; }

Options m_options;
std::thread m_load_block;
//! A single BlockManager instance is shared across each constructed
//! chainstate to avoid duplicating block metadata.
Expand Down

0 comments on commit 6db2c00

Please sign in to comment.