@@ -3538,25 +3538,23 @@ bool static FlushStateToDisk(CValidationState& state, FlushStateMode mode)
35383538 // First make sure all block and undo data is flushed to disk.
35393539 FlushBlockFile ();
35403540 // Then update all block file information (which may refer to block and undo files).
3541- bool fileschanged = false ;
3542- for (set<int >::iterator it = setDirtyFileInfo.begin (); it != setDirtyFileInfo.end ();) {
3543- if (!pblocktree->WriteBlockFileInfo (*it, vinfoBlockFile[*it])) {
3544- return state.Abort (" Failed to write to block index" );
3541+ {
3542+ std::vector<std::pair<int , const CBlockFileInfo*> > vFiles;
3543+ vFiles.reserve (setDirtyFileInfo.size ());
3544+ for (set<int >::iterator it = setDirtyFileInfo.begin (); it != setDirtyFileInfo.end (); ) {
3545+ vFiles.push_back (make_pair (*it, &vinfoBlockFile[*it]));
3546+ setDirtyFileInfo.erase (it++);
35453547 }
3546- fileschanged = true ;
3547- setDirtyFileInfo.erase (it++);
3548- }
3549- if (fileschanged && !pblocktree->WriteLastBlockFile (nLastBlockFile)) {
3550- return state.Abort (" Failed to write to block index" );
3551- }
3552- for (set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin (); it != setDirtyBlockIndex.end ();) {
3553- if (!pblocktree->WriteBlockIndex (CDiskBlockIndex (*it))) {
3554- return state.Abort (" Failed to write to block index" );
3548+ std::vector<const CBlockIndex*> vBlocks;
3549+ vBlocks.reserve (setDirtyBlockIndex.size ());
3550+ for (set<CBlockIndex*>::iterator it = setDirtyBlockIndex.begin (); it != setDirtyBlockIndex.end (); ) {
3551+ vBlocks.push_back (*it);
3552+ setDirtyBlockIndex.erase (it++);
3553+ }
3554+ if (!pblocktree->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
3555+ return state.Abort (" Files to write to block index database" );
35553556 }
3556- setDirtyBlockIndex.erase (it++);
35573557 }
3558-
3559- pblocktree->Sync ();
35603558 // Finally flush the chainstate (which may refer to block index entries).
35613559 if (!pcoinsTip->Flush ())
35623560 return state.Abort (" Failed to write to coin database" );
0 commit comments