From 4ebdaf69bcd08316d79d46e2c61623d3201a1ea4 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sun, 7 Jan 2024 08:28:47 +0700 Subject: [PATCH] fix: withdrawal (asset unlock) txes to use Platform Quorum on RegTest (#5800) ## Issue being fixed or feature implemented Asset Unlock tx uses platform's quorum on devnets, testnet, mainnet, but still quorum type "Test (100)" on Reg Tests That's part II PR, prior work is here: https://github.com/dashpay/dash/pull/5618 ## What was done? - Removed `consensus.llmqTypeAssetLocks` which has been kept only for RegTest - use `consensus.llmqTypePlatform` instead. - Functional test `feature_asset_locks.py` uses `llmq_type_test = 106` instead `llmq_type_test = 100` for asset unlock tx - there's 4 MNs + 3 evo nodes instead 3 MNs as before: evo nodes requires to have IS to be active ## How Has This Been Tested? Run unit/functional tests ## Breaking Changes Asset Unlock tx uses correct quorum "106 llmq_test_platform" on reg test instead "100 llmq_test" ## 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 --- src/chainparams.cpp | 5 --- src/consensus/params.h | 1 - src/evo/assetlocktx.cpp | 2 +- test/functional/feature_asset_locks.py | 45 +++++++++++++++---- .../test_framework/test_framework.py | 1 + 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9e485057de..05eb2738c5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -284,7 +284,6 @@ public: consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_100_67; consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_400_85; - consensus.llmqTypeAssetLocks = consensus.llmqTypePlatform; fDefaultConsistencyChecks = false; fRequireStandard = true; @@ -477,7 +476,6 @@ public: consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_60_75; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_25_67; consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_50_60; - consensus.llmqTypeAssetLocks = consensus.llmqTypePlatform; fDefaultConsistencyChecks = false; fRequireStandard = false; @@ -653,7 +651,6 @@ public: consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_DEVNET_DIP0024; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_DEVNET_PLATFORM; consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_DEVNET; - consensus.llmqTypeAssetLocks = consensus.llmqTypePlatform; UpdateDevnetLLMQChainLocksFromArgs(args); UpdateDevnetLLMQInstantSendFromArgs(args); @@ -735,7 +732,6 @@ public: void UpdateDevnetLLMQPlatform(Consensus::LLMQType llmqType) { consensus.llmqTypePlatform = llmqType; - consensus.llmqTypeAssetLocks = llmqType; } /** @@ -940,7 +936,6 @@ public: consensus.llmqTypeDIP0024InstantSend = Consensus::LLMQType::LLMQ_TEST_DIP0024; consensus.llmqTypePlatform = Consensus::LLMQType::LLMQ_TEST_PLATFORM; consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_TEST; - consensus.llmqTypeAssetLocks = Consensus::LLMQType::LLMQ_TEST; UpdateLLMQTestParametersFromArgs(args, Consensus::LLMQType::LLMQ_TEST); UpdateLLMQTestParametersFromArgs(args, Consensus::LLMQType::LLMQ_TEST_INSTANTSEND); diff --git a/src/consensus/params.h b/src/consensus/params.h index 5962b2028e..2162993049 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -163,7 +163,6 @@ struct Params { LLMQType llmqTypeDIP0024InstantSend{LLMQType::LLMQ_NONE}; LLMQType llmqTypePlatform{LLMQType::LLMQ_NONE}; LLMQType llmqTypeMnhf{LLMQType::LLMQ_NONE}; - LLMQType llmqTypeAssetLocks{LLMQType::LLMQ_NONE}; int DeploymentHeight(BuriedDeployment dep) const { diff --git a/src/evo/assetlocktx.cpp b/src/evo/assetlocktx.cpp index caf7a3e5fd..03480ca994 100644 --- a/src/evo/assetlocktx.cpp +++ b/src/evo/assetlocktx.cpp @@ -114,7 +114,7 @@ bool CAssetUnlockPayload::VerifySig(const uint256& msgHash, gsl::not_nullScanQuorums(llmqType, pindexTip, 2); diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index 465a363f2a..a96c071f50 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -45,13 +45,13 @@ from test_framework.util import ( hex_str_to_bytes, ) -llmq_type_test = 100 +llmq_type_test = 106 # LLMQType::LLMQ_TEST_PLATFORM tiny_amount = int(Decimal("0.0007") * COIN) blocks_in_one_day = 576 class AssetLocksTest(DashTestFramework): def set_test_params(self): - self.set_dash_test_params(5, 3) + self.set_dash_test_params(6, 4, evo_count=3) def skip_test_if_missing_module(self): self.skip_if_no_wallet() @@ -98,7 +98,9 @@ class AssetLocksTest(DashTestFramework): request_id = hash256(request_id_buf)[::-1].hex() height = node_wallet.getblockcount() + self.log.info(f"Creating asset unlock: {llmq_type_test} {request_id}") quorumHash = mninfo[0].node.quorum("selectquorum", llmq_type_test, request_id)["quorumHash"] + self.log.info(f"Used quorum hash: {quorumHash}") unlockTx_payload = CAssetUnlockTx( version = 1, index = index, @@ -235,8 +237,35 @@ class AssetLocksTest(DashTestFramework): node = self.nodes[1] self.set_sporks() - self.activate_v20() + self.activate_v19(expected_activation_height=900) + self.log.info("Activated v19 at height:" + str(node.getblockcount())) + + # TODO: need to refactor this part to common code + # enabling instantsend -> 3 rotating quorums -> new 103 quorum + # with following dynamically adding evo nodes one-by-one seems + # as little too much complex for functional test (each which use Evo nodes) + self.nodes[0].sporkupdate("SPORK_2_INSTANTSEND_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) + + for i in range(3): + self.dynamically_add_masternode(evo=True) + node.generate(8) + self.sync_blocks() + + self.set_sporks() + self.activate_v20() + node.generate(1) + self.sync_all() self.mempool_size = 0 key = ECKey() @@ -253,13 +282,13 @@ class AssetLocksTest(DashTestFramework): coin = coins.pop() asset_lock_tx = self.create_assetlock(coin, locked_1, pubkey) + self.check_mempool_result(tx=asset_lock_tx, result_expected={'allowed': True}) self.validate_credit_pool_balance(0) txid_in_block = self.send_tx(asset_lock_tx) assert "assetLockTx" in node.getrawtransaction(txid_in_block, 1) self.validate_credit_pool_balance(0) node.generate(1) - assert_equal(self.get_credit_pool_balance(node=node_wallet), 0) assert_equal(self.get_credit_pool_balance(node=node), locked_1) self.log.info("Generate a number of blocks to ensure this is the longest chain for later in the test when we reconsiderblock") node.generate(12) @@ -295,7 +324,7 @@ class AssetLocksTest(DashTestFramework): self.create_and_check_block([extra_lock_tx], expected_error = 'bad-cbtx-assetlocked-amount') self.log.info("Mine a quorum...") - self.mine_quorum() + self.mine_quorum(llmq_type_name='llmq_test_platform', llmq_type=106, expected_connections=2, expected_members=3, expected_contributions=3, expected_complaints=0, expected_justifications=0, expected_commitments=3 ) self.validate_credit_pool_balance(locked_1) @@ -345,7 +374,7 @@ class AssetLocksTest(DashTestFramework): reason = "double copy") self.log.info("Mining next quorum to check tx 'asset_unlock_tx_late' is still valid...") - self.mine_quorum() + self.mine_quorum(llmq_type_name="llmq_test_platform", llmq_type=106) self.log.info("Checking credit pool amount is same...") self.validate_credit_pool_balance(locked_1 - 1 * COIN) self.check_mempool_result(tx=asset_unlock_tx_late, result_expected={'allowed': True}) @@ -365,7 +394,7 @@ class AssetLocksTest(DashTestFramework): result_expected={'allowed': False, 'reject-reason' : 'bad-assetunlock-too-late'}) self.log.info("Checking that two quorums later it is too late because quorum is not active...") - self.mine_quorum() + self.mine_quorum(llmq_type_name="llmq_test_platform", llmq_type=106) self.log.info("Expecting new reject-reason...") self.check_mempool_result(tx=asset_unlock_tx_too_late, result_expected={'allowed': False, 'reject-reason' : 'bad-assetunlock-not-active-quorum'}) @@ -423,7 +452,7 @@ class AssetLocksTest(DashTestFramework): self.log.info("Fast forward to the next day to reset all current unlock limits...") self.slowly_generate_batch(blocks_in_one_day + 1) - self.mine_quorum() + self.mine_quorum(llmq_type_name="llmq_test_platform", llmq_type=106) total = self.get_credit_pool_balance() while total <= 10_900 * COIN: diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index c390078abb..e92a13da2e 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -1155,6 +1155,7 @@ class DashTestFramework(BitcoinTestFramework): for i in range(0, idx): self.connect_nodes(i, idx) + # TODO: to let creating Evo Nodes without instant-send available def dynamically_add_masternode(self, evo=False, rnd=None, should_be_rejected=False): mn_idx = len(self.nodes)