diff options
author | Carl Dong <contact@carldong.me> | 2022-01-11 14:49:28 -0500 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-04-27 11:13:38 -0400 |
commit | 572d8319272ae84a81d6bfd53dd9685585697f65 (patch) | |
tree | 7e847d5748c09523338d195cb45908a7cbf9858e | |
parent | eca4ca4d60599c9dbdd4e03a73beb33e9b44655a (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.cpp | 17 | ||||
-rw-r--r-- | src/validation.h | 5 |
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*)>; |