aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-01-11 14:49:28 -0500
committerCarl Dong <contact@carldong.me>2022-04-27 11:13:38 -0400
commit572d8319272ae84a81d6bfd53dd9685585697f65 (patch)
tree7e847d5748c09523338d195cb45908a7cbf9858e
parenteca4ca4d60599c9dbdd4e03a73beb33e9b44655a (diff)
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.
-rw-r--r--src/validation.cpp17
-rw-r--r--src/validation.h5
2 files changed, 14 insertions, 8 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 76dc5b7fc4..8448e45051 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -4151,10 +4151,6 @@ void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman)
AssertLockHeld(::cs_main);
chainman.Unload();
if (mempool) mempool->clear();
- g_versionbitscache.Clear();
- for (auto& i : warningcache) {
- i.clear();
- }
}
bool ChainstateManager::LoadBlockIndex()
@@ -5231,3 +5227,16 @@ void ChainstateManager::MaybeRebalanceCaches()
}
}
}
+
+ChainstateManager::~ChainstateManager()
+{
+ LOCK(::cs_main);
+ UnloadBlockIndex(/*mempool=*/nullptr, *this);
+
+ // TODO: The version bits cache and warning cache should probably become
+ // non-globals
+ g_versionbitscache.Clear();
+ for (auto& i : warningcache) {
+ i.clear();
+ }
+}
diff --git a/src/validation.h b/src/validation.h
index a8f6f007c3..3996086ced 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -995,10 +995,7 @@ public:
//! ResizeCoinsCaches() as needed.
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
- ~ChainstateManager() {
- LOCK(::cs_main);
- UnloadBlockIndex(/*mempool=*/nullptr, *this);
- }
+ ~ChainstateManager();
};
using FopenFn = std::function<FILE*(const fs::path&, const char*)>;