diff options
author | Pieter Wuille <pieter@wuille.net> | 2020-12-07 09:12:37 -0800 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-12-10 11:37:22 +0100 |
commit | bead93547067e4b62b44fba335f1d4697119c2d7 (patch) | |
tree | 4feb1322298a1bc06dee4c96ca3949cb5d1cbcc6 | |
parent | 9e806887a8f9ef63431b28d7dfd0470aa663dd02 (diff) | |
download | bitcoin-bead93547067e4b62b44fba335f1d4697119c2d7.tar.xz |
Send and require SENDADDRV2 before VERACK
See the corresponding BIP change: https://github.com/bitcoin/bips/pull/1043
Github-Pull: #20564
Rebased-From: 1583498fb6781c01ca2f33c09319ed793964c574
-rw-r--r-- | src/net_processing.cpp | 20 | ||||
-rwxr-xr-x | test/functional/test_framework/p2p.py | 2 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 44f6f5d6b6..98e3d90c2d 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2364,8 +2364,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::WTXIDRELAY)); } - m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::VERACK)); - // Signal ADDRv2 support (BIP155). if (greatest_common_version >= 70016) { // BIP155 defines addrv2 and sendaddrv2 for all protocol versions, but some @@ -2375,6 +2373,8 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDADDRV2)); } + m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::VERACK)); + pfrom.nServices = nServices; pfrom.SetAddrLocal(addrMe); { @@ -2546,6 +2546,17 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat return; } + if (msg_type == NetMsgType::SENDADDRV2) { + if (pfrom.fSuccessfullyConnected) { + // Disconnect peers that send SENDADDRV2 message after VERACK; this + // must be negotiated between VERSION and VERACK. + pfrom.fDisconnect = true; + return; + } + pfrom.m_wants_addrv2 = true; + return; + } + if (!pfrom.fSuccessfullyConnected) { LogPrint(BCLog::NET, "Unsupported message \"%s\" prior to verack from peer=%d\n", SanitizeString(msg_type), pfrom.GetId()); return; @@ -2613,11 +2624,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat return; } - if (msg_type == NetMsgType::SENDADDRV2) { - pfrom.m_wants_addrv2 = true; - return; - } - if (msg_type == NetMsgType::SENDHEADERS) { LOCK(cs_main); State(pfrom.GetId())->fPreferHeaders = true; diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 6846d31221..8b79a4dc2f 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -396,9 +396,9 @@ class P2PInterface(P2PConnection): assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED) if message.nVersion >= 70016: self.send_message(msg_wtxidrelay()) - self.send_message(msg_verack()) if self.support_addrv2: self.send_message(msg_sendaddrv2()) + self.send_message(msg_verack()) self.nServices = message.nServices # Connection helper methods |