v29.4-roots.4 · Commit 3: [PATCH 03/37] 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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/p2p_filter.py
CHANGED
|
@@ -12,6 +12,7 @@ from test_framework.messages import (
|
|
| 12 |
MAX_BLOOM_FILTER_SIZE,
|
| 13 |
MAX_BLOOM_HASH_FUNCS,
|
| 14 |
MSG_WTX,
|
|
|
|
| 15 |
MSG_BLOCK,
|
| 16 |
MSG_FILTERED_BLOCK,
|
| 17 |
msg_filteradd,
|
|
@@ -47,6 +48,7 @@ class P2PBloomFilter(P2PInterface):
|
|
| 47 |
nTweak=0,
|
| 48 |
nFlags=1,
|
| 49 |
)
|
|
|
|
| 50 |
|
| 51 |
def __init__(self):
|
| 52 |
super().__init__()
|
|
@@ -58,7 +60,7 @@ class P2PBloomFilter(P2PInterface):
|
|
| 58 |
for i in message.inv:
|
| 59 |
# inv messages can only contain TX or BLOCK, so translate BLOCK to FILTERED_BLOCK
|
| 60 |
if i.type == MSG_BLOCK:
|
| 61 |
-
want.inv.append(CInv(MSG_FILTERED_BLOCK, i.hash))
|
| 62 |
else:
|
| 63 |
want.inv.append(i)
|
| 64 |
if len(want.inv):
|
|
@@ -222,6 +224,28 @@ class FilterTest(BitcoinTestFramework):
|
|
| 222 |
filter_peer.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
|
| 223 |
self.nodes[0].disconnect_p2ps()
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
def run_test(self):
|
| 226 |
self.wallet = MiniWallet(self.nodes[0])
|
| 227 |
|
|
@@ -248,6 +272,9 @@ class FilterTest(BitcoinTestFramework):
|
|
| 248 |
self.test_frelay_false(filter_peer_without_nrelay)
|
| 249 |
self.test_filter(filter_peer_without_nrelay)
|
| 250 |
|
|
|
|
|
|
|
|
|
|
| 251 |
self.test_msg_mempool()
|
| 252 |
|
| 253 |
|
|
|
|
| 12 |
MAX_BLOOM_FILTER_SIZE,
|
| 13 |
MAX_BLOOM_HASH_FUNCS,
|
| 14 |
MSG_WTX,
|
| 15 |
+
MSG_WITNESS_FLAG,
|
| 16 |
MSG_BLOCK,
|
| 17 |
MSG_FILTERED_BLOCK,
|
| 18 |
msg_filteradd,
|
|
|
|
| 48 |
nTweak=0,
|
| 49 |
nFlags=1,
|
| 50 |
)
|
| 51 |
+
filtered_block_type = MSG_FILTERED_BLOCK
|
| 52 |
|
| 53 |
def __init__(self):
|
| 54 |
super().__init__()
|
|
|
|
| 60 |
for i in message.inv:
|
| 61 |
# inv messages can only contain TX or BLOCK, so translate BLOCK to FILTERED_BLOCK
|
| 62 |
if i.type == MSG_BLOCK:
|
| 63 |
+
want.inv.append(CInv(self.filtered_block_type, i.hash))
|
| 64 |
else:
|
| 65 |
want.inv.append(i)
|
| 66 |
if len(want.inv):
|
|
|
|
| 224 |
filter_peer.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
|
| 225 |
self.nodes[0].disconnect_p2ps()
|
| 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 |
+
|
| 249 |
def run_test(self):
|
| 250 |
self.wallet = MiniWallet(self.nodes[0])
|
| 251 |
|
|
|
|
| 272 |
self.test_frelay_false(filter_peer_without_nrelay)
|
| 273 |
self.test_filter(filter_peer_without_nrelay)
|
| 274 |
|
| 275 |
+
filter_peer = self.nodes[0].add_p2p_connection(P2PBloomFilter())
|
| 276 |
+
self.test_filtered_witness_block(filter_peer)
|
| 277 |
+
|
| 278 |
self.test_msg_mempool()
|
| 279 |
|
| 280 |
|