diff options
author | fanquake <fanquake@gmail.com> | 2023-02-16 15:57:28 +0000 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-02-16 16:01:41 +0000 |
commit | 0567787f5ef9e45f96cb375dcd7e06117a9fd629 (patch) | |
tree | 9372684c0336e77b1c793d611a41b253cef1f751 | |
parent | dd04f2dda5fa9bd60a665ec11761669ca78421e8 (diff) | |
parent | 52376d9217060ce84e992e374d5dc2beae40bb06 (diff) |
Merge bitcoin/bitcoin#26921: [23.x] Backports
52376d9217060ce84e992e374d5dc2beae40bb06 depends: fix systemtap download URL (fanquake)
af862661654966d5de614755ab9bd1b5913e0959 23.x Add missing includes to fix gcc-13 compile error (fanquake)
398768769f85cc1b6ff212ed931646b59fa1acd6 Add missing includes to fix gcc-13 compile error (MarcoFalke)
412cd1a34e035c1a2f35f4b4ac14eb192835950c addrdb: Only call Serialize() once (Martin Zumsande)
fd94befbc62e5f6b93f87979cc2011508378043d hash: add HashedSourceWriter (Martin Zumsande)
Pull request description:
Backports:
* https://github.com/bitcoin/bitcoin/pull/26909
* https://github.com/bitcoin/bitcoin/pull/26924
* https://github.com/bitcoin/bitcoin/pull/26944
ACKs for top commit:
instagibbs:
ACK https://github.com/bitcoin/bitcoin/pull/26921/commits/52376d9217060ce84e992e374d5dc2beae40bb06
Tree-SHA512: fa6463d5086667107b4ce4d87545e0b3f9b7841a52761a4dc6286377f958ecc026ed6694d1cf1e91cbad686309b5d637608f3991c46a20b02421318a804ffcea
-rw-r--r-- | depends/packages/systemtap.mk | 2 | ||||
-rw-r--r-- | src/addrdb.cpp | 7 | ||||
-rw-r--r-- | src/addrman.cpp | 3 | ||||
-rw-r--r-- | src/hash.h | 24 | ||||
-rw-r--r-- | src/support/lockedpool.cpp | 3 | ||||
-rw-r--r-- | src/support/lockedpool.h | 4 | ||||
-rw-r--r-- | src/test/streams_tests.cpp | 14 | ||||
-rw-r--r-- | src/util/bip32.h | 1 | ||||
-rw-r--r-- | src/util/string.h | 1 |
9 files changed, 50 insertions, 9 deletions
diff --git a/depends/packages/systemtap.mk b/depends/packages/systemtap.mk index 833e75b978..498db4982f 100644 --- a/depends/packages/systemtap.mk +++ b/depends/packages/systemtap.mk @@ -1,6 +1,6 @@ package=systemtap $(package)_version=4.5 -$(package)_download_path=https://sourceware.org/systemtap/ftp/releases/ +$(package)_download_path=https://sourceware.org/ftp/systemtap/releases/ $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=75078ed37e0dd2a769c9d1f9394170b2d9f4d7daa425f43ca80c13bad6cfc925 $(package)_patches=remove_SDT_ASM_SECTION_AUTOGROUP_SUPPORT_check.patch diff --git a/src/addrdb.cpp b/src/addrdb.cpp index 0fa8f3c3da..0d68719478 100644 --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -33,10 +33,9 @@ bool SerializeDB(Stream& stream, const Data& data) { // Write and commit header, data try { - CHashWriter hasher(stream.GetType(), stream.GetVersion()); - stream << Params().MessageStart() << data; - hasher << Params().MessageStart() << data; - stream << hasher.GetHash(); + HashedSourceWriter hashwriter{stream}; + hashwriter << Params().MessageStart() << data; + stream << hashwriter.GetHash(); } catch (const std::exception& e) { return error("%s: Serialize or I/O error - %s", __func__, e.what()); } diff --git a/src/addrman.cpp b/src/addrman.cpp index f91a979934..64137e1523 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -1171,8 +1171,7 @@ void AddrMan::Unserialize(Stream& s_) } // explicit instantiation -template void AddrMan::Serialize(CHashWriter& s) const; -template void AddrMan::Serialize(CAutoFile& s) const; +template void AddrMan::Serialize(HashedSourceWriter<CAutoFile>& s) const; template void AddrMan::Serialize(CDataStream& s) const; template void AddrMan::Unserialize(CAutoFile& s); template void AddrMan::Unserialize(CHashVerifier<CAutoFile>& s); diff --git a/src/hash.h b/src/hash.h index 9f582842c1..7515fc45a6 100644 --- a/src/hash.h +++ b/src/hash.h @@ -188,6 +188,30 @@ public: } }; +/** Writes data to an underlying source stream, while hashing the written data. */ +template <typename Source> +class HashedSourceWriter : public CHashWriter +{ +private: + Source& m_source; + +public: + explicit HashedSourceWriter(Source& source LIFETIMEBOUND) : CHashWriter{source.GetType(), source.GetVersion()}, m_source{source} {} + + void write(Span<const std::byte> src) + { + m_source.write(src); + CHashWriter::write(src); + } + + template <typename T> + HashedSourceWriter& operator<<(const T& obj) + { + ::Serialize(*this, obj); + return *this; + } +}; + /** Compute the 256-bit hash of an object's serialization. */ template<typename T> uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION) diff --git a/src/support/lockedpool.cpp b/src/support/lockedpool.cpp index 6965f40253..2ad3161563 100644 --- a/src/support/lockedpool.cpp +++ b/src/support/lockedpool.cpp @@ -22,6 +22,9 @@ #endif #include <algorithm> +#include <limits> +#include <stdexcept> +#include <utility> #ifdef ARENA_DEBUG #include <iomanip> #include <iostream> diff --git a/src/support/lockedpool.h b/src/support/lockedpool.h index 03e4e371a3..66fbc218ab 100644 --- a/src/support/lockedpool.h +++ b/src/support/lockedpool.h @@ -5,11 +5,11 @@ #ifndef BITCOIN_SUPPORT_LOCKEDPOOL_H #define BITCOIN_SUPPORT_LOCKEDPOOL_H -#include <stdint.h> +#include <cstddef> #include <list> #include <map> -#include <mutex> #include <memory> +#include <mutex> #include <unordered_map> /** diff --git a/src/test/streams_tests.cpp b/src/test/streams_tests.cpp index 0925e2e9ee..e30ae845ef 100644 --- a/src/test/streams_tests.cpp +++ b/src/test/streams_tests.cpp @@ -441,4 +441,18 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand) fs::remove(streams_test_filename); } +BOOST_AUTO_TEST_CASE(streams_hashed) +{ + CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION); + HashedSourceWriter hash_writer{stream}; + const std::string data{"bitcoin"}; + hash_writer << data; + + CHashVerifier hash_verifier{&stream}; + std::string result; + hash_verifier >> result; + BOOST_CHECK_EQUAL(data, result); + BOOST_CHECK_EQUAL(hash_writer.GetHash(), hash_verifier.GetHash()); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/util/bip32.h b/src/util/bip32.h index 8f86f2aaa6..b1d53616a4 100644 --- a/src/util/bip32.h +++ b/src/util/bip32.h @@ -6,6 +6,7 @@ #define BITCOIN_UTIL_BIP32_H #include <attributes.h> +#include <cstdint> #include <string> #include <vector> diff --git a/src/util/string.h b/src/util/string.h index a3b8df8d78..5f4859f1d7 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -9,6 +9,7 @@ #include <algorithm> #include <array> +#include <cstdint> #include <cstring> #include <locale> #include <sstream> |