diff --git a/src/init.cpp b/src/init.cpp index eb4fd0d685..88610adfcb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1971,7 +1971,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) fReindexChainState, chainparams, check_blocks, - args.GetArg("-checklevel", DEFAULT_CHECKLEVEL)); + args.GetArg("-checklevel", DEFAULT_CHECKLEVEL), + static_cast(GetTime)); } catch (const std::exception& e) { LogPrintf("%s\n", e.what()); rv2 = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE; diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 59a91679ef..6ea69fcbb5 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -6,7 +6,6 @@ #include // for CChainParams #include // for DeploymentActiveAfter -#include // for GetTime #include // for CleanupBlockRevFiles, fHavePruned, fReindex #include // for ShutdownRequested #include // for a lot of things @@ -233,7 +232,8 @@ std::optional VerifyLoadedChainstate(ChainstateManage bool fReindexChainState, const CChainParams& chainparams, unsigned int check_blocks, - unsigned int check_level) + unsigned int check_level, + std::function get_unix_time_seconds) { auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull(); @@ -245,7 +245,7 @@ std::optional VerifyLoadedChainstate(ChainstateManage for (CChainState* chainstate : chainman.GetAll()) { if (!is_coinsview_empty(chainstate)) { const CBlockIndex* tip = chainstate->m_chain.Tip(); - if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) { + if (tip && tip->nTime > get_unix_time_seconds() + 2 * 60 * 60) { return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE; } const bool v19active{DeploymentActiveAfter(tip, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V19)}; diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 442d8b5f92..c838fd7851 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -120,6 +120,7 @@ std::optional VerifyLoadedChainstate(ChainstateManage bool fReindexChainState, const CChainParams& chainparams, unsigned int check_blocks, - unsigned int check_level); + unsigned int check_level, + std::function get_unix_time_seconds); #endif // BITCOIN_NODE_CHAINSTATE_H