From f8e88adadcc981dc218d60d53898f3865240a5a0 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 30 Nov 2023 23:16:45 +0300 Subject: [PATCH] fix: avoid a crash on -reindex-chainstate (#5746) ## Issue being fixed or feature implemented Avoid a crash on -reindex-chainstate. ## What was done? `ResetBlockFailureFlags` is crashing when `m_chain.Tip()` is null. Call `ResetBlockFailureFlags` inside `if (!is_coinsview_empty(chainstate)) {...}` block - we know `m_chain.Tip()` is not null there. ## How Has This Been Tested? Try running a node with `-reindex-chainstate` cmd-line param w/ and w/out this patch. ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ --- src/init.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 518bb71c76..9b139e4b5a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2121,6 +2121,10 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load()); } + if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) { + chainstate->ResetBlockFailureFlags(nullptr); + } + } else { // TODO: CEvoDB instance should probably be a part of CChainState // (for multiple chainstates to actually work in parallel) @@ -2132,10 +2136,6 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc break; } } - - if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) { - ::ChainstateActive().ResetBlockFailureFlags(nullptr); - } } } catch (const std::exception& e) { LogPrintf("%s\n", e.what());