From a877ff10f8d32e372edbb972d908ec188b9595eb Mon Sep 17 00:00:00 2001 From: lateminer <9951982+lateminer@users.noreply.github.com> Date: Thu, 4 Jan 2024 19:35:06 +0100 Subject: [PATCH] Remove `nVersion` from class BufferedFile --- src/bench/streams_findbyte.cpp | 2 +- src/streams.h | 8 +++----- src/test/fuzz/buffered_file.cpp | 2 +- src/test/streams_tests.cpp | 8 ++++---- src/validation.cpp | 2 +- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/bench/streams_findbyte.cpp b/src/bench/streams_findbyte.cpp index eb38ef117f..38d18215bd 100644 --- a/src/bench/streams_findbyte.cpp +++ b/src/bench/streams_findbyte.cpp @@ -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); diff --git a/src/streams.h b/src/streams.h index 2e1554b163..ea010c07c0 100644 --- a/src/streams.h +++ b/src/streams.h @@ -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 @@ -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::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::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 diff --git a/src/test/fuzz/buffered_file.cpp b/src/test/fuzz/buffered_file.cpp index ddcb3219ed..344b6373c8 100644 --- a/src/test/fuzz/buffered_file.cpp +++ b/src/test/fuzz/buffered_file.cpp @@ -21,7 +21,7 @@ FUZZ_TARGET(buffered_file) std::optional opt_buffered_file; CAutoFile fuzzed_file{fuzzed_file_provider.open(), 0}; try { - opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), SER_NETWORK, PROTOCOL_VERSION); + opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange(0, 4096), SER_NETWORK); } catch (const std::ios_base::failure&) { } if (opt_buffered_file && !fuzzed_file.IsNull()) { diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index b48544e05d..f42d965c2c 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -260,7 +260,7 @@ 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(), @@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file) } // 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. @@ -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 @@ -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) { diff --git a/src/validation.cpp b/src/validation.cpp index ca6baf1918..1b5a6331f6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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();