Merge bitcoin/bitcoin#25284: net: Use serialization parameters for CAddress serialization

fa626af3ed Remove unused legacy CHashVerifier (MarcoFalke)
fafa3fc5a6 test: add tests that exercise WithParams() (MarcoFalke)
fac81affb5 Use serialization parameters for CAddress serialization (MarcoFalke)
faec591d64 Support for serialization parameters (MarcoFalke)
fac42e9d35 Rename CSerAction* to Action* (MarcoFalke)
aaaa3fa947 Replace READWRITEAS macro with AsBase wrapping function (MarcoFalke)

Pull request description:

  It seems confusing that picking a wrong value for `ADDRV2_FORMAT` could have effects on consensus. (See the docstring of `ADDRV2_FORMAT`).

  Fix this by implementing https://github.com/bitcoin/bitcoin/issues/19477#issuecomment-1147421608 .

  This may also help with libbitcoinkernel, see https://github.com/bitcoin/bitcoin/pull/28327

ACKs for top commit:
  TheCharlatan:
    ACK fa626af3ed
  ajtowns:
    ACK fa626af3ed

Tree-SHA512: 229d379da27308890de212b1fd2b85dac13f3f768413cb56a4b0c2da708f28344d04356ffd75bfcbaa4cabf0b6cc363c4f812a8f1648cff9e436811498278318
This commit is contained in:
fanquake
2023-09-07 11:27:36 +01:00
26 changed files with 594 additions and 297 deletions

View File

@@ -71,9 +71,9 @@ template<typename B = uint8_t>
return BytesToBits(ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length));
}
[[nodiscard]] inline CDataStream ConsumeDataStream(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
[[nodiscard]] inline DataStream ConsumeDataStream(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
{
return CDataStream{ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length), SER_NETWORK, INIT_PROTO_VERSION};
return DataStream{ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length)};
}
[[nodiscard]] inline std::vector<std::string> ConsumeRandomLengthStringVector(FuzzedDataProvider& fuzzed_data_provider, const size_t max_vector_size = 16, const size_t max_string_length = 16) noexcept
@@ -97,6 +97,23 @@ template <typename T>
return r;
}
template <typename P>
[[nodiscard]] P ConsumeDeserializationParams(FuzzedDataProvider& fuzzed_data_provider) noexcept;
template <typename T, typename P>
[[nodiscard]] std::optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, const P& params, const std::optional<size_t>& max_length = std::nullopt) noexcept
{
const std::vector<uint8_t> buffer{ConsumeRandomLengthByteVector(fuzzed_data_provider, max_length)};
DataStream ds{buffer};
T obj;
try {
ds >> WithParams(params, obj);
} catch (const std::ios_base::failure&) {
return std::nullopt;
}
return obj;
}
template <typename T>
[[nodiscard]] inline std::optional<T> ConsumeDeserializable(FuzzedDataProvider& fuzzed_data_provider, const std::optional<size_t>& max_length = std::nullopt) noexcept
{