refactor: simplify and optimize creation of rotation IS quorum in functional tests

This commit is contained in:
Konstantin Akimov 2024-11-23 15:10:07 +07:00
parent a82d33e31a
commit f8cfda60f1
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
11 changed files with 49 additions and 113 deletions

View File

@ -50,14 +50,7 @@ class DashGovernanceTest (DashTestFramework):
self.wait_for_sporks_same() self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle() self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
self.sync_blocks() self.sync_blocks()
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())

View File

@ -49,13 +49,7 @@ class LLMQChainLocksTest(DashTestFramework):
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
self.wait_for_sporks_same() self.wait_for_sporks_same()
self.move_to_next_cycle() self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name="llmq_test_dip0024", llmq_type=103)
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
self.log.info("Mine single block, ensure it includes latest chainlock") self.log.info("Mine single block, ensure it includes latest chainlock")

View File

@ -76,13 +76,7 @@ class LLMQConnections(DashTestFramework):
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle() self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
# Since we IS quorums are mined only using dip24 (rotation) we need to enable rotation, and continue tests on llmq_test_dip0024 for connections. # Since we IS quorums are mined only using dip24 (rotation) we need to enable rotation, and continue tests on llmq_test_dip0024 for connections.
@ -93,7 +87,7 @@ class LLMQConnections(DashTestFramework):
try: try:
with mn.node.assert_debug_log(['removing masternodes quorum connections']): with mn.node.assert_debug_log(['removing masternodes quorum connections']):
with mn.node.assert_debug_log(['keeping mn quorum connections']): with mn.node.assert_debug_log(['keeping mn quorum connections']):
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103) self.mine_cycle_quorum(is_first=False)
mn.node.mockscheduler(60) # we check for old connections via the scheduler every 60 seconds mn.node.mockscheduler(60) # we check for old connections via the scheduler every 60 seconds
removed = True removed = True
except: except:
@ -108,7 +102,7 @@ class LLMQConnections(DashTestFramework):
if len(mn.node.quorum("memberof", mn.proTxHash)) > 0: if len(mn.node.quorum("memberof", mn.proTxHash)) > 0:
try: try:
with mn.node.assert_debug_log(['adding mn inter-quorum connections']): with mn.node.assert_debug_log(['adding mn inter-quorum connections']):
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103) self.mine_cycle_quorum(is_first=False)
added = True added = True
except: except:
pass # it's ok to not add connections sometimes pass # it's ok to not add connections sometimes

View File

@ -61,14 +61,7 @@ class LLMQ_IS_CL_Conflicts(DashTestFramework):
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle() self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
# mine single block, wait for chainlock # mine single block, wait for chainlock
self.generate(self.nodes[0], 1, sync_fun=self.no_op) self.generate(self.nodes[0], 1, sync_fun=self.no_op)

View File

@ -31,15 +31,7 @@ class LLMQ_IS_RetroactiveSigning(DashTestFramework):
self.wait_for_sporks_same() self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.mine_cycle_quorum()
self.move_to_next_cycle()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
# Make sure that all nodes are chainlocked at the same height before starting actual tests # Make sure that all nodes are chainlocked at the same height before starting actual tests
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash(), timeout=30) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash(), timeout=30)

View File

@ -154,7 +154,7 @@ class LLMQQuorumRotationTest(DashTestFramework):
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
(quorum_info_0_0, quorum_info_0_1) = self.mine_cycle_quorum(llmq_type_name=llmq_type_name, llmq_type=llmq_type) (quorum_info_0_0, quorum_info_0_1) = self.mine_cycle_quorum(is_first=False)
assert(self.test_quorum_listextended(quorum_info_0_0, llmq_type_name)) assert(self.test_quorum_listextended(quorum_info_0_0, llmq_type_name))
assert(self.test_quorum_listextended(quorum_info_0_1, llmq_type_name)) assert(self.test_quorum_listextended(quorum_info_0_1, llmq_type_name))
quorum_members_0_0 = extract_quorum_members(quorum_info_0_0) quorum_members_0_0 = extract_quorum_members(quorum_info_0_0)
@ -176,7 +176,7 @@ class LLMQQuorumRotationTest(DashTestFramework):
self.log.info("Wait for chainlock") self.log.info("Wait for chainlock")
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
(quorum_info_1_0, quorum_info_1_1) = self.mine_cycle_quorum(llmq_type_name=llmq_type_name, llmq_type=llmq_type) (quorum_info_1_0, quorum_info_1_1) = self.mine_cycle_quorum(is_first=False)
assert(self.test_quorum_listextended(quorum_info_1_0, llmq_type_name)) assert(self.test_quorum_listextended(quorum_info_1_0, llmq_type_name))
assert(self.test_quorum_listextended(quorum_info_1_1, llmq_type_name)) assert(self.test_quorum_listextended(quorum_info_1_1, llmq_type_name))
quorum_members_1_0 = extract_quorum_members(quorum_info_1_0) quorum_members_1_0 = extract_quorum_members(quorum_info_1_0)
@ -210,7 +210,7 @@ class LLMQQuorumRotationTest(DashTestFramework):
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
self.log.info("Mine a quorum to invalidate") self.log.info("Mine a quorum to invalidate")
(quorum_info_3_0, quorum_info_3_1) = self.mine_cycle_quorum(llmq_type_name=llmq_type_name, llmq_type=llmq_type) (quorum_info_3_0, quorum_info_3_1) = self.mine_cycle_quorum(is_first=False)
new_quorum_list = self.nodes[0].quorum("list", llmq_type) new_quorum_list = self.nodes[0].quorum("list", llmq_type)
assert_equal(len(new_quorum_list[llmq_type_name]), len(quorum_list[llmq_type_name]) + 2) assert_equal(len(new_quorum_list[llmq_type_name]), len(quorum_list[llmq_type_name]) + 2)
@ -383,6 +383,20 @@ class LLMQQuorumRotationTest(DashTestFramework):
return True return True
return False return False
def move_to_next_cycle(self):
cycle_length = 24
mninfos_online = self.mninfo.copy()
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
cur_block = self.nodes[0].getblockcount()
# move forward to next DKG
skip_count = cycle_length - (cur_block % cycle_length)
if skip_count != 0:
self.bump_mocktime(1, nodes=nodes)
self.generate(self.nodes[0], skip_count, sync_fun=self.no_op)
self.sync_blocks(nodes)
self.log.info('Moved from block %d to %d' % (cur_block, self.nodes[0].getblockcount()))
if __name__ == '__main__': if __name__ == '__main__':
LLMQQuorumRotationTest().main() LLMQQuorumRotationTest().main()

View File

@ -106,14 +106,7 @@ class NotificationsTest(DashTestFramework):
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0) self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 4070908800) self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 4070908800)
self.wait_for_sporks_same() self.wait_for_sporks_same()
self.move_to_next_cycle() (quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
(quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0) self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0)
self.wait_for_sporks_same() self.wait_for_sporks_same()

View File

@ -139,14 +139,8 @@ class DashZMQTest (DashTestFramework):
self.wait_for_sporks_same() self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103) self.mine_cycle_quorum()
self.sync_blocks() self.sync_blocks()
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
@ -162,12 +156,7 @@ class DashZMQTest (DashTestFramework):
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash()) self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
self.test_instantsend_publishers() self.test_instantsend_publishers()
# At this point, we need to move forward 3 cycles (3 x 24 blocks) so the first 3 quarters can be created (without DKG sessions) # At this point, we need to move forward 3 cycles (3 x 24 blocks) so the first 3 quarters can be created (without DKG sessions)
self.move_to_next_cycle() self.generate(self.nodes[0], 24)
self.test_instantsend_publishers()
self.move_to_next_cycle()
self.test_instantsend_publishers()
self.move_to_next_cycle()
self.test_instantsend_publishers()
self.mine_cycle_quorum() self.mine_cycle_quorum()
self.test_instantsend_publishers() self.test_instantsend_publishers()
finally: finally:

View File

@ -25,13 +25,7 @@ class InstantSendTest(DashTestFramework):
self.wait_for_sporks_same() self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle() (quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
(quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
self.test_mempool_doublespend() self.test_mempool_doublespend()
self.test_block_doublespend() self.test_block_doublespend()

View File

@ -35,14 +35,7 @@ class RPCVerifyISLockTest(DashTestFramework):
self.activate_v19(expected_activation_height=900) self.activate_v19(expected_activation_height=900)
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount())) self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle() self.mine_cycle_quorum()
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
self.move_to_next_cycle()
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
self.bump_mocktime(1) self.bump_mocktime(1)
self.generate(self.nodes[0], 8, sync_fun=self.sync_blocks()) self.generate(self.nodes[0], 8, sync_fun=self.sync_blocks())
@ -64,7 +57,7 @@ class RPCVerifyISLockTest(DashTestFramework):
assert node.verifyislock(request_id, txid, rec_sig, node.getblockcount() + 100) assert node.verifyislock(request_id, txid, rec_sig, node.getblockcount() + 100)
# Mine one more cycle of rotated quorums # Mine one more cycle of rotated quorums
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103) self.mine_cycle_quorum(is_first=False)
# Create an ISLOCK using an active quorum which will be replaced when a new cycle happens # Create an ISLOCK using an active quorum which will be replaced when a new cycle happens
request_id = None request_id = None
utxos = node.listunspent() utxos = node.listunspent()
@ -87,7 +80,7 @@ class RPCVerifyISLockTest(DashTestFramework):
# Create the ISDLOCK, then mine a cycle quorum to move renew active set # Create the ISDLOCK, then mine a cycle quorum to move renew active set
isdlock = self.create_isdlock(rawtx) isdlock = self.create_isdlock(rawtx)
# Mine one block to trigger the "signHeight + dkgInterval" verification for the ISDLOCK # Mine one block to trigger the "signHeight + dkgInterval" verification for the ISDLOCK
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103) self.mine_cycle_quorum(is_first=False)
# Verify the ISLOCK for a transaction that is not yet known by the node # Verify the ISLOCK for a transaction that is not yet known by the node
rawtx_txid = node.decoderawtransaction(rawtx)["txid"] rawtx_txid = node.decoderawtransaction(rawtx)["txid"]
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction, rawtx_txid) assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction, rawtx_txid)

View File

@ -1895,31 +1895,32 @@ class DashTestFramework(BitcoinTestFramework):
return new_quorum return new_quorum
def mine_cycle_quorum(self, llmq_type_name="llmq_test_dip0024", llmq_type=103, expected_connections=None, expected_members=None, expected_contributions=None, expected_complaints=0, expected_justifications=0, expected_commitments=None, mninfos_online=None): def mine_cycle_quorum(self, is_first=True):
spork21_active = self.nodes[0].spork('show')['SPORK_21_QUORUM_ALL_CONNECTED'] <= 1 spork21_active = self.nodes[0].spork('show')['SPORK_21_QUORUM_ALL_CONNECTED'] <= 1
spork23_active = self.nodes[0].spork('show')['SPORK_23_QUORUM_POSE'] <= 1 spork23_active = self.nodes[0].spork('show')['SPORK_23_QUORUM_POSE'] <= 1
if expected_connections is None: llmq_type_name="llmq_test_dip0024"
expected_connections = (self.llmq_size_dip0024 - 1) if spork21_active else 2 llmq_type=103
if expected_members is None: expected_connections = (self.llmq_size_dip0024 - 1) if spork21_active else 2
expected_members = self.llmq_size_dip0024 expected_members = self.llmq_size_dip0024
if expected_contributions is None: expected_contributions = self.llmq_size_dip0024
expected_contributions = self.llmq_size_dip0024 expected_commitments = self.llmq_size_dip0024
if expected_commitments is None: mninfos_online = self.mninfo.copy()
expected_commitments = self.llmq_size_dip0024 expected_complaints=0
if mninfos_online is None: expected_justifications=0
mninfos_online = self.mninfo.copy()
self.log.info("Mining quorum: expected_members=%d, expected_connections=%d, expected_contributions=%d, expected_complaints=%d, expected_justifications=%d, " self.log.info(f"Mining quorum: expected_members={expected_members}, expected_connections={expected_connections}, expected_contributions={expected_contributions}, expected_commitments={expected_commitments}, no complains and justfications expected")
"expected_commitments=%d" % (expected_members, expected_connections, expected_contributions, expected_complaints,
expected_justifications, expected_commitments))
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online] nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
# move forward to next DKG cycle_length = 24
skip_count = 24 - (self.nodes[0].getblockcount() % 24) cur_block = self.nodes[0].getblockcount()
self.move_blocks(nodes, skip_count) skip_count = cycle_length - (cur_block % cycle_length)
# move forward to next 3 DKG rounds for the first quorum
extra_blocks = 24 * 3 if is_first else 0
self.move_blocks(nodes, extra_blocks + skip_count)
self.log.info('Moved from block %d to %d' % (cur_block, self.nodes[0].getblockcount()))
q_0 = self.nodes[0].getbestblockhash() q_0 = self.nodes[0].getbestblockhash()
self.log.info("Expected quorum_0 at:" + str(self.nodes[0].getblockcount())) self.log.info("Expected quorum_0 at:" + str(self.nodes[0].getblockcount()))
@ -2018,20 +2019,6 @@ class DashTestFramework(BitcoinTestFramework):
return (quorum_info_0, quorum_info_1) return (quorum_info_0, quorum_info_1)
def move_to_next_cycle(self):
cycle_length = 24
mninfos_online = self.mninfo.copy()
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
cur_block = self.nodes[0].getblockcount()
# move forward to next DKG
skip_count = cycle_length - (cur_block % cycle_length)
if skip_count != 0:
self.bump_mocktime(1, nodes=nodes)
self.generate(self.nodes[0], skip_count, sync_fun=self.no_op)
self.sync_blocks(nodes)
self.log.info('Moved from block %d to %d' % (cur_block, self.nodes[0].getblockcount()))
def wait_for_recovered_sig(self, rec_sig_id, rec_sig_msg_hash, llmq_type=100, timeout=10): def wait_for_recovered_sig(self, rec_sig_id, rec_sig_msg_hash, llmq_type=100, timeout=10):
def check_recovered_sig(): def check_recovered_sig():
self.bump_mocktime(1) self.bump_mocktime(1)