Skip to content

Commit f8e88ad

Browse files
UdjinM6ogabrielides
authored andcommitted
fix: avoid a crash on -reindex-chainstate (dashpay#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)_
1 parent 5132c11 commit f8e88ad

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/init.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,10 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
21212121
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
21222122
}
21232123

2124+
if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) {
2125+
chainstate->ResetBlockFailureFlags(nullptr);
2126+
}
2127+
21242128
} else {
21252129
// TODO: CEvoDB instance should probably be a part of CChainState
21262130
// (for multiple chainstates to actually work in parallel)
@@ -2132,10 +2136,6 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
21322136
break;
21332137
}
21342138
}
2135-
2136-
if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) {
2137-
::ChainstateActive().ResetBlockFailureFlags(nullptr);
2138-
}
21392139
}
21402140
} catch (const std::exception& e) {
21412141
LogPrintf("%s\n", e.what());

0 commit comments

Comments
 (0)