diff options
author | fanquake <fanquake@gmail.com> | 2023-09-07 11:27:36 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-09-07 11:34:34 +0100 |
commit | 8e0d9796da8cfb6c4e918788a03eea125d0633a6 (patch) | |
tree | 4b6aee429ac616e1b419de8dc7b73f202a487a24 /src/net_processing.cpp | |
parent | 5ad4eb33656cc6d3a56253d116b0b4e17fe9b712 (diff) | |
parent | fa626af3edbe8d98b2de91dd71729ceef90389fb (diff) |
Merge bitcoin/bitcoin#25284: net: Use serialization parameters for CAddress serialization
fa626af3edbe8d98b2de91dd71729ceef90389fb Remove unused legacy CHashVerifier (MarcoFalke)
fafa3fc5a62702da72991497e3270034eb9159c0 test: add tests that exercise WithParams() (MarcoFalke)
fac81affb527132945773a5315bd27fec61ec52f Use serialization parameters for CAddress serialization (MarcoFalke)
faec591d64e40ba7ec7656cbfdda1a05953bde13 Support for serialization parameters (MarcoFalke)
fac42e9d35f6ba046999b2e3a757ab720c51b6bb Rename CSerAction* to Action* (MarcoFalke)
aaaa3fa9477eef9ea72e4a501d130c57b47b470a Replace READWRITEAS macro with AsBase wrapping function (MarcoFalke)
Pull request description:
It seems confusing that picking a wrong value for `ADDRV2_FORMAT` could have effects on consensus. (See the docstring of `ADDRV2_FORMAT`).
Fix this by implementing https://github.com/bitcoin/bitcoin/issues/19477#issuecomment-1147421608 .
This may also help with libbitcoinkernel, see https://github.com/bitcoin/bitcoin/pull/28327
ACKs for top commit:
TheCharlatan:
ACK fa626af3edbe8d98b2de91dd71729ceef90389fb
ajtowns:
ACK fa626af3edbe8d98b2de91dd71729ceef90389fb
Tree-SHA512: 229d379da27308890de212b1fd2b85dac13f3f768413cb56a4b0c2da708f28344d04356ffd75bfcbaa4cabf0b6cc363c4f812a8f1648cff9e436811498278318
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r-- | src/net_processing.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index c5a22f258a..6b415b3a1e 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1415,8 +1415,8 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer) const bool tx_relay{!RejectIncomingTxs(pnode)}; m_connman.PushMessage(&pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, my_services, nTime, - your_services, addr_you, // Together the pre-version-31402 serialization of CAddress "addrYou" (without nTime) - my_services, CService(), // Together the pre-version-31402 serialization of CAddress "addrMe" (without nTime) + your_services, WithParams(CNetAddr::V1, addr_you), // Together the pre-version-31402 serialization of CAddress "addrYou" (without nTime) + my_services, WithParams(CNetAddr::V1, CService{}), // Together the pre-version-31402 serialization of CAddress "addrMe" (without nTime) nonce, strSubVersion, nNodeStartingHeight, tx_relay)); if (fLogIPs) { @@ -3293,7 +3293,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, nTime = 0; } vRecv.ignore(8); // Ignore the addrMe service bits sent by the peer - vRecv >> addrMe; + vRecv >> WithParams(CNetAddr::V1, addrMe); if (!pfrom.IsInboundConn()) { m_addrman.SetServices(pfrom.addr, nServices); @@ -3672,17 +3672,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, } if (msg_type == NetMsgType::ADDR || msg_type == NetMsgType::ADDRV2) { - int stream_version = vRecv.GetVersion(); - if (msg_type == NetMsgType::ADDRV2) { - // Add ADDRV2_FORMAT to the version so that the CNetAddr and CAddress + const auto ser_params{ + msg_type == NetMsgType::ADDRV2 ? + // Set V2 param so that the CNetAddr and CAddress // unserialize methods know that an address in v2 format is coming. - stream_version |= ADDRV2_FORMAT; - } + CAddress::V2_NETWORK : + CAddress::V1_NETWORK, + }; - OverrideStream<CDataStream> s(&vRecv, vRecv.GetType(), stream_version); std::vector<CAddress> vAddr; - s >> vAddr; + vRecv >> WithParams(ser_params, vAddr); if (!SetupAddressRelay(pfrom, *peer)) { LogPrint(BCLog::NET, "ignoring %s message from %s peer=%d\n", msg_type, pfrom.ConnectionTypeAsString(), pfrom.GetId()); @@ -5289,15 +5289,15 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros if (peer.m_addrs_to_send.empty()) return; const char* msg_type; - int make_flags; + CNetAddr::Encoding ser_enc; if (peer.m_wants_addrv2) { msg_type = NetMsgType::ADDRV2; - make_flags = ADDRV2_FORMAT; + ser_enc = CNetAddr::Encoding::V2; } else { msg_type = NetMsgType::ADDR; - make_flags = 0; + ser_enc = CNetAddr::Encoding::V1; } - m_connman.PushMessage(&node, CNetMsgMaker(node.GetCommonVersion()).Make(make_flags, msg_type, peer.m_addrs_to_send)); + m_connman.PushMessage(&node, CNetMsgMaker(node.GetCommonVersion()).Make(msg_type, WithParams(CAddress::SerParams{{ser_enc}, CAddress::Format::Network}, peer.m_addrs_to_send))); peer.m_addrs_to_send.clear(); // we only send the big addr message once |