@@ -42,7 +42,7 @@ std::set<CBlockIndex*> setDirtyBlockIndex;
42
42
std::set<int > setDirtyFileInfo;
43
43
// } // namespace
44
44
45
- static FILE* OpenUndoFile (const FlatFilePos & pos, bool fReadOnly = false );
45
+ static FILE* OpenUndoFile (const FlatFilePos& pos, bool fReadOnly = false );
46
46
static FlatFileSeq BlockFileSeq ();
47
47
static FlatFileSeq UndoFileSeq ();
48
48
@@ -71,10 +71,11 @@ void CleanupBlockRevFiles()
71
71
it->path ().filename ().string ().length () == 12 &&
72
72
it->path ().filename ().string ().substr (8 ,4 ) == " .dat" )
73
73
{
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" ) {
77
77
remove (it->path ());
78
+ }
78
79
}
79
80
}
80
81
@@ -108,17 +109,19 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
108
109
{
109
110
// Open history file to append
110
111
CAutoFile fileout (OpenUndoFile (pos), SER_DISK, CLIENT_VERSION);
111
- if (fileout.IsNull ())
112
+ if (fileout.IsNull ()) {
112
113
return error (" %s: OpenUndoFile failed" , __func__);
114
+ }
113
115
114
116
// Write index header
115
117
unsigned int nSize = GetSerializeSize (blockundo, fileout.GetVersion ());
116
118
fileout << messageStart << nSize;
117
119
118
120
// Write undo data
119
121
long fileOutPos = ftell (fileout.Get ());
120
- if (fileOutPos < 0 )
122
+ if (fileOutPos < 0 ) {
121
123
return error (" %s: ftell failed" , __func__);
124
+ }
122
125
pos.nPos = (unsigned int )fileOutPos;
123
126
fileout << blockundo;
124
127
@@ -140,8 +143,9 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
140
143
141
144
// Open history file to read
142
145
CAutoFile filein (OpenUndoFile (pos, true ), SER_DISK, CLIENT_VERSION);
143
- if (filein.IsNull ())
146
+ if (filein.IsNull ()) {
144
147
return error (" %s: OpenUndoFile failed" , __func__);
148
+ }
145
149
146
150
// Read block
147
151
uint256 hashChecksum;
@@ -150,14 +154,14 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
150
154
verifier << pindex->pprev ->GetBlockHash ();
151
155
verifier >> blockundo;
152
156
filein >> hashChecksum;
153
- }
154
- catch (const std::exception& e) {
157
+ } catch (const std::exception& e) {
155
158
return error (" %s: Deserialize or I/O error - %s" , __func__, e.what ());
156
159
}
157
160
158
161
// Verify checksum
159
- if (hashChecksum != verifier.GetHash ())
162
+ if (hashChecksum != verifier.GetHash ()) {
160
163
return error (" %s: Checksum mismatch" , __func__);
164
+ }
161
165
162
166
return true ;
163
167
}
@@ -187,7 +191,7 @@ uint64_t CalculateCurrentUsage()
187
191
LOCK (cs_LastBlockFile);
188
192
189
193
uint64_t retval = 0 ;
190
- for (const CBlockFileInfo & file : vinfoBlockFile) {
194
+ for (const CBlockFileInfo& file : vinfoBlockFile) {
191
195
retval += file.nSize + file.nUndoSize ;
192
196
}
193
197
return retval;
@@ -213,16 +217,18 @@ static FlatFileSeq UndoFileSeq()
213
217
return FlatFileSeq (gArgs .GetBlocksDirPath (), " rev" , UNDOFILE_CHUNK_SIZE);
214
218
}
215
219
216
- FILE* OpenBlockFile (const FlatFilePos &pos, bool fReadOnly ) {
220
+ FILE* OpenBlockFile (const FlatFilePos& pos, bool fReadOnly )
221
+ {
217
222
return BlockFileSeq ().Open (pos, fReadOnly );
218
223
}
219
224
220
225
/* * 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
+ {
222
228
return UndoFileSeq ().Open (pos, fReadOnly );
223
229
}
224
230
225
- fs::path GetBlockPosFilename (const FlatFilePos & pos)
231
+ fs::path GetBlockPosFilename (const FlatFilePos& pos)
226
232
{
227
233
return BlockFileSeq ().FileName (pos);
228
234
}
@@ -262,10 +268,11 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
262
268
}
263
269
264
270
vinfoBlockFile[nFile].AddBlock (nHeight, nTime);
265
- if (fKnown )
271
+ if (fKnown ) {
266
272
vinfoBlockFile[nFile].nSize = std::max (pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize );
267
- else
273
+ } else {
268
274
vinfoBlockFile[nFile].nSize += nAddSize;
275
+ }
269
276
270
277
if (!fKnown ) {
271
278
bool out_of_space;
@@ -282,7 +289,7 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
282
289
return true ;
283
290
}
284
291
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)
286
293
{
287
294
pos.nFile = nFile;
288
295
@@ -332,10 +339,12 @@ bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& st
332
339
// Write undo information to disk
333
340
if (pindex->GetUndoPos ().IsNull ()) {
334
341
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 )) {
336
343
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 ())) {
338
346
return AbortNode (state, " Failed to write undo data" );
347
+ }
339
348
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
340
349
// we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
341
350
// 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