From 572d8319272ae84a81d6bfd53dd9685585697f65 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Tue, 11 Jan 2022 14:49:28 -0500 Subject: [PATCH] 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. --- src/validation.cpp | 17 +++++++++++++---- src/validation.h | 5 +---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 76dc5b7fc4c..8448e45051d 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 a8f6f007c31..3996086cedf 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;