File tree Expand file tree Collapse file tree 3 files changed +22
-13
lines changed Expand file tree Collapse file tree 3 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -350,6 +350,26 @@ void BlockManager::Unload()
350
350
m_block_index.clear ();
351
351
}
352
352
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
+
353
373
bool BlockManager::LoadBlockIndexDB (ChainstateManager& chainman)
354
374
{
355
375
if (!LoadBlockIndex (::Params ().GetConsensus (), chainman)) {
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ class BlockManager
102
102
103
103
std::unique_ptr<CBlockTreeDB> m_block_tree_db GUARDED_BY (::cs_main);
104
104
105
+ bool WriteBlockIndexDB () EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
105
106
bool LoadBlockIndexDB (ChainstateManager& chainman) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
106
107
107
108
/* *
Original file line number Diff line number Diff line change @@ -2276,19 +2276,7 @@ bool CChainState::FlushStateToDisk(
2276
2276
{
2277
2277
LOG_TIME_MILLIS_WITH_CATEGORY (" write block index to disk" , BCLog::BENCH);
2278
2278
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 ()) {
2292
2280
return AbortNode (state, " Failed to write to block index database" );
2293
2281
}
2294
2282
}
You can’t perform that action at this time.
0 commit comments