Merge #6431: test: improve mine rotation quorums for IS in functional tests

f8cfda60f1 refactor: simplify and optimize creation of rotation IS quorum in functional tests (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented

  Mining rotation quorum currently is not trivial. All over a codebase used this template to get a rotating 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)
  ```
  The performance of this code is not great also because generating 3 or 4 batches of blocks requires time to sync nodes after each batch.

  ## What was done?
  This PR move instantly to 3-4 DKG sessions forward and starts from cycling quorum.
  It's only one cycling quorum (instant-send), so, extra params are also removed.
  To get it just call:
  ```
  self.mine_cycle_quorum() # first time, which is usually used to get IS feature working in functional tests
  self.mine_cycle_quorum(is_first=False) # if you don't need preparing 3 DKG sessions in advance
  ```

  ## How Has This Been Tested?
  Run unit and functional tests
  By my benchmark it gives roughly 10 seconds for each functional test that uses rotation quorum.

  ## 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
  - [x] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)

ACKs for top commit:
  PastaPastaPasta:
    utACK f8cfda60f1b47c358f8fbca3eaccb6f7a7fbf310; I wish that is_first could be automatically detected instead of manually set.
  UdjinM6:
    utACK f8cfda60f1

Tree-SHA512: 993f42b54c0c11ba146e164cc6db8b5c3f302dd78488aa2572b3ed199d25c266d8d1ff1a027a4e450eab2349b691c19fcd8f5859e2c423ccf2357db29ee3d536
This commit is contained in:
pasta 2024-12-04 09:53:56 -06:00
commit 678d28d8ab
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38
11 changed files with 49 additions and 113 deletions

View File

@ -50,14 +50,7 @@ class DashGovernanceTest (DashTestFramework):
self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900)
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.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.wait_for_sporks_same()
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.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
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.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()
# 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:
with mn.node.assert_debug_log(['removing masternodes 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
removed = True
except:
@ -108,7 +102,7 @@ class LLMQConnections(DashTestFramework):
if len(mn.node.quorum("memberof", mn.proTxHash)) > 0:
try:
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
except:
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.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()
# mine single block, wait for chainlock
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.activate_v19(expected_activation_height=900)
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()
# 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)

View File

@ -154,7 +154,7 @@ class LLMQQuorumRotationTest(DashTestFramework):
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_1, llmq_type_name))
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.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_1, llmq_type_name))
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.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)
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 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__':
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_19_CHAINLOCKS_ENABLED", 4070908800)
self.wait_for_sporks_same()
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()))
(quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
(quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum()
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0)
self.wait_for_sporks_same()

View File

@ -139,14 +139,8 @@ class DashZMQTest (DashTestFramework):
self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900)
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.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.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)
self.move_to_next_cycle()
self.test_instantsend_publishers()
self.move_to_next_cycle()
self.test_instantsend_publishers()
self.move_to_next_cycle()
self.test_instantsend_publishers()
self.generate(self.nodes[0], 24)
self.mine_cycle_quorum()
self.test_instantsend_publishers()
finally:

View File

@ -25,13 +25,7 @@ class InstantSendTest(DashTestFramework):
self.wait_for_sporks_same()
self.activate_v19(expected_activation_height=900)
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()))
(quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
(quorum_info_i_0, quorum_info_i_1) = self.mine_cycle_quorum()
self.test_mempool_doublespend()
self.test_block_doublespend()

View File

@ -35,14 +35,7 @@ class RPCVerifyISLockTest(DashTestFramework):
self.activate_v19(expected_activation_height=900)
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.bump_mocktime(1)
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)
# 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
request_id = None
utxos = node.listunspent()
@ -87,7 +80,7 @@ class RPCVerifyISLockTest(DashTestFramework):
# Create the ISDLOCK, then mine a cycle quorum to move renew active set
isdlock = self.create_isdlock(rawtx)
# 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
rawtx_txid = node.decoderawtransaction(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
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
spork23_active = self.nodes[0].spork('show')['SPORK_23_QUORUM_POSE'] <= 1
if expected_connections is None:
llmq_type_name="llmq_test_dip0024"
llmq_type=103
expected_connections = (self.llmq_size_dip0024 - 1) if spork21_active else 2
if expected_members is None:
expected_members = self.llmq_size_dip0024
if expected_contributions is None:
expected_contributions = self.llmq_size_dip0024
if expected_commitments is None:
expected_commitments = self.llmq_size_dip0024
if mninfos_online is None:
mninfos_online = self.mninfo.copy()
expected_complaints=0
expected_justifications=0
self.log.info("Mining quorum: expected_members=%d, expected_connections=%d, expected_contributions=%d, expected_complaints=%d, expected_justifications=%d, "
"expected_commitments=%d" % (expected_members, expected_connections, expected_contributions, expected_complaints,
expected_justifications, expected_commitments))
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")
nodes = [self.nodes[0]] + [mn.node for mn in mninfos_online]
# move forward to next DKG
skip_count = 24 - (self.nodes[0].getblockcount() % 24)
cycle_length = 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()
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)
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 check_recovered_sig():
self.bump_mocktime(1)