Skip to content

Commit fa467f3

Browse files
author
MarcoFalke
committed
move-only: Create WriteBlockIndexDB helper
Can be reviewed with --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
1 parent fa88cfd commit fa467f3

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/node/blockstorage.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,26 @@ void BlockManager::Unload()
350350
m_block_index.clear();
351351
}
352352

353+
bool BlockManager::WriteBlockIndexDB()
354+
{
355+
std::vector<std::pair<int, const CBlockFileInfo*>> vFiles;
356+
vFiles.reserve(setDirtyFileInfo.size());
357+
for (std::set<int>::iterator it = setDirtyFileInfo.begin(); it != setDirtyFileInfo.end();) {
358+
vFiles.push_back(std::make_pair(*it, &vinfoBlockFile[*it]));
359+
setDirtyFileInfo.erase(it++);
360+
}
361+
std::vector<const CBlockIndex*> vBlocks;
362+
vBlocks.reserve(setDirtyBlockIndex.size());
363+
for (std::set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin(); it != setDirtyBlockIndex.end();) {
364+
vBlocks.push_back(*it);
365+
setDirtyBlockIndex.erase(it++);
366+
}
367+
if (!m_block_tree_db->WriteBatchSync(vFiles, nLastBlockFile, vBlocks)) {
368+
return false;
369+
}
370+
return true;
371+
}
372+
353373
bool BlockManager::LoadBlockIndexDB(ChainstateManager& chainman)
354374
{
355375
if (!LoadBlockIndex(::Params().GetConsensus(), chainman)) {

src/node/blockstorage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class BlockManager
102102

103103
std::unique_ptr<CBlockTreeDB> m_block_tree_db GUARDED_BY(::cs_main);
104104

105+
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
105106
bool LoadBlockIndexDB(ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
106107

107108
/**

src/validation.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,19 +2276,7 @@ bool CChainState::FlushStateToDisk(
22762276
{
22772277
LOG_TIME_MILLIS_WITH_CATEGORY("write block index to disk", BCLog::BENCH);
22782278

2279-
std::vector<std::pair<int, const CBlockFileInfo*> > vFiles;
2280-
vFiles.reserve(setDirtyFileInfo.size());
2281-
for (std::set<int>::iterator it = setDirtyFileInfo.begin(); it != setDirtyFileInfo.end(); ) {
2282-
vFiles.push_back(std::make_pair(*it, &vinfoBlockFile[*it]));
2283-
setDirtyFileInfo.erase(it++);
2284-
}
2285-
std::vector<const CBlockIndex*> vBlocks;
2286-
vBlocks.reserve(setDirtyBlockIndex.size());
2287-
for (std::set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin(); it != setDirtyBlockIndex.end(); ) {
2288-
vBlocks.push_back(*it);
2289-
setDirtyBlockIndex.erase(it++);
2290-
}
2291-
if (!m_blockman.m_block_tree_db->WriteBatchSync(vFiles, nLastBlockFile, vBlocks)) {
2279+
if (!m_blockman.WriteBlockIndexDB()) {
22922280
return AbortNode(state, "Failed to write to block index database");
22932281
}
22942282
}

0 commit comments

Comments
 (0)