Skip to content

Commit e8d9aab

Browse files
committed
Move many hardcoded mainnet/testnet magic numbers to consensus part of chainparams,
get rid of most `if(Params().NetworkIDString() == CBaseChainParams::MAIN)` and alike to unify formulas. Further improvements will require testnet restart (see TODO notes in changed code) so I'm keeping few things as they are till then.
1 parent 8ad088a commit e8d9aab

File tree

9 files changed

+116
-114
lines changed

9 files changed

+116
-114
lines changed

src/chainparams.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class CMainParams : public CChainParams {
7373
CMainParams() {
7474
strNetworkID = "main";
7575
consensus.nSubsidyHalvingInterval = 210240;
76+
consensus.nMasternodePaymentsStartBlock = 100000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
77+
consensus.nMasternodePaymentsIncreaseBlock = 158000;
78+
consensus.nMasternodePaymentsIncreasePeriod = 576*30;
79+
consensus.nBudgetPaymentsStartBlock = 328008;
80+
consensus.nBudgetPaymentsCycleBlocks = 16616;
81+
consensus.nBudgetPaymentsWindowBlocks = 100;
82+
consensus.nBudgetProposalEstablishingTime = 60*60*24;
7683
consensus.nMajorityEnforceBlockUpgrade = 750;
7784
consensus.nMajorityRejectBlockOutdated = 950;
7885
consensus.nMajorityWindow = 1000;
@@ -132,7 +139,6 @@ class CMainParams : public CChainParams {
132139
strSporkKey = "04549ac134f694c0243f503e8c8a9a986f5de6610049c40b07816809b0d1d06a21b07be27b9bb555931773f62ba6cf35a25fd52f694d4e1106ccd237a7bb899fdd";
133140
strMasternodePaymentsPubKey = "04549ac134f694c0243f503e8c8a9a986f5de6610049c40b07816809b0d1d06a21b07be27b9bb555931773f62ba6cf35a25fd52f694d4e1106ccd237a7bb899fdd";
134141
strDarksendPoolDummyAddress = "Xq19GqFvajRrEdDHYRKGYjTsQfpV5jyipF";
135-
nStartMasternodePayments = 1403728576; //Wed, 25 Jun 2014 20:36:16 GMT
136142

137143
checkpointData = (CCheckpointData) {
138144
boost::assign::map_list_of
@@ -177,6 +183,13 @@ class CTestNetParams : public CChainParams {
177183
vAlertPubKey = ParseHex("04517d8a699cb43d3938d7b24faaff7cda448ca4ea267723ba614784de661949bf632d6304316b244646dea079735b9a6fc4af804efb4752075b9fe2245e14e412");
178184
nDefaultPort = 19999;
179185
consensus.nSubsidyHalvingInterval = 210240;
186+
consensus.nMasternodePaymentsStartBlock = 10000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
187+
consensus.nMasternodePaymentsIncreaseBlock = 46000;
188+
consensus.nMasternodePaymentsIncreasePeriod = 576;
189+
consensus.nBudgetPaymentsStartBlock = 78476;
190+
consensus.nBudgetPaymentsCycleBlocks = 50;
191+
consensus.nBudgetPaymentsWindowBlocks = 10;
192+
consensus.nBudgetProposalEstablishingTime = 60*20;
180193
consensus.nMajorityEnforceBlockUpgrade = 51;
181194
consensus.nMajorityRejectBlockOutdated = 75;
182195
consensus.nMajorityWindow = 100;
@@ -234,7 +247,6 @@ class CTestNetParams : public CChainParams {
234247
strSporkKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
235248
strMasternodePaymentsPubKey = "046f78dcf911fbd61910136f7f0f8d90578f68d0b3ac973b5040fb7afb501b5939f39b108b0569dca71488f5bbf498d92e4d1194f6f941307ffd95f75e76869f0e";
236249
strDarksendPoolDummyAddress = "y1EZuxhhNMAUofTBEeLqGE1bJrpC2TWRNp";
237-
nStartMasternodePayments = 1420837558; //Fri, 09 Jan 2015 21:05:58 GMT
238250
checkpointData = (CCheckpointData) {
239251
boost::assign::map_list_of
240252
( 261, uint256S("00000c26026d0815a7e2ce4fa270775f61403c040647ff2c3091f99e894a4618"))
@@ -257,6 +269,13 @@ class CRegTestParams : public CChainParams {
257269
CRegTestParams() {
258270
strNetworkID = "regtest";
259271
consensus.nSubsidyHalvingInterval = 150;
272+
consensus.nMasternodePaymentsStartBlock = 40;
273+
consensus.nMasternodePaymentsIncreaseBlock = 50;
274+
consensus.nMasternodePaymentsIncreasePeriod = 100;
275+
consensus.nBudgetPaymentsStartBlock = 1000;
276+
consensus.nBudgetPaymentsCycleBlocks = 50;
277+
consensus.nBudgetPaymentsWindowBlocks = 100;
278+
consensus.nBudgetProposalEstablishingTime = 60*20;
260279
consensus.nMajorityEnforceBlockUpgrade = 750;
261280
consensus.nMajorityRejectBlockOutdated = 950;
262281
consensus.nMajorityWindow = 1000;

src/chainparams.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class CChainParams
8181
std::string SporkKey() const { return strSporkKey; }
8282
std::string DarksendPoolDummyAddress() const { return strDarksendPoolDummyAddress; }
8383
std::string MasternodePaymentPubKey() const { return strMasternodePaymentsPubKey; }
84-
int64_t StartMasternodePayments() const { return nStartMasternodePayments; }
8584
protected:
8685
CChainParams() {}
8786

@@ -107,7 +106,6 @@ class CChainParams
107106
std::string strSporkKey;
108107
std::string strMasternodePaymentsPubKey;
109108
std::string strDarksendPoolDummyAddress;
110-
int64_t nStartMasternodePayments;
111109
};
112110

113111
/**

src/consensus/params.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace Consensus {
1515
struct Params {
1616
uint256 hashGenesisBlock;
1717
int nSubsidyHalvingInterval;
18+
int nMasternodePaymentsStartBlock;
19+
int nMasternodePaymentsIncreaseBlock;
20+
int nMasternodePaymentsIncreasePeriod; // in blocks
21+
int nBudgetPaymentsStartBlock;
22+
int nBudgetPaymentsCycleBlocks;
23+
int nBudgetPaymentsWindowBlocks;
24+
int nBudgetProposalEstablishingTime; // in seconds
1825
/** Used to check majorities for block version upgrade */
1926
int nMajorityEnforceBlockUpgrade;
2027
int nMajorityRejectBlockOutdated;

src/main.cpp

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,61 +1527,55 @@ CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params&
15271527
// LogPrintf("height %u diff %4.2f reward %i \n", nPrevHeight, dDiff, nSubsidy);
15281528
nSubsidy *= COIN;
15291529

1530+
// TODO: Remove this to further unify logic among mainnet/testnet/whatevernet,
1531+
// use single formula instead (the one that is for current mainnet).
1532+
// Probably a good idea to use a significally lower consensusParams.nSubsidyHalvingInterval
1533+
// for testnet (like 10 times for example) to see the effect of halving there faster.
1534+
// Will require testnet restart.
15301535
if(Params().NetworkIDString() == CBaseChainParams::TESTNET){
15311536
for(int i = 46200; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14;
15321537
} else {
15331538
// yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050.
15341539
for(int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14;
15351540
}
15361541

1537-
/*
1538-
1539-
Hard fork will activate on block 328008, reducing the block reward by 10 extra percent (allowing budget super-blocks)
1540-
1541-
*/
1542+
// Hard fork to reduce the block reward by 10 extra percent (allowing budget super-blocks)
1543+
if(nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) nSubsidy -= nSubsidy/10;
15421544

1543-
if(Params().NetworkIDString() == CBaseChainParams::TESTNET){
1544-
if(nPrevHeight > 77900+576) nSubsidy -= nSubsidy/10;
1545-
} else {
1546-
if(nPrevHeight > 309759+(553*33)) nSubsidy -= nSubsidy/10; // 328008 - 10.0% - 2015-08-30
1547-
}
1548-
15491545
return nSubsidy;
15501546
}
15511547

15521548
CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
15531549
{
15541550
CAmount ret = blockValue/5; // start at 20%
15551551

1556-
if(Params().NetworkIDString() == CBaseChainParams::TESTNET) {
1557-
if(nHeight > 46000) ret += blockValue / 20; //25% - 2014-10-07
1558-
if(nHeight > 46000+((576*1)*1)) ret += blockValue / 20; //30% - 2014-10-08
1559-
if(nHeight > 46000+((576*1)*2)) ret += blockValue / 20; //35% - 2014-10-09
1560-
if(nHeight > 46000+((576*1)*3)) ret += blockValue / 20; //40% - 2014-10-10
1561-
if(nHeight > 46000+((576*1)*4)) ret += blockValue / 20; //45% - 2014-10-11
1562-
if(nHeight > 46000+((576*1)*5)) ret += blockValue / 20; //50% - 2014-10-12
1563-
if(nHeight > 46000+((576*1)*6)) ret += blockValue / 20; //55% - 2014-10-13
1564-
if(nHeight > 46000+((576*1)*7)) ret += blockValue / 20; //60% - 2014-10-14
1565-
}
1566-
1567-
if(nHeight > 158000) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
1568-
if(nHeight > 158000+((576*30)* 1)) ret += blockValue / 20; // 175280 - 30.0% - 2014-11-25
1569-
if(nHeight > 158000+((576*30)* 2)) ret += blockValue / 20; // 192560 - 35.0% - 2014-12-26
1570-
if(nHeight > 158000+((576*30)* 3)) ret += blockValue / 40; // 209840 - 37.5% - 2015-01-26
1571-
if(nHeight > 158000+((576*30)* 4)) ret += blockValue / 40; // 227120 - 40.0% - 2015-02-27
1572-
if(nHeight > 158000+((576*30)* 5)) ret += blockValue / 40; // 244400 - 42.5% - 2015-03-30
1573-
if(nHeight > 158000+((576*30)* 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
1574-
if(nHeight > 158000+((576*30)* 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
1575-
if(nHeight > 158000+((576*30)* 9)) ret += blockValue / 40; // 313520 - 50.0% - 2015-08-03
1576-
1577-
/*
1578-
Hard for will activate on block 348080 separating the two networks (v11 and earier and v12)
1552+
int nMNPIBlock = Params().GetConsensus().nMasternodePaymentsIncreaseBlock;
1553+
int nMNPIPeriod = Params().GetConsensus().nMasternodePaymentsIncreasePeriod;
15791554

1580-
if(nHeight > 158000+((576*30)*11)) ret += blockValue / 40; // 348080 - 52.5% - 2015-10-05
1581-
if(nHeight > 158000+((576*30)*13)) ret += blockValue / 40; // 382640 - 55.0% - 2015-12-07
1582-
if(nHeight > 158000+((576*30)*15)) ret += blockValue / 40; // 417200 - 57.5% - 2016-02-08
1583-
if(nHeight > 158000+((576*30)*17)) ret += blockValue / 40; // 451760 - 60.0% - 2016-04-11
1584-
*/
1555+
// TODO: Remove this to further unify logic among mainnet/testnet/whatevernet,
1556+
// use single formula instead (the one that is for current mainnet).
1557+
// Will require testnet restart.
1558+
if(Params().NetworkIDString() == CBaseChainParams::TESTNET) {
1559+
if(nHeight > nMNPIBlock) ret += blockValue / 20; //25% - 2014-10-07
1560+
if(nHeight > nMNPIBlock+(nMNPIPeriod*1)) ret += blockValue / 20; //30% - 2014-10-08
1561+
if(nHeight > nMNPIBlock+(nMNPIPeriod*2)) ret += blockValue / 20; //35% - 2014-10-09
1562+
if(nHeight > nMNPIBlock+(nMNPIPeriod*3)) ret += blockValue / 20; //40% - 2014-10-10
1563+
if(nHeight > nMNPIBlock+(nMNPIPeriod*4)) ret += blockValue / 20; //45% - 2014-10-11
1564+
if(nHeight > nMNPIBlock+(nMNPIPeriod*5)) ret += blockValue / 20; //50% - 2014-10-12
1565+
if(nHeight > nMNPIBlock+(nMNPIPeriod*6)) ret += blockValue / 20; //55% - 2014-10-13
1566+
if(nHeight > nMNPIBlock+(nMNPIPeriod*7)) ret += blockValue / 20; //60% - 2014-10-14
1567+
}
1568+
1569+
// mainnet:
1570+
if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
1571+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 1)) ret += blockValue / 20; // 175280 - 30.0% - 2014-11-25
1572+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 2)) ret += blockValue / 20; // 192560 - 35.0% - 2014-12-26
1573+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 3)) ret += blockValue / 40; // 209840 - 37.5% - 2015-01-26
1574+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 4)) ret += blockValue / 40; // 227120 - 40.0% - 2015-02-27
1575+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 5)) ret += blockValue / 40; // 244400 - 42.5% - 2015-03-30
1576+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
1577+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
1578+
if(nHeight > nMNPIBlock+(nMNPIPeriod* 9)) ret += blockValue / 40; // 313520 - 50.0% - 2015-08-03
15851579

15861580
return ret;
15871581
}
@@ -3298,25 +3292,19 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
32983292
const Consensus::Params& consensusParams = Params().GetConsensus();
32993293
int nHeight = pindexPrev->nHeight + 1;
33003294
// Check proof of work
3301-
if(Params().NetworkIDString() == CBaseChainParams::TESTNET) {
3295+
if(Params().NetworkIDString() == CBaseChainParams::MAIN && nHeight <= 68589){
3296+
// architecture issues with DGW v1 and v2)
3297+
unsigned int nBitsNext = GetNextWorkRequired(pindexPrev, &block, consensusParams);
3298+
double n1 = ConvertBitsToDouble(block.nBits);
3299+
double n2 = ConvertBitsToDouble(nBitsNext);
3300+
3301+
if (abs(n1-n2) > n1*0.5)
3302+
return state.DoS(100, error("%s : incorrect proof of work (DGW pre-fork) - %f %f %f at %d", __func__, abs(n1-n2), n1, n2, nHeight),
3303+
REJECT_INVALID, "bad-diffbits");
3304+
} else {
33023305
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
33033306
return state.DoS(100, error("%s : incorrect proof of work at %d", __func__, nHeight),
3304-
REJECT_INVALID, "bad-diffbits");
3305-
} else {
3306-
// Check proof of work (Here for the architecture issues with DGW v1 and v2)
3307-
if(nHeight <= 68589){
3308-
unsigned int nBitsNext = GetNextWorkRequired(pindexPrev, &block, consensusParams);
3309-
double n1 = ConvertBitsToDouble(block.nBits);
3310-
double n2 = ConvertBitsToDouble(nBitsNext);
3311-
3312-
if (abs(n1-n2) > n1*0.5)
3313-
return state.DoS(100, error("%s : incorrect proof of work (DGW pre-fork) - %f %f %f at %d", __func__, abs(n1-n2), n1, n2, nHeight),
3314-
REJECT_INVALID, "bad-diffbits");
3315-
} else {
3316-
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
3317-
return state.DoS(100, error("%s : incorrect proof of work at %d", __func__, nHeight),
3318-
REJECT_INVALID, "bad-diffbits");
3319-
}
3307+
REJECT_INVALID, "bad-diffbits");
33203308
}
33213309

33223310
// Check timestamp against prev

0 commit comments

Comments
 (0)