mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-15 12:19:46 +01:00
Merge bitcoin/bitcoin#26921: [23.x] Backports
52376d9217
depends: fix systemtap download URL (fanquake)af86266165
23.x Add missing includes to fix gcc-13 compile error (fanquake)398768769f
Add missing includes to fix gcc-13 compile error (MarcoFalke)412cd1a34e
addrdb: Only call Serialize() once (Martin Zumsande)fd94befbc6
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: ACK52376d9217
Tree-SHA512: fa6463d5086667107b4ce4d87545e0b3f9b7841a52761a4dc6286377f958ecc026ed6694d1cf1e91cbad686309b5d637608f3991c46a20b02421318a804ffcea
This commit is contained in:
commit
0567787f5e
9 changed files with 50 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
package=systemtap
|
package=systemtap
|
||||||
$(package)_version=4.5
|
$(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)_file_name=$(package)-$($(package)_version).tar.gz
|
||||||
$(package)_sha256_hash=75078ed37e0dd2a769c9d1f9394170b2d9f4d7daa425f43ca80c13bad6cfc925
|
$(package)_sha256_hash=75078ed37e0dd2a769c9d1f9394170b2d9f4d7daa425f43ca80c13bad6cfc925
|
||||||
$(package)_patches=remove_SDT_ASM_SECTION_AUTOGROUP_SUPPORT_check.patch
|
$(package)_patches=remove_SDT_ASM_SECTION_AUTOGROUP_SUPPORT_check.patch
|
||||||
|
|
|
@ -33,10 +33,9 @@ bool SerializeDB(Stream& stream, const Data& data)
|
||||||
{
|
{
|
||||||
// Write and commit header, data
|
// Write and commit header, data
|
||||||
try {
|
try {
|
||||||
CHashWriter hasher(stream.GetType(), stream.GetVersion());
|
HashedSourceWriter hashwriter{stream};
|
||||||
stream << Params().MessageStart() << data;
|
hashwriter << Params().MessageStart() << data;
|
||||||
hasher << Params().MessageStart() << data;
|
stream << hashwriter.GetHash();
|
||||||
stream << hasher.GetHash();
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return error("%s: Serialize or I/O error - %s", __func__, e.what());
|
return error("%s: Serialize or I/O error - %s", __func__, e.what());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1171,8 +1171,7 @@ void AddrMan::Unserialize(Stream& s_)
|
||||||
}
|
}
|
||||||
|
|
||||||
// explicit instantiation
|
// explicit instantiation
|
||||||
template void AddrMan::Serialize(CHashWriter& s) const;
|
template void AddrMan::Serialize(HashedSourceWriter<CAutoFile>& s) const;
|
||||||
template void AddrMan::Serialize(CAutoFile& s) const;
|
|
||||||
template void AddrMan::Serialize(CDataStream& s) const;
|
template void AddrMan::Serialize(CDataStream& s) const;
|
||||||
template void AddrMan::Unserialize(CAutoFile& s);
|
template void AddrMan::Unserialize(CAutoFile& s);
|
||||||
template void AddrMan::Unserialize(CHashVerifier<CAutoFile>& s);
|
template void AddrMan::Unserialize(CHashVerifier<CAutoFile>& s);
|
||||||
|
|
24
src/hash.h
24
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. */
|
/** Compute the 256-bit hash of an object's serialization. */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <utility>
|
||||||
#ifdef ARENA_DEBUG
|
#ifdef ARENA_DEBUG
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
#ifndef BITCOIN_SUPPORT_LOCKEDPOOL_H
|
#ifndef BITCOIN_SUPPORT_LOCKEDPOOL_H
|
||||||
#define BITCOIN_SUPPORT_LOCKEDPOOL_H
|
#define BITCOIN_SUPPORT_LOCKEDPOOL_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <mutex>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -441,4 +441,18 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
|
||||||
fs::remove(streams_test_filename);
|
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()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define BITCOIN_UTIL_BIP32_H
|
#define BITCOIN_UTIL_BIP32_H
|
||||||
|
|
||||||
#include <attributes.h>
|
#include <attributes.h>
|
||||||
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
Loading…
Add table
Reference in a new issue