Skip to content

Commit fa14e1d

Browse files
author
MarcoFalke
committed
log: Fix __func__ in LogError in blockstorage module
These errors should never happen. However, when they do happen, it is useful to log the correct error location (function name). For example, this fixes an incorrect "ConnectBlock()" in "WriteUndoDataForBlock".
1 parent fad59a2 commit fa14e1d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/node/blockstorage.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
981981
// Open history file to append
982982
AutoFile fileout{OpenBlockFile(pos)};
983983
if (fileout.IsNull()) {
984-
LogError("WriteBlockToDisk: OpenBlockFile failed\n");
984+
LogError("%s: OpenBlockFile failed\n", __func__);
985985
return false;
986986
}
987987

@@ -992,7 +992,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
992992
// Write block
993993
long fileOutPos = ftell(fileout.Get());
994994
if (fileOutPos < 0) {
995-
LogError("WriteBlockToDisk: ftell failed\n");
995+
LogError("%s: ftell failed\n", __func__);
996996
return false;
997997
}
998998
pos.nPos = (unsigned int)fileOutPos;
@@ -1011,7 +1011,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
10111011
if (block.GetUndoPos().IsNull()) {
10121012
FlatFilePos _pos;
10131013
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) {
1014-
LogError("ConnectBlock(): FindUndoPos failed\n");
1014+
LogError("%s: FindUndoPos failed\n", __func__);
10151015
return false;
10161016
}
10171017
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
@@ -1050,7 +1050,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
10501050
// Open history file to read
10511051
AutoFile filein{OpenBlockFile(pos, true)};
10521052
if (filein.IsNull()) {
1053-
LogError("ReadBlockFromDisk: OpenBlockFile failed for %s\n", pos.ToString());
1053+
LogError("%s: OpenBlockFile failed for %s\n", __func__, pos.ToString());
10541054
return false;
10551055
}
10561056

@@ -1064,13 +1064,13 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
10641064

10651065
// Check the header
10661066
if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) {
1067-
LogError("ReadBlockFromDisk: Errors in block header at %s\n", pos.ToString());
1067+
LogError("%s: Errors in block header at %s\n", __func__, pos.ToString());
10681068
return false;
10691069
}
10701070

10711071
// Signet only: check block solution
10721072
if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) {
1073-
LogError("ReadBlockFromDisk: Errors in block solution at %s\n", pos.ToString());
1073+
LogError("%s: Errors in block solution at %s\n", __func__, pos.ToString());
10741074
return false;
10751075
}
10761076

@@ -1085,8 +1085,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
10851085
return false;
10861086
}
10871087
if (block.GetHash() != index.GetBlockHash()) {
1088-
LogError("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s\n",
1089-
index.ToString(), block_pos.ToString());
1088+
LogError("%s: GetHash() doesn't match index for %s at %s\n", __func__, index.ToString(), block_pos.ToString());
10901089
return false;
10911090
}
10921091
return true;

0 commit comments

Comments
 (0)