Skip to content

Commit 572d831

Browse files
committed
Clear {versionbits,warning}cache in ~Chainstatemanager
Also add TODO item to deglobalize the {versionbits,warning}cache, which should really only need to be cleared if we change the chainparams.
1 parent eca4ca4 commit 572d831

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/validation.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,10 +4151,6 @@ void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
41514151
AssertLockHeld(::cs_main);
41524152
chainman.Unload();
41534153
if (mempool) mempool->clear();
4154-
g_versionbitscache.Clear();
4155-
for (auto& i : warningcache) {
4156-
i.clear();
4157-
}
41584154
}
41594155

41604156
bool ChainstateManager::LoadBlockIndex()
@@ -5231,3 +5227,16 @@ void ChainstateManager::MaybeRebalanceCaches()
52315227
}
52325228
}
52335229
}
5230+
5231+
ChainstateManager::~ChainstateManager()
5232+
{
5233+
LOCK(::cs_main);
5234+
UnloadBlockIndex(/*mempool=*/nullptr, *this);
5235+
5236+
// TODO: The version bits cache and warning cache should probably become
5237+
// non-globals
5238+
g_versionbitscache.Clear();
5239+
for (auto& i : warningcache) {
5240+
i.clear();
5241+
}
5242+
}

src/validation.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -995,10 +995,7 @@ class ChainstateManager
995995
//! ResizeCoinsCaches() as needed.
996996
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
997997

998-
~ChainstateManager() {
999-
LOCK(::cs_main);
1000-
UnloadBlockIndex(/*mempool=*/nullptr, *this);
1001-
}
998+
~ChainstateManager();
1002999
};
10031000

10041001
using FopenFn = std::function<FILE*(const fs::path&, const char*)>;

0 commit comments

Comments
 (0)