Skip to content

Commit

Permalink
Remove nVersion from class BufferedFile
Browse files Browse the repository at this point in the history
  • Loading branch information
lateminer committed Jan 4, 2024
1 parent 9c1da25 commit a877ff1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/bench/streams_findbyte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void FindByte(benchmark::Bench& bench)
data[file_size-1] = 1;
file << data;
std::rewind(file.Get());
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, SER_NETWORK, PROTOCOL_VERSION};
BufferedFile bf{file, /*nBufSize=*/file_size + 1, /*nRewindIn=*/file_size, SER_NETWORK};

bench.run([&] {
bf.SetPos(0);
Expand Down
8 changes: 3 additions & 5 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ class BufferedFile
{
private:
const int nType;
const int nVersion;

CAutoFile& m_src;
uint64_t nSrcPos{0}; //!< how many bytes have been read from source
Expand Down Expand Up @@ -640,15 +639,14 @@ class BufferedFile
}

public:
BufferedFile(CAutoFile& file, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
: nType(nTypeIn), nVersion(nVersionIn), m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
BufferedFile(CAutoFile& file, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn)
: nType(nTypeIn), m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
{
if (nRewindIn >= nBufSize)
throw std::ios_base::failure("Rewind limit must be less than buffer size");
}

// int GetVersion() const { return m_src.GetVersion(); }
int GetVersion() const { return nVersion; }
int GetVersion() const { return m_src.GetVersion(); }
int GetType() const { return nType; }

//! check whether we're at the end of the source file
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/buffered_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ FUZZ_TARGET(buffered_file)
std::optional<BufferedFile> opt_buffered_file;
CAutoFile fuzzed_file{fuzzed_file_provider.open(), 0};
try {
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), SER_NETWORK, PROTOCOL_VERSION);
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), SER_NETWORK);
} catch (const std::ios_base::failure&) {
}
if (opt_buffered_file && !fuzzed_file.IsNull()) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/streams_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
// The buffer size (second arg) must be greater than the rewind
// amount (third arg).
try {
BufferedFile bfbad{file, 25, 25, SER_NETWORK, PROTOCOL_VERSION};
BufferedFile bfbad{file, 25, 25, SER_NETWORK};
BOOST_CHECK(false);
} catch (const std::exception& e) {
BOOST_CHECK(strstr(e.what(),
"Rewind limit must be less than buffer size") != nullptr);
}

// The buffer is 25 bytes, allow rewinding 10 bytes.
BufferedFile bf{file, 25, 10, SER_NETWORK, PROTOCOL_VERSION};
BufferedFile bf{file, 25, 10, SER_NETWORK};
BOOST_CHECK(!bf.eof());

// This member has no functional effect.
Expand Down Expand Up @@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
std::rewind(file.Get());

// The buffer is 25 bytes, allow rewinding 10 bytes.
BufferedFile bf{file, 25, 10, SER_NETWORK, PROTOCOL_VERSION};
BufferedFile bf{file, 25, 10, SER_NETWORK};

uint8_t i;
// This is like bf >> (7-byte-variable), in that it will cause data
Expand Down Expand Up @@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)

size_t bufSize = InsecureRandRange(300) + 1;
size_t rewindSize = InsecureRandRange(bufSize);
BufferedFile bf{file, bufSize, rewindSize, SER_NETWORK, PROTOCOL_VERSION};
BufferedFile bf{file, bufSize, rewindSize, SER_NETWORK};
size_t currentPos = 0;
size_t maxPos = 0;
for (int step = 0; step < 100; ++step) {
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4845,7 +4845,7 @@ void ChainstateManager::LoadExternalBlockFile(

int nLoaded = 0;
try {
BufferedFile blkdat{file_in, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, SER_NETWORK, PROTOCOL_VERSION};
BufferedFile blkdat{file_in, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, SER_NETWORK};
// nRewind indicates where to resume scanning in case something goes wrong,
// such as a block fails to deserialize.
uint64_t nRewind = blkdat.GetPos();
Expand Down

0 comments on commit a877ff1

Please sign in to comment.