aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-09-22 15:36:10 -0400
committerCarl Dong <contact@carldong.me>2021-12-07 14:48:49 -0500
commit05441c2dc5f60e2025476d8ec94c9025032d118c (patch)
tree50585cd5303a9adb3af83dfc73a2e6405400f396 /src/node
parent2414ebc18b8bebf79c47e58a4293d0fc6420a811 (diff)
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.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/chainstate.cpp6
-rw-r--r--src/node/chainstate.h3
2 files changed, 5 insertions, 4 deletions
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp
index 56d1073bab..242b202d2f 100644
--- a/src/node/chainstate.cpp
+++ b/src/node/chainstate.cpp
@@ -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;
}
diff --git a/src/node/chainstate.h b/src/node/chainstate.h
index 84a86a082b..3c950409d3 100644
--- a/src/node/chainstate.h
+++ b/src/node/chainstate.h
@@ -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