init: close the notarizations DB in Shutdown()

Shutdown() deleted pcoinsTip, pcoinsdbview and pblocktree but never
pnotarizations, so notarizations/LOCK was the one LevelDB lock still held
after "Shutdown: done". It was only released when the process was torn
down, after the static datadir .lock had already been released. A
successor started in that window took .lock, blocks/index and chainstate
and then failed to open notarizations/LOCK (EAGAIN), which the open
fallback "fixed" by moving the live notarizations DB aside and wiping it.

Delete it under cs_main next to pblocktree, and null the pointer after
the delete in the block-index load loop so a throwing reopen can never
leave it dangling for Shutdown() to delete twice.

Every user of pnotarizations now treats NULL as an empty DB
(GetBlockNotarizations, GetBackNotarization, ScanNotarizationsDB,
ConnectNotarizations, DisconnectNotarizations; crosschain.cpp,
rpc/crosschain.cpp, hush_nSPV_fullnode.h and hush_dailysnapshot only
reach it through those), so a straggler after Shutdown() cannot
dereference it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 10:23:20 -05:00
co-authored by Claude Opus 5.5
parent fe988d6fbe
commit f09f5a7b95
3 changed files with 22 additions and 1 deletions
+4
View File
@@ -2980,6 +2980,8 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const CO
void ConnectNotarizations(const CBlock &block, int height)
{
if (pnotarizations == NULL) // closed by Shutdown()
return;
NotarizationsInBlock notarizations = ScanBlockNotarizations(block, height);
if (notarizations.size() > 0) {
CDBBatch batch = CDBBatch(*pnotarizations);
@@ -2992,6 +2994,8 @@ void ConnectNotarizations(const CBlock &block, int height)
void DisconnectNotarizations(const CBlock &block)
{
if (pnotarizations == NULL) // closed by Shutdown()
return;
NotarizationsInBlock nibs;
if (GetBlockNotarizations(block.GetHash(), nibs)) {
CDBBatch batch = CDBBatch(*pnotarizations);