Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_sendheaders.py
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | from test_framework.messages import ( | ||||
msg_inv, | msg_inv, | ||||
msg_sendheaders, | msg_sendheaders, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
mininode_lock, | mininode_lock, | ||||
P2PInterface, | P2PInterface, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal, sync_blocks, wait_until | from test_framework.util import ( | ||||
assert_equal, | |||||
wait_until, | |||||
) | |||||
DIRECT_FETCH_RESPONSE_TIME = 0.05 | DIRECT_FETCH_RESPONSE_TIME = 0.05 | ||||
class BaseNode(P2PInterface): | class BaseNode(P2PInterface): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | def mine_reorg(self, length): | ||||
Note: we clear the state of our p2p connections after the | Note: we clear the state of our p2p connections after the | ||||
to-be-reorged-out blocks are mined, so that we don't break later tests. | to-be-reorged-out blocks are mined, so that we don't break later tests. | ||||
return the list of block hashes newly mined.""" | return the list of block hashes newly mined.""" | ||||
# make sure all invalidated blocks are node0's | # make sure all invalidated blocks are node0's | ||||
self.nodes[0].generatetoaddress( | self.nodes[0].generatetoaddress( | ||||
length, self.nodes[0].get_deterministic_priv_key().address) | length, self.nodes[0].get_deterministic_priv_key().address) | ||||
sync_blocks(self.nodes, wait=0.1) | self.sync_blocks(self.nodes, wait=0.1) | ||||
for x in self.nodes[0].p2ps: | for x in self.nodes[0].p2ps: | ||||
x.wait_for_block_announcement( | x.wait_for_block_announcement( | ||||
int(self.nodes[0].getbestblockhash(), 16)) | int(self.nodes[0].getbestblockhash(), 16)) | ||||
x.clear_block_announcements() | x.clear_block_announcements() | ||||
tip_height = self.nodes[1].getblockcount() | tip_height = self.nodes[1].getblockcount() | ||||
hash_to_invalidate = self.nodes[1].getblockhash( | hash_to_invalidate = self.nodes[1].getblockhash( | ||||
tip_height - (length - 1)) | tip_height - (length - 1)) | ||||
self.nodes[1].invalidateblock(hash_to_invalidate) | self.nodes[1].invalidateblock(hash_to_invalidate) | ||||
# Must be longer than the orig chain | # Must be longer than the orig chain | ||||
all_hashes = self.nodes[1].generatetoaddress( | all_hashes = self.nodes[1].generatetoaddress( | ||||
length + 1, self.nodes[1].get_deterministic_priv_key().address) | length + 1, self.nodes[1].get_deterministic_priv_key().address) | ||||
sync_blocks(self.nodes, wait=0.1) | self.sync_blocks(self.nodes, wait=0.1) | ||||
return [int(x, 16) for x in all_hashes] | return [int(x, 16) for x in all_hashes] | ||||
def run_test(self): | def run_test(self): | ||||
# Setup the p2p connections | # Setup the p2p connections | ||||
inv_node = self.nodes[0].add_p2p_connection(BaseNode()) | inv_node = self.nodes[0].add_p2p_connection(BaseNode()) | ||||
# Make sure NODE_NETWORK is not set for test_node, so no block download | # Make sure NODE_NETWORK is not set for test_node, so no block download | ||||
# will occur outside of direct fetching | # will occur outside of direct fetching | ||||
test_node = self.nodes[0].add_p2p_connection(BaseNode(), services=0) | test_node = self.nodes[0].add_p2p_connection(BaseNode(), services=0) | ||||
▲ Show 20 Lines • Show All 393 Lines • Show Last 20 Lines |