Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_blockfilters.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Nodes 0 & 1 share the same first 999 blocks in the chain. | # Nodes 0 & 1 share the same first 999 blocks in the chain. | ||||
self.nodes[0].generate(999) | self.nodes[0].generate(999) | ||||
self.sync_blocks(timeout=600) | self.sync_blocks(timeout=600) | ||||
# Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting | # Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting | ||||
self.disconnect_nodes(0, 1) | self.disconnect_nodes(0, 1) | ||||
self.nodes[0].generate(1) | stale_block_hash = self.nodes[0].generate(1)[0] | ||||
self.wait_until(lambda: self.nodes[0].getblockcount() == 1000) | assert_equal(self.nodes[0].getblockcount(), 1000) | ||||
stale_block_hash = self.nodes[0].getblockhash(1000) | |||||
self.nodes[1].generate(1001) | self.nodes[1].generate(1001) | ||||
self.wait_until(lambda: self.nodes[1].getblockcount() == 2000) | assert_equal(self.nodes[1].getblockcount(), 2000) | ||||
# Check that nodes have signalled NODE_COMPACT_FILTERS correctly. | # Check that nodes have signalled NODE_COMPACT_FILTERS correctly. | ||||
assert peer_0.nServices & NODE_COMPACT_FILTERS != 0 | assert peer_0.nServices & NODE_COMPACT_FILTERS != 0 | ||||
assert peer_1.nServices & NODE_COMPACT_FILTERS == 0 | assert peer_1.nServices & NODE_COMPACT_FILTERS == 0 | ||||
# Check that the localservices is as expected. | # Check that the localservices is as expected. | ||||
assert int( | assert int( | ||||
self.nodes[0].getnetworkinfo()['localservices'], | self.nodes[0].getnetworkinfo()['localservices'], | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info("Check that peers can fetch cfilters.") | self.log.info("Check that peers can fetch cfilters.") | ||||
stop_hash = self.nodes[0].getblockhash(10) | stop_hash = self.nodes[0].getblockhash(10) | ||||
request = msg_getcfilters( | request = msg_getcfilters( | ||||
filter_type=FILTER_TYPE_BASIC, | filter_type=FILTER_TYPE_BASIC, | ||||
start_height=1, | start_height=1, | ||||
stop_hash=int(stop_hash, 16), | stop_hash=int(stop_hash, 16), | ||||
) | ) | ||||
peer_0.send_message(request) | peer_0.send_and_ping(request) | ||||
peer_0.sync_with_ping() | |||||
response = peer_0.pop_cfilters() | response = peer_0.pop_cfilters() | ||||
assert_equal(len(response), 10) | assert_equal(len(response), 10) | ||||
self.log.info("Check that cfilter responses are correct.") | self.log.info("Check that cfilter responses are correct.") | ||||
for cfilter, cfhash, height in zip( | for cfilter, cfhash, height in zip( | ||||
response, main_cfhashes, range(1, 11)): | response, main_cfhashes, range(1, 11)): | ||||
block_hash = self.nodes[0].getblockhash(height) | block_hash = self.nodes[0].getblockhash(height) | ||||
assert_equal(cfilter.filter_type, FILTER_TYPE_BASIC) | assert_equal(cfilter.filter_type, FILTER_TYPE_BASIC) | ||||
assert_equal(cfilter.block_hash, int(block_hash, 16)) | assert_equal(cfilter.block_hash, int(block_hash, 16)) | ||||
computed_cfhash = uint256_from_str(hash256(cfilter.filter_data)) | computed_cfhash = uint256_from_str(hash256(cfilter.filter_data)) | ||||
assert_equal(computed_cfhash, cfhash) | assert_equal(computed_cfhash, cfhash) | ||||
self.log.info("Check that peers can fetch cfilters for stale blocks.") | self.log.info("Check that peers can fetch cfilters for stale blocks.") | ||||
request = msg_getcfilters( | request = msg_getcfilters( | ||||
filter_type=FILTER_TYPE_BASIC, | filter_type=FILTER_TYPE_BASIC, | ||||
start_height=1000, | start_height=1000, | ||||
stop_hash=int(stale_block_hash, 16), | stop_hash=int(stale_block_hash, 16), | ||||
) | ) | ||||
peer_0.send_message(request) | peer_0.send_and_ping(request) | ||||
peer_0.sync_with_ping() | |||||
response = peer_0.pop_cfilters() | response = peer_0.pop_cfilters() | ||||
assert_equal(len(response), 1) | assert_equal(len(response), 1) | ||||
cfilter = response[0] | cfilter = response[0] | ||||
assert_equal(cfilter.filter_type, FILTER_TYPE_BASIC) | assert_equal(cfilter.filter_type, FILTER_TYPE_BASIC) | ||||
assert_equal(cfilter.block_hash, int(stale_block_hash, 16)) | assert_equal(cfilter.block_hash, int(stale_block_hash, 16)) | ||||
computed_cfhash = uint256_from_str(hash256(cfilter.filter_data)) | computed_cfhash = uint256_from_str(hash256(cfilter.filter_data)) | ||||
assert_equal(computed_cfhash, stale_cfhashes[999]) | assert_equal(computed_cfhash, stale_cfhashes[999]) | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |