Skip to content

Commit 4d1c696

Browse files
committed
[Refactor] Consensus: nStakeMinAge, nStakeMinDepth, nFutureTimeDrift
1 parent e69cee2 commit 4d1c696

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

src/chainparams.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ bool CChainParams::HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t
157157
{
158158
// before stake modifier V2, the age required was 60 * 60 (1 hour).
159159
if (!IsStakeModifierV2(contextHeight))
160-
return (utxoFromBlockTime + nStakeMinAge <= contextTime);
160+
return (utxoFromBlockTime + consensus.nStakeMinAge <= contextTime);
161161

162162
// after stake modifier V2, we require the utxo to be nStakeMinDepth deep in the chain
163-
return (contextHeight - utxoFromBlockHeight >= nStakeMinDepth);
163+
return (contextHeight - utxoFromBlockHeight >= consensus.nStakeMinDepth);
164164
}
165165

166166
int CChainParams::FutureBlockTimeDrift(const int nHeight) const
@@ -196,8 +196,10 @@ class CMainParams : public CChainParams
196196
consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12
197197
consensus.posLimitV1 = ~uint256(0) >> 24;
198198
consensus.posLimitV2 = ~uint256(0) >> 20;
199-
consensus.nMaxMoneyOut = 21000000 * COIN;
200199
consensus.nCoinbaseMaturity = 100;
200+
consensus.nMaxMoneyOut = 21000000 * COIN;
201+
consensus.nStakeMinAge = 60 * 60;
202+
consensus.nStakeMinDepth = 600;
201203
consensus.nTargetTimespan = 40 * 60;
202204
consensus.nTargetTimespanV2 = 30 * 60;
203205
consensus.nTargetSpacing = 1 * 60;
@@ -228,8 +230,6 @@ class CMainParams : public CChainParams
228230
nRejectBlockOutdatedMajority = 10260; // 95%
229231
nToCheckBlockUpgradeMajority = 10800; // Approximate expected amount of blocks in 7 days (1440*7.5)
230232
nMinerThreads = 0;
231-
nStakeMinAge = 60 * 60; // 1 hour
232-
nStakeMinDepth = 600;
233233
nFutureTimeDriftPoW = 7200;
234234
nFutureTimeDriftPoS = 180;
235235
nMasternodeCountDrift = 20;
@@ -345,6 +345,8 @@ class CTestNetParams : public CMainParams
345345
consensus.posLimitV2 = ~uint256(0) >> 20;
346346
consensus.nCoinbaseMaturity = 15;
347347
consensus.nMaxMoneyOut = 43199500 * COIN;
348+
consensus.nStakeMinAge = 60 * 60;
349+
consensus.nStakeMinDepth = 100;
348350
consensus.nTargetTimespan = 40 * 60;
349351
consensus.nTargetTimespanV2 = 30 * 60;
350352
consensus.nTargetSpacing = 1 * 60;
@@ -378,7 +380,6 @@ class CTestNetParams : public CMainParams
378380
nLastPOWBlock = 200;
379381
nPivxBadBlockTime = 1489001494; // Skip nBit validation of Block 259201 per PR #915
380382
nPivxBadBlocknBits = 0x1e0a20bd; // Skip nBit validation of Block 201 per PR #915
381-
nStakeMinDepth = 100;
382383
nMasternodeCountDrift = 4;
383384
nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
384385
nZerocoinStartHeight = 201576;
@@ -469,6 +470,8 @@ class CRegTestParams : public CTestNetParams
469470
consensus.posLimitV2 = ~uint256(0) >> 20;
470471
consensus.nCoinbaseMaturity = 100;
471472
consensus.nMaxMoneyOut = 43199500 * COIN;
473+
consensus.nStakeMinAge = 0;
474+
consensus.nStakeMinDepth = 0;
472475
consensus.nTargetTimespan = 40 * 60;
473476
consensus.nTargetTimespanV2 = 30 * 60;
474477
consensus.nTargetSpacing = 1 * 60;
@@ -500,8 +503,6 @@ class CRegTestParams : public CTestNetParams
500503
nToCheckBlockUpgradeMajority = 1000;
501504
nMinerThreads = 1;
502505
nLastPOWBlock = 250;
503-
nStakeMinAge = 0;
504-
nStakeMinDepth = 0;
505506
nMasternodeCountDrift = 4;
506507
nModifierUpdateBlock = 0;
507508
nZerocoinStartHeight = 300;

src/chainparams.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ class CChainParams
7676
bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; }
7777
/** Make standard checks */
7878
bool RequireStandard() const { return fRequireStandard; }
79-
80-
8179
/** returns the coinstake maturity (min depth required) **/
82-
int COINSTAKE_MIN_AGE() const { return nStakeMinAge; }
83-
int COINSTAKE_MIN_DEPTH() const { return nStakeMinDepth; }
8480
bool HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t contextTime, const int utxoFromBlockHeight, const uint32_t utxoFromBlockTime) const;
8581

8682
/** Time Protocol V2 **/
@@ -174,8 +170,6 @@ class CChainParams
174170
unsigned int nPivxBadBlocknBits;
175171
int nMasternodeCountDrift;
176172
int nMaturity;
177-
int nStakeMinDepth;
178-
int nStakeMinAge;
179173
int nFutureTimeDriftPoW;
180174
int nFutureTimeDriftPoS;
181175

src/consensus/params.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct Params {
2424
uint256 posLimitV2;
2525
int nCoinbaseMaturity;
2626
CAmount nMaxMoneyOut;
27+
int nStakeMinAge;
28+
int nStakeMinDepth;
2729
int64_t nTargetTimespan;
2830
int64_t nTargetTimespanV2;
2931
int64_t nTargetSpacing;

src/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ bool Stake(const CBlockIndex* pindexPrev, CStakeInput* stakeInput, unsigned int
204204

205205
// check required min depth for stake
206206
const int nHeightBlockFrom = pindexFrom->nHeight;
207-
if (nHeight < nHeightBlockFrom + Params().COINSTAKE_MIN_DEPTH())
207+
if (nHeight < nHeightBlockFrom + Params().GetConsensus().nStakeMinDepth)
208208
return error("%s : min depth violation, nHeight=%d, nHeightBlockFrom=%d", __func__, nHeight, nHeightBlockFrom);
209209

210210
const bool fRegTest = Params().IsRegTestNet();

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ bool CWallet::AvailableCoins(
18961896
if (nDepth == 0 && !pcoin->InMempool()) continue;
18971897

18981898
// Check min depth requirement for stake inputs
1899-
if (nCoinType == STAKEABLE_COINS && nDepth <= Params().COINSTAKE_MIN_DEPTH()) continue;
1899+
if (nCoinType == STAKEABLE_COINS && nDepth <= Params().GetConsensus().nStakeMinDepth) continue;
19001900

19011901
for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
19021902
bool found = false;

0 commit comments

Comments
 (0)