Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_sendheaders.py
Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | |||||
class SendHeadersTest(BitcoinTestFramework): | class SendHeadersTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"]] | self.extra_args = [["-noparkdeepreorg"], ["-noparkdeepreorg"]] | ||||
def skip_test_if_missing_module(self): | |||||
self.skip_if_no_wallet() | |||||
def mine_blocks(self, count): | def mine_blocks(self, count): | ||||
"""Mine count blocks and return the new tip.""" | """Mine count blocks and return the new tip.""" | ||||
# Clear out block announcements from each p2p listener | # Clear out block announcements from each p2p listener | ||||
[x.clear_block_announcements() for x in self.nodes[0].p2ps] | [x.clear_block_announcements() for x in self.nodes[0].p2ps] | ||||
self.nodes[0].generate(count) | self.nodes[0].generatetoaddress( | ||||
count, self.nodes[0].get_deterministic_priv_key().address) | |||||
return int(self.nodes[0].getbestblockhash(), 16) | return int(self.nodes[0].getbestblockhash(), 16) | ||||
def mine_reorg(self, length): | def mine_reorg(self, length): | ||||
"""Mine a reorg that invalidates length blocks (replacing them with # length+1 blocks). | """Mine a reorg that invalidates length blocks (replacing them with # length+1 blocks). | ||||
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].generate(length) | self.nodes[0].generatetoaddress( | ||||
length, self.nodes[0].get_deterministic_priv_key().address) | |||||
sync_blocks(self.nodes, wait=0.1) | 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].generate(length + 1) | all_hashes = self.nodes[1].generatetoaddress( | ||||
length + 1, self.nodes[1].get_deterministic_priv_key().address) | |||||
sync_blocks(self.nodes, wait=0.1) | 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) | ||||
# Ensure verack's have been processed by our peer | # Ensure verack's have been processed by our peer | ||||
inv_node.sync_with_ping() | inv_node.sync_with_ping() | ||||
test_node.sync_with_ping() | test_node.sync_with_ping() | ||||
self.test_null_locators(test_node, inv_node) | self.test_null_locators(test_node, inv_node) | ||||
self.test_nonnull_locators(test_node, inv_node) | self.test_nonnull_locators(test_node, inv_node) | ||||
def test_null_locators(self, test_node, inv_node): | def test_null_locators(self, test_node, inv_node): | ||||
tip = self.nodes[0].getblockheader(self.nodes[0].generate(1)[0]) | tip = self.nodes[0].getblockheader(self.nodes[0].generatetoaddress( | ||||
1, self.nodes[0].get_deterministic_priv_key().address)[0]) | |||||
tip_hash = int(tip["hash"], 16) | tip_hash = int(tip["hash"], 16) | ||||
inv_node.check_last_inv_announcement(inv=[tip_hash]) | inv_node.check_last_inv_announcement(inv=[tip_hash]) | ||||
test_node.check_last_inv_announcement(inv=[tip_hash]) | test_node.check_last_inv_announcement(inv=[tip_hash]) | ||||
self.log.info( | self.log.info( | ||||
"Verify getheaders with null locator and valid hashstop returns headers.") | "Verify getheaders with null locator and valid hashstop returns headers.") | ||||
test_node.clear_block_announcements() | test_node.clear_block_announcements() | ||||
▲ Show 20 Lines • Show All 374 Lines • Show Last 20 Lines |