Skip to content

Commit

Permalink
log: unify error messages for (read/write)[undo]block
Browse files Browse the repository at this point in the history
  • Loading branch information
l0rinc committed Jan 24, 2025
1 parent c4c3bf1 commit 97b4a50
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,11 @@ bool BlockManager::ReadBlockUndo(CBlockUndo& blockundo, const CBlockIndex& index
uint256 hashChecksum;
filein >> hashChecksum;
if (hashChecksum != verifier.GetHash()) {
LogError("%s: Checksum mismatch at %s\n", __func__, pos.ToString());
LogError("%s: Checksum mismatch at %s", __func__, pos.ToString());
return false;
}
} catch (const std::exception& e) {
LogError("%s: Deserialize or I/O error - %s at %s\n", __func__, e.what(), pos.ToString());
LogError("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
return false;
}

Expand Down Expand Up @@ -959,13 +959,13 @@ bool BlockManager::WriteBlockUndo(const CBlockUndo& blockundo, BlockValidationSt
FlatFilePos pos;
const unsigned int blockundo_size{static_cast<unsigned int>(GetSerializeSize(blockundo))};
if (!FindUndoPos(state, block.nFile, pos, blockundo_size + UNDO_DATA_DISK_OVERHEAD)) {
LogError("FindUndoPos failed");
LogError("%s: FindUndoPos failed", __func__);
return false;
}
// Open history file to append
AutoFile fileout{m_undo_file_seq.Open(pos, false), {}}; // We'll obfuscate ourselves
if (fileout.IsNull()) {
LogError("FlatFileSeq::Open failed");
LogError("%s: FlatFileSeq::Open failed", __func__);
return FatalError(m_opts.notifications, state, _("Failed to write undo data."));
}

Expand Down Expand Up @@ -1029,35 +1029,35 @@ bool BlockManager::ReadBlock(CBlock& block, FlatFilePos pos) const
// Open history file to read
AutoFile filein{OpenBlockFile(pos, true)};
if (filein.IsNull()) {
LogError("%s: OpenBlockFile failed for %s\n", __func__, pos.ToString());
LogError("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
return false;
}

try {
// Read block
filein >> blk_size;
if (blk_size > MAX_SIZE) {
LogError("Refusing to read block of size: %s", blk_size);
LogError("Refusing to read block of size: %d", blk_size);
return false;
}

std::vector<uint8_t> mem(blk_size);
filein >> Span{mem};
SpanReader(mem) >> TX_WITH_WITNESS(block);
} catch (const std::exception& e) {
LogError("%s: Deserialize or I/O error - %s at %s\n", __func__, e.what(), pos.ToString());
LogError("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
return false;
}

// Check the header
if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) {
LogError("%s: Errors in block header at %s\n", __func__, pos.ToString());
LogError("%s: Errors in block header at %s", __func__, pos.ToString());
return false;
}

// Signet only: check block solution
if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) {
LogError("%s: Errors in block solution at %s\n", __func__, pos.ToString());
LogError("%s: Errors in block solution at %s", __func__, pos.ToString());
return false;
}

Expand Down Expand Up @@ -1128,12 +1128,12 @@ FlatFilePos BlockManager::WriteBlock(const CBlock& block, int nHeight)
const unsigned int block_size{static_cast<unsigned int>(GetSerializeSize(TX_WITH_WITNESS(block)))};
FlatFilePos pos{FindNextBlockPos(block_size + BLOCK_SERIALIZATION_HEADER_SIZE, nHeight, block.GetBlockTime())};
if (pos.IsNull()) {
LogError("FindNextBlockPos failed");
LogError("%s: FindNextBlockPos failed", __func__);
return FlatFilePos();
}
AutoFile fileout{m_block_file_seq.Open(pos, false), {}}; // We'll obfuscate ourselves
if (fileout.IsNull()) {
LogError("FlatFileSeq::Open failed");
LogError("%s: FlatFileSeq::Open failed", __func__);
m_opts.notifications.fatalError(_("Failed to write block."));
return FlatFilePos();
}
Expand Down

0 comments on commit 97b4a50

Please sign in to comment.