Skip to content

Commit 83c7269

Browse files
committed
Merge bitcoin/bitcoin#27800: streams: Drop confusing DataStream::Serialize method and << operator
5cd0717 streams: Drop confusing DataStream::Serialize method and << operator (Ryan Ofsky) Pull request description: DataStream Serialize method has surprising behavior because it just serializes raw bytes without a length prefix. When you serialize a string or vector, a length prefix is serialized before the raw object contents so the object can be unambiguously deserialized later. But DataStreams don't support deserializing at all and just dump the raw bytes. Having this inconsistency is not necessary and could be confusing (see bitcoin/bitcoin#27790 (comment)) so this PR just drops the DataStream::Serialize method. ACKs for top commit: furszy: lgtm ACK 5cd0717 MarcoFalke: lgtm ACK 5cd0717 🌙 Tree-SHA512: 49dd117de266f091a5336b13a91c5d8658abe1b3a0a9c51c8b5f6a2e0e814781b73afc39256353e79dade603a8a2761e8536716d1a48499720c266f4500477e2
2 parents dba757f + 5cd0717 commit 83c7269

File tree

4 files changed

+4
-18
lines changed

4 files changed

+4
-18
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,8 +3418,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
34183418

34193419
// If the peer is old enough to have the old alert system, send it the final alert.
34203420
if (greatest_common_version <= 70012) {
3421-
DataStream finalAlert{ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50")};
3422-
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make("alert", finalAlert));
3421+
const auto finalAlert{ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50")};
3422+
m_connman.PushMessage(&pfrom, CNetMsgMaker(greatest_common_version).Make("alert", Span{finalAlert}));
34233423
}
34243424

34253425
// Feeler connections exist only to verify if address is online.

src/streams.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,6 @@ class DataStream
293293
vch.insert(vch.end(), src.begin(), src.end());
294294
}
295295

296-
template<typename Stream>
297-
void Serialize(Stream& s) const
298-
{
299-
// Special case: stream << stream concatenates like stream += stream
300-
if (!vch.empty())
301-
s.write(MakeByteSpan(vch));
302-
}
303-
304296
template<typename T>
305297
DataStream& operator<<(const T& obj)
306298
{

src/wallet/dump.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs::
255255

256256
std::vector<unsigned char> k = ParseHex(key);
257257
std::vector<unsigned char> v = ParseHex(value);
258-
259-
DataStream ss_key{k};
260-
DataStream ss_value{v};
261-
262-
if (!batch->Write(ss_key, ss_value)) {
258+
if (!batch->Write(Span{k}, Span{v})) {
263259
error = strprintf(_("Error: Unable to write record to new wallet"));
264260
ret = false;
265261
break;

src/wallet/wallet.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,9 +3875,7 @@ bool CWallet::MigrateToSQLite(bilingual_str& error)
38753875
bool began = batch->TxnBegin();
38763876
assert(began); // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
38773877
for (const auto& [key, value] : records) {
3878-
DataStream ss_key{key};
3879-
DataStream ss_value{value};
3880-
if (!batch->Write(ss_key, ss_value)) {
3878+
if (!batch->Write(MakeUCharSpan(key), MakeUCharSpan(value))) {
38813879
batch->TxnAbort();
38823880
m_database->Close();
38833881
fs::remove(m_database->Filename());

0 commit comments

Comments
 (0)