v29.4-roots.2 · Commit 3: [PATCH 03/21] policy: restore conservative relay and network controls
test/functional/p2p_filter.py
Before: test/functional/p2p_filter.py · After: test/functional/p2p_filter.py
File metadata
index e4aaf507cf3479e5bc70ed55b55e6e15e5563c28..207d177d151dc63e37f93fc63a759ec2208a6945 100755
Download original patch · Release notes
Diff rows 1–59 of 59. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
test/functional/p2p_filter.py
CHANGED
|
@@ -12,6 +12,7 @@ from test_framework.messages import (
|
|
|
12
12
|
MAX_BLOOM_FILTER_SIZE,
|
|
13
13
|
MAX_BLOOM_HASH_FUNCS,
|
|
14
14
|
MSG_WTX,
|
|
15
|
+
MSG_WITNESS_FLAG,
|
|
15
16
|
MSG_BLOCK,
|
|
16
17
|
MSG_FILTERED_BLOCK,
|
|
17
18
|
msg_filteradd,
|
|
@@ -47,6 +48,7 @@ class P2PBloomFilter(P2PInterface):
|
|
|
47
48
|
nTweak=0,
|
|
48
49
|
nFlags=1,
|
|
49
50
|
)
|
|
51
|
+
filtered_block_type = MSG_FILTERED_BLOCK
|
|
50
52
|
|
|
51
53
|
def __init__(self):
|
|
52
54
|
super().__init__()
|
|
@@ -58,7 +60,7 @@ class P2PBloomFilter(P2PInterface):
|
|
|
58
60
|
for i in message.inv:
|
|
59
61
|
# inv messages can only contain TX or BLOCK, so translate BLOCK to FILTERED_BLOCK
|
|
60
62
|
if i.type == MSG_BLOCK:
|
|
61
|
-
want.inv.append(CInv(MSG_FILTERED_BLOCK, i.hash))
|
|
63
|
+
want.inv.append(CInv(self.filtered_block_type, i.hash))
|
|
62
64
|
else:
|
|
63
65
|
want.inv.append(i)
|
|
64
66
|
if len(want.inv):
|
|
@@ -222,6 +224,28 @@ class FilterTest(BitcoinTestFramework):
|
|
|
222
224
|
filter_peer.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
|
|
223
225
|
self.nodes[0].disconnect_p2ps()
|
|
224
226
|
|
|
227
|
+
def test_filtered_witness_block(self, filter_peer):
|
|
228
|
+
self.log.info("Check filtered witness-block requests preserve matched transaction witnesses")
|
|
229
|
+
assert "BLOOM" in self.nodes[0].getnetworkinfo()["localservicesnames"]
|
|
230
|
+
filter_peer.send_and_ping(filter_peer.watch_filter_init)
|
|
231
|
+
|
|
232
|
+
txid = self.wallet.send_to(
|
|
233
|
+
from_node=self.nodes[0],
|
|
234
|
+
scriptPubKey=filter_peer.watch_script_pubkey,
|
|
235
|
+
amount=1 * COIN,
|
|
236
|
+
)["txid"]
|
|
237
|
+
block_hash = self.generate(self.nodes[0], 1)[0]
|
|
238
|
+
filter_peer.wait_for_merkleblock(block_hash)
|
|
239
|
+
filter_peer.wait_for_tx(txid)
|
|
240
|
+
assert filter_peer.last_message["tx"].tx.wit.is_null()
|
|
241
|
+
|
|
242
|
+
with p2p_lock:
|
|
243
|
+
filter_peer.last_message.pop("tx", None)
|
|
244
|
+
filter_peer.send_and_ping(msg_getdata([CInv(MSG_FILTERED_BLOCK | MSG_WITNESS_FLAG, int(block_hash, 16))]))
|
|
245
|
+
filter_peer.wait_for_tx(txid)
|
|
246
|
+
assert not filter_peer.last_message["tx"].tx.wit.is_null()
|
|
247
|
+
self.nodes[0].disconnect_p2ps()
|
|
248
|
+
|
|
225
249
|
def run_test(self):
|
|
226
250
|
self.wallet = MiniWallet(self.nodes[0])
|
|
227
251
|
|
|
@@ -248,6 +272,9 @@ class FilterTest(BitcoinTestFramework):
|
|
|
248
272
|
self.test_frelay_false(filter_peer_without_nrelay)
|
|
249
273
|
self.test_filter(filter_peer_without_nrelay)
|
|
250
274
|
|
|
275
|
+
filter_peer = self.nodes[0].add_p2p_connection(P2PBloomFilter())
|
|
276
|
+
self.test_filtered_witness_block(filter_peer)
|
|
277
|
+
|
|
251
278
|
self.test_msg_mempool()
|
|
252
279
|
|
|
253
280
|
|