Skip to content

Commit 37ad935

Browse files
committed
refactor: freed CMNPaymentsProcessor from global chain-params access
1 parent 7f43be8 commit 37ad935

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

src/evo/creditpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex* pindexP
251251

252252
if (DeploymentActiveAfter(pindexPrev, consensusParams, Consensus::DEPLOYMENT_MN_RR)) {
253253
// If credit pool exists, it means v20 is activated
254-
platformReward = PlatformShare(GetMasternodePayment(pindexPrev->nHeight + 1, blockSubsidy, MnRewardEra::EvoReward));
254+
platformReward = PlatformShare(GetMasternodePayment(pindexPrev->nHeight + 1, blockSubsidy, consensusParams, MnRewardEra::EvoReward));
255255
}
256256
}
257257

src/masternode/payments.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <masternode/sync.h>
1010

1111
#include <chain.h>
12-
#include <chainparams.h>
1312
#include <consensus/amount.h>
1413
#include <deploymentstatus.h>
1514
#include <key_io.h>
@@ -30,13 +29,13 @@ CAmount PlatformShare(const CAmount reward)
3029
return platformReward;
3130
}
3231

33-
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, MnRewardEra era)
32+
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, const Consensus::Params& consensus_params, MnRewardEra era)
3433
{
3534
CAmount ret = blockValue/5; // start at 20%
3635

37-
const int nMNPIBlock = Params().GetConsensus().nMasternodePaymentsIncreaseBlock;
38-
const int nMNPIPeriod = Params().GetConsensus().nMasternodePaymentsIncreasePeriod;
39-
const int nReallocActivationHeight = Params().GetConsensus().BRRHeight;
36+
const int nMNPIBlock = consensus_params.nMasternodePaymentsIncreaseBlock;
37+
const int nMNPIPeriod = consensus_params.nMasternodePaymentsIncreasePeriod;
38+
const int nReallocActivationHeight = consensus_params.BRRHeight;
4039

4140
// mainnet:
4241
if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
@@ -54,7 +53,7 @@ CAmount GetMasternodePayment(int nHeight, CAmount blockValue, MnRewardEra era)
5453
return ret;
5554
}
5655

57-
int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle;
56+
int nSuperblockCycle = consensus_params.nSuperblockCycle;
5857
// Actual realocation starts in the cycle next to one activation happens in
5958
int nReallocStart = nReallocActivationHeight - nReallocActivationHeight % nSuperblockCycle + nSuperblockCycle;
6059

@@ -106,12 +105,12 @@ CAmount GetMasternodePayment(int nHeight, CAmount blockValue, MnRewardEra era)
106105

107106
const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
108107

109-
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockSubsidy + feeReward, era);
108+
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockSubsidy + feeReward, m_consensus_params, era);
110109

111110
// Credit Pool doesn't exist before V20. If any part of reward will re-allocated to credit pool before v20
112111
// activation these fund will be just permanently lost. Applicable for devnets, regtest, testnet
113112
if (era == MnRewardEra::EvoReward) {
114-
CAmount masternodeSubsidyReward = GetMasternodePayment(nBlockHeight, blockSubsidy, era);
113+
CAmount masternodeSubsidyReward = GetMasternodePayment(nBlockHeight, blockSubsidy, m_consensus_params, era);
115114
const CAmount platformReward = PlatformShare(masternodeSubsidyReward);
116115
masternodeReward -= platformReward;
117116

src/masternode/payments.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum class MnRewardEra {
4444
EvoReward, // MN_RR: platform share is reallocated from the masternode reward
4545
};
4646

47-
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, MnRewardEra era);
47+
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, const Consensus::Params& consensus_params, MnRewardEra era);
4848

4949
class CMNPaymentsProcessor
5050
{

src/test/block_reward_reallocation_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
214214
dmnman.UpdatedBlockTip(tip);
215215
BOOST_REQUIRE(dmnman.GetListAtChainTip().HasMN(tx.GetHash()));
216216
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
217-
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, era);
217+
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, consensus_params, era);
218218
const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, m_node.mempool.get(), Params()).CreateNewBlock(coinbasePubKey);
219219
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
220220
}
@@ -229,7 +229,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
229229
const MnRewardEra era{GetMnRewardEraAfter(tip, *m_node.chainman)};
230230
const bool isV20Active{era != MnRewardEra::Classic};
231231
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
232-
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, era);
232+
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, consensus_params, era);
233233
const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, m_node.mempool.get(), Params()).CreateNewBlock(coinbasePubKey);
234234
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 28847249686);
235235
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
@@ -247,7 +247,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
247247
const MnRewardEra era{GetMnRewardEraAfter(tip, *m_node.chainman)};
248248
const bool isV20Active{era != MnRewardEra::Classic};
249249
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
250-
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, era);
250+
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, consensus_params, era);
251251
const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, m_node.mempool.get(), Params()).CreateNewBlock(coinbasePubKey);
252252
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
253253
}
@@ -266,7 +266,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
266266
BOOST_CHECK_EQUAL(block_subsidy_potential, 177167660);
267267
CAmount expected_block_reward = block_subsidy_potential - block_subsidy_potential / 5;
268268

269-
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, era);
269+
const CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, consensus_params, era);
270270
const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, m_node.mempool.get(), Params()).CreateNewBlock(coinbasePubKey);
271271
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), expected_block_reward);
272272
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 141734128);
@@ -287,7 +287,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
287287
const bool isV20Active{era != MnRewardEra::Classic};
288288
const bool isMNRewardReallocated{era == MnRewardEra::EvoReward};
289289
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
290-
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, era);
290+
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, consensus_params, era);
291291
const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, m_node.mempool.get(), Params()).CreateNewBlock(coinbasePubKey);
292292

293293
if (isMNRewardReallocated) {
@@ -308,7 +308,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
308308
const bool isV20Active{era != MnRewardEra::Classic};
309309
const CAmount block_subsidy = GetBlockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
310310
const CAmount block_subsidy_sb = GetSuperblockSubsidyInner(tip->nBits, tip->nHeight, consensus_params, isV20Active);
311-
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, era);
311+
CAmount masternode_payment = GetMasternodePayment(tip->nHeight, block_subsidy, consensus_params, era);
312312
const CAmount platform_payment = PlatformShare(masternode_payment);
313313
masternode_payment -= platform_payment;
314314
const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, m_node.mempool.get(), Params()).CreateNewBlock(coinbasePubKey);

0 commit comments

Comments
 (0)