0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

Merge bitcoin/bitcoin#25905: refactor: Move ChainstateManager options into m_options struct

7bc33a88f7 refactor: Move ChainstateManager options into m_options struct (Ryan Ofsky)

Pull request description:

  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.

ACKs for top commit:
  naumenkogs:
    ACK 7bc33a88f7

Tree-SHA512: 1c3c77be7db60222732221c087fd01cb802b84ac93333fccb38c8d16645f5f950c3362981021e7a3ae054f19fa7dd9e1cd15daaa101b61ca8853e42a1fd21474
This commit is contained in:
MacroFake 2022-08-25 09:48:05 +02:00
commit d36bec9b3b
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 8 additions and 10 deletions

View file

@ -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;
}

View file

@ -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.