style: Add { } to multi-line if

Can be reviewed with --word-diff-regex=. --ignore-all-space
pull/21727/head
MarcoFalke 4 years ago
parent fadafab833
commit fa09a9eac8
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

@ -42,7 +42,7 @@ std::set<CBlockIndex*> setDirtyBlockIndex;
std::set<int> setDirtyFileInfo; std::set<int> setDirtyFileInfo;
// } // namespace // } // namespace
static FILE* OpenUndoFile(const FlatFilePos &pos, bool fReadOnly = false); static FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false);
static FlatFileSeq BlockFileSeq(); static FlatFileSeq BlockFileSeq();
static FlatFileSeq UndoFileSeq(); static FlatFileSeq UndoFileSeq();
@ -71,10 +71,11 @@ 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());
}
} }
} }
@ -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;
} }
@ -187,7 +191,7 @@ uint64_t CalculateCurrentUsage()
LOCK(cs_LastBlockFile); LOCK(cs_LastBlockFile);
uint64_t retval = 0; uint64_t retval = 0;
for (const CBlockFileInfo &file : vinfoBlockFile) { for (const CBlockFileInfo& file : vinfoBlockFile) {
retval += file.nSize + file.nUndoSize; retval += file.nSize + file.nUndoSize;
} }
return retval; return retval;
@ -213,16 +217,18 @@ 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);
} }
fs::path GetBlockPosFilename(const FlatFilePos &pos) fs::path GetBlockPosFilename(const FlatFilePos& pos)
{ {
return BlockFileSeq().FileName(pos); return BlockFileSeq().FileName(pos);
} }
@ -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;
@ -282,7 +289,7 @@ bool FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight,
return true; return true;
} }
static bool FindUndoPos(BlockValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize) static bool FindUndoPos(BlockValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize)
{ {
pos.nFile = nFile; pos.nFile = nFile;
@ -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

@ -50,9 +50,9 @@ bool IsBlockPruned(const CBlockIndex* pblockindex);
void CleanupBlockRevFiles(); void CleanupBlockRevFiles();
/** Open a block file (blk?????.dat) */ /** Open a block file (blk?????.dat) */
FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly = false); FILE* OpenBlockFile(const FlatFilePos& pos, bool fReadOnly = false);
/** Translation to a filesystem path */ /** Translation to a filesystem path */
fs::path GetBlockPosFilename(const FlatFilePos &pos); fs::path GetBlockPosFilename(const FlatFilePos& pos);
/** Get block file info entry for one block file */ /** Get block file info entry for one block file */
CBlockFileInfo* GetBlockFileInfo(size_t n); CBlockFileInfo* GetBlockFileInfo(size_t n);

Loading…
Cancel
Save