aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2024-07-15 12:59:19 -0400
committerRyan Ofsky <ryan@ofsky.org>2024-07-15 13:42:53 -0400
commit8426e018bf22b5e7e1ffa4b42e06813c470b1cc6 (patch)
treeaf062b2782f279e7b04564e51c6bb31c3e32ed12 /src/node
parentff827a8f46e504712285c145e13e72e1b19eb169 (diff)
parentfa14e1d9d5c5dc44396a01583ae94480b7bc29ee (diff)
Merge bitcoin/bitcoin#30428: log: LogError with FlatFilePos in UndoReadFromDisk
fa14e1d9d5c5dc44396a01583ae94480b7bc29ee log: Fix __func__ in LogError in blockstorage module (MarcoFalke) fad59a2f0f37f5b7f6076fd91be43448e35f4b7e log: LogError with FlatFilePos in UndoReadFromDisk (MarcoFalke) aaaa3323f37526862ebf2a2a4bf522c661e6976e refactor: Mark IsBlockPruned const (MarcoFalke) Pull request description: These errors should never happen in normal operation. If they do, knowing the `FlatFilePos` may be useful to determine if data corruption happened. Also, handle the error `pos.IsNull()` as part of `OpenUndoFile`, because it may as well have happened due to data corruption. This mirrors the `LogError` behavior from `ReadBlockFromDisk`. Also, two other fixup commits in this module. ACKs for top commit: kevkevinpal: ACK [fa14e1d](https://github.com/bitcoin/bitcoin/pull/30428/commits/fa14e1d9d5c5dc44396a01583ae94480b7bc29ee) tdb3: cr and light test ACK fa14e1d9d5c5dc44396a01583ae94480b7bc29ee ryanofsky: Code review ACK fa14e1d9d5c5dc44396a01583ae94480b7bc29ee. This should make logging clearer and more consistent Tree-SHA512: abb492a919b4796698d1de0a7874c8eae355422b992aa80dcd6b59c2de1ee0d2949f62b3cf649cd62892976fee640358f7522867ed9d48a595d6f8f4e619df50
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp28
-rw-r--r--src/node/blockstorage.h2
2 files changed, 12 insertions, 18 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 80aceb312a..c50625f58d 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -588,7 +588,7 @@ const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
return nullptr;
}
-bool BlockManager::IsBlockPruned(const CBlockIndex& block)
+bool BlockManager::IsBlockPruned(const CBlockIndex& block) const
{
AssertLockHeld(::cs_main);
return m_have_pruned && !(block.nStatus & BLOCK_HAVE_DATA) && (block.nTx > 0);
@@ -703,15 +703,10 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
{
const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
- if (pos.IsNull()) {
- LogError("%s: no undo data available\n", __func__);
- return false;
- }
-
// Open history file to read
AutoFile filein{OpenUndoFile(pos, true)};
if (filein.IsNull()) {
- LogError("%s: OpenUndoFile failed\n", __func__);
+ LogError("%s: OpenUndoFile failed for %s\n", __func__, pos.ToString());
return false;
}
@@ -723,13 +718,13 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
verifier >> blockundo;
filein >> hashChecksum;
} catch (const std::exception& e) {
- LogError("%s: Deserialize or I/O error - %s\n", __func__, e.what());
+ LogError("%s: Deserialize or I/O error - %s at %s\n", __func__, e.what(), pos.ToString());
return false;
}
// Verify checksum
if (hashChecksum != verifier.GetHash()) {
- LogError("%s: Checksum mismatch\n", __func__);
+ LogError("%s: Checksum mismatch at %s\n", __func__, pos.ToString());
return false;
}
@@ -986,7 +981,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
// Open history file to append
AutoFile fileout{OpenBlockFile(pos)};
if (fileout.IsNull()) {
- LogError("WriteBlockToDisk: OpenBlockFile failed\n");
+ LogError("%s: OpenBlockFile failed\n", __func__);
return false;
}
@@ -997,7 +992,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
// Write block
long fileOutPos = ftell(fileout.Get());
if (fileOutPos < 0) {
- LogError("WriteBlockToDisk: ftell failed\n");
+ LogError("%s: ftell failed\n", __func__);
return false;
}
pos.nPos = (unsigned int)fileOutPos;
@@ -1016,7 +1011,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
if (block.GetUndoPos().IsNull()) {
FlatFilePos _pos;
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) {
- LogError("ConnectBlock(): FindUndoPos failed\n");
+ LogError("%s: FindUndoPos failed\n", __func__);
return false;
}
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
@@ -1055,7 +1050,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
// Open history file to read
AutoFile filein{OpenBlockFile(pos, true)};
if (filein.IsNull()) {
- LogError("ReadBlockFromDisk: OpenBlockFile failed for %s\n", pos.ToString());
+ LogError("%s: OpenBlockFile failed for %s\n", __func__, pos.ToString());
return false;
}
@@ -1069,13 +1064,13 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
// Check the header
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;
}
// Signet only: check block solution
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;
}
@@ -1090,8 +1085,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
return false;
}
if (block.GetHash() != index.GetBlockHash()) {
- LogError("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s\n",
- index.ToString(), block_pos.ToString());
+ LogError("%s: GetHash() doesn't match index for %s at %s\n", __func__, index.ToString(), block_pos.ToString());
return false;
}
return true;
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index 0a46d79764..a946b4ea94 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -404,7 +404,7 @@ public:
bool m_have_pruned = false;
//! Check whether the block associated with this index entry is pruned or not.
- bool IsBlockPruned(const CBlockIndex& block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+ bool IsBlockPruned(const CBlockIndex& block) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
//! Create or update a prune lock identified by its name
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);