Skip to content

Commit 0567787

Browse files
committed
Merge bitcoin/bitcoin#26921: [23.x] Backports
52376d9 depends: fix systemtap download URL (fanquake) af86266 23.x Add missing includes to fix gcc-13 compile error (fanquake) 3987687 Add missing includes to fix gcc-13 compile error (MarcoFalke) 412cd1a addrdb: Only call Serialize() once (Martin Zumsande) fd94bef hash: add HashedSourceWriter (Martin Zumsande) Pull request description: Backports: * bitcoin/bitcoin#26909 * bitcoin/bitcoin#26924 * bitcoin/bitcoin#26944 ACKs for top commit: instagibbs: ACK bitcoin/bitcoin@52376d9 Tree-SHA512: fa6463d5086667107b4ce4d87545e0b3f9b7841a52761a4dc6286377f958ecc026ed6694d1cf1e91cbad686309b5d637608f3991c46a20b02421318a804ffcea
2 parents dd04f2d + 52376d9 commit 0567787

File tree

9 files changed

+50
-9
lines changed

9 files changed

+50
-9
lines changed

depends/packages/systemtap.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package=systemtap
22
$(package)_version=4.5
3-
$(package)_download_path=https://sourceware.org/systemtap/ftp/releases/
3+
$(package)_download_path=https://sourceware.org/ftp/systemtap/releases/
44
$(package)_file_name=$(package)-$($(package)_version).tar.gz
55
$(package)_sha256_hash=75078ed37e0dd2a769c9d1f9394170b2d9f4d7daa425f43ca80c13bad6cfc925
66
$(package)_patches=remove_SDT_ASM_SECTION_AUTOGROUP_SUPPORT_check.patch

src/addrdb.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ bool SerializeDB(Stream& stream, const Data& data)
3333
{
3434
// Write and commit header, data
3535
try {
36-
CHashWriter hasher(stream.GetType(), stream.GetVersion());
37-
stream << Params().MessageStart() << data;
38-
hasher << Params().MessageStart() << data;
39-
stream << hasher.GetHash();
36+
HashedSourceWriter hashwriter{stream};
37+
hashwriter << Params().MessageStart() << data;
38+
stream << hashwriter.GetHash();
4039
} catch (const std::exception& e) {
4140
return error("%s: Serialize or I/O error - %s", __func__, e.what());
4241
}

src/addrman.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,7 @@ void AddrMan::Unserialize(Stream& s_)
11711171
}
11721172

11731173
// explicit instantiation
1174-
template void AddrMan::Serialize(CHashWriter& s) const;
1175-
template void AddrMan::Serialize(CAutoFile& s) const;
1174+
template void AddrMan::Serialize(HashedSourceWriter<CAutoFile>& s) const;
11761175
template void AddrMan::Serialize(CDataStream& s) const;
11771176
template void AddrMan::Unserialize(CAutoFile& s);
11781177
template void AddrMan::Unserialize(CHashVerifier<CAutoFile>& s);

src/hash.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,30 @@ class CHashVerifier : public CHashWriter
188188
}
189189
};
190190

191+
/** Writes data to an underlying source stream, while hashing the written data. */
192+
template <typename Source>
193+
class HashedSourceWriter : public CHashWriter
194+
{
195+
private:
196+
Source& m_source;
197+
198+
public:
199+
explicit HashedSourceWriter(Source& source LIFETIMEBOUND) : CHashWriter{source.GetType(), source.GetVersion()}, m_source{source} {}
200+
201+
void write(Span<const std::byte> src)
202+
{
203+
m_source.write(src);
204+
CHashWriter::write(src);
205+
}
206+
207+
template <typename T>
208+
HashedSourceWriter& operator<<(const T& obj)
209+
{
210+
::Serialize(*this, obj);
211+
return *this;
212+
}
213+
};
214+
191215
/** Compute the 256-bit hash of an object's serialization. */
192216
template<typename T>
193217
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)

src/support/lockedpool.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#endif
2323

2424
#include <algorithm>
25+
#include <limits>
26+
#include <stdexcept>
27+
#include <utility>
2528
#ifdef ARENA_DEBUG
2629
#include <iomanip>
2730
#include <iostream>

src/support/lockedpool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#ifndef BITCOIN_SUPPORT_LOCKEDPOOL_H
66
#define BITCOIN_SUPPORT_LOCKEDPOOL_H
77

8-
#include <stdint.h>
8+
#include <cstddef>
99
#include <list>
1010
#include <map>
11-
#include <mutex>
1211
#include <memory>
12+
#include <mutex>
1313
#include <unordered_map>
1414

1515
/**

src/test/streams_tests.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,18 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
441441
fs::remove(streams_test_filename);
442442
}
443443

444+
BOOST_AUTO_TEST_CASE(streams_hashed)
445+
{
446+
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION);
447+
HashedSourceWriter hash_writer{stream};
448+
const std::string data{"bitcoin"};
449+
hash_writer << data;
450+
451+
CHashVerifier hash_verifier{&stream};
452+
std::string result;
453+
hash_verifier >> result;
454+
BOOST_CHECK_EQUAL(data, result);
455+
BOOST_CHECK_EQUAL(hash_writer.GetHash(), hash_verifier.GetHash());
456+
}
457+
444458
BOOST_AUTO_TEST_SUITE_END()

src/util/bip32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_UTIL_BIP32_H
77

88
#include <attributes.h>
9+
#include <cstdint>
910
#include <string>
1011
#include <vector>
1112

src/util/string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <algorithm>
1111
#include <array>
12+
#include <cstdint>
1213
#include <cstring>
1314
#include <locale>
1415
#include <sstream>

0 commit comments

Comments
 (0)