validation: Prune UnloadBlockIndex and callees

In previous commits in this patchset, we've made sure that every
Unload/UnloadBlockIndex member function resets its own members, and does
not reach out to globals.

This means that their corresponding classes' default destructors can now
replace them, and do an even more thorough job without the need to be
updated for every new member variable.

Therefore, we can remove them, and also remove UnloadBlockIndex since
that's not used anymore.

Unfortunately, chainstatemanager_loadblockindex relies on
CChainState::UnloadBlockIndex, so that needs to stay for now.
This commit is contained in:
Carl Dong
2021-01-12 13:38:53 -05:00
parent 7d99d725cd
commit 7ab07e0332
6 changed files with 0 additions and 54 deletions

View File

@@ -256,7 +256,5 @@ epilogue:
}
GetMainSignals().UnregisterBackgroundSignalScheduler();
WITH_LOCK(::cs_main, UnloadBlockIndex(chainman));
init::UnsetGlobals();
}

View File

@@ -297,20 +297,6 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
return true;
}
void BlockManager::Unload()
{
m_blocks_unlinked.clear();
m_block_index.clear();
m_blockfile_info.clear();
m_last_blockfile = 0;
m_dirty_blockindex.clear();
m_dirty_fileinfo.clear();
m_have_pruned = false;
}
bool BlockManager::WriteBlockIndexDB()
{
AssertLockHeld(::cs_main);

View File

@@ -154,9 +154,6 @@ public:
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
bool LoadBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/** Clear all data members. */
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
CBlockIndex* AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/** Create a new block index entry for a given block hash */
CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -189,11 +186,6 @@ public:
//! Create or update a prune lock identified by its name
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
~BlockManager()
{
Unload();
}
};
//! Find the first block that is not pruned

View File

@@ -182,7 +182,6 @@ ChainTestingSetup::~ChainTestingSetup()
m_node.addrman.reset();
m_node.netgroupman.reset();
m_node.args = nullptr;
WITH_LOCK(::cs_main, UnloadBlockIndex(*m_node.chainman));
m_node.mempool.reset();
m_node.scheduler.reset();
m_node.chainman.reset();

View File

@@ -4143,15 +4143,6 @@ void CChainState::UnloadBlockIndex()
setBlockIndexCandidates.clear();
}
// May NOT be used after any connections are up as much
// of the peer-processing logic assumes a consistent
// block index state
void UnloadBlockIndex(ChainstateManager& chainman)
{
AssertLockHeld(::cs_main);
chainman.Unload();
}
bool ChainstateManager::LoadBlockIndex()
{
AssertLockHeld(cs_main);
@@ -5182,20 +5173,6 @@ bool ChainstateManager::IsSnapshotActive() const
return m_snapshot_chainstate && m_active_chainstate == m_snapshot_chainstate.get();
}
void ChainstateManager::Unload()
{
AssertLockHeld(::cs_main);
for (CChainState* chainstate : this->GetAll()) {
chainstate->m_chain.SetTip(nullptr);
chainstate->UnloadBlockIndex();
}
m_failed_blocks.clear();
m_blockman.Unload();
m_best_header = nullptr;
m_best_invalid = nullptr;
}
void ChainstateManager::MaybeRebalanceCaches()
{
AssertLockHeld(::cs_main);
@@ -5230,7 +5207,6 @@ void ChainstateManager::MaybeRebalanceCaches()
ChainstateManager::~ChainstateManager()
{
LOCK(::cs_main);
UnloadBlockIndex(*this);
// TODO: The version bits cache and warning cache should probably become
// non-globals

View File

@@ -134,8 +134,6 @@ extern arith_uint256 nMinimumChainWork;
/** Documentation for argument 'checklevel'. */
extern const std::vector<std::string> CHECKLEVEL_DOC;
/** Unload database information */
void UnloadBlockIndex(ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/** Run instances of script checking worker threads */
void StartScriptCheckWorkerThreads(int threads_num);
/** Stop all of the script checking worker threads */
@@ -988,9 +986,6 @@ public:
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
//! Unload block index and chain data before shutdown.
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
//! Check to see if caches are out of balance and if so, call
//! ResizeCoinsCaches() as needed.
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);