Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#30927: Follow-up after AutoFile position cachin…
Browse files Browse the repository at this point in the history
…g: remove unused code

caac06f streams: reorder/document functions (Pieter Wuille)
67a3d59 streams: remove unused code (Pieter Wuille)

Pull request description:

  This is a follow-up to #30884.

  Remove a number of dead code paths, and improve the code organization and documentation, in `AutoFile`.

ACKs for top commit:
  maflcko:
    re-ACK caac06f
  theStack:
    Code-review ACK caac06f
  l0rinc:
    ACK caac06f
  tdb3:
    CR ACK caac06f

Tree-SHA512: 297791f093e0142730f815c11dd3466b98f7e7edea86094a815dae989ef40d8056db10e0fed6e575d530903c18e80c08d36d3f1e6b828f2d955528f365b22008
  • Loading branch information
fanquake committed Sep 19, 2024
2 parents 2db926f + caac06f commit 84cd647
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
8 changes: 0 additions & 8 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions src/node/utxo_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ std::optional<uint256> 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;
}
Expand Down
5 changes: 0 additions & 5 deletions src/streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,18 @@ class AutoFile
/** Implementation detail, only used internally. */
std::size_t detail_fread(Span<std::byte> 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
//
Expand All @@ -453,10 +462,6 @@ class AutoFile
::Unserialize(*this, obj);
return *this;
}

bool Commit();
bool IsError();
bool Truncate(unsigned size);
};

/** Wrapper around an AutoFile& that implements a ring buffer to
Expand Down

0 comments on commit 84cd647

Please sign in to comment.