dash/test/functional/feature_llmq_is_migration.py
Odysseas Gabrielides 83ef1c6c66
feat: implement quorum rotation and updated LLMQ parameters (#4752)
* Added GET_SNAPSHOT_INFO message handling

* Quorum members by rotation

* Quorum utils functions

* Handle GET_QUORUM_ROTATION_INFO with baseBlockHash from client

* Storing QuorumSnaphots in evoDB when requesting them

* Added DIP Enforcement param

* quorumIndex cache

* Quorum Rotation deployment control

* Usage of Bitsets for storing CQuorumSnapshots

* Correct handling of early quorum quarters

* More asserts

* Corrections

* Handling of quorumIndex

* Refactoring of truncate mechanism

* Various fixes

* Interface correction

* Added template type for indexed cache

* Added quorumIndex into commitmenHash

* Various changes

* Needs to update maqQuorumsCache along with indexedQuorumsCache

* Added CFinalCommitment version 2

* Renamed variables

* Fixes

* Refactoring & correct caching of quorumMembers by rotation

* Added assertions

* Refactoring

* Interface change

* Handling of previous DKG session failure

* Applied refactoring

* Build quarter members improvments

* Merge Quorum Rotation and Decreased fee into one deployment (DIP24)

* Added new LLMQ Type

* Added functional tests + refactoring

* Refactoring

* Spreaded Quorum creation and Quorum Index adaptation

* quorumIndex adaptations

* Added quorumIndex in CFinalCommitment

* Latest work

* Final refactoring

* Batch of refactoring

* Fixes for tests

* Fix for CFinalCommitment

* Fix for Quorums

* Fix

* Small changes

* Thread sync fic

* Safety changes

* Reuse mns when needed

* Refactoring

* More refactoring

* Fixes for rotationinfo handling

* Fix for rotation of members

* Correct order of MNs lists in Quorum Snapshots

* Adding extra logs

* Sync rotation quorums + qrinfo changes

* Fix + extra logs

* Removed redundant field

* Fix for null final commitment + refactoring

* Added timers in tests

* Fix for qrinfo message: quorumdiff and merkleRootQuorums

* Small changes for rotation test

* Remove reading from scanQuorumCache

* Added quorum list output

* Crash fix

* Experimental commit

* apply changes to specialtxman.cpp from specialtx.cpp

* all the changes

* substancially speed up feature_llmq_rotation.py

* reenable asserts, add check for reorgs

* Refactoring

* Added extra logs

* format

* trivial

* drop extra boost includes

* drop ContainsMN

* fix ScanQuorums

* check quorum hash and index in CFinalCommitment::Verify

* fix/tweak tests

* IsQuorumRotationEnabled should be aware of the context

* Calculating members based on earlier block.

* Fix for Quorum Members Cache

* Removed duplicate size of baseBlockHashes

* Adaptations of qrinfo to -8 mn lists

* Introduction of llmqTypeDIP24InstantSend

* Adaptation for llmqTypeDIP24InstantSend

* Adaptations for IS

* bump protocol version

* Added feature_llmq_is_migration test

* Various cleanups

* use unordered_lru_cache for quorumSnapshotCache

* trivial refactor ComputeQuorumMembersByQuarterRotation

* Reduced CFinalCommitment::quorumIndex from 32 to 16 bits

* Keep verified LLMQ relay connections

* Experimental Relay connection fix

* Fix for EnsureQuorumConnections rotation

* Using only valid Mns for checking

* Override of nPowTargetSpacing (devnet only)

* Show penalty score in masternode rpc

* fixups

* Rotation refactoring

* Update src/chainparams.cpp

* Replaced LogPrintf with LogPrint

* IS locking fix once DIP24 activation

* Various cleanup

* Updated MIN_MASTERNODE_PROTO_VERSION

* Introduce LLMQ_TEST_INSTANTSEND reg-test only quorum and actually test switching to dip0024 quorums

* Renamed field lastQuorumHashPerIndex

* Renamed to DIP0024

* chore: update nStartTime and nTimeout for mainnet / testnet for DEPLOYMENT_DIP0024

Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
Co-authored-by: pasta <pasta@dashboost.org>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2022-04-16 17:46:04 +03:00

138 lines
5.2 KiB
Python
Executable File

#!/usr/bin/env python3
# Copyright (c) 2020-2021 The Dash Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
import time
from test_framework.messages import CTransaction, FromHex, hash256, ser_compact_size, ser_string
from test_framework.test_framework import DashTestFramework
from test_framework.util import wait_until, connect_nodes, sync_blocks
'''
feature_llmq_is_migration.py
Test IS LLMQ migration with DIP0024
'''
class LLMQISMigrationTest(DashTestFramework):
def set_test_params(self):
# -whitelist is needed to avoid the trickling logic on node0
self.set_dash_test_params(16, 15, [["-whitelist=127.0.0.1"], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []], fast_dip3_enforcement=True)
self.set_dash_llmq_test_params(4, 4)
def get_request_id(self, tx_hex):
tx = FromHex(CTransaction(), tx_hex)
request_id_buf = ser_string(b"islock") + ser_compact_size(len(tx.vin))
for txin in tx.vin:
request_id_buf += txin.prevout.serialize()
return hash256(request_id_buf)[::-1].hex()
def run_test(self):
for i in range(len(self.nodes)):
if i != 1:
connect_nodes(self.nodes[i], 0)
self.activate_dip8()
node = self.nodes[0]
node.spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
node.spork("SPORK_2_INSTANTSEND_ENABLED", 0)
self.wait_for_sporks_same()
self.mine_quorum()
self.mine_quorum()
self.log.info(self.nodes[0].quorum("list"))
txid1 = node.sendtoaddress(node.getnewaddress(), 1)
self.wait_for_instantlock(txid1, node)
request_id = self.get_request_id(self.nodes[0].getrawtransaction(txid1))
wait_until(lambda: node.quorum("hasrecsig", 104, request_id, txid1))
rec_sig = node.quorum("getrecsig", 104, request_id, txid1)['sig']
assert node.verifyislock(request_id, txid1, rec_sig)
self.activate_dip0024()
self.log.info("Activated DIP0024 at height:" + str(self.nodes[0].getblockcount()))
q_list = self.nodes[0].quorum("list")
self.log.info(q_list)
assert len(q_list['llmq_test']) == 2
assert len(q_list['llmq_test_instantsend']) == 2
assert len(q_list['llmq_test_v17']) == 0
assert len(q_list['llmq_test_dip0024']) == 0
txid1 = node.sendtoaddress(node.getnewaddress(), 1)
self.wait_for_instantlock(txid1, node)
# at this point, DIP0024 is active, but we have old quorums, and they should still create islocks!
txid3 = node.sendtoaddress(node.getnewaddress(), 1)
self.wait_for_instantlock(txid3, node)
request_id = self.get_request_id(self.nodes[0].getrawtransaction(txid3))
wait_until(lambda: node.quorum("hasrecsig", 104, request_id, txid3))
rec_sig = node.quorum("getrecsig", 104, request_id, txid3)['sig']
assert node.verifyislock(request_id, txid3, rec_sig)
#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.log.info("Start at H 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_0_0, quorum_info_0_1) = self.mine_cycle_quorum("llmq_test_dip0024", 103)
q_list = self.nodes[0].quorum("list")
self.log.info(q_list)
assert len(q_list['llmq_test']) == 2
assert 'llmq_test_instantsend' not in q_list
assert len(q_list['llmq_test_v17']) == 1
assert len(q_list['llmq_test_dip0024']) == 2
# Check that the earliest islock is still present
self.wait_for_instantlock(txid1, node)
txid2 = node.sendtoaddress(node.getnewaddress(), 1)
self.wait_for_instantlock(txid2, node)
request_id2 = self.get_request_id(self.nodes[0].getrawtransaction(txid2))
wait_until(lambda: node.quorum("hasrecsig", 103, request_id2, txid2))
rec_sig2 = node.quorum("getrecsig", 103, request_id2, txid2)['sig']
assert node.verifyislock(request_id2, txid2, rec_sig2)
# Check that original islock quorum type doesn't sign
time.sleep(10)
for n in self.nodes:
assert not n.quorum("hasrecsig", 104, request_id2, txid2)
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.nodes[0].generate(skip_count)
sync_blocks(nodes)
time.sleep(1)
self.log.info('Moved from block %d to %d' % (cur_block, self.nodes[0].getblockcount()))
if __name__ == '__main__':
LLMQISMigrationTest().main()