From c8342e1b552ddd6be15a2035432cfeecbf8df484 Mon Sep 17 00:00:00 2001 From: pasta Date: Tue, 29 Oct 2024 12:53:47 -0500 Subject: [PATCH 1/4] refactor: pull LimitBlocksToTrace into CChainParams (reduce regtest to 100) --- src/chainparams.cpp | 8 ++++++++ src/chainparams.h | 3 +++ src/evo/creditpool.cpp | 4 ++-- src/evo/creditpool.h | 1 - 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c27d1cf5aa..1ea13b59ff 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -295,6 +295,8 @@ public: vSporkAddresses = {"Xgtyuk76vhuFW2iT7UAiHgNdWXCf3J34wh"}; nMinSporkKeys = 1; + nCreditPoolPeriodBlocks = 576; + checkpointData = { { {1500, uint256S("0x000000aaf0300f59f49bc3e970bad15c11f961fe2347accffff19d96ec9778e3")}, @@ -484,6 +486,8 @@ public: vSporkAddresses = {"yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55"}; nMinSporkKeys = 1; + nCreditPoolPeriodBlocks = 576; + checkpointData = { { {255, uint256S("0x0000080b600e06f4c07880673f027210f9314575f5f875fafe51971e268b886a")}, @@ -664,6 +668,8 @@ public: vSporkAddresses = {"yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55"}; nMinSporkKeys = 1; + nCreditPoolPeriodBlocks = 576; + checkpointData = (CCheckpointData) { { { 0, uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e")}, @@ -866,6 +872,8 @@ public: vSporkAddresses = {"yj949n1UH6fDhw6HtVE5VMj2iSTaSWBMcW"}; nMinSporkKeys = 1; + nCreditPoolPeriodBlocks = 100; + checkpointData = { { {0, uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e")}, diff --git a/src/chainparams.h b/src/chainparams.h index 7dc89a36b9..b832f04880 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -152,6 +152,7 @@ public: int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; } const std::vector& SporkAddresses() const { return vSporkAddresses; } int MinSporkKeys() const { return nMinSporkKeys; } + int CreditPoolPeriodBlocks() const { return nCreditPoolPeriodBlocks; } [[nodiscard]] std::optional GetLLMQ(Consensus::LLMQType llmqType) const; protected: @@ -188,6 +189,8 @@ protected: int nMinSporkKeys; uint16_t nDefaultPlatformP2PPort; uint16_t nDefaultPlatformHTTPPort; + /// The number of blocks the credit pool tracks; 576 (one day) on mainnet, reduced on regtest + int nCreditPoolPeriodBlocks; void AddLLMQ(Consensus::LLMQType llmqType); }; diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index b3474a78a3..424915cc1e 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -153,7 +153,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo return opt_cbTx->creditPoolBalance; }(); - // We use here sliding window with LimitBlocksToTrace to determine + // We use here sliding window with Params().CreditPoolPeriodBlocks to determine // current limits for asset unlock transactions. // Indexes should not be duplicated since genesis block, but the Unlock Amount // of withdrawal transaction is limited only by this window @@ -164,7 +164,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo } const CBlockIndex* distant_block_index = block_index; - for (size_t i = 0; i < CCreditPoolManager::LimitBlocksToTrace; ++i) { + for (auto i = 0; i < Params().CreditPoolPeriodBlocks(); ++i) { distant_block_index = distant_block_index->pprev; if (distant_block_index == nullptr) break; } diff --git a/src/evo/creditpool.h b/src/evo/creditpool.h index 9545922caf..dfb3004f8e 100644 --- a/src/evo/creditpool.h +++ b/src/evo/creditpool.h @@ -114,7 +114,6 @@ private: static constexpr int DISK_SNAPSHOT_PERIOD = 576; // once per day public: - static constexpr int LimitBlocksToTrace = 576; static constexpr CAmount LimitAmountLow = 100 * COIN; static constexpr CAmount LimitAmountHigh = 1000 * COIN; static constexpr CAmount LimitAmountV22 = 2000 * COIN; From bfe1d2768d244bbe711314f03816d244f2eb48dc Mon Sep 17 00:00:00 2001 From: pasta Date: Tue, 29 Oct 2024 12:54:04 -0500 Subject: [PATCH 2/4] refactor: activate DEPLOYMENT_WITHDRAWALS sooner on regtest --- src/chainparams.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1ea13b59ff..eeab97c2c4 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -818,9 +818,9 @@ public: consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].bit = 11; consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nStartTime = 0; consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT; - consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nWindowSize = 600; - consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nThresholdStart = 600 / 5 * 4; // 80% of window size - consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nThresholdMin = 600 / 5 * 3; // 60% of window size + consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nWindowSize = 200; + consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nThresholdStart = 200 / 5 * 4; // 80% of window size + consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nThresholdMin = 200 / 5 * 3; // 60% of window size consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].nFalloffCoeff = 5; // this corresponds to 10 periods consensus.vDeployments[Consensus::DEPLOYMENT_WITHDRAWALS].useEHF = true; From 4cc3ee6286195748a9c8bbb6d2d91a1b58d0ed15 Mon Sep 17 00:00:00 2001 From: pasta Date: Tue, 29 Oct 2024 12:57:35 -0500 Subject: [PATCH 3/4] test: update feature_asset_locks.py to reflect changes This results in test time locally going from ~4 minutes to ~3 minutes --- test/functional/feature_asset_locks.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index 1bc8309c6b..a6ecb4debf 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -44,7 +44,7 @@ from test_framework.wallet_util import bytes_to_wif llmq_type_test = 106 # LLMQType::LLMQ_TEST_PLATFORM tiny_amount = int(Decimal("0.0007") * COIN) -blocks_in_one_day = 576 +blocks_in_one_day = 100 HEIGHT_DIFF_EXPIRING = 48 class AssetLocksTest(DashTestFramework): @@ -52,7 +52,7 @@ class AssetLocksTest(DashTestFramework): self.set_dash_test_params(4, 2, [[ "-whitelist=127.0.0.1", "-llmqtestinstantsenddip0024=llmq_test_instantsend", - "-testactivationheight=mn_rr@2500", + "-testactivationheight=mn_rr@1400", ]] * 4, evo_count=2) def skip_test_if_missing_module(self): @@ -621,9 +621,10 @@ class AssetLocksTest(DashTestFramework): def test_mn_rr(self, node_wallet, node, pubkey): + self.log.info(node_wallet.getblockcount()) self.log.info("Activate mn_rr...") locked = self.get_credit_pool_balance() - self.activate_mn_rr(expected_activation_height=2500) + self.activate_mn_rr(expected_activation_height=1400) self.log.info(f'mn-rr height: {node.getblockcount()} credit: {self.get_credit_pool_balance()}') assert_equal(locked, self.get_credit_pool_balance()) @@ -635,7 +636,7 @@ class AssetLocksTest(DashTestFramework): all_mn_rewards = platform_reward + owner_reward + operator_reward assert_equal(all_mn_rewards, bt['coinbasevalue'] * 3 // 4) # 75/25 mn/miner reward split assert_equal(platform_reward, all_mn_rewards * 375 // 1000) # 0.375 platform share - assert_equal(platform_reward, 34371430) + assert_equal(platform_reward, 57741807) assert_equal(locked, self.get_credit_pool_balance()) self.generate(node, 1) locked += platform_reward From 2d05df04fd6cd5a29144e3be7cf5e5877eacfcff Mon Sep 17 00:00:00 2001 From: pasta Date: Tue, 29 Oct 2024 13:18:47 -0500 Subject: [PATCH 4/4] refactor: use irange --- src/evo/creditpool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/evo/creditpool.cpp b/src/evo/creditpool.cpp index 424915cc1e..abcf72650a 100644 --- a/src/evo/creditpool.cpp +++ b/src/evo/creditpool.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -164,7 +165,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo } const CBlockIndex* distant_block_index = block_index; - for (auto i = 0; i < Params().CreditPoolPeriodBlocks(); ++i) { + for ([[maybe_unused]] auto _ : irange::range(Params().CreditPoolPeriodBlocks())) { distant_block_index = distant_block_index->pprev; if (distant_block_index == nullptr) break; }