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".
This commit is contained in:
MarcoFalke 2024-07-11 16:41:42 +02:00
parent fad59a2f0f
commit fa14e1d9d5
No known key found for this signature in database

View file

@ -981,7 +981,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
// Open history file to append // Open history file to append
AutoFile fileout{OpenBlockFile(pos)}; AutoFile fileout{OpenBlockFile(pos)};
if (fileout.IsNull()) { if (fileout.IsNull()) {
LogError("WriteBlockToDisk: OpenBlockFile failed\n"); LogError("%s: OpenBlockFile failed\n", __func__);
return false; return false;
} }
@ -992,7 +992,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
// Write block // Write block
long fileOutPos = ftell(fileout.Get()); long fileOutPos = ftell(fileout.Get());
if (fileOutPos < 0) { if (fileOutPos < 0) {
LogError("WriteBlockToDisk: ftell failed\n"); LogError("%s: ftell failed\n", __func__);
return false; return false;
} }
pos.nPos = (unsigned int)fileOutPos; pos.nPos = (unsigned int)fileOutPos;
@ -1011,7 +1011,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
if (block.GetUndoPos().IsNull()) { if (block.GetUndoPos().IsNull()) {
FlatFilePos _pos; FlatFilePos _pos;
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) { if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) {
LogError("ConnectBlock(): FindUndoPos failed\n"); LogError("%s: FindUndoPos failed\n", __func__);
return false; return false;
} }
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) { if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
@ -1050,7 +1050,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
// Open history file to read // Open history file to read
AutoFile filein{OpenBlockFile(pos, true)}; AutoFile filein{OpenBlockFile(pos, true)};
if (filein.IsNull()) { if (filein.IsNull()) {
LogError("ReadBlockFromDisk: OpenBlockFile failed for %s\n", pos.ToString()); LogError("%s: OpenBlockFile failed for %s\n", __func__, pos.ToString());
return false; return false;
} }
@ -1064,13 +1064,13 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
// Check the header // Check the header
if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) { if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) {
LogError("ReadBlockFromDisk: Errors in block header at %s\n", pos.ToString()); LogError("%s: Errors in block header at %s\n", __func__, pos.ToString());
return false; return false;
} }
// Signet only: check block solution // Signet only: check block solution
if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) { if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) {
LogError("ReadBlockFromDisk: Errors in block solution at %s\n", pos.ToString()); LogError("%s: Errors in block solution at %s\n", __func__, pos.ToString());
return false; return false;
} }
@ -1085,8 +1085,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
return false; return false;
} }
if (block.GetHash() != index.GetBlockHash()) { if (block.GetHash() != index.GetBlockHash()) {
LogError("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s\n", LogError("%s: GetHash() doesn't match index for %s at %s\n", __func__, index.ToString(), block_pos.ToString());
index.ToString(), block_pos.ToString());
return false; return false;
} }
return true; return true;