style: Add { } to multi-line if

Can be reviewed with --word-diff-regex=. --ignore-all-space
This commit is contained in:
MarcoFalke 2021-04-19 08:45:35 +02:00
parent fadafab833
commit fa09a9eac8
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548
2 changed files with 30 additions and 21 deletions

View File

@ -71,12 +71,13 @@ void CleanupBlockRevFiles()
it->path().filename().string().length() == 12 && it->path().filename().string().length() == 12 &&
it->path().filename().string().substr(8,4) == ".dat") it->path().filename().string().substr(8,4) == ".dat")
{ {
if (it->path().filename().string().substr(0,3) == "blk") if (it->path().filename().string().substr(0, 3) == "blk") {
mapBlockFiles[it->path().filename().string().substr(3, 5)] = it->path(); mapBlockFiles[it->path().filename().string().substr(3, 5)] = it->path();
else if (it->path().filename().string().substr(0,3) == "rev") } else if (it->path().filename().string().substr(0, 3) == "rev") {
remove(it->path()); remove(it->path());
} }
} }
}
// Remove all block files that aren't part of a contiguous set starting at // Remove all block files that aren't part of a contiguous set starting at
// zero by walking the ordered map (keys are block file indices) by // zero by walking the ordered map (keys are block file indices) by
@ -108,8 +109,9 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
{ {
// Open history file to append // Open history file to append
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
if (fileout.IsNull()) if (fileout.IsNull()) {
return error("%s: OpenUndoFile failed", __func__); return error("%s: OpenUndoFile failed", __func__);
}
// Write index header // Write index header
unsigned int nSize = GetSerializeSize(blockundo, fileout.GetVersion()); unsigned int nSize = GetSerializeSize(blockundo, fileout.GetVersion());
@ -117,8 +119,9 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const
// Write undo data // Write undo data
long fileOutPos = ftell(fileout.Get()); long fileOutPos = ftell(fileout.Get());
if (fileOutPos < 0) if (fileOutPos < 0) {
return error("%s: ftell failed", __func__); return error("%s: ftell failed", __func__);
}
pos.nPos = (unsigned int)fileOutPos; pos.nPos = (unsigned int)fileOutPos;
fileout << blockundo; fileout << blockundo;
@ -140,8 +143,9 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
// Open history file to read // Open history file to read
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION); CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
if (filein.IsNull()) if (filein.IsNull()) {
return error("%s: OpenUndoFile failed", __func__); return error("%s: OpenUndoFile failed", __func__);
}
// Read block // Read block
uint256 hashChecksum; uint256 hashChecksum;
@ -150,14 +154,14 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
verifier << pindex->pprev->GetBlockHash(); verifier << pindex->pprev->GetBlockHash();
verifier >> blockundo; verifier >> blockundo;
filein >> hashChecksum; filein >> hashChecksum;
} } catch (const std::exception& e) {
catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what()); return error("%s: Deserialize or I/O error - %s", __func__, e.what());
} }
// Verify checksum // Verify checksum
if (hashChecksum != verifier.GetHash()) if (hashChecksum != verifier.GetHash()) {
return error("%s: Checksum mismatch", __func__); return error("%s: Checksum mismatch", __func__);
}
return true; return true;
} }
@ -213,12 +217,14 @@ static FlatFileSeq UndoFileSeq()
return FlatFileSeq(gArgs.GetBlocksDirPath(), "rev", UNDOFILE_CHUNK_SIZE); return FlatFileSeq(gArgs.GetBlocksDirPath(), "rev", UNDOFILE_CHUNK_SIZE);
} }
FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly) { FILE* OpenBlockFile(const FlatFilePos& pos, bool fReadOnly)
{
return BlockFileSeq().Open(pos, fReadOnly); return BlockFileSeq().Open(pos, fReadOnly);
} }
/** Open an undo file (rev?????.dat) */ /** Open an undo file (rev?????.dat) */
static FILE* OpenUndoFile(const FlatFilePos &pos, bool fReadOnly) { static FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly)
{
return UndoFileSeq().Open(pos, fReadOnly); return UndoFileSeq().Open(pos, fReadOnly);
} }
@ -262,10 +268,11 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
} }
vinfoBlockFile[nFile].AddBlock(nHeight, nTime); vinfoBlockFile[nFile].AddBlock(nHeight, nTime);
if (fKnown) if (fKnown) {
vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize); vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize);
else } else {
vinfoBlockFile[nFile].nSize += nAddSize; vinfoBlockFile[nFile].nSize += nAddSize;
}
if (!fKnown) { if (!fKnown) {
bool out_of_space; bool out_of_space;
@ -332,10 +339,12 @@ bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& st
// Write undo information to disk // Write undo information to disk
if (pindex->GetUndoPos().IsNull()) { if (pindex->GetUndoPos().IsNull()) {
FlatFilePos _pos; FlatFilePos _pos;
if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
return error("ConnectBlock(): FindUndoPos failed"); return error("ConnectBlock(): FindUndoPos failed");
if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) }
if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) {
return AbortNode(state, "Failed to write undo data"); return AbortNode(state, "Failed to write undo data");
}
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order) // rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
// we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height // we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
// in the block file info as below; note that this does not catch the case where the undo writes are keeping up // in the block file info as below; note that this does not catch the case where the undo writes are keeping up