Skip to content

Commit fadd425

Browse files
committed
refactor: rid-of magic constant by introducing MasternodePayments::PlatformShare
1 parent 2444540 commit fadd425

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/masternode/payments.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <validation.h>
2323
#include <evo/creditpool.h>
2424

25+
#include <cassert>
2526
#include <string>
2627

2728
/**
@@ -40,10 +41,9 @@ static bool GetBlockTxOuts(const int nBlockHeight, const CAmount blockReward, st
4041
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindex);
4142

4243
if (fMNRewardReallocated) {
43-
const CAmount platformReward = masternodeReward * 0.375;
44+
const CAmount platformReward = MasternodePayments::PlatformShare(masternodeReward);
4445
masternodeReward -= platformReward;
4546

46-
assert(MoneyRange(platformReward));
4747
assert(MoneyRange(masternodeReward));
4848

4949
LogPrint(BCLog::MNPAYMENTS, "CMasternodePayments::%s -- MN reward %lld reallocated to credit pool\n", __func__, platformReward);
@@ -345,4 +345,13 @@ void FillBlockPayments(const CSporkManager& sporkManager, CGovernanceManager& go
345345
nBlockHeight, blockReward, voutMasternodeStr, txNew.ToString());
346346
}
347347

348+
CAmount PlatformShare(const CAmount reward)
349+
{
350+
constexpr double platformShare = 0.375;
351+
const CAmount platformReward = reward * platformShare;
352+
assert(MoneyRange(platformReward));
353+
354+
return platformReward;
355+
}
356+
348357
} // namespace MasternodePayments

src/masternode/payments.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ bool IsBlockPayeeValid(const CSporkManager& sporkManager, CGovernanceManager& go
3232
void FillBlockPayments(const CSporkManager& sporkManager, CGovernanceManager& governanceManager,
3333
CMutableTransaction& txNew, const int nBlockHeight, const CAmount blockReward,
3434
std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet);
35+
36+
/**
37+
* this helper returns amount that should be reallocated to platform
38+
* it is calculated based on total amount of Masternode rewards (not block reward)
39+
*/
40+
CAmount PlatformShare(const CAmount masternodeReward);
41+
3542
} // namespace MasternodePayments
3643

3744
#endif // BITCOIN_MASTERNODE_PAYMENTS_H

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
235235
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindexPrev);
236236
if (fMNRewardReallocated) {
237237
const CAmount masternodeReward = GetMasternodePayment(nHeight, blockReward, Params().GetConsensus().BRRHeight);
238-
const CAmount reallocedReward = masternodeReward * 0.375;
238+
const CAmount reallocedReward = MasternodePayments::PlatformShare(masternodeReward);
239239
LogPrint(BCLog::MNPAYMENTS, "%s: add MN reward %lld (%lld) to credit pool\n", __func__, masternodeReward, reallocedReward);
240240
creditPoolDiff->AddRewardRealloced(reallocedReward);
241241
}

src/test/block_reward_reallocation_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <llmq/context.h>
2727
#include <llmq/instantsend.h>
2828
#include <llmq/utils.h>
29+
#include <masternode/payments.h>
2930
#include <util/enumerate.h>
3031
#include <util/irange.h>
3132

@@ -257,7 +258,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
257258

258259
bool isMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(::ChainActive().Tip());
259260
if (isMNRewardReallocated) {
260-
CAmount platform_payment = 0.375 * masternode_payment;
261+
const CAmount platform_payment = MasternodePayments::PlatformShare(masternode_payment);
261262
masternode_payment -= platform_payment;
262263
}
263264
size_t payment_index = isMNRewardReallocated ? 1 : 0;
@@ -269,7 +270,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS
269270
// Reward split should reach ~60/40 after reallocation is done
270271
LOCK(cs_main);
271272
CAmount masternode_payment = GetMasternodePayment(::ChainActive().Height(), GetBlockSubsidyInner(::ChainActive().Tip()->nBits, ::ChainActive().Height(), consensus_params), 2500);
272-
CAmount platform_payment = 0.375 * masternode_payment;
273+
const CAmount platform_payment = MasternodePayments::PlatformShare(masternode_payment);
273274
masternode_payment -= platform_payment;
274275
const auto pblocktemplate = BlockAssembler(*sporkManager, *governance, *m_node.llmq_ctx, *m_node.evodb, ::ChainstateActive(), *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey);
275276
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx[0]->GetValueOut(), 9491484944);

0 commit comments

Comments
 (0)