Skip to content

Commit 9bf39a9

Browse files
Merge #6222: fix: adjust payee predictions after mn_rr activation, add tests
715bc1a test: check `masternode winners` before and after mn_rr (UdjinM6) 9d47cd2 fix: adjust payee predictions after mn_rr activation (UdjinM6) Pull request description: ## Issue being fixed or feature implemented Payment predictions in GUI are wrong when mn_rr is active, `masternode winners` RPC is affected by the same issue too. Actual payments aren't affected. ## What was done? Adjust calculations, add tests for `masternode winners`. ## How Has This Been Tested? Run dash-qt on testnet, check "Next Payment" on "Masternode" tab. Run tests. ## Breaking Changes n/a ## Checklist: - [x] 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 - [ ] I have assigned this pull request to a milestone ACKs for top commit: PastaPastaPasta: utACK 715bc1a Tree-SHA512: 293c77974bcb50c6f9c51449d7bb12f89ad8db5871cad3a6083fe1951fe77e0deba8de7688b2f600fabe977bdc7390a66a984a6a076be19183c23742e00e27bf
1 parent 87bebfc commit 9bf39a9

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

src/evo/deterministicmns.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,16 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(gsl
215215
if (nCount < 0 ) {
216216
return {};
217217
}
218-
const auto weighted_count = GetValidWeightedMNsCount();
218+
const bool isMNRewardReallocation = DeploymentActiveAfter(pindexPrev, Params().GetConsensus(),
219+
Consensus::DEPLOYMENT_MN_RR);
220+
const auto weighted_count = isMNRewardReallocation ? GetValidMNsCount() : GetValidWeightedMNsCount();
219221
nCount = std::min(nCount, int(weighted_count));
220222

221223
std::vector<CDeterministicMNCPtr> result;
222224
result.reserve(weighted_count);
223225

224226
int remaining_evo_payments{0};
225227
CDeterministicMNCPtr evo_to_be_skipped{nullptr};
226-
const bool isMNRewardReallocation{DeploymentActiveAfter(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR)};
227228
if (!isMNRewardReallocation) {
228229
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
229230
if (dmn->pdmnState->nLastPaidHeight == nHeight) {
@@ -242,7 +243,7 @@ std::vector<CDeterministicMNCPtr> CDeterministicMNList::GetProjectedMNPayees(gsl
242243

243244
ForEachMNShared(true, [&](const CDeterministicMNCPtr& dmn) {
244245
if (dmn == evo_to_be_skipped) return;
245-
for ([[maybe_unused]] auto _ : irange::range(GetMnType(dmn->nType).voting_weight)) {
246+
for ([[maybe_unused]] auto _ : irange::range(isMNRewardReallocation ? 1 : GetMnType(dmn->nType).voting_weight)) {
246247
result.emplace_back(dmn);
247248
}
248249
});

test/functional/feature_llmq_evo.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
QuorumId, ser_uint256
1818
from test_framework.test_framework import DashTestFramework
1919
from test_framework.util import (
20-
assert_equal, p2p_port
20+
assert_equal, assert_greater_than_or_equal, p2p_port
2121
)
2222

2323

@@ -46,7 +46,7 @@ def getmnlistdiff(self, baseBlockHash, blockHash):
4646

4747
class LLMQEvoNodesTest(DashTestFramework):
4848
def set_test_params(self):
49-
self.set_dash_test_params(5, 4, fast_dip3_enforcement=True, evo_count=7)
49+
self.set_dash_test_params(5, 4, fast_dip3_enforcement=True, evo_count=5)
5050
self.set_dash_llmq_test_params(4, 4)
5151

5252
def run_test(self):
@@ -92,7 +92,7 @@ def run_test(self):
9292
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
9393

9494
evo_protxhash_list = list()
95-
for i in range(5):
95+
for i in range(self.evo_count):
9696
evo_info = self.dynamically_add_masternode(evo=True)
9797
evo_protxhash_list.append(evo_info.proTxHash)
9898
self.nodes[0].generate(8)
@@ -115,6 +115,7 @@ def run_test(self):
115115

116116
self.log.info("Test that EvoNodes are paid 4x blocks in a row")
117117
self.test_evo_payments(window_analysis=48)
118+
self.test_masternode_winners()
118119

119120
self.activate_v20()
120121
self.activate_mn_rr()
@@ -127,6 +128,7 @@ def run_test(self):
127128

128129
self.log.info("Test that EvoNodes are paid 1 block in a row after MN RewardReallocation activation")
129130
self.test_evo_payments(window_analysis=48, v20active=True)
131+
self.test_masternode_winners(mn_rr_active=True)
130132

131133
self.log.info(self.nodes[0].masternodelist())
132134

@@ -248,6 +250,40 @@ def test_masternode_count(self, expected_mns_count, expected_evo_count):
248250
assert_equal(detailed_count['regular']['total'], expected_mns_count)
249251
assert_equal(detailed_count['evo']['total'], expected_evo_count)
250252

253+
def test_masternode_winners(self, mn_rr_active=False):
254+
# ignore recent winners, test future ones only
255+
# we get up to 21 entries here: tip + up to 20 future payees
256+
winners = self.nodes[0].masternode('winners', '0')
257+
weighted_count = self.mn_count + self.evo_count * (1 if mn_rr_active else 4)
258+
assert_equal(len(winners.keys()) - 1, 20 if weighted_count > 20 else weighted_count)
259+
consecutive_payments = 0
260+
full_consecutive_payments_found = 0
261+
payment_cycles = 0
262+
first_payee = None
263+
prev_winner = None
264+
for height in winners.keys():
265+
winner = winners[height]
266+
if mn_rr_active:
267+
assert_equal(prev_winner == winner, False)
268+
else:
269+
if prev_winner == winner:
270+
consecutive_payments += 1
271+
else:
272+
if consecutive_payments == 3:
273+
full_consecutive_payments_found += 1
274+
consecutive_payments = 0
275+
assert_greater_than_or_equal(3, consecutive_payments)
276+
if consecutive_payments == 0 and winner == first_payee:
277+
payment_cycles += 1
278+
if first_payee is None:
279+
first_payee = winner
280+
prev_winner = winner
281+
if mn_rr_active:
282+
assert_equal(full_consecutive_payments_found, 0)
283+
else:
284+
assert_greater_than_or_equal(full_consecutive_payments_found, (len(winners.keys()) - 1 - self.mn_count) // 4 - 1)
285+
assert_equal(payment_cycles, (len(winners.keys()) - 1) // weighted_count)
286+
251287
def test_getmnlistdiff(self, baseBlockHash, blockHash, baseMNList, expectedDeleted, expectedUpdated):
252288
d = self.test_getmnlistdiff_base(baseBlockHash, blockHash)
253289

0 commit comments

Comments
 (0)