From 6b83576388e205116a0ebc67b9949f309eea1207 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Thu, 23 Dec 2021 16:26:15 -0500 Subject: [PATCH 1/4] node/chainstate: Use MAX_FUTURE_BLOCK_TIME --- src/node/chainstate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index abeebad1a6d..0274587e17b 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -141,7 +141,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 > get_unix_time_seconds() + 2 * 60 * 60) { + if (tip && tip->nTime > get_unix_time_seconds() + MAX_FUTURE_BLOCK_TIME) { return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE; } From 1dd582782d3c182aa952f23ec577f6a0a8672e7b Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Thu, 23 Dec 2021 16:41:53 -0500 Subject: [PATCH 2/4] docs: Make LoadChainstate comment more accurate --- src/node/chainstate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 11278a09911..4df917a281f 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -50,7 +50,7 @@ enum class ChainstateLoadingError { * this sequence, when we explicitly checked shutdown_requested() at * arbitrary points, one of those calls returned true". Therefore, a * return value other than SHUTDOWN_PROBED does not guarantee that - * shutdown_requested() hasn't been called indirectly. + * shutdown hasn't been called indirectly. * - else * - Success! */ From 3401630417d994b53ff3a89db2ea759ab1ec6f0f Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Thu, 23 Dec 2021 16:40:03 -0500 Subject: [PATCH 3/4] style-only: Rename *Chainstate return values --- src/init.cpp | 64 +++++++++++++++++----------------- src/test/util/setup_common.cpp | 28 +++++++-------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 1f4537a975d..d14a0baef1b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1404,31 +1404,31 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) uiInterface.InitMessage(_("Loading block index…").translated); const int64_t load_block_index_start_time = GetTimeMillis(); - std::optional rv; + std::optional maybe_load_error; try { - rv = LoadChainstate(fReset, - chainman, - Assert(node.mempool.get()), - fPruneMode, - chainparams.GetConsensus(), - fReindexChainState, - cache_sizes.block_tree_db, - cache_sizes.coins_db, - cache_sizes.coins, - false, - false, - ShutdownRequested, - []() { - uiInterface.ThreadSafeMessageBox( - _("Error reading from database, shutting down."), - "", CClientUIInterface::MSG_ERROR); - }); + maybe_load_error = LoadChainstate(fReset, + chainman, + Assert(node.mempool.get()), + fPruneMode, + chainparams.GetConsensus(), + fReindexChainState, + cache_sizes.block_tree_db, + cache_sizes.coins_db, + cache_sizes.coins, + false, + false, + ShutdownRequested, + []() { + uiInterface.ThreadSafeMessageBox( + _("Error reading from database, shutting down."), + "", CClientUIInterface::MSG_ERROR); + }); } catch (const std::exception& e) { LogPrintf("%s\n", e.what()); - rv = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED; + maybe_load_error = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED; } - if (rv.has_value()) { - switch (rv.value()) { + if (maybe_load_error.has_value()) { + switch (maybe_load_error.value()) { case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB: strLoadError = _("Error loading block database"); break; @@ -1462,7 +1462,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) break; } } else { - std::optional rv2; + std::optional maybe_verify_error; try { uiInterface.InitMessage(_("Verifying blocks…").translated); auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS); @@ -1470,19 +1470,19 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n", MIN_BLOCKS_TO_KEEP); } - rv2 = VerifyLoadedChainstate(chainman, - fReset, - fReindexChainState, - chainparams.GetConsensus(), - check_blocks, - args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL), - static_cast(GetTime)); + maybe_verify_error = VerifyLoadedChainstate(chainman, + fReset, + fReindexChainState, + chainparams.GetConsensus(), + check_blocks, + args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL), + static_cast(GetTime)); } catch (const std::exception& e) { LogPrintf("%s\n", e.what()); - rv2 = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE; + maybe_verify_error = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE; } - if (rv2.has_value()) { - switch (rv2.value()) { + if (maybe_verify_error.has_value()) { + switch (maybe_verify_error.value()) { case ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE: strLoadError = _("The block database contains a block which appears to be from the future. " "This may be due to your computer's date and time being set incorrectly. " diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index eb23e8725f1..38b07b35baa 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -182,20 +182,20 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector(GetTime)); - assert(!maybe_verify_failure.has_value()); + assert(!maybe_verify_error.has_value()); BlockValidationState state; if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) { From e3544c864e3e56867de25b8db7b012d58b378050 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Thu, 23 Dec 2021 17:38:09 -0500 Subject: [PATCH 4/4] init: Use clang-tidy named args syntax --- src/init.cpp | 10 +++++----- src/test/util/setup_common.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index d14a0baef1b..5a3134f9d63 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1415,10 +1415,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) cache_sizes.block_tree_db, cache_sizes.coins_db, cache_sizes.coins, - false, - false, - ShutdownRequested, - []() { + /*block_tree_db_in_memory=*/false, + /*coins_db_in_memory=*/false, + /*shutdown_requested=*/ShutdownRequested, + /*coins_error_cb=*/[]() { uiInterface.ThreadSafeMessageBox( _("Error reading from database, shutting down."), "", CClientUIInterface::MSG_ERROR); @@ -1476,7 +1476,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) chainparams.GetConsensus(), check_blocks, args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL), - static_cast(GetTime)); + /*get_unix_time_seconds=*/static_cast(GetTime)); } catch (const std::exception& e) { LogPrintf("%s\n", e.what()); maybe_verify_error = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE; diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 38b07b35baa..dcb2e75932a 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -191,8 +191,8 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector(GetTime)); + /*get_unix_time_seconds=*/static_cast(GetTime)); assert(!maybe_verify_error.has_value()); BlockValidationState state;