Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_blockfilters.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2019 The Bitcoin Core developers | # Copyright (c) 2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Tests NODE_COMPACT_FILTERS (BIP 157/158). | """Tests NODE_COMPACT_FILTERS (BIP 157/158). | ||||
Tests that a node configured with -blockfilterindex and -peerblockfilters can serve | Tests that a node configured with -blockfilterindex and -peerblockfilters signals | ||||
cfilters, cfheaders and cfcheckpts. | NODE_COMPACT_FILTERS and can serve cfilters, cfheaders and cfcheckpts. | ||||
""" | """ | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
FILTER_TYPE_BASIC, | FILTER_TYPE_BASIC, | ||||
NODE_COMPACT_FILTERS, | |||||
hash256, | hash256, | ||||
msg_getcfcheckpt, | msg_getcfcheckpt, | ||||
msg_getcfheaders, | msg_getcfheaders, | ||||
msg_getcfilters, | msg_getcfilters, | ||||
ser_uint256, | ser_uint256, | ||||
uint256_from_str, | uint256_from_str, | ||||
) | ) | ||||
from test_framework.mininode import P2PInterface | from test_framework.mininode import P2PInterface | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
wait_until(lambda: self.nodes[0].getblockcount() == 1000) | wait_until(lambda: self.nodes[0].getblockcount() == 1000) | ||||
stale_block_hash = self.nodes[0].getblockhash(1000) | stale_block_hash = self.nodes[0].getblockhash(1000) | ||||
self.nodes[1].generate(1001) | self.nodes[1].generate(1001) | ||||
wait_until(lambda: self.nodes[1].getblockcount() == 2000) | wait_until(lambda: self.nodes[1].getblockcount() == 2000) | ||||
# Check that nodes have signalled NODE_COMPACT_FILTERS correctly. | |||||
assert node0.nServices & NODE_COMPACT_FILTERS != 0 | |||||
assert node1.nServices & NODE_COMPACT_FILTERS == 0 | |||||
# Check that the localservices is as expected. | |||||
assert int( | |||||
self.nodes[0].getnetworkinfo()['localservices'], | |||||
16) & NODE_COMPACT_FILTERS != 0 | |||||
assert int( | |||||
self.nodes[1].getnetworkinfo()['localservices'], | |||||
16) & NODE_COMPACT_FILTERS == 0 | |||||
self.log.info("get cfcheckpt on chain to be re-orged out.") | self.log.info("get cfcheckpt on chain to be re-orged out.") | ||||
request = msg_getcfcheckpt( | request = msg_getcfcheckpt( | ||||
filter_type=FILTER_TYPE_BASIC, | filter_type=FILTER_TYPE_BASIC, | ||||
stop_hash=int(stale_block_hash, 16) | stop_hash=int(stale_block_hash, 16) | ||||
) | ) | ||||
node0.send_and_ping(message=request) | node0.send_and_ping(message=request) | ||||
response = node0.last_message['cfcheckpt'] | response = node0.last_message['cfcheckpt'] | ||||
assert_equal(response.filter_type, request.filter_type) | assert_equal(response.filter_type, request.filter_type) | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |