forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backport: Merge bitcoin#22423, 22096 #5884
Merged
+95
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2021 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
""" | ||
Test p2p addr-fetch connections | ||
""" | ||
|
||
import time | ||
|
||
from test_framework.messages import msg_addr, CAddress, NODE_NETWORK | ||
from test_framework.p2p import P2PInterface, p2p_lock | ||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import assert_equal | ||
|
||
ADDR = CAddress() | ||
ADDR.time = int(time.time()) | ||
ADDR.nServices = NODE_NETWORK | ||
ADDR.ip = "192.0.0.8" | ||
ADDR.port = 18444 | ||
|
||
|
||
class P2PAddrFetch(BitcoinTestFramework): | ||
|
||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 1 | ||
|
||
def run_test(self): | ||
node = self.nodes[0] | ||
self.log.info("Connect to an addr-fetch peer") | ||
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="addr-fetch") | ||
info = node.getpeerinfo() | ||
assert_equal(len(info), 1) | ||
assert_equal(info[0]['connection_type'], 'addr-fetch') | ||
|
||
self.log.info("Check that we send getaddr but don't try to sync headers with the addr-fetch peer") | ||
peer.sync_send_with_ping() | ||
with p2p_lock: | ||
assert peer.message_count['getaddr'] == 1 | ||
assert peer.message_count['getheaders'] == 0 | ||
|
||
self.log.info("Check that answering the getaddr with a single address does not lead to disconnect") | ||
# This prevents disconnecting on self-announcements | ||
msg = msg_addr() | ||
msg.addrs = [ADDR] | ||
peer.send_and_ping(msg) | ||
assert_equal(len(node.getpeerinfo()), 1) | ||
|
||
self.log.info("Check that answering with larger addr messages leads to disconnect") | ||
msg.addrs = [ADDR] * 2 | ||
peer.send_message(msg) | ||
peer.wait_for_disconnect(timeout=5) | ||
|
||
self.log.info("Check timeout for addr-fetch peer that does not send addrs") | ||
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=1, connection_type="addr-fetch") | ||
node.setmocktime(int(time.time()) + 301) # Timeout: 5 minutes | ||
peer.wait_for_disconnect(timeout=5) | ||
|
||
|
||
if __name__ == '__main__': | ||
P2PAddrFetch().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider to backport bitcoin#22568 in a follow-up PR. There are no any important/critical fix, just tests improvements, so, that's an out-of-scope of current PR