Skip to content

Commit 5ea6da9

Browse files
committed
feat: changed activation way of MN reward location reallocation, added functional tests
1 parent 36ab095 commit 5ea6da9

File tree

15 files changed

+87
-39
lines changed

15 files changed

+87
-39
lines changed

src/chainparams.cpp

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

238+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
239+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later
240+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
241+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 4032;
242+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 3226; // 80% of 4032
243+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 2420; // 60% of 4032
244+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
238245

239246
// The best chain should have at least this much work.
240247
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000082094584a23266cbb5f8"); // 1850400
@@ -466,6 +473,14 @@ class CTestNetParams : public CChainParams {
466473
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100
467474
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
468475

476+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
477+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 19999999999; // TODO: To be determined later
478+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
479+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 100;
480+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
481+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
482+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
483+
469484
// The best chain should have at least this much work.
470485
consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000002d68cb6c090031f"); // 864000
471486

@@ -669,6 +684,14 @@ class CDevNetParams : public CChainParams {
669684
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 60; // 60% of 100
670685
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
671686

687+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
688+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 1661990400; // Sep 1st, 2022
689+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
690+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 120;
691+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 80; // 80% of 100
692+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 60; // 60% of 100
693+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
694+
672695
// The best chain should have at least this much work.
673696
consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000000000000000000000");
674697

@@ -933,6 +956,14 @@ class CRegTestParams : public CChainParams {
933956
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nThresholdMin = 288; // 60% of 480
934957
consensus.vDeployments[Consensus::DEPLOYMENT_V20].nFalloffCoeff = 5; // this corresponds to 10 periods
935958

959+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].bit = 10;
960+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nStartTime = 0;
961+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nTimeout = 999999999999ULL;
962+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nWindowSize = 1030;
963+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdStart = 800; // 80% of 1000
964+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nThresholdMin = 600; // 60% of 1000
965+
consensus.vDeployments[Consensus::DEPLOYMENT_MN_RR].nFalloffCoeff = 5; // this corresponds to 10 periods
966+
936967
// The best chain should have at least this much work.
937968
consensus.nMinimumChainWork = uint256S("0x00");
938969

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum DeploymentPos {
2222
DEPLOYMENT_DIP0024, // Deployment of DIP0024 (Quorum Rotation) and decreased governance proposal fee
2323
DEPLOYMENT_V19, // Deployment of Basic BLS, AssetLocks
2424
DEPLOYMENT_V20, // Deployment of EHF, LLMQ Randomness Beacon
25+
DEPLOYMENT_MN_RR, // Deployment of Masternode Reward Location Reallocation
2526
// NOTE: Also add new deployments to VersionBitsDeploymentInfo in versionbits.cpp
2627
MAX_VERSION_BITS_DEPLOYMENTS
2728
};

src/evo/creditpool.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <chain.h>
1111
#include <llmq/utils.h>
1212
#include <logging.h>
13-
#include <spork.h>
1413
#include <util/validation.h>
1514
#include <validation.h>
1615

@@ -246,7 +245,8 @@ CCreditPoolManager::CCreditPoolManager(CEvoDB& _evoDb)
246245

247246
CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams) :
248247
pool(std::move(starter)),
249-
pindex(pindex)
248+
pindex(pindex),
249+
params(consensusParams)
250250
{
251251
assert(pindex);
252252
}
@@ -267,13 +267,13 @@ bool CCreditPoolDiff::setTarget(const CTransaction& tx, TxValidationState& state
267267
targetLocked = cbTx.assetLockedAmount;
268268

269269

270-
if (isIgnoringMNRewardReallocation(*sporkManager)) return true;
270+
if (!llmq::utils::IsMNRewardReallocationActive(pindex)) return true;
271271

272272
CAmount blockReward = 0;
273273
for (const CTxOut& txout : tx.vout) {
274274
blockReward += txout.nValue;
275275
}
276-
masternodeReward = GetMasternodePayment(cbTx.nHeight, blockReward, Params().GetConsensus().BRRHeight);
276+
masternodeReward = GetMasternodePayment(cbTx.nHeight, blockReward, params.BRRHeight);
277277
LogPrintf("CreditPool: set target to %lld with MN reward %lld\n", *targetLocked, masternodeReward);
278278

279279
return true;
@@ -348,11 +348,3 @@ bool CCreditPoolDiff::processTransaction(const CTransaction& tx, TxValidationSta
348348
return state.Invalid(TxValidationResult::TX_CONSENSUS, "failed-procassetlocksinblock");
349349
}
350350
}
351-
352-
bool isIgnoringMNRewardReallocation(const CSporkManager& spork_manager) {
353-
if (Params().NetworkIDString() != CBaseChainParams::REGTEST) return false;
354-
355-
bool ret = spork_manager.IsSporkActive(SPORK_24_IGNORE_MN_REWARD_REALLOCED);
356-
LogPrintf("%s: spork IGNORE_MN_REWARD_REALLOCED value: %d\n", __func__, ret);
357-
return ret;
358-
}

src/evo/creditpool.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
class CBlockIndex;
2323
class TxValidationState;
24-
class CSporkManager;
2524

2625
namespace Consensus
2726
{
@@ -110,6 +109,7 @@ class CCreditPoolDiff {
110109
std::optional<CAmount> targetLocked;
111110

112111
const CBlockIndex *pindex{nullptr};
112+
const Consensus::Params& params;
113113
public:
114114
explicit CCreditPoolDiff(CCreditPool starter, const CBlockIndex *pindex, const Consensus::Params& consensusParams);
115115

@@ -122,7 +122,6 @@ class CCreditPoolDiff {
122122

123123
/**
124124
* This function should be called by miner for initalization of MasterNode reward
125-
*
126125
*/
127126
void addRewardRealloced(const CAmount reward);
128127

@@ -178,8 +177,6 @@ class CCreditPoolManager
178177
CCreditPool constructCreditPool(const CBlockIndex* block_index, CCreditPool prev, const Consensus::Params& consensusParams);
179178
};
180179

181-
bool isIgnoringMNRewardReallocation(const CSporkManager& spork_manager);
182-
183180
extern std::unique_ptr<CCreditPoolManager> creditPoolManager;
184181

185182
#endif

src/evo/specialtxman.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
#include <llmq/commitment.h>
1818
#include <llmq/utils.h>
1919
#include <primitives/block.h>
20-
#include <spork.h>
2120
#include <validation.h>
2221

23-
#include <masternode/payments.h>
2422
bool CheckSpecialTx(const CTransaction& tx, const CBlockIndex* pindexPrev, const CCoinsViewCache& view, const CCreditPool& creditPool, bool check_sigs, TxValidationState& state)
2523
{
2624
AssertLockHeld(cs_main);

src/llmq/utils.cpp

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

681+
bool IsMNRewardReallocationActive(const CBlockIndex* pindex)
682+
{
683+
if (!IsV20Active(pindex)) return false;
684+
685+
LOCK(cs_llmq_vbc);
686+
return VersionBitsState(pindex, Params().GetConsensus(), Consensus::DEPLOYMENT_MN_RR, llmq_versionbitscache) == ThresholdState::ACTIVE;
687+
}
688+
681689
bool IsInstantSendLLMQTypeShared()
682690
{
683691
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
@@ -86,6 +86,7 @@ bool IsDIP0024Active(const CBlockIndex* pindex);
8686
bool IsV19Active(const CBlockIndex* pindex);
8787
const CBlockIndex* V19ActivationIndex(const CBlockIndex* pindex);
8888
bool IsV20Active(const CBlockIndex* pindex);
89+
bool IsMNRewardReallocationActive(const CBlockIndex* pindex);
8990

9091
/// Returns the state of `-llmq-data-recovery`
9192
bool QuorumDataRecoveryEnabled();

src/masternode/payments.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include <masternode/sync.h>
1717
#include <primitives/block.h>
1818
#include <script/standard.h>
19-
#include <spork.h>
2019
#include <tinyformat.h>
2120
#include <util/ranges.h>
2221
#include <util/system.h>
2322
#include <validation.h>
2423
#include <evo/creditpool.h>
24+
2525
#include <string>
2626

2727
CMasternodePayments mnpayments;
@@ -280,8 +280,9 @@ bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, CAmount blockReward,
280280

281281
CAmount masternodeReward = GetMasternodePayment(nBlockHeight, blockReward, Params().GetConsensus().BRRHeight);
282282

283-
bool fV20Active_context = llmq::utils::IsV20Active(::ChainActive().Tip());
284-
if (fV20Active_context && !isIgnoringMNRewardReallocation(*sporkManager)) {
283+
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(::ChainActive().Tip());
284+
285+
if (fMNRewardReallocated) {
285286
LogPrintf("CMasternodePayments::%s -- MN reward %lld reallocated to credit pool\n", __func__, masternodeReward);
286287
voutMasternodePaymentsRet.emplace_back(masternodeReward, CScript() << OP_RETURN);
287288
return true;
@@ -294,12 +295,14 @@ bool CMasternodePayments::GetBlockTxOuts(int nBlockHeight, CAmount blockReward,
294295
}
295296

296297
CAmount operatorReward = 0;
298+
297299
if (dmnPayee->nOperatorReward != 0 && dmnPayee->pdmnState->scriptOperatorPayout != CScript()) {
298300
// This calculation might eventually turn out to result in 0 even if an operator reward percentage is given.
299301
// This will however only happen in a few years when the block rewards drops very low.
300302
operatorReward = (masternodeReward * dmnPayee->nOperatorReward) / 10000;
301303
masternodeReward -= operatorReward;
302304
}
305+
303306
if (masternodeReward > 0) {
304307
voutMasternodePaymentsRet.emplace_back(masternodeReward, dmnPayee->pdmnState->scriptPayout);
305308
}

src/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(CChainState& chai
233233
}
234234
assert(creditPoolDiff);
235235

236-
if (!isIgnoringMNRewardReallocation(spork_manager)) {
236+
bool fMNRewardReallocated = llmq::utils::IsMNRewardReallocationActive(pindexPrev);
237+
if (fMNRewardReallocated) {
237238
if (!CMasternodePayments::GetMasternodeTxOuts(nHeight, blockReward, pblocktemplate->voutMasternodePayments)) {
238239
LogPrint(BCLog::MNPAYMENTS, "%s -- no masternode to pay (MN list probably empty)\n", __func__);
239240
}
240241
for (const auto& txout : pblocktemplate->voutMasternodePayments) {
241-
// subtract MN payment from miner reward
242242
LogPrintf("CreateNewBlock() add MN reward %lld to credit pool\n", txout.nValue);
243243
creditPoolDiff->addRewardRealloced(txout.nValue);
244244
}

src/spork.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ enum SporkId : int32_t {
3838
SPORK_19_CHAINLOCKS_ENABLED = 10018,
3939
SPORK_21_QUORUM_ALL_CONNECTED = 10020,
4040
SPORK_23_QUORUM_POSE = 10022,
41-
SPORK_24_IGNORE_MN_REWARD_REALLOCED = 10023,
4241

4342
SPORK_INVALID = -1,
4443
};
@@ -64,15 +63,14 @@ struct CSporkDef
6463
};
6564

6665
#define MAKE_SPORK_DEF(name, defaultValue) CSporkDef{name, defaultValue, #name}
67-
[[maybe_unused]] static constexpr std::array<CSporkDef, 8> sporkDefs = {
66+
[[maybe_unused]] static constexpr std::array<CSporkDef, 7> sporkDefs = {
6867
MAKE_SPORK_DEF(SPORK_2_INSTANTSEND_ENABLED, 4070908800ULL), // OFF
6968
MAKE_SPORK_DEF(SPORK_3_INSTANTSEND_BLOCK_FILTERING, 4070908800ULL), // OFF
7069
MAKE_SPORK_DEF(SPORK_9_SUPERBLOCKS_ENABLED, 4070908800ULL), // OFF
7170
MAKE_SPORK_DEF(SPORK_17_QUORUM_DKG_ENABLED, 4070908800ULL), // OFF
7271
MAKE_SPORK_DEF(SPORK_19_CHAINLOCKS_ENABLED, 4070908800ULL), // OFF
7372
MAKE_SPORK_DEF(SPORK_21_QUORUM_ALL_CONNECTED, 4070908800ULL), // OFF
7473
MAKE_SPORK_DEF(SPORK_23_QUORUM_POSE, 4070908800ULL), // OFF
75-
MAKE_SPORK_DEF(SPORK_24_IGNORE_MN_REWARD_REALLOCED, 4070908800ULL), // OFF
7674
};
7775
#undef MAKE_SPORK_DEF
7876
extern std::unique_ptr<CSporkManager> sporkManager;

0 commit comments

Comments
 (0)