Skip to content

Commit d36bec9

Browse files
author
MacroFake
committed
Merge bitcoin#25905: refactor: Move ChainstateManager options into m_options struct
7bc33a8 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 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. ACKs for top commit: naumenkogs: ACK 7bc33a8 Tree-SHA512: 1c3c77be7db60222732221c087fd01cb802b84ac93333fccb38c8d16645f5f950c3362981021e7a3ae054f19fa7dd9e1cd15daaa101b61ca8853e42a1fd21474
2 parents 1420547 + 7bc33a8 commit d36bec9

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3608,7 +3608,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
36083608
LogPrint(BCLog::VALIDATION, "%s: %s prev block invalid\n", __func__, hash.ToString());
36093609
return state.Invalid(BlockValidationResult::BLOCK_INVALID_PREV, "bad-prevblk");
36103610
}
3611-
if (!ContextualCheckBlockHeader(block, state, m_blockman, *this, pindexPrev, m_adjusted_time_callback())) {
3611+
if (!ContextualCheckBlockHeader(block, state, m_blockman, *this, pindexPrev, m_options.adjusted_time_callback())) {
36123612
LogPrint(BCLog::VALIDATION, "%s: Consensus::ContextualCheckBlockHeader: %s, %s\n", __func__, hash.ToString(), state.ToString());
36133613
return false;
36143614
}

src/validation.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,6 @@ class ChainstateManager
838838

839839
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
840840

841-
const CChainParams m_chainparams;
842-
843-
const std::function<NodeClock::time_point()> m_adjusted_time_callback;
844-
845841
//! Internal helper for ActivateSnapshot().
846842
[[nodiscard]] bool PopulateAndValidateSnapshot(
847843
CChainState& snapshot_chainstate,
@@ -861,12 +857,13 @@ class ChainstateManager
861857
public:
862858
using Options = kernel::ChainstateManagerOpts;
863859

864-
explicit ChainstateManager(const Options& opts)
865-
: m_chainparams{opts.chainparams},
866-
m_adjusted_time_callback{Assert(opts.adjusted_time_callback)} {};
860+
explicit ChainstateManager(Options options) : m_options{std::move(options)}
861+
{
862+
Assert(m_options.adjusted_time_callback);
863+
}
867864

868-
const CChainParams& GetParams() const { return m_chainparams; }
869-
const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }
865+
const CChainParams& GetParams() const { return m_options.chainparams; }
866+
const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
870867

871868
/**
872869
* Alias for ::cs_main.
@@ -881,6 +878,7 @@ class ChainstateManager
881878
*/
882879
RecursiveMutex& GetMutex() const LOCK_RETURNED(::cs_main) { return ::cs_main; }
883880

881+
const Options m_options;
884882
std::thread m_load_block;
885883
//! A single BlockManager instance is shared across each constructed
886884
//! chainstate to avoid duplicating block metadata.

0 commit comments

Comments
 (0)