Skip to content

Commit 79e007d

Browse files
committed
Merge bitcoin/bitcoin#25296: Add DataStream without ser-type and ser-version and use it where possible
fa035fe Remove unused CDataStream::SetType (MarcoFalke) fa29e73 Use DataStream where possible (MarcoFalke) fa9becf streams: Add DataStream without ser-type and ser-version (MarcoFalke) Pull request description: This was done in the context of bitcoin/bitcoin#25284 , but I think it also makes sense standalone. The basic idea is that serialization type should not be initialized when it is not needed. Same for the serialization version. So do this here for `DataStream`. `CDataStream` remains in places where it is not yet possible. ACKs for top commit: stickies-v: re-ACK [fa035fe](bitcoin/bitcoin@fa035fe) aureleoules: diff re-ACK fa035fe https://github.com/bitcoin/bitcoin/compare/fa0e6640bac8c6426af7c5744125c85c0f74b9e5..fa035fe2d61d0c98d1bfd0153a0c3b5eb9d40de4 Tree-SHA512: cb5e53d0df7c94319ffadc6ea1d887fc38516decaf43f0673396d79cc62d450a1a61173654a91b8c2b52d2cecea53fe4a500b8f6466596f35731471163fb051c
2 parents 77a3603 + fa035fe commit 79e007d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+196
-181
lines changed

src/bench/load_external.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
2727
// Create a single block as in the blocks files (magic bytes, block size,
2828
// block data) as a stream object.
2929
const fs::path blkfile{testing_setup.get()->m_path_root / "blk.dat"};
30-
CDataStream ss(SER_DISK, 0);
30+
DataStream ss{};
3131
auto params{testing_setup->m_node.chainman->GetParams()};
3232
ss << params.MessageStart();
3333
ss << static_cast<uint32_t>(benchmark::data::block413567.size());

src/bench/prevector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void PrevectorResize(benchmark::Bench& bench)
6161
template <typename T>
6262
static void PrevectorDeserialize(benchmark::Bench& bench)
6363
{
64-
CDataStream s0(SER_NETWORK, 0);
64+
DataStream s0{};
6565
prevector<28, T> t0;
6666
t0.resize(28);
6767
for (auto x = 0; x < 900; ++x) {

src/bitcoin-util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int Grind(const std::vector<std::string>& args, std::string& strPrint)
139139
return EXIT_FAILURE;
140140
}
141141

142-
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
142+
DataStream ss{};
143143
ss << header;
144144
strPrint = HexStr(ss);
145145
return EXIT_SUCCESS;

src/blockencodings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block) :
2929
}
3030

3131
void CBlockHeaderAndShortTxIDs::FillShortTxIDSelector() const {
32-
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
32+
DataStream stream{};
3333
stream << header << nonce;
3434
CSHA256 hasher;
3535
hasher.Write((unsigned char*)&(*stream.begin()), stream.end() - stream.begin());

src/common/bloom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void CBloomFilter::insert(Span<const unsigned char> vKey)
6060

6161
void CBloomFilter::insert(const COutPoint& outpoint)
6262
{
63-
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
63+
DataStream stream{};
6464
stream << outpoint;
6565
insert(MakeUCharSpan(stream));
6666
}
@@ -81,7 +81,7 @@ bool CBloomFilter::contains(Span<const unsigned char> vKey) const
8181

8282
bool CBloomFilter::contains(const COutPoint& outpoint) const
8383
{
84-
CDataStream stream(SER_NETWORK, PROTOCOL_VERSION);
84+
DataStream stream{};
8585
stream << outpoint;
8686
return contains(MakeUCharSpan(stream));
8787
}

src/core_read.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ bool DecodeHexBlockHeader(CBlockHeader& header, const std::string& hex_header)
207207
if (!IsHex(hex_header)) return false;
208208

209209
const std::vector<unsigned char> header_data{ParseHex(hex_header)};
210-
CDataStream ser_header(header_data, SER_NETWORK, PROTOCOL_VERSION);
210+
DataStream ser_header{header_data};
211211
try {
212212
ser_header >> header;
213213
} catch (const std::exception&) {

src/dbwrapper.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CDBBatch
6868
const CDBWrapper &parent;
6969
leveldb::WriteBatch batch;
7070

71-
CDataStream ssKey;
71+
DataStream ssKey{};
7272
CDataStream ssValue;
7373

7474
size_t size_estimate;
@@ -77,7 +77,7 @@ class CDBBatch
7777
/**
7878
* @param[in] _parent CDBWrapper that this batch is to be submitted to
7979
*/
80-
explicit CDBBatch(const CDBWrapper &_parent) : parent(_parent), ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION), size_estimate(0) { };
80+
explicit CDBBatch(const CDBWrapper& _parent) : parent(_parent), ssValue(SER_DISK, CLIENT_VERSION), size_estimate(0){};
8181

8282
void Clear()
8383
{
@@ -151,7 +151,7 @@ class CDBIterator
151151
void SeekToFirst();
152152

153153
template<typename K> void Seek(const K& key) {
154-
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
154+
DataStream ssKey{};
155155
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
156156
ssKey << key;
157157
leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
@@ -163,7 +163,7 @@ class CDBIterator
163163
template<typename K> bool GetKey(K& key) {
164164
leveldb::Slice slKey = piter->key();
165165
try {
166-
CDataStream ssKey{MakeByteSpan(slKey), SER_DISK, CLIENT_VERSION};
166+
DataStream ssKey{MakeByteSpan(slKey)};
167167
ssKey >> key;
168168
} catch (const std::exception&) {
169169
return false;
@@ -247,7 +247,7 @@ class CDBWrapper
247247
template <typename K, typename V>
248248
bool Read(const K& key, V& value) const
249249
{
250-
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
250+
DataStream ssKey{};
251251
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
252252
ssKey << key;
253253
leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
@@ -289,7 +289,7 @@ class CDBWrapper
289289
template <typename K>
290290
bool Exists(const K& key) const
291291
{
292-
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
292+
DataStream ssKey{};
293293
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
294294
ssKey << key;
295295
leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
@@ -331,7 +331,7 @@ class CDBWrapper
331331
template<typename K>
332332
size_t EstimateSize(const K& key_begin, const K& key_end) const
333333
{
334-
CDataStream ssKey1(SER_DISK, CLIENT_VERSION), ssKey2(SER_DISK, CLIENT_VERSION);
334+
DataStream ssKey1{}, ssKey2{};
335335
ssKey1.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
336336
ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
337337
ssKey1 << key_begin;

src/kernel/coinstats.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ uint64_t GetBogoSize(const CScript& script_pub_key)
4848
script_pub_key.size() /* scriptPubKey */;
4949
}
5050

51-
CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin) {
52-
CDataStream ss(SER_DISK, PROTOCOL_VERSION);
51+
DataStream TxOutSer(const COutPoint& outpoint, const Coin& coin)
52+
{
53+
DataStream ss{};
5354
ss << outpoint;
5455
ss << static_cast<uint32_t>(coin.nHeight * 2 + coin.fCoinBase);
5556
ss << coin.out;

src/kernel/coinstats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct CCoinsStats {
7272

7373
uint64_t GetBogoSize(const CScript& script_pub_key);
7474

75-
CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
75+
DataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
7676

7777
std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, CCoinsView* view, node::BlockManager& blockman, const std::function<void()>& interruption_point = {});
7878
} // namespace kernel

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
33623362

33633363
// If the peer is old enough to have the old alert system, send it the final alert.
33643364
if (greatest_common_version <= 70012) {
3365-
CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION);
3365+
DataStream finalAlert{ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50")};
33663366
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make("alert", finalAlert));
33673367
}
33683368

0 commit comments

Comments
 (0)