@@ -42,7 +42,7 @@ std::set<CBlockIndex*> setDirtyBlockIndex;
4242std::set<int > setDirtyFileInfo;
4343// } // namespace
4444
45- static FILE* OpenUndoFile (const FlatFilePos & pos, bool fReadOnly = false );
45+ static FILE* OpenUndoFile (const FlatFilePos& pos, bool fReadOnly = false );
4646static FlatFileSeq BlockFileSeq ();
4747static FlatFileSeq UndoFileSeq ();
4848
@@ -71,10 +71,11 @@ void CleanupBlockRevFiles()
7171 it->path ().filename ().string ().length () == 12 &&
7272 it->path ().filename ().string ().substr (8 ,4 ) == " .dat" )
7373 {
74- if (it->path ().filename ().string ().substr (0 ,3 ) == " blk" )
75- mapBlockFiles[it->path ().filename ().string ().substr (3 ,5 )] = it->path ();
76- else if (it->path ().filename ().string ().substr (0 ,3 ) == " rev" )
74+ if (it->path ().filename ().string ().substr (0 , 3 ) == " blk" ) {
75+ mapBlockFiles[it->path ().filename ().string ().substr (3 , 5 )] = it->path ();
76+ } else if (it->path ().filename ().string ().substr (0 , 3 ) == " rev" ) {
7777 remove (it->path ());
78+ }
7879 }
7980 }
8081
@@ -108,17 +109,19 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
108109{
109110 // Open history file to append
110111 CAutoFile fileout (OpenUndoFile (pos), SER_DISK, CLIENT_VERSION);
111- if (fileout.IsNull ())
112+ if (fileout.IsNull ()) {
112113 return error (" %s: OpenUndoFile failed" , __func__);
114+ }
113115
114116 // Write index header
115117 unsigned int nSize = GetSerializeSize (blockundo, fileout.GetVersion ());
116118 fileout << messageStart << nSize;
117119
118120 // Write undo data
119121 long fileOutPos = ftell (fileout.Get ());
120- if (fileOutPos < 0 )
122+ if (fileOutPos < 0 ) {
121123 return error (" %s: ftell failed" , __func__);
124+ }
122125 pos.nPos = (unsigned int )fileOutPos;
123126 fileout << blockundo;
124127
@@ -140,8 +143,9 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
140143
141144 // Open history file to read
142145 CAutoFile filein (OpenUndoFile (pos, true ), SER_DISK, CLIENT_VERSION);
143- if (filein.IsNull ())
146+ if (filein.IsNull ()) {
144147 return error (" %s: OpenUndoFile failed" , __func__);
148+ }
145149
146150 // Read block
147151 uint256 hashChecksum;
@@ -150,14 +154,14 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
150154 verifier << pindex->pprev ->GetBlockHash ();
151155 verifier >> blockundo;
152156 filein >> hashChecksum;
153- }
154- catch (const std::exception& e) {
157+ } catch (const std::exception& e) {
155158 return error (" %s: Deserialize or I/O error - %s" , __func__, e.what ());
156159 }
157160
158161 // Verify checksum
159- if (hashChecksum != verifier.GetHash ())
162+ if (hashChecksum != verifier.GetHash ()) {
160163 return error (" %s: Checksum mismatch" , __func__);
164+ }
161165
162166 return true ;
163167}
@@ -187,7 +191,7 @@ uint64_t CalculateCurrentUsage()
187191 LOCK (cs_LastBlockFile);
188192
189193 uint64_t retval = 0 ;
190- for (const CBlockFileInfo & file : vinfoBlockFile) {
194+ for (const CBlockFileInfo& file : vinfoBlockFile) {
191195 retval += file.nSize + file.nUndoSize ;
192196 }
193197 return retval;
@@ -213,16 +217,18 @@ static FlatFileSeq UndoFileSeq()
213217 return FlatFileSeq (gArgs .GetBlocksDirPath (), " rev" , UNDOFILE_CHUNK_SIZE);
214218}
215219
216- FILE* OpenBlockFile (const FlatFilePos &pos, bool fReadOnly ) {
220+ FILE* OpenBlockFile (const FlatFilePos& pos, bool fReadOnly )
221+ {
217222 return BlockFileSeq ().Open (pos, fReadOnly );
218223}
219224
220225/* * Open an undo file (rev?????.dat) */
221- static FILE* OpenUndoFile (const FlatFilePos &pos, bool fReadOnly ) {
226+ static FILE* OpenUndoFile (const FlatFilePos& pos, bool fReadOnly )
227+ {
222228 return UndoFileSeq ().Open (pos, fReadOnly );
223229}
224230
225- fs::path GetBlockPosFilename (const FlatFilePos & pos)
231+ fs::path GetBlockPosFilename (const FlatFilePos& pos)
226232{
227233 return BlockFileSeq ().FileName (pos);
228234}
@@ -262,10 +268,11 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
262268 }
263269
264270 vinfoBlockFile[nFile].AddBlock (nHeight, nTime);
265- if (fKnown )
271+ if (fKnown ) {
266272 vinfoBlockFile[nFile].nSize = std::max (pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize );
267- else
273+ } else {
268274 vinfoBlockFile[nFile].nSize += nAddSize;
275+ }
269276
270277 if (!fKnown ) {
271278 bool out_of_space;
@@ -282,7 +289,7 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
282289 return true ;
283290}
284291
285- static bool FindUndoPos (BlockValidationState & state, int nFile, FlatFilePos & pos, unsigned int nAddSize)
292+ static bool FindUndoPos (BlockValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize)
286293{
287294 pos.nFile = nFile;
288295
@@ -332,10 +339,12 @@ bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& st
332339 // Write undo information to disk
333340 if (pindex->GetUndoPos ().IsNull ()) {
334341 FlatFilePos _pos;
335- if (!FindUndoPos (state, pindex->nFile , _pos, ::GetSerializeSize (blockundo, CLIENT_VERSION) + 40 ))
342+ if (!FindUndoPos (state, pindex->nFile , _pos, ::GetSerializeSize (blockundo, CLIENT_VERSION) + 40 )) {
336343 return error (" ConnectBlock(): FindUndoPos failed" );
337- if (!UndoWriteToDisk (blockundo, _pos, pindex->pprev ->GetBlockHash (), chainparams.MessageStart ()))
344+ }
345+ if (!UndoWriteToDisk (blockundo, _pos, pindex->pprev ->GetBlockHash (), chainparams.MessageStart ())) {
338346 return AbortNode (state, " Failed to write undo data" );
347+ }
339348 // rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
340349 // we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
341350 // in the block file info as below; note that this does not catch the case where the undo writes are keeping up
0 commit comments