mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
node/chainstate: Decouple from GetTime
...instead pass in a std::function<int64_t()> Note that the static_cast is needed (apparently) for the compiler to know which overloaded GetTime to choose.
This commit is contained in:
parent
2414ebc18b
commit
05441c2dc5
@ -1487,7 +1487,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
fReindexChainState,
|
||||
chainparams,
|
||||
check_blocks,
|
||||
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL));
|
||||
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
|
||||
static_cast<int64_t(*)()>(GetTime));
|
||||
} catch (const std::exception& e) {
|
||||
LogPrintf("%s\n", e.what());
|
||||
rv2 = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <node/chainstate.h>
|
||||
|
||||
#include <chainparams.h> // for CChainParams
|
||||
#include <util/time.h> // for GetTime
|
||||
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
|
||||
#include <shutdown.h> // for ShutdownRequested
|
||||
#include <validation.h> // for a lot of things
|
||||
@ -131,7 +130,8 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
|
||||
bool fReindexChainState,
|
||||
const CChainParams& chainparams,
|
||||
unsigned int check_blocks,
|
||||
unsigned int check_level)
|
||||
unsigned int check_level,
|
||||
std::function<int64_t()> get_unix_time_seconds)
|
||||
{
|
||||
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
|
||||
@ -143,7 +143,7 @@ std::optional<ChainstateLoadVerifyError> 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;
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
|
||||
bool fReindexChainState,
|
||||
const CChainParams& chainparams,
|
||||
unsigned int check_blocks,
|
||||
unsigned int check_level);
|
||||
unsigned int check_level,
|
||||
std::function<int64_t()> get_unix_time_seconds);
|
||||
|
||||
#endif // BITCOIN_NODE_CHAINSTATE_H
|
||||
|
Loading…
Reference in New Issue
Block a user