Add ChainstateManager::m_adjusted_time_callback

This decouples validation.cpp from netaddress.cpp (transitively,
timedata.cpp, and asmap.cpp).

This is important for libbitcoinkernel as:

- There is no reason for the consensus engine to be coupled with
  netaddress, timedata, and asmap
- Users of libbitcoinkernel can now easily supply their own
  std::function that provides the adjusted time.

See the src/Makefile.am changes for some satisfying removals.
This commit is contained in:
Carl Dong
2022-03-01 16:14:12 -05:00
parent dbe45c34f8
commit 04c31c1295
11 changed files with 24 additions and 14 deletions

View File

@@ -362,6 +362,7 @@ bool TestBlockValidity(BlockValidationState& state,
CChainState& chainstate,
const CBlock& block,
CBlockIndex* pindexPrev,
const std::function<int64_t()>& adjusted_time_callback,
bool fCheckPOW = true,
bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -837,6 +838,8 @@ private:
const CChainParams& m_chainparams;
const std::function<int64_t()> m_adjusted_time_callback;
//! Internal helper for ActivateSnapshot().
[[nodiscard]] bool PopulateAndValidateSnapshot(
CChainState& snapshot_chainstate,
@@ -857,7 +860,8 @@ public:
using Options = ChainstateManagerOpts;
explicit ChainstateManager(const Options& opts)
: m_chainparams(opts.chainparams) {};
: m_chainparams{opts.chainparams},
m_adjusted_time_callback{Assert(opts.adjusted_time_callback)} {};
const CChainParams& GetParams() const { return m_chainparams; }
const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }