Skip to content

Commit 3185dae

Browse files
committed
refactor: pass Consensus::Params to GetMasternodePayment
1 parent f4180b1 commit 3185dae

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/masternode/payments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static bool GetBlockTxOuts(const int nBlockHeight, const CAmount blockReward, st
3939
}
4040

4141
CAmount operatorReward = 0;
42-
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward, Params().GetConsensus().BRRHeight);
42+
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward, Params().GetConsensus(), Params().GetConsensus().BRRHeight);
4343

4444
if (dmnPayee->nOperatorReward != 0 && dmnPayee->pdmnState->scriptOperatorPayout != CScript()) {
4545
// This calculation might eventually turn out to result in 0 even if an operator reward percentage is given.

src/test/block_reward_reallocation_tests.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ BOOST_AUTO_TEST_SUITE(block_reward_reallocation_tests)
144144
BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationSetup)
145145
{
146146
const auto& chainparams = Params();
147+
const auto& consensusParams = chainparams.GetConsensus();
147148
CScript coinbasePubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
148149

149150
BOOST_ASSERT(deterministicMNManager->IsDIP3Enforced(WITH_LOCK(cs_main, return ::ChainActive().Height())));
@@ -201,7 +202,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
201202
LOCK(cs_main);
202203
deterministicMNManager->UpdatedBlockTip(::ChainActive().Tip());
203204
BOOST_ASSERT(deterministicMNManager->GetListAtChainTip().HasMN(tx.GetHash()));
204-
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), 2500);
205+
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), consensusParams, 2500);
205206
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
206207
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
207208
}
@@ -212,7 +213,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
212213

213214
{
214215
LOCK(cs_main);
215-
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), 2500);
216+
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), consensusParams, 2500);
216217
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
217218
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 13748571607);
218219
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
@@ -227,7 +228,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
227228
CreateAndProcessBlock({}, coinbaseKey);
228229
}
229230
LOCK(cs_main);
230-
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), 2500);
231+
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), consensusParams, 2500);
231232
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
232233
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
233234
}
@@ -236,7 +237,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
236237
{
237238
// Reward split should reach ~60/40 after reallocation is done
238239
LOCK(cs_main);
239-
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), 2500);
240+
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), consensusParams, 2500);
240241
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
241242
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 10221599170);
242243
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
@@ -250,15 +251,15 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
250251
CreateAndProcessBlock({}, coinbaseKey);
251252
}
252253
LOCK(cs_main);
253-
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), 2500);
254+
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), consensusParams, 2500);
254255
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
255256
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);
256257
}
257258

258259
{
259260
// Reward split should reach ~60/40 after reallocation is done
260261
LOCK(cs_main);
261-
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), 2500);
262+
auto masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidy(::ChainActive().Tip()->nBits, ::ChainActive().Height(), chainparams), consensusParams, 2500);
262263
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
263264
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 9491484944);
264265
BOOST_CHECK_EQUAL(pblocktemplate->voutMasternodePayments[0].nValue, masternode_payment);

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,12 +1175,12 @@ CAmount GetBlockSubsidy(const CBlockIndex* pindexPrev, const CChainParams& param
11751175
return GetBlockSubsidy(pindexPrev->nBits, pindexPrev->nHeight, params, fSuperblockPartOnly);
11761176
}
11771177

1178-
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, int nReallocActivationHeight)
1178+
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, const Consensus::Params& consensusParams, int nReallocActivationHeight)
11791179
{
11801180
CAmount ret = blockValue/5; // start at 20%
11811181

1182-
int nMNPIBlock = Params().GetConsensus().nMasternodePaymentsIncreaseBlock;
1183-
int nMNPIPeriod = Params().GetConsensus().nMasternodePaymentsIncreasePeriod;
1182+
int nMNPIBlock = consensusParams.nMasternodePaymentsIncreaseBlock;
1183+
int nMNPIPeriod = consensusParams.nMasternodePaymentsIncreasePeriod;
11841184

11851185
// mainnet:
11861186
if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
@@ -1198,7 +1198,7 @@ CAmount GetMasternodePayment(int nHeight, CAmount blockValue, int nReallocActiva
11981198
return ret;
11991199
}
12001200

1201-
int nSuperblockCycle = Params().GetConsensus().nSuperblockCycle;
1201+
int nSuperblockCycle = consensusParams.nSuperblockCycle;
12021202
// Actual realocation starts in the cycle next to one activation happens in
12031203
int nReallocStart = nReallocActivationHeight - nReallocActivationHeight % nSuperblockCycle + nSuperblockCycle;
12041204

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
208208
double ConvertBitsToDouble(unsigned int nBits);
209209
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const CChainParams& params, bool fSuperblockPartOnly = false);
210210
CAmount GetBlockSubsidy(const CBlockIndex* pindexPrev, const CChainParams& params, bool fSuperblockPartOnly = false);
211-
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, int nReallocActivationHeight = std::numeric_limits<int>::max() /* not activated */);
211+
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, const Consensus::Params& consensusParams, int nReallocActivationHeight = std::numeric_limits<int>::max() /* not activated */);
212212

213213
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
214214
double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pindex);

0 commit comments

Comments
 (0)