Skip to content

Commit 1644bc3

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 4e713bc commit 1644bc3

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
@@ -196,6 +196,13 @@ class CMainParams : public CChainParams {
196196
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 2420; // 60% of 4032
197197
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
198198

199+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
200+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later
201+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
202+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 4032;
203+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 3226; // 80% of 4032
204+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 2420; // 60% of 4032
205+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
199206

200207
// The best chain should have at least this much work.
201208
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000008677827656704520eb39"); // 1889000
@@ -393,6 +400,14 @@ class CTestNetParams : public CChainParams {
393400
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100
394401
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
395402

403+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
404+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later
405+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
406+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 100;
407+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
408+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
409+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
410+
396411
// The best chain should have at least this much work.
397412
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000002d68c8cc1b8e54b"); // 851000
398413

@@ -563,6 +578,14 @@ class CDevNetParams : public CChainParams {
563578
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100
564579
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
565580

581+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
582+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 1661990400; // Sep 1st, 2022
583+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
584+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 120;
585+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
586+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
587+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
588+
566589
// The best chain should have at least this much work.
567590
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000");
568591

@@ -799,6 +822,14 @@ class CRegTestParams : public CChainParams {
799822
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 288; // 60% of 480
800823
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
801824

825+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
826+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 0;
827+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
828+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 1030;
829+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 800; // 80% of 1000
830+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 600; // 60% of 1000
831+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
832+
802833
// The best chain should have at least this much work.
803834
consensus.nMinimumChainWork = uint256S("0x00");
804835

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum DeploymentPos {
1717
DEPLOYMENT_TESTDUMMY,
1818
DEPLOYMENT_V19, // Deployment of Basic BLS, AssetLocks
1919
DEPLOYMENT_V20, // Deployment of EHF, LLMQ Randomness Beacon
20+
DEPLOYMENT_MN_RR, // Deployment of Masternode Reward Location Reallocation
2021
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
2122
MAX_VERSION_BITS_DEPLOYMENTS
2223
};

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

@@ -212,21 +211,38 @@ CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb)
212211

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

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

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

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
@@ -737,6 +737,14 @@ bool IsV20Active(const CBlockIndex* pindex)
737737
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_V20, llmq_versionbitscache) == ThresholdState::ACTIVE;
738738
}
739739

740+
bool IsMNRewardReallocationActive(const CBlockIndex* pindex)
741+
{
742+
if (!IsV20Active(pindex)) return false;
743+
744+
LOCK(cs_llmq_vbc);
745+
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR, llmq_versionbitscache) == ThresholdState::ACTIVE;
746+
}
747+
740748
bool IsInstantSendLLMQTypeShared()
741749
{
742750
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
@@ -77,6 +77,7 @@ bool IsV19Active(const CBlockIndex* pindex);
7777
const int V19ActivationHeight(const CBlockIndex* pindex);
7878
const CBlockIndex* V19ActivationIndex(const CBlockIndex* pindex);
7979
bool IsV20Active(const CBlockIndex* pindex);
80+
bool IsMNRewardReallocationActive(const CBlockIndex* pindex);
8081

8182
/// Returns the state of `-llmq-data-recovery`
8283
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
@@ -232,6 +232,13 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
232232
LogPrintf("CreateNewBlock() h[%d] CbTx failed to find best CL. Inserting null CL\n", nHeight);
233233
}
234234
assert(creditPoolDiff != std::nullopt);
235+
236+
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindexPrev);
237+
if (fMNRewardReallocated) {
238+
const CAmount masternodeReward = GetMasternodePayment(nHeight, blockReward, Params().GetConsensus().BRRHeight);
239+
LogPrintf("CreateNewBlock() add MN reward %lld to credit pool\n", masternodeReward);
240+
creditPoolDiff->AddRewardRealloced(masternodeReward);
241+
}
235242
cbTx.assetLockedAmount = creditPoolDiff->GetTotalLocked();
236243
}
237244
}

src/rpc/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
15721572
BuriedForkDescPushBack(softforks, "realloc", consensusParams.BRRHeight);
15731573
BIP9SoftForkDescPushBack(softforks, "v19", consensusParams, Consensus::DEPLOYMENT_V19);
15741574
BIP9SoftForkDescPushBack(softforks, "v20", consensusParams, Consensus::DEPLOYMENT_V20);
1575+
BIP9SoftForkDescPushBack(softforks, "mn_rr", consensusParams, Consensus::DEPLOYMENT_MN_RR);
15751576
BIP9SoftForkDescPushBack(softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
15761577

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

src/versionbitsinfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_B
1919
/*.name =*/"v20",
2020
/*.gbt_force =*/true,
2121
},
22+
{
23+
/*.name =*/"mn_rr",
24+
/*.gbt_force =*/true,
25+
},
2226
};

0 commit comments

Comments
 (0)