Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: optimize feature asset locks test #6374

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe then apply 100 on all test nets? (Trstnet, devnet, regtest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a point to introduce breaking changes for devnet / testnet over this. Only real benefit is in CI situations imo

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
Loading