Skip to content

Commit 1583498

Browse files
committed
Send and require SENDADDRV2 before VERACK
See the corresponding BIP change: bitcoin/bips#1043
1 parent c5a8919 commit 1583498

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,8 +2362,6 @@ 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).
23682366
if (greatest_common_version >= 70016) {
23692367
// BIP155 defines addrv2 and sendaddrv2 for all protocol versions, but some
@@ -2373,6 +2371,8 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
23732371
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDADDRV2));
23742372
}
23752373

2374+
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::VERACK));
2375+
23762376
pfrom.nServices = nServices;
23772377
pfrom.SetAddrLocal(addrMe);
23782378
{
@@ -2541,6 +2541,17 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25412541
return;
25422542
}
25432543

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+
25442555
if (!pfrom.fSuccessfullyConnected) {
25452556
LogPrint(BCLog::NET, "Unsupported message \"%s\" prior to verack from peer=%d\n", SanitizeString(msg_type), pfrom.GetId());
25462557
return;
@@ -2608,11 +2619,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
26082619
return;
26092620
}
26102621

2611-
if (msg_type == NetMsgType::SENDADDRV2) {
2612-
pfrom.m_wants_addrv2 = true;
2613-
return;
2614-
}
2615-
26162622
if (msg_type == NetMsgType::SENDHEADERS) {
26172623
LOCK(cs_main);
26182624
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)