Skip to content

Commit 7ab07e0

Browse files
committed
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.
1 parent 7d99d72 commit 7ab07e0

File tree

6 files changed

+0
-54
lines changed

6 files changed

+0
-54
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,5 @@ int main(int argc, char* argv[])
256256
}
257257
GetMainSignals().UnregisterBackgroundSignalScheduler();
258258

259-
WITH_LOCK(::cs_main, UnloadBlockIndex(chainman));
260-
261259
init::UnsetGlobals();
262260
}

src/node/blockstorage.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,6 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
297297
return true;
298298
}
299299

300-
void BlockManager::Unload()
301-
{
302-
m_blocks_unlinked.clear();
303-
304-
m_block_index.clear();
305-
306-
m_blockfile_info.clear();
307-
m_last_blockfile = 0;
308-
m_dirty_blockindex.clear();
309-
m_dirty_fileinfo.clear();
310-
311-
m_have_pruned = false;
312-
}
313-
314300
bool BlockManager::WriteBlockIndexDB()
315301
{
316302
AssertLockHeld(::cs_main);

src/node/blockstorage.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ class BlockManager
154154
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
155155
bool LoadBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
156156

157-
/** Clear all data members. */
158-
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
159-
160157
CBlockIndex* AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
161158
/** Create a new block index entry for a given block hash */
162159
CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@@ -189,11 +186,6 @@ class BlockManager
189186

190187
//! Create or update a prune lock identified by its name
191188
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
192-
193-
~BlockManager()
194-
{
195-
Unload();
196-
}
197189
};
198190

199191
//! Find the first block that is not pruned

src/test/util/setup_common.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ ChainTestingSetup::~ChainTestingSetup()
182182
m_node.addrman.reset();
183183
m_node.netgroupman.reset();
184184
m_node.args = nullptr;
185-
WITH_LOCK(::cs_main, UnloadBlockIndex(*m_node.chainman));
186185
m_node.mempool.reset();
187186
m_node.scheduler.reset();
188187
m_node.chainman.reset();

src/validation.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4143,15 +4143,6 @@ void CChainState::UnloadBlockIndex()
41434143
setBlockIndexCandidates.clear();
41444144
}
41454145

4146-
// May NOT be used after any connections are up as much
4147-
// of the peer-processing logic assumes a consistent
4148-
// block index state
4149-
void UnloadBlockIndex(ChainstateManager& chainman)
4150-
{
4151-
AssertLockHeld(::cs_main);
4152-
chainman.Unload();
4153-
}
4154-
41554146
bool ChainstateManager::LoadBlockIndex()
41564147
{
41574148
AssertLockHeld(cs_main);
@@ -5182,20 +5173,6 @@ bool ChainstateManager::IsSnapshotActive() const
51825173
return m_snapshot_chainstate && m_active_chainstate == m_snapshot_chainstate.get();
51835174
}
51845175

5185-
void ChainstateManager::Unload()
5186-
{
5187-
AssertLockHeld(::cs_main);
5188-
for (CChainState* chainstate : this->GetAll()) {
5189-
chainstate->m_chain.SetTip(nullptr);
5190-
chainstate->UnloadBlockIndex();
5191-
}
5192-
5193-
m_failed_blocks.clear();
5194-
m_blockman.Unload();
5195-
m_best_header = nullptr;
5196-
m_best_invalid = nullptr;
5197-
}
5198-
51995176
void ChainstateManager::MaybeRebalanceCaches()
52005177
{
52015178
AssertLockHeld(::cs_main);
@@ -5230,7 +5207,6 @@ void ChainstateManager::MaybeRebalanceCaches()
52305207
ChainstateManager::~ChainstateManager()
52315208
{
52325209
LOCK(::cs_main);
5233-
UnloadBlockIndex(*this);
52345210

52355211
// TODO: The version bits cache and warning cache should probably become
52365212
// non-globals

src/validation.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ extern arith_uint256 nMinimumChainWork;
134134
/** Documentation for argument 'checklevel'. */
135135
extern const std::vector<std::string> CHECKLEVEL_DOC;
136136

137-
/** Unload database information */
138-
void UnloadBlockIndex(ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
139137
/** Run instances of script checking worker threads */
140138
void StartScriptCheckWorkerThreads(int threads_num);
141139
/** Stop all of the script checking worker threads */
@@ -988,9 +986,6 @@ class ChainstateManager
988986
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
989987
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
990988

991-
//! Unload block index and chain data before shutdown.
992-
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
993-
994989
//! Check to see if caches are out of balance and if so, call
995990
//! ResizeCoinsCaches() as needed.
996991
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

0 commit comments

Comments
 (0)