From 67a3d590768301fb46a93fdb0a5c66c0c2de1082 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 19 Sep 2024 07:29:12 -0400 Subject: [PATCH 1/2] streams: remove unused code --- src/node/blockstorage.cpp | 8 -------- src/node/utxo_snapshot.cpp | 2 -- src/streams.cpp | 5 ----- src/streams.h | 1 - 4 files changed, 16 deletions(-) diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 44c2808c3bd46..07878a560297c 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -684,10 +684,6 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos // Write undo data long fileOutPos = fileout.tell(); - if (fileOutPos < 0) { - LogError("%s: ftell failed\n", __func__); - return false; - } pos.nPos = (unsigned int)fileOutPos; fileout << blockundo; @@ -982,10 +978,6 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const // Write block long fileOutPos = fileout.tell(); - if (fileOutPos < 0) { - LogError("%s: ftell failed\n", __func__); - return false; - } pos.nPos = (unsigned int)fileOutPos; fileout << TX_WITH_WITNESS(block); diff --git a/src/node/utxo_snapshot.cpp b/src/node/utxo_snapshot.cpp index 7d589c886b824..ca5491bdc2b5c 100644 --- a/src/node/utxo_snapshot.cpp +++ b/src/node/utxo_snapshot.cpp @@ -77,8 +77,6 @@ std::optional ReadSnapshotBaseBlockhash(fs::path chaindir) afile.seek(0, SEEK_END); if (position != afile.tell()) { LogPrintf("[snapshot] warning: unexpected trailing data in %s\n", read_from_str); - } else if (afile.IsError()) { - LogPrintf("[snapshot] warning: i/o error reading %s\n", read_from_str); } return base_blockhash; } diff --git a/src/streams.cpp b/src/streams.cpp index 5f7baf92b9e8e..baa5ad7abed21 100644 --- a/src/streams.cpp +++ b/src/streams.cpp @@ -106,11 +106,6 @@ bool AutoFile::Commit() return ::FileCommit(m_file); } -bool AutoFile::IsError() -{ - return ferror(m_file); -} - bool AutoFile::Truncate(unsigned size) { return ::TruncateFile(m_file, size); diff --git a/src/streams.h b/src/streams.h index 431a4d77c6ced..8a5af68dee8ff 100644 --- a/src/streams.h +++ b/src/streams.h @@ -455,7 +455,6 @@ class AutoFile } bool Commit(); - bool IsError(); bool Truncate(unsigned size); }; From caac06f784c5d94c6a5f7d0b586f9ddbbe55c369 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 19 Sep 2024 07:57:45 -0400 Subject: [PATCH 2/2] streams: reorder/document functions --- src/streams.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/streams.h b/src/streams.h index 8a5af68dee8ff..e9f3562c6ce79 100644 --- a/src/streams.h +++ b/src/streams.h @@ -430,9 +430,18 @@ class AutoFile /** Implementation detail, only used internally. */ std::size_t detail_fread(Span dst); + /** Wrapper around fseek(). Will throw if seeking is not possible. */ void seek(int64_t offset, int origin); + + /** Find position within the file. Will throw if unknown. */ int64_t tell(); + /** Wrapper around FileCommit(). */ + bool Commit(); + + /** Wrapper around TruncateFile(). */ + bool Truncate(unsigned size); + // // Stream subset // @@ -453,9 +462,6 @@ class AutoFile ::Unserialize(*this, obj); return *this; } - - bool Commit(); - bool Truncate(unsigned size); }; /** Wrapper around an AutoFile& that implements a ring buffer to