Skip to content

Commit 90ef622

Browse files
author
MarcoFalke
committed
Merge #20564: Don't send 'sendaddrv2' to pre-70016 software, and send before 'verack'
1583498 Send and require SENDADDRV2 before VERACK (Pieter Wuille) c5a8919 Don't send 'sendaddrv2' to pre-70016 software (Pieter Wuille) Pull request description: BIP155 defines addrv2 and sendaddrv2 for all protocol versions, but some implementations reject messages they don't know. As a courtesy, don't send it to nodes with a version before 70016, as no software is known to support BIP155 that doesn't announce at least that protocol version number. Also move the sending of sendaddrv2 earlier (before sending verack), as proposed in bitcoin/bips#1043. This has the side effect that local address broadcast of torv3 will work (as it'll only trigger after we know whether or not the peer supports addrv2). ACKs for top commit: MarcoFalke: ACK 1583498 jnewbery: ACK 1583498 jonatack: ACK 1583498 vasild: ACK 1583498 Tree-SHA512: 3bd5833fa8c8567b6dedd99e4a9b6bb71c127aa66d5284b217503c86d597dc59aa7382c41f3a4bf561bb658b89db81d1a7703a700eef4ffc17cb916660e23a82
2 parents e98d1d6 + 1583498 commit 90ef622

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/net_processing.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,10 +2362,16 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
23622362
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::WTXIDRELAY));
23632363
}
23642364

2365-
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::VERACK));
2366-
23672365
// Signal ADDRv2 support (BIP155).
2368-
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDADDRV2));
2366+
if (greatest_common_version >= 70016) {
2367+
// BIP155 defines addrv2 and sendaddrv2 for all protocol versions, but some
2368+
// implementations reject messages they don't know. As a courtesy, don't send
2369+
// it to nodes with a version before 70016, as no software is known to support
2370+
// BIP155 that doesn't announce at least that protocol version number.
2371+
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDADDRV2));
2372+
}
2373+
2374+
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::VERACK));
23692375

23702376
pfrom.nServices = nServices;
23712377
pfrom.SetAddrLocal(addrMe);
@@ -2535,6 +2541,17 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25352541
return;
25362542
}
25372543

2544+
if (msg_type == NetMsgType::SENDADDRV2) {
2545+
if (pfrom.fSuccessfullyConnected) {
2546+
// Disconnect peers that send SENDADDRV2 message after VERACK; this
2547+
// must be negotiated between VERSION and VERACK.
2548+
pfrom.fDisconnect = true;
2549+
return;
2550+
}
2551+
pfrom.m_wants_addrv2 = true;
2552+
return;
2553+
}
2554+
25382555
if (!pfrom.fSuccessfullyConnected) {
25392556
LogPrint(BCLog::NET, "Unsupported message \"%s\" prior to verack from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
25402557
return;
@@ -2602,11 +2619,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
26022619
return;
26032620
}
26042621

2605-
if (msg_type == NetMsgType::SENDADDRV2) {
2606-
pfrom.m_wants_addrv2 = true;
2607-
return;
2608-
}
2609-
26102622
if (msg_type == NetMsgType::SENDHEADERS) {
26112623
LOCK(cs_main);
26122624
State(pfrom.GetId())->fPreferHeaders = true;

test/functional/test_framework/p2p.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ def on_version(self, message):
396396
assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED)
397397
if message.nVersion >= 70016:
398398
self.send_message(msg_wtxidrelay())
399-
self.send_message(msg_verack())
400399
if self.support_addrv2:
401400
self.send_message(msg_sendaddrv2())
401+
self.send_message(msg_verack())
402402
self.nServices = message.nServices
403403

404404
# Connection helper methods

0 commit comments

Comments
 (0)