diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-11-17 16:32:29 +0100 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-11-28 12:42:07 +0100 |
commit | fac39b56b723f79ba0aa9570708a1d4a600f4e12 (patch) | |
tree | 7876f1bdcf0be8a9ae7efe0f61b3359db134612d /src | |
parent | c252a0fc0f4dc7d262b971a5e7ff01508159193b (diff) |
refactor: SpanReader without nVersion
The field is unused, so remove it.
This is also required for future commits.
Diffstat (limited to 'src')
-rw-r--r-- | src/blockfilter.cpp | 11 | ||||
-rw-r--r-- | src/psbt.h | 12 | ||||
-rw-r--r-- | src/signet.cpp | 3 | ||||
-rw-r--r-- | src/streams.h | 7 | ||||
-rw-r--r-- | src/test/fuzz/golomb_rice.cpp | 8 | ||||
-rw-r--r-- | src/test/fuzz/script_assets_test_minimizer.cpp | 4 | ||||
-rw-r--r-- | src/test/script_tests.cpp | 6 | ||||
-rw-r--r-- | src/test/streams_tests.cpp | 6 | ||||
-rw-r--r-- | src/wallet/test/wallet_tests.cpp | 2 |
9 files changed, 25 insertions, 34 deletions
diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp index 404c9ecc4f..e045b88513 100644 --- a/src/blockfilter.cpp +++ b/src/blockfilter.cpp @@ -16,9 +16,6 @@ #include <util/golombrice.h> #include <util/string.h> -/// Protocol version used to serialize parameters in GCS filter encoding. -static constexpr int GCS_SER_VERSION = 0; - static const std::map<BlockFilterType, std::string> g_filter_types = { {BlockFilterType::BASIC, "basic"}, }; @@ -49,7 +46,7 @@ GCSFilter::GCSFilter(const Params& params) GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_filter, bool skip_decode_check) : m_params(params), m_encoded(std::move(encoded_filter)) { - SpanReader stream{GCS_SER_VERSION, m_encoded}; + SpanReader stream{m_encoded}; uint64_t N = ReadCompactSize(stream); m_N = static_cast<uint32_t>(N); @@ -62,7 +59,7 @@ GCSFilter::GCSFilter(const Params& params, std::vector<unsigned char> encoded_fi // Verify that the encoded filter contains exactly N elements. If it has too much or too little // data, a std::ios_base::failure exception will be raised. - BitStreamReader<SpanReader> bitreader{stream}; + BitStreamReader bitreader{stream}; for (uint64_t i = 0; i < m_N; ++i) { GolombRiceDecode(bitreader, m_params.m_P); } @@ -103,13 +100,13 @@ GCSFilter::GCSFilter(const Params& params, const ElementSet& elements) bool GCSFilter::MatchInternal(const uint64_t* element_hashes, size_t size) const { - SpanReader stream{GCS_SER_VERSION, m_encoded}; + SpanReader stream{m_encoded}; // Seek forward by size of N uint64_t N = ReadCompactSize(stream); assert(N == m_N); - BitStreamReader<SpanReader> bitreader{stream}; + BitStreamReader bitreader{stream}; uint64_t value = 0; size_t hashes_index = 0; diff --git a/src/psbt.h b/src/psbt.h index ac2d246a27..3f74083717 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -382,7 +382,7 @@ struct PSBTInput } // Type is compact size uint at beginning of key - SpanReader skey{s.GetVersion(), key}; + SpanReader skey{key}; uint64_t type = ReadCompactSize(skey); // Do stuff based on type @@ -590,7 +590,7 @@ struct PSBTInput } else if (key.size() != 65) { throw std::ios_base::failure("Input Taproot script signature key is not 65 bytes"); } - SpanReader s_key{s.GetVersion(), Span{key}.subspan(1)}; + SpanReader s_key{Span{key}.subspan(1)}; XOnlyPubKey xonly; uint256 hash; s_key >> xonly; @@ -632,7 +632,7 @@ struct PSBTInput } else if (key.size() != 33) { throw std::ios_base::failure("Input Taproot BIP32 keypath key is not at 33 bytes"); } - SpanReader s_key{s.GetVersion(), Span{key}.subspan(1)}; + SpanReader s_key{Span{key}.subspan(1)}; XOnlyPubKey xonly; s_key >> xonly; std::set<uint256> leaf_hashes; @@ -807,7 +807,7 @@ struct PSBTOutput } // Type is compact size uint at beginning of key - SpanReader skey{s.GetVersion(), key}; + SpanReader skey{key}; uint64_t type = ReadCompactSize(skey); // Do stuff based on type @@ -856,7 +856,7 @@ struct PSBTOutput } std::vector<unsigned char> tree_v; s >> tree_v; - SpanReader s_tree{s.GetVersion(), tree_v}; + SpanReader s_tree{tree_v}; if (s_tree.empty()) { throw std::ios_base::failure("Output Taproot tree must not be empty"); } @@ -1060,7 +1060,7 @@ struct PartiallySignedTransaction } // Type is compact size uint at beginning of key - SpanReader skey{s.GetVersion(), key}; + SpanReader skey{key}; uint64_t type = ReadCompactSize(skey); // Do stuff based on type diff --git a/src/signet.cpp b/src/signet.cpp index ef9913218a..ebf0de09d3 100644 --- a/src/signet.cpp +++ b/src/signet.cpp @@ -22,7 +22,6 @@ #include <streams.h> #include <uint256.h> #include <util/strencodings.h> -#include <version.h> static constexpr uint8_t SIGNET_HEADER[4] = {0xec, 0xc7, 0xda, 0xa2}; @@ -99,7 +98,7 @@ std::optional<SignetTxs> SignetTxs::Create(const CBlock& block, const CScript& c // no signet solution -- allow this to support OP_TRUE as trivial block challenge } else { try { - SpanReader v{INIT_PROTO_VERSION, signet_solution}; + SpanReader v{signet_solution}; v >> tx_spending.vin[0].scriptSig; v >> tx_spending.vin[0].scriptWitness.stack; if (!v.empty()) return std::nullopt; // extraneous data encountered diff --git a/src/streams.h b/src/streams.h index 5fec289e34..39e9a56f11 100644 --- a/src/streams.h +++ b/src/streams.h @@ -100,16 +100,13 @@ private: class SpanReader { private: - const int m_version; Span<const unsigned char> m_data; public: /** - * @param[in] version Serialization Version (including any flags) * @param[in] data Referenced byte vector to overwrite/append */ - SpanReader(int version, Span<const unsigned char> data) - : m_version{version}, m_data{data} {} + explicit SpanReader(Span<const unsigned char> data) : m_data{data} {} template<typename T> SpanReader& operator>>(T&& obj) @@ -118,8 +115,6 @@ public: return (*this); } - int GetVersion() const { return m_version; } - size_t size() const { return m_data.size(); } bool empty() const { return m_data.empty(); } diff --git a/src/test/fuzz/golomb_rice.cpp b/src/test/fuzz/golomb_rice.cpp index 8b395f3ea9..92e49445ba 100644 --- a/src/test/fuzz/golomb_rice.cpp +++ b/src/test/fuzz/golomb_rice.cpp @@ -68,8 +68,8 @@ FUZZ_TARGET(golomb_rice) std::vector<uint64_t> decoded_deltas; { - SpanReader stream{0, golomb_rice_data}; - BitStreamReader<SpanReader> bitreader{stream}; + SpanReader stream{golomb_rice_data}; + BitStreamReader bitreader{stream}; const uint32_t n = static_cast<uint32_t>(ReadCompactSize(stream)); for (uint32_t i = 0; i < n; ++i) { decoded_deltas.push_back(GolombRiceDecode(bitreader, BASIC_FILTER_P)); @@ -80,14 +80,14 @@ FUZZ_TARGET(golomb_rice) { const std::vector<uint8_t> random_bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider, 1024); - SpanReader stream{0, random_bytes}; + SpanReader stream{random_bytes}; uint32_t n; try { n = static_cast<uint32_t>(ReadCompactSize(stream)); } catch (const std::ios_base::failure&) { return; } - BitStreamReader<SpanReader> bitreader{stream}; + BitStreamReader bitreader{stream}; for (uint32_t i = 0; i < std::min<uint32_t>(n, 1024); ++i) { try { (void)GolombRiceDecode(bitreader, BASIC_FILTER_P); diff --git a/src/test/fuzz/script_assets_test_minimizer.cpp b/src/test/fuzz/script_assets_test_minimizer.cpp index 55a4fbc75c..511b581f60 100644 --- a/src/test/fuzz/script_assets_test_minimizer.cpp +++ b/src/test/fuzz/script_assets_test_minimizer.cpp @@ -54,7 +54,7 @@ CMutableTransaction TxFromHex(const std::string& str) { CMutableTransaction tx; try { - SpanReader{0, CheckedParseHex(str)} >> TX_NO_WITNESS(tx); + SpanReader{CheckedParseHex(str)} >> TX_NO_WITNESS(tx); } catch (const std::ios_base::failure&) { throw std::runtime_error("Tx deserialization failure"); } @@ -68,7 +68,7 @@ std::vector<CTxOut> TxOutsFromJSON(const UniValue& univalue) for (size_t i = 0; i < univalue.size(); ++i) { CTxOut txout; try { - SpanReader{0, CheckedParseHex(univalue[i].get_str())} >> txout; + SpanReader{CheckedParseHex(univalue[i].get_str())} >> txout; } catch (const std::ios_base::failure&) { throw std::runtime_error("Prevout invalid format"); } diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index 874f3e51f7..e988ce2194 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -1470,7 +1470,7 @@ BOOST_AUTO_TEST_CASE(script_HasValidOps) static CMutableTransaction TxFromHex(const std::string& str) { CMutableTransaction tx; - SpanReader{0, ParseHex(str)} >> TX_NO_WITNESS(tx); + SpanReader{ParseHex(str)} >> TX_NO_WITNESS(tx); return tx; } @@ -1480,7 +1480,7 @@ static std::vector<CTxOut> TxOutsFromJSON(const UniValue& univalue) std::vector<CTxOut> prevouts; for (size_t i = 0; i < univalue.size(); ++i) { CTxOut txout; - SpanReader{0, ParseHex(univalue[i].get_str())} >> txout; + SpanReader{ParseHex(univalue[i].get_str())} >> txout; prevouts.push_back(std::move(txout)); } return prevouts; @@ -1816,7 +1816,7 @@ BOOST_AUTO_TEST_CASE(bip341_keypath_test_vectors) for (const auto& vec : vectors.getValues()) { auto txhex = ParseHex(vec["given"]["rawUnsignedTx"].get_str()); CMutableTransaction tx; - SpanReader{PROTOCOL_VERSION, txhex} >> TX_WITH_WITNESS(tx); + SpanReader{txhex} >> TX_WITH_WITNESS(tx); std::vector<CTxOut> utxos; for (const auto& utxo_spent : vec["given"]["utxosSpent"].getValues()) { auto script_bytes = ParseHex(utxo_spent["scriptPubKey"].get_str()); diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 693247b8d4..7d1ac5a19a 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader) { std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6}; - SpanReader reader{INIT_PROTO_VERSION, vch}; + SpanReader reader{vch}; BOOST_CHECK_EQUAL(reader.size(), 6U); BOOST_CHECK(!reader.empty()); @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader) BOOST_CHECK_THROW(reader >> d, std::ios_base::failure); // Read a 4 bytes as a signed int from the beginning of the buffer. - SpanReader new_reader{INIT_PROTO_VERSION, vch}; + SpanReader new_reader{vch}; new_reader >> d; BOOST_CHECK_EQUAL(d, 67370753); // 1,255,3,4 in little-endian base-256 BOOST_CHECK_EQUAL(new_reader.size(), 2U); @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(streams_vector_reader) BOOST_AUTO_TEST_CASE(streams_vector_reader_rvalue) { std::vector<uint8_t> data{0x82, 0xa7, 0x31}; - SpanReader reader{INIT_PROTO_VERSION, data}; + SpanReader reader{data}; uint32_t varint = 0; // Deserialize into r-value reader >> VARINT(varint); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 6d7b9100b5..dd43705a84 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -759,7 +759,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_descriptor_test, BasicTestingSetup) vw << int32_t{0}; vw << int32_t{1}; - SpanReader vr{0, malformed_record}; + SpanReader vr{malformed_record}; WalletDescriptor w_desc; BOOST_CHECK_EXCEPTION(vr >> w_desc, std::ios_base::failure, malformed_descriptor); } |