Skip to content

Commit

Permalink
Merge #6374: test: optimize feature asset locks test
Browse files Browse the repository at this point in the history
2d05df0 refactor: use irange (pasta)
4cc3ee6 test: update feature_asset_locks.py to reflect changes (pasta)
bfe1d27 refactor: activate DEPLOYMENT_WITHDRAWALS sooner on regtest (pasta)
c8342e1 refactor: pull LimitBlocksToTrace into CChainParams (reduce regtest to 100) (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  Minimize number of blocks needed to be mined in asset locks test

  Based on CI test goes from about 270s -> 213s

  ## What was done?
  Reduce number of blocks needed by reducing hard fork activation points

  ## How Has This Been Tested?
  Ran test locally, built

  ## Breaking Changes
  Breaking for regtests, nothing else.

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] 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 _(for repository code-owners and collaborators only)_

ACKs for top commit:
  knst:
    utACK 2d05df0
  UdjinM6:
    utACK 2d05df0

Tree-SHA512: b52ec2570912ccb578b14baa4ef5c6e69454db7d83e7476c4451bca62b0c57e4c961e4bfafc9e5b0b4eebd6226840ac00505d3787316d7bdaeb64cb66b08fb30
  • Loading branch information
PastaPastaPasta committed Oct 30, 2024
2 parents 841ea27 + 2d05df0 commit 88a8e7a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ class CMainParams : public CChainParams {
vSporkAddresses = {"Xgtyuk76vhuFW2iT7UAiHgNdWXCf3J34wh"};
nMinSporkKeys = 1;

nCreditPoolPeriodBlocks = 576;

checkpointData = {
{
{1500, uint256S("0x000000aaf0300f59f49bc3e970bad15c11f961fe2347accffff19d96ec9778e3")},
Expand Down Expand Up @@ -484,6 +486,8 @@ class CTestNetParams : public CChainParams {
vSporkAddresses = {"yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55"};
nMinSporkKeys = 1;

nCreditPoolPeriodBlocks = 576;

checkpointData = {
{
{255, uint256S("0x0000080b600e06f4c07880673f027210f9314575f5f875fafe51971e268b886a")},
Expand Down Expand Up @@ -664,6 +668,8 @@ class CDevNetParams : public CChainParams {
vSporkAddresses = {"yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55"};
nMinSporkKeys = 1;

nCreditPoolPeriodBlocks = 576;

checkpointData = (CCheckpointData) {
{
{ 0, uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e")},
Expand Down Expand Up @@ -812,9 +818,9 @@ class CRegTestParams : public CChainParams {
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;

Expand Down Expand Up @@ -866,6 +872,8 @@ class CRegTestParams : public CChainParams {
vSporkAddresses = {"yj949n1UH6fDhw6HtVE5VMj2iSTaSWBMcW"};
nMinSporkKeys = 1;

nCreditPoolPeriodBlocks = 100;

checkpointData = {
{
{0, uint256S("0x000008ca1832a4baf228eb1553c03d3a2c8e02399550dd6ea8d65cec3ef23d2e")},
Expand Down
3 changes: 3 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class CChainParams
int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; }
const std::vector<std::string>& SporkAddresses() const { return vSporkAddresses; }
int MinSporkKeys() const { return nMinSporkKeys; }
int CreditPoolPeriodBlocks() const { return nCreditPoolPeriodBlocks; }
[[nodiscard]] std::optional<Consensus::LLMQParams> GetLLMQ(Consensus::LLMQType llmqType) const;

protected:
Expand Down Expand Up @@ -188,6 +189,8 @@ class CChainParams
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);
};
Expand Down
5 changes: 3 additions & 2 deletions src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <deploymentstatus.h>
#include <logging.h>
#include <node/blockstorage.h>
#include <util/irange.h>
#include <validation.h>

#include <algorithm>
Expand Down Expand Up @@ -153,7 +154,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
Expand All @@ -164,7 +165,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 ([[maybe_unused]] auto _ : irange::range(Params().CreditPoolPeriodBlocks())) {
distant_block_index = distant_block_index->pprev;
if (distant_block_index == nullptr) break;
}
Expand Down
1 change: 0 additions & 1 deletion src/evo/creditpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class CCreditPoolManager
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;
Expand Down
9 changes: 5 additions & 4 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@

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):
def set_test_params(self):
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):
Expand Down Expand Up @@ -621,9 +621,10 @@ def test_withdrawal_limits(self, node_wallet, node, pubkey):


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())

Expand All @@ -635,7 +636,7 @@ def test_mn_rr(self, node_wallet, node, pubkey):
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
Expand Down

0 comments on commit 88a8e7a

Please sign in to comment.