Skip to content

Commit cd7ffcf

Browse files
committed
refactor: store only the node index in MasternodeInfo
We don't register nodeIdx and node at the same time. This creates a problem that we aren't entirely sure if the node is online when we access node since we don't really own the TestNode instance, it is always in the control of BitcoinTestFramework. So let's try to be more explicit about that and add some belt-and-suspenders assertions.
1 parent 07c7319 commit cd7ffcf

13 files changed

+205
-198
lines changed

test/functional/feature_asset_locks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def create_assetunlock(self, index, withdrawal, pubkey=None, fee=tiny_amount):
103103

104104
height = node_wallet.getblockcount()
105105
self.log.info(f"Creating asset unlock: index={index} {request_id}")
106-
quorumHash = mninfo[0].node.quorum("selectquorum", llmq_type_test, request_id)["quorumHash"]
106+
quorumHash = mninfo[0].get_node(self).quorum("selectquorum", llmq_type_test, request_id)["quorumHash"]
107107
self.log.info(f"Used quorum hash: {quorumHash}")
108108
unlockTx_payload = CAssetUnlockTx(
109109
version = 1,
@@ -368,7 +368,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
368368
asset_unlock_tx_payload = CAssetUnlockTx()
369369
asset_unlock_tx_payload.deserialize(BytesIO(asset_unlock_tx.vExtraPayload))
370370

371-
assert_equal(asset_unlock_tx_payload.quorumHash, int(self.mninfo[0].node.quorum("selectquorum", llmq_type_test, 'e6c7a809d79f78ea85b72d5df7e9bd592aecf151e679d6e976b74f053a7f9056')["quorumHash"], 16))
371+
assert_equal(asset_unlock_tx_payload.quorumHash, int(self.mninfo[0].get_node(self).quorum("selectquorum", llmq_type_test, 'e6c7a809d79f78ea85b72d5df7e9bd592aecf151e679d6e976b74f053a7f9056')["quorumHash"], 16))
372372

373373
self.log.info("Test no IS for asset unlock...")
374374
self.nodes[0].sporkupdate("SPORK_2_INSTANTSEND_ENABLED", 0)

test/functional/feature_llmq_connections.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def run_test(self):
3535
self.log.info("checking for old intra quorum connections")
3636
total_count = 0
3737
for mn in self.get_quorum_masternodes(q):
38-
count = self.get_mn_connection_count(mn.node)
38+
count = self.get_mn_connection_count(mn.get_node(self))
3939
total_count += count
4040
assert_greater_than_or_equal(count, 2)
4141
assert total_count < 40
@@ -49,24 +49,24 @@ def run_test(self):
4949
self.log.info("mining one block and waiting for all members to connect to each other")
5050
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
5151
for mn in self.get_quorum_masternodes(q):
52-
self.wait_for_mnauth(mn.node, 4)
52+
self.wait_for_mnauth(mn.get_node(self), 4)
5353

5454
self.log.info("mine a new quorum and verify that all members connect to each other")
5555
q = self.mine_quorum()
5656

5757
self.log.info("checking that all MNs got probed")
5858
for mn in self.get_quorum_masternodes(q):
59-
self.wait_until(lambda: self.get_mn_probe_count(mn.node, q, False) == 4)
59+
self.wait_until(lambda: self.get_mn_probe_count(mn.get_node(self), q, False) == 4)
6060

6161
self.log.info("checking that probes age")
6262
self.bump_mocktime(self.MAX_AGE)
6363
for mn in self.get_quorum_masternodes(q):
64-
self.wait_until(lambda: self.get_mn_probe_count(mn.node, q, False) == 0)
64+
self.wait_until(lambda: self.get_mn_probe_count(mn.get_node(self), q, False) == 0)
6565

6666
self.log.info("mine a new quorum and re-check probes")
6767
q = self.mine_quorum()
6868
for mn in self.get_quorum_masternodes(q):
69-
self.wait_until(lambda: self.get_mn_probe_count(mn.node, q, True) == 4)
69+
self.wait_until(lambda: self.get_mn_probe_count(mn.get_node(self), q, True) == 4)
7070

7171
self.log.info("Activating SPORK_21_QUORUM_ALL_CONNECTED")
7272
self.nodes[0].sporkupdate("SPORK_21_QUORUM_ALL_CONNECTED", 0)
@@ -84,12 +84,12 @@ def run_test(self):
8484
self.log.info("check that old masternode connections are dropped")
8585
removed = False
8686
for mn in self.mninfo: # type: MasternodeInfo
87-
if len(mn.node.quorum("memberof", mn.proTxHash)) > 0:
87+
if len(mn.get_node(self).quorum("memberof", mn.proTxHash)) > 0:
8888
try:
89-
with mn.node.assert_debug_log(['removing masternodes quorum connections']):
90-
with mn.node.assert_debug_log(['keeping mn quorum connections']):
89+
with mn.get_node(self).assert_debug_log(['removing masternodes quorum connections']):
90+
with mn.get_node(self).assert_debug_log(['keeping mn quorum connections']):
9191
self.mine_cycle_quorum(is_first=False)
92-
mn.node.mockscheduler(60) # we check for old connections via the scheduler every 60 seconds
92+
mn.get_node(self).mockscheduler(60) # we check for old connections via the scheduler every 60 seconds
9393
removed = True
9494
except:
9595
pass # it's ok to not remove connections sometimes
@@ -100,9 +100,9 @@ def run_test(self):
100100
self.log.info("check that inter-quorum masternode connections are added")
101101
added = False
102102
for mn in self.mninfo: # type: MasternodeInfo
103-
if len(mn.node.quorum("memberof", mn.proTxHash)) > 0:
103+
if len(mn.get_node(self).quorum("memberof", mn.proTxHash)) > 0:
104104
try:
105-
with mn.node.assert_debug_log(['adding mn inter-quorum connections']):
105+
with mn.get_node(self).assert_debug_log(['adding mn inter-quorum connections']):
106106
self.mine_cycle_quorum(is_first=False)
107107
added = True
108108
except:
@@ -114,17 +114,17 @@ def run_test(self):
114114
def check_reconnects(self, expected_connection_count):
115115
self.log.info("disable and re-enable networking on all masternodes")
116116
for mn in self.mninfo: # type: MasternodeInfo
117-
mn.node.setnetworkactive(False)
117+
mn.get_node(self).setnetworkactive(False)
118118
for mn in self.mninfo: # type: MasternodeInfo
119-
self.wait_until(lambda: len(mn.node.getpeerinfo()) == 0)
119+
self.wait_until(lambda: len(mn.get_node(self).getpeerinfo()) == 0)
120120
for mn in self.mninfo: # type: MasternodeInfo
121-
mn.node.setnetworkactive(True)
121+
mn.get_node(self).setnetworkactive(True)
122122
self.bump_mocktime(60)
123123

124124
self.log.info("verify that all masternodes re-connected")
125125
for q in self.nodes[0].quorum('list')['llmq_test']:
126126
for mn in self.get_quorum_masternodes(q):
127-
self.wait_for_mnauth(mn.node, expected_connection_count)
127+
self.wait_for_mnauth(mn.get_node(self), expected_connection_count)
128128

129129
# Also re-connect non-masternode connections
130130
for i in range(1, len(self.nodes)):

test/functional/feature_llmq_data_recovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ def restart_mn(self, mn: MasternodeInfo, reindex=False, qvvec_sync=None, qdata_r
4141
args.append('-llmq-qvvec-sync=%s:%d' % (llmq_type_strings[llmq_sync[0]], llmq_sync[1]))
4242
if reindex:
4343
args.append('-reindex')
44-
bb_hash = mn.node.getbestblockhash()
44+
bb_hash = mn.get_node(self).getbestblockhash()
4545
self.restart_node(mn.nodeIdx, args)
46-
self.wait_until(lambda: mn.node.getbestblockhash() == bb_hash)
46+
self.wait_until(lambda: mn.get_node(self).getbestblockhash() == bb_hash)
4747
else:
4848
self.restart_node(mn.nodeIdx, args)
49-
force_finish_mnsync(mn.node)
49+
force_finish_mnsync(mn.get_node(self))
5050
self.connect_nodes(mn.nodeIdx, 0)
5151
if qdata_recovery_enabled:
5252
# trigger recovery threads and wait for them to start

test/functional/feature_llmq_dkgerrors.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,46 @@ def run_test(self):
2727
mninfos_valid = self.mninfo.copy()[1:]
2828

2929
self.log.info("Lets omit the contribution")
30-
self.mninfo[0].node.quorum('dkgsimerror', 'contribution-omit', '100')
30+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'contribution-omit', '100')
3131
qh = self.mine_quorum(expected_contributions=2, mninfos_valid=mninfos_valid)
3232
self.assert_member_valid(qh, self.mninfo[0].proTxHash, False)
3333

3434
self.log.info("Lets lie in the contribution but provide a correct justification")
35-
self.mninfo[0].node.quorum('dkgsimerror', 'contribution-omit', '0')
36-
self.mninfo[0].node.quorum('dkgsimerror', 'contribution-lie', '100')
35+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'contribution-omit', '0')
36+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'contribution-lie', '100')
3737
qh = self.mine_quorum(expected_contributions=3, expected_complaints=2, expected_justifications=1, mninfos_valid=mninfos_valid)
3838
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
3939

4040
self.log.info("Lets lie in the contribution and then omit the justification")
41-
self.mninfo[0].node.quorum('dkgsimerror', 'justify-omit', '100')
41+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'justify-omit', '100')
4242
qh = self.mine_quorum(expected_contributions=3, expected_complaints=2, mninfos_valid=mninfos_valid)
4343
self.assert_member_valid(qh, self.mninfo[0].proTxHash, False)
4444

4545
self.log.info("Heal some damage (don't get PoSe banned)")
4646
self.heal_masternodes(33)
4747

4848
self.log.info("Lets lie in the contribution and then also lie in the justification")
49-
self.mninfo[0].node.quorum('dkgsimerror', 'justify-omit', '0')
50-
self.mninfo[0].node.quorum('dkgsimerror', 'justify-lie', '100')
49+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'justify-omit', '0')
50+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'justify-lie', '100')
5151
qh = self.mine_quorum(expected_contributions=3, expected_complaints=2, expected_justifications=1, mninfos_valid=mninfos_valid)
5252
self.assert_member_valid(qh, self.mninfo[0].proTxHash, False)
5353

5454
self.log.info("Lets lie about another MN")
55-
self.mninfo[0].node.quorum('dkgsimerror', 'contribution-lie', '0')
56-
self.mninfo[0].node.quorum('dkgsimerror', 'justify-lie', '0')
57-
self.mninfo[0].node.quorum('dkgsimerror', 'complain-lie', '100')
55+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'contribution-lie', '0')
56+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'justify-lie', '0')
57+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'complain-lie', '100')
5858
qh = self.mine_quorum(expected_contributions=3, expected_complaints=1, expected_justifications=2, mninfos_valid=mninfos_valid)
5959
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
6060

6161
self.log.info("Lets omit 1 premature commitments")
62-
self.mninfo[0].node.quorum('dkgsimerror', 'complain-lie', '0')
63-
self.mninfo[0].node.quorum('dkgsimerror', 'commit-omit', '100')
62+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'complain-lie', '0')
63+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'commit-omit', '100')
6464
qh = self.mine_quorum(expected_contributions=3, expected_complaints=0, expected_justifications=0, expected_commitments=2, mninfos_valid=mninfos_valid)
6565
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
6666

6767
self.log.info("Lets lie in 1 premature commitments")
68-
self.mninfo[0].node.quorum('dkgsimerror', 'commit-omit', '0')
69-
self.mninfo[0].node.quorum('dkgsimerror', 'commit-lie', '100')
68+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'commit-omit', '0')
69+
self.mninfo[0].get_node(self).quorum('dkgsimerror', 'commit-lie', '100')
7070
qh = self.mine_quorum(expected_contributions=3, expected_complaints=0, expected_justifications=0, expected_commitments=2, mninfos_valid=mninfos_valid)
7171
self.assert_member_valid(qh, self.mninfo[0].proTxHash, True)
7272

test/functional/feature_llmq_rotation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def run_test(self):
140140

141141
# At this point, we want to wait for CLs just before the self.mine_cycle_quorum to diversify the CLs in CbTx.
142142
# Although because here a new quorum cycle is starting, and we don't want to mine them now, mine 8 blocks (to skip all DKG phases)
143-
nodes = [self.nodes[0]] + [mn.node for mn in self.mninfo.copy()]
143+
nodes = [self.nodes[0]] + [mn.get_node(self) for mn in self.mninfo.copy()]
144144
self.generate(self.nodes[0], 8, sync_fun=lambda: self.sync_blocks(nodes))
145145
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
146146

@@ -193,7 +193,7 @@ def run_test(self):
193193
quorumList = self.test_getmnlistdiff_quorums(b_1, b_2, quorumList, expectedDeleted, expectedNew)
194194

195195
mninfos_online = self.mninfo.copy()
196-
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
196+
nodes = [self.nodes[0]] + [mn.get_node(self) for mn in mninfos_online]
197197
self.sync_blocks(nodes)
198198
quorum_list = self.nodes[0].quorum("list", llmq_type)
199199
quorum_blockhash = self.nodes[0].getbestblockhash()
@@ -398,7 +398,7 @@ def test_quorum_listextended(self, quorum_info, llmq_type_name):
398398
def move_to_next_cycle(self):
399399
cycle_length = 24
400400
mninfos_online = self.mninfo.copy()
401-
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
401+
nodes = [self.nodes[0]] + [mn.get_node(self) for mn in mninfos_online]
402402
cur_block = self.nodes[0].getblockcount()
403403

404404
# move forward to next DKG

0 commit comments

Comments
 (0)