Skip to content

Commit 52976e1

Browse files
Merge #7301: test: adds QSENDRECSIGS functional tests for watchquorum nodes
737fec7 test: require every recsigs observer to receive the ISDLOCK inv (UdjinM6) 59dec1c test: rename msg_qsendrecsigs.on to wants_recsigs and tear down observers (UdjinM6) 3a4fea7 test: adds QSENDRECSIGS functional tests (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Addresses #7293 (comment) ## What was done? Adds functional tests for QSENDRECSIGS for watch-quorum nodes. ## How Has This Been Tested? Run on the top of #7293 and on develop with #7293 reverted. ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: UdjinM6: utACK 737fec7 Tree-SHA512: 21c56abf5d10fc315fa9ad2976552f149612126fa62027a4190f925348300928606c411ca1ef38569013071cfd36718f8c6ca2dbf7c4f64510e95c81b23639c3
2 parents 843475a + 737fec7 commit 52976e1

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

test/functional/p2p_instantsend.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
from test_framework.messages import msg_qsendrecsigs
7+
from test_framework.p2p import P2PInterface
68
from test_framework.test_framework import DashTestFramework
79
from test_framework.util import assert_equal, assert_raises_rpc_error, force_finish_mnsync
810

@@ -12,6 +14,24 @@
1214
Tests InstantSend functionality (prevent doublespend for unconfirmed transactions)
1315
'''
1416

17+
class RecSigsObserver(P2PInterface):
18+
"""Non-MN peer that opts in to recsigs and records every ISDLOCK inv it sees."""
19+
20+
def __init__(self):
21+
super().__init__()
22+
self.isdlock_inv_seen = False
23+
24+
def send_qsendrecsigs(self, wants_recsigs=True):
25+
self.send_message(msg_qsendrecsigs(wants_recsigs))
26+
27+
def on_inv(self, message):
28+
for inv in message.inv:
29+
# MSG_ISDLOCK inv type, see src/protocol.h
30+
if inv.type == 31:
31+
self.isdlock_inv_seen = True
32+
super().on_inv(message)
33+
34+
1535
class InstantSendTest(DashTestFramework):
1636
def add_options(self, parser):
1737
self.add_wallet_options(parser)
@@ -36,6 +56,7 @@ def run_test(self):
3656

3757
self.test_mempool_doublespend()
3858
self.test_block_doublespend()
59+
self.test_isdlock_relayed_to_recsigs_observer()
3960
self.test_instantsend_after_restart()
4061

4162
def test_block_doublespend(self):
@@ -131,6 +152,25 @@ def test_mempool_doublespend(self):
131152
# mine more blocks
132153
self.generate(self.nodes[0], 2)
133154

155+
def test_isdlock_relayed_to_recsigs_observer(self):
156+
self.log.info("Non-MN peer started with -watchquorums must still get ISDLOCK invs")
157+
observers = []
158+
for mn in self.mninfo:
159+
node = mn.get_node(self)
160+
obs = node.add_p2p_connection(RecSigsObserver())
161+
obs.send_qsendrecsigs(True)
162+
obs.sync_with_ping()
163+
observers.append((node, obs))
164+
165+
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
166+
self.wait_for_instantlock(txid)
167+
168+
for _, obs in observers:
169+
obs.wait_until(lambda obs=obs: obs.isdlock_inv_seen, timeout=10)
170+
171+
for node, _ in observers:
172+
node.disconnect_p2ps()
173+
134174
def test_instantsend_after_restart(self):
135175
self.log.info("Testing InstantSend works after full restart without new blocks")
136176

test/functional/test_framework/messages.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,23 @@ def __repr__(self):
24472447
return "msg_qsigshare(sigShares=%d)" % (len(self.sig_shares))
24482448

24492449

2450+
class msg_qsendrecsigs:
2451+
__slots__ = ("wants_recsigs",)
2452+
msgtype = b"qsendrecsigs"
2453+
2454+
def __init__(self, wants_recsigs=True):
2455+
self.wants_recsigs = wants_recsigs
2456+
2457+
def deserialize(self, f):
2458+
self.wants_recsigs = bool(struct.unpack("<?", f.read(1))[0])
2459+
2460+
def serialize(self):
2461+
return struct.pack("<?", self.wants_recsigs)
2462+
2463+
def __repr__(self):
2464+
return f"msg_qsendrecsigs(wants_recsigs={self.wants_recsigs})"
2465+
2466+
24502467
class msg_qwatch:
24512468
__slots__ = ()
24522469
msgtype = b"qwatch"

test/functional/test_framework/p2p.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
msg_pong,
7070
msg_qdata,
7171
msg_qgetdata,
72+
msg_qsendrecsigs,
7273
msg_sendaddrv2,
7374
msg_sendcmpct,
7475
msg_sendheaders,
@@ -177,7 +178,7 @@
177178
b"qjustify": None,
178179
b"qpcommit": None,
179180
b"qrinfo": None,
180-
b"qsendrecsigs": None,
181+
b"qsendrecsigs": msg_qsendrecsigs,
181182
b"qsigrec": None,
182183
b"qsigsesann": None,
183184
b"qsigshare": None,
@@ -621,6 +622,7 @@ def on_isdlock(self, message): pass
621622
def on_platformban(self, message): pass
622623
def on_qgetdata(self, message): pass
623624
def on_qdata(self, message): pass
625+
def on_qsendrecsigs(self, message): pass
624626
def on_qwatch(self, message): pass
625627

626628
def on_verack(self, message): pass

0 commit comments

Comments
 (0)