Skip to content

Commit a281dee

Browse files
committed
[Refactor] Consensus: remove unneeded getters. Rename BIP65Height
1 parent 284271c commit a281dee

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

src/chainparams.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class CMainParams : public CChainParams
192192
networkID = CBaseChainParams::MAIN;
193193
strNetworkID = "main";
194194

195-
consensus.BIP65Height = 1808634; // 82629b7a9978f5c7ea3f70a12db92633a7d2e436711500db28b97efd48b1e527
196195
consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12
197196
consensus.posLimitV1 = ~uint256(0) >> 24;
198197
consensus.posLimitV2 = ~uint256(0) >> 20;
@@ -202,6 +201,9 @@ class CMainParams : public CChainParams
202201
consensus.fPowAllowMinDifficultyBlocks = false;
203202
consensus.fPowNoRetargeting = false;
204203

204+
// height based activations
205+
consensus.height_start_BIP65 = 1808634; // 82629b7a9978f5c7ea3f70a12db92633a7d2e436711500db28b97efd48b1e527
206+
205207
// The best chain should have at least this much work.
206208
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
207209

@@ -346,7 +348,6 @@ class CTestNetParams : public CMainParams
346348
networkID = CBaseChainParams::TESTNET;
347349
strNetworkID = "test";
348350

349-
consensus.BIP65Height = 851019;
350351
consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12
351352
consensus.posLimitV1 = ~uint256(0) >> 24;
352353
consensus.posLimitV2 = ~uint256(0) >> 20;
@@ -356,6 +357,9 @@ class CTestNetParams : public CMainParams
356357
consensus.fPowAllowMinDifficultyBlocks = false;
357358
consensus.fPowNoRetargeting = false;
358359

360+
// height based activations
361+
consensus.height_start_BIP65 = 851019;
362+
359363
// The best chain should have at least this much work.
360364
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
361365

@@ -473,7 +477,6 @@ class CRegTestParams : public CTestNetParams
473477
networkID = CBaseChainParams::REGTEST;
474478
strNetworkID = "regtest";
475479

476-
consensus.BIP65Height = 851019; // Not defined for regtest. Inherit TestNet value.
477480
consensus.powLimit = ~uint256(0) >> 20; // PIVX starting difficulty is 1 / 2^12
478481
consensus.posLimitV1 = ~uint256(0) >> 24;
479482
consensus.posLimitV2 = ~uint256(0) >> 20;
@@ -483,6 +486,9 @@ class CRegTestParams : public CTestNetParams
483486
consensus.fPowAllowMinDifficultyBlocks = true;
484487
consensus.fPowNoRetargeting = true;
485488

489+
// height based activations
490+
consensus.height_start_BIP65 = 851019; // Not defined for regtest. Inherit TestNet value.
491+
486492
// The best chain should have at least this much work.
487493
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000000000000000000000000");
488494

src/consensus/params.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@ namespace Consensus {
1717
*/
1818
struct Params {
1919
uint256 hashGenesisBlock;
20-
/** Block height at which BIP65 becomes active */
21-
int BIP65Height;
22-
int nCoinbaseMaturity;
23-
24-
// TODO: Implement the following parameters
2520
uint256 powLimit;
2621
uint256 posLimitV1;
2722
uint256 posLimitV2;
23+
int nCoinbaseMaturity;
24+
25+
// Height based activations
26+
int height_start_BIP65;
27+
28+
// TODO: Implement the following parameters
2829
bool fPowAllowMinDifficultyBlocks;
2930
bool fPowNoRetargeting;
3031
int64_t nTargetSpacing;
3132
int64_t nTargetTimespan;
3233

33-
int CoinbaseMaturity() const { return nCoinbaseMaturity; }
34-
3534
// TODO: Implement the following methods
3635
int64_t DifficultyAdjustmentInterval() const { return nTargetTimespan / nTargetSpacing; }
3736
uint256 ProofOfStakeLimit(const bool fV2) const { return fV2 ? posLimitV2 : posLimitV1; }

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa
13471347
__func__, hash.ToString(), nFees, ::minRelayTxFee.GetFee(nSize) * 10000);
13481348
}
13491349

1350-
bool fCLTVIsActivated = (chainHeight >= Params().GetConsensus().BIP65Height);
1350+
bool fCLTVIsActivated = (chainHeight >= Params().GetConsensus().height_start_BIP65);
13511351

13521352
// Check against previous transactions
13531353
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -1553,7 +1553,7 @@ bool AcceptableInputs(CTxMemPool& pool, CValidationState& state, const CTransact
15531553
hash.ToString(),
15541554
nFees, ::minRelayTxFee.GetFee(nSize) * 10000);
15551555

1556-
bool fCLTVIsActivated = chainActive.Tip()->nHeight >= Params().GetConsensus().BIP65Height;
1556+
bool fCLTVIsActivated = chainActive.Tip()->nHeight >= Params().GetConsensus().height_start_BIP65;
15571557

15581558
// Check against previous transactions
15591559
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -2340,7 +2340,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState& state, const CCoinsVi
23402340

23412341
// If prev is coinbase, check that it's matured
23422342
if (coins->IsCoinBase() || coins->IsCoinStake()) {
2343-
if (nSpendHeight - coins->nHeight < Params().GetConsensus().CoinbaseMaturity())
2343+
if (nSpendHeight - coins->nHeight < Params().GetConsensus().nCoinbaseMaturity)
23442344
return state.Invalid(
23452345
error("CheckInputs() : tried to spend coinbase at depth %d, coinstake=%d", nSpendHeight - coins->nHeight, coins->IsCoinStake()),
23462346
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase");
@@ -2939,7 +2939,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
29392939
// If scripts won't be checked anyways, don't bother seeing if CLTV is activated
29402940
bool fCLTVIsActivated = false;
29412941
if (fScriptChecks && pindex->pprev) {
2942-
fCLTVIsActivated = pindex->pprev->nHeight >= Params().GetConsensus().BIP65Height;
2942+
fCLTVIsActivated = pindex->pprev->nHeight >= Params().GetConsensus().height_start_BIP65;
29432943
}
29442944

29452945
CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : nullptr);

src/qt/transactiondesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ QString TransactionDesc::toHTML(CWallet* wallet, CWalletTx& wtx, TransactionReco
267267
}
268268

269269
if (wtx.IsCoinBase()) {
270-
//quint32 numBlocksToMaturity = Params().GetConsensus().CoinbaseMaturity() + 1;
270+
//quint32 numBlocksToMaturity = Params().GetConsensus().nCoinbaseMaturity + 1;
271271
//strHTML += "<br>" + tr("Generated coins must mature %1 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(numBlocksToMaturity)) + "<br>";
272272
}
273273

src/qt/transactionrecord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void TransactionRecord::updateStatus(const CWalletTx& wtx)
463463
int depth = 0;
464464
bool isTrusted = wtx.IsTrusted(depth, fConflicted);
465465
const bool isOffline = (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0);
466-
int nBlocksToMaturity = (wtx.IsCoinBase() || wtx.IsCoinStake()) ? std::max(0, (Params().GetConsensus().CoinbaseMaturity() + 1) - depth) : 0;
466+
int nBlocksToMaturity = (wtx.IsCoinBase() || wtx.IsCoinStake()) ? std::max(0, (Params().GetConsensus().nCoinbaseMaturity + 1) - depth) : 0;
467467

468468
status.countsForBalance = isTrusted && !(nBlocksToMaturity > 0);
469469
status.cur_num_blocks = chainHeight;

src/txmempool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ void CTxMemPool::removeCoinbaseSpends(const CCoinsViewCache* pcoins, unsigned in
478478
continue;
479479
const CCoins* coins = pcoins->AccessCoins(txin.prevout.hash);
480480
if (fSanityCheck) assert(coins);
481-
if (!coins || ((coins->IsCoinBase() || coins->IsCoinStake()) && nMemPoolHeight - coins->nHeight < (unsigned)Params().GetConsensus().CoinbaseMaturity())) {
481+
if (!coins || ((coins->IsCoinBase() || coins->IsCoinStake()) && nMemPoolHeight - coins->nHeight < (unsigned)Params().GetConsensus().nCoinbaseMaturity)) {
482482
transactionsToRemove.push_back(tx);
483483
break;
484484
}

src/wallet/wallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,7 +3426,7 @@ void CWallet::AutoCombineDust()
34263426
if (!out.fSpendable)
34273427
continue;
34283428
//no coins should get this far if they dont have proper maturity, this is double checking
3429-
if (out.tx->IsCoinStake() && out.tx->GetDepthInMainChain() < Params().GetConsensus().CoinbaseMaturity() + 1)
3429+
if (out.tx->IsCoinStake() && out.tx->GetDepthInMainChain() < Params().GetConsensus().nCoinbaseMaturity + 1)
34303430
continue;
34313431

34323432
// no p2cs accepted, those coins are "locked"
@@ -3521,7 +3521,7 @@ bool CWallet::MultiSend()
35213521
for (const COutput& out : vCoins) {
35223522

35233523
//need output with precise confirm count - this is how we identify which is the output to send
3524-
if (out.tx->GetDepthInMainChain() != Params().GetConsensus().CoinbaseMaturity() + 1)
3524+
if (out.tx->GetDepthInMainChain() != Params().GetConsensus().nCoinbaseMaturity + 1)
35253525
continue;
35263526

35273527
COutPoint outpoint(out.tx->GetHash(), out.i);
@@ -3707,7 +3707,7 @@ int CMerkleTx::GetBlocksToMaturity() const
37073707
LOCK(cs_main);
37083708
if (!(IsCoinBase() || IsCoinStake()))
37093709
return 0;
3710-
return std::max(0, (Params().GetConsensus().CoinbaseMaturity() + 1) - GetDepthInMainChain());
3710+
return std::max(0, (Params().GetConsensus().nCoinbaseMaturity + 1) - GetDepthInMainChain());
37113711
}
37123712

37133713
bool CMerkleTx::IsInMainChain() const
@@ -3719,7 +3719,7 @@ bool CMerkleTx::IsInMainChainImmature() const
37193719
{
37203720
if (!IsCoinBase() && !IsCoinStake()) return false;
37213721
const int depth = GetDepthInMainChain(false);
3722-
return (depth > 0 && depth <= Params().GetConsensus().CoinbaseMaturity());
3722+
return (depth > 0 && depth <= Params().GetConsensus().nCoinbaseMaturity);
37233723
}
37243724

37253725

0 commit comments

Comments
 (0)