Skip to content

Commit c5b42c9

Browse files
committed
feat: masternode payment reallocation from coin base to platform
Move funds from the coinbase, into the Asset Lock Pool. This is to incentivize MNs to upgrade to platform, because only MNs running platform will get these migrated rewards
1 parent 9bb1b10 commit c5b42c9

File tree

13 files changed

+126
-7
lines changed

13 files changed

+126
-7
lines changed

src/chainparams.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ class CMainParams : public CChainParams {
188188
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 2420; // 60% of 4032
189189
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
190190

191+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
192+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later
193+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
194+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 4032;
195+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 3226; // 80% of 4032
196+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 2420; // 60% of 4032
197+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
191198

192199
// The best chain should have at least this much work.
193200
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000008677827656704520eb39"); // 1889000
@@ -377,6 +384,14 @@ class CTestNetParams : public CChainParams {
377384
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100
378385
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
379386

387+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
388+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later
389+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
390+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 100;
391+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
392+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
393+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
394+
380395
// The best chain should have at least this much work.
381396
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000002d68c8cc1b8e54b"); // 851000
382397

@@ -539,6 +554,14 @@ class CDevNetParams : public CChainParams {
539554
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100
540555
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
541556

557+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
558+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 1661990400; // Sep 1st, 2022
559+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
560+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 120;
561+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
562+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
563+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
564+
542565
// The best chain should have at least this much work.
543566
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000");
544567

@@ -767,6 +790,14 @@ class CRegTestParams : public CChainParams {
767790
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 288; // 60% of 480
768791
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
769792

793+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
794+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 0;
795+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
796+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 1030;
797+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 800; // 80% of 1000
798+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 600; // 60% of 1000
799+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
800+
770801
// The best chain should have at least this much work.
771802
consensus.nMinimumChainWork = uint256S("0x00");
772803

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Consensus {
1616
enum DeploymentPos {
1717
DEPLOYMENT_TESTDUMMY,
1818
DEPLOYMENT_V20, // Deployment of EHF, LLMQ Randomness Beacon
19+
DEPLOYMENT_MN_RR, // Deployment of Masternode Reward Location Reallocation
1920
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
2021
MAX_VERSION_BITS_DEPLOYMENTS
2122
};

src/evo/creditpool.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
#include <evo/assetlocktx.h>
88
#include <evo/cbtx.h>
99

10-
#include <llmq/utils.h>
11-
1210
#include <chain.h>
11+
#include <llmq/utils.h>
1312
#include <logging.h>
1413
#include <validation.h>
1514
#include <node/blockstorage.h>
@@ -213,21 +212,38 @@ CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb)
213212

214213
CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams) :
215214
pool(std::move(starter)),
216-
pindex(pindex)
215+
pindex(pindex),
216+
params(consensusParams)
217217
{
218218
assert(pindex);
219219
}
220220

221+
void CCreditPoolDiff::AddRewardRealloced(const CAmount reward) {
222+
assert(MoneyRange(reward));
223+
masternodeReward += reward;
224+
}
225+
221226
bool CCreditPoolDiff::SetTarget(const CTransaction& tx, TxValidationState& state)
222227
{
223228
CCbTx cbTx;
224229
if (!GetTxPayload(tx, cbTx)) {
225230
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-cbtx-payload");
226231
}
227232

228-
if (cbTx.nVersion == 3) {
229-
targetLocked = cbTx.assetLockedAmount;
233+
if (cbTx.nVersion != 3) return true;
234+
235+
targetLocked = cbTx.assetLockedAmount;
236+
237+
238+
if (!llmq::utils::IsMNRewardReallocationActive(pindex)) return true;
239+
240+
CAmount blockReward = 0;
241+
for (const CTxOut& txout : tx.vout) {
242+
blockReward += txout.nValue;
230243
}
244+
masternodeReward = GetMasternodePayment(cbTx.nHeight, blockReward, params.BRRHeight);
245+
LogPrintf("CreditPool: set target to %lld with MN reward %lld\n", *targetLocked, masternodeReward);
246+
231247
return true;
232248
}
233249

src/evo/creditpool.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ class CCreditPoolDiff {
6767

6868
CAmount sessionLocked{0};
6969
CAmount sessionUnlocked{0};
70+
CAmount masternodeReward{0};
7071

7172
// target value is used to validate CbTx. If values mismatched, block is invalid
7273
std::optional<CAmount> targetLocked;
7374

7475
const CBlockIndex *pindex{nullptr};
76+
const Consensus::Params& params;
7577
public:
7678
explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams);
7779

@@ -82,8 +84,13 @@ class CCreditPoolDiff {
8284
*/
8385
bool ProcessTransaction(const CTransaction& tx, TxValidationState& state);
8486

87+
/**
88+
* This function should be called by miner for initalization of MasterNode reward
89+
*/
90+
void AddRewardRealloced(const CAmount reward);
91+
8592
CAmount GetTotalLocked() const {
86-
return pool.locked + sessionLocked - sessionUnlocked;
93+
return pool.locked + sessionLocked - sessionUnlocked + masternodeReward;
8794
}
8895

8996
const std::optional<CAmount>& GetTargetLocked() const {

src/llmq/utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ bool IsV20Active(const CBlockIndex* pindex)
724724
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache) == ThresholdState::ACTIVE;
725725
}
726726

727+
bool IsMNRewardReallocationActive(const CBlockIndex* pindex)
728+
{
729+
if (!IsV20Active(pindex)) return false;
730+
731+
LOCK(cs_llmq_vbc);
732+
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR, llmq_versionbitscache) == ThresholdState::ACTIVE;
733+
}
734+
727735
bool IsInstantSendLLMQTypeShared()
728736
{
729737
if (Params().GetConsensus().llmqTypeInstantSend == Params().GetConsensus().llmqTypeChainLocks ||

src/llmq/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ bool IsDIP0024Active(const CBlockIndex* pindex);
7676
bool IsV19Active(const CBlockIndex* pindex);
7777
const CBlockIndex* V19ActivationIndex(const CBlockIndex* pindex);
7878
bool IsV20Active(const CBlockIndex* pindex);
79+
bool IsMNRewardReallocationActive(const CBlockIndex* pindex);
7980

8081
/// Returns the state of `-llmq-data-recovery`
8182
bool QuorumDataRecoveryEnabled();

src/masternode/payments.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
#include <governance/governance.h>
1313
#include <key_io.h>
1414
#include <logging.h>
15+
#include <llmq/utils.h>
1516
#include <masternode/sync.h>
1617
#include <primitives/block.h>
1718
#include <script/standard.h>
1819
#include <tinyformat.h>
1920
#include <util/ranges.h>
2021
#include <util/system.h>
2122
#include <validation.h>
23+
#include <evo/creditpool.h>
2224

2325
#include <string>
2426

@@ -32,14 +34,23 @@ static bool GetBlockTxOuts(const int nBlockHeight, const CAmount blockReward, st
3234
{
3335
voutMasternodePaymentsRet.clear();
3436

37+
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward, Params().GetConsensus().BRRHeight);
38+
3539
const CBlockIndex* pindex = WITH_LOCK(cs_main, return ::ChainActive()[nBlockHeight - 1]);
40+
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindex);
41+
42+
if (fMNRewardReallocated) {
43+
LogPrintf("CMasternodePayments::%s -- MN reward %lld reallocated to credit pool\n", __func__, masternodeReward);
44+
voutMasternodePaymentsRet.emplace_back(masternodeReward, CScript() << OP_RETURN);
45+
return true;
46+
}
47+
3648
auto dmnPayee = deterministicMNManager->GetListForBlock(pindex).GetMNPayee(pindex);
3749
if (!dmnPayee) {
3850
return false;
3951
}
4052

4153
CAmount operatorReward = 0;
42-
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward, Params().GetConsensus().BRRHeight);
4354

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

src/miner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
231231
LogPrintf("CreateNewBlock() h[%d] CbTx failed to find best CL. Inserting null CL\n", nHeight);
232232
}
233233
assert(creditPoolDiff != std::nullopt);
234+
235+
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindexPrev);
236+
if (fMNRewardReallocated) {
237+
const CAmount masternodeReward = GetMasternodePayment(nHeight, blockReward, Params().GetConsensus().BRRHeight);
238+
LogPrintf("CreateNewBlock() add MN reward %lld to credit pool\n", masternodeReward);
239+
creditPoolDiff->AddRewardRealloced(masternodeReward);
240+
}
234241
cbTx.assetLockedAmount = creditPoolDiff->GetTotalLocked();
235242
}
236243
}

src/rpc/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
16421642
BuriedForkDescPushBack(softforks, "realloc", consensusParams.BRRHeight, height);
16431643
BuriedForkDescPushBack(softforks, "v19", consensusParams.V19Height, height);
16441644
BIP9SoftForkDescPushBack(tip, softforks, "v20", consensusParams, Consensus::DEPLOYMENT_V20);
1645+
BIP9SoftForkDescPushBack(tip, softforks, "mn_rr", consensusParams, Consensus::DEPLOYMENT_MN_RR);
16451646
BIP9SoftForkDescPushBack(tip, softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
16461647

16471648
obj.pushKV("softforks", softforks);

src/versionbitsinfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
1515
/*.name =*/"v20",
1616
/*.gbt_force =*/true,
1717
},
18+
{
19+
/*.name =*/"mn_rr",
20+
/*.gbt_force =*/true,
21+
},
1822
};

0 commit comments

Comments
 (0)