Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
401a986
[Consensus] Placeholder block height for modifier V2 enforcement
random-zebra Aug 13, 2019
1e4c864
[Cleanup] Clean error messages in CheckBlock
random-zebra Aug 13, 2019
f73a27f
[Core] Do not check block if it's not the one needed
random-zebra Aug 13, 2019
3c1fd7a
[PoS] Stake Modifier V2
random-zebra Aug 13, 2019
3b97fc0
[PoS] Cleaning GetStakeModifierSelectionInterval() constant method +
furszy Aug 13, 2019
e9c07d0
[Consensus] V2 modifier protocol change, two new fields in chainparam…
furszy Aug 15, 2019
a48a7a5
[Trivial] Compiler warning, uint_32 compared against int.
furszy Aug 15, 2019
74d85c2
[Refactor][PoS] Do not calculate the prevBlock medianTimePast on ever…
furszy Aug 15, 2019
01ed69a
[PoS] Remove extra nTime check in Stake()
random-zebra Aug 16, 2019
d805952
[Wallet] SelectStakeCoins using block time and fix GetBlocksToMaturity
random-zebra Aug 16, 2019
117f815
[PoS] New logic for stake input maturity
random-zebra Aug 16, 2019
eab9944
version bumped
furszy Aug 16, 2019
d94931f
[Trivial] Add logs to CheckKernelHash
random-zebra Aug 17, 2019
0d31ac2
[Wallet] HasMintableCoins, don't call GetAdjustedTime on every cycle …
furszy Aug 17, 2019
b8c59ae
[PoS] CheckStakeKernelHash, was checking the previous block instead of
furszy Aug 17, 2019
6297e77
[Core] Introduce Blocks version 6
random-zebra Aug 18, 2019
4c24934
[PoS] read/write block index modifier based on height and not block v…
furszy Aug 19, 2019
843dc56
[PoS] Allign ComputeStakeModifier (v2) to nHeight logic
random-zebra Aug 19, 2019
ffb0dd5
[Trivial] logging, removing none required jump lines.
furszy Aug 19, 2019
41ccf6b
[PoS][Wallet] CreateCoinStake, if the block is from the future then s…
furszy Aug 19, 2019
4d5cc97
[Wallet] Staking, unreacheable code removed..
furszy Aug 19, 2019
820e08c
[PoS][RPC][Refactor] GetHashProofOfStake and initStakeInput methods c…
furszy Aug 21, 2019
81446bb
[PoS][RPC] getblock command, adding more information about the coin s…
furszy Aug 21, 2019
beaba47
[RPC] getblock, validate that PoS blocks to return the coin stake data.
furszy Aug 21, 2019
8c7522b
[PoS] Compute old modifier, invalid integer division removal plus ext…
furszy Aug 22, 2019
f8777c6
[Refactor] Add future block time drift to chainparams
random-zebra Aug 20, 2019
d3db3e6
[PoS] Stake(): Add check for staked blocks in the future
random-zebra Aug 21, 2019
6c69cfe
[PoS] * GetKernelStakeModifier, look for the next block in the mapBlo…
furszy Aug 22, 2019
6a33fff
[Mempool] // As zero fee transactions are not going to be accepted in…
furszy Aug 14, 2019
a74f6cf
[GUI] sendCoinsdialog, removing zero tx fee checkbox and label.
furszy Aug 17, 2019
85fa96e
[Consensus] New modifier enforcement height set.
furszy Aug 24, 2019
2835111
Don't shadow global fDebug
Fuzzbawls Aug 24, 2019
dddca50
Use better JSON key names in block coinstake output
Fuzzbawls Aug 24, 2019
c212587
[PoS] fix regtest nBlockStakeModifierlV2 and cbase maturity
random-zebra Aug 25, 2019
b1416f5
[Tests] fix blocks/maturity fakestake_accepted
random-zebra Aug 25, 2019
d085ed0
[Consensus] Fix old block version check (including v.6)
random-zebra Aug 25, 2019
6b6ef32
Don't load old stake modifier from disk after changeover height
Fuzzbawls Aug 25, 2019
bf16514
[Consensus] New modifier enforcement height changed for mainnet
random-zebra Aug 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef BITCOIN_CHAIN_H
#define BITCOIN_CHAIN_H

#include "chainparams.h"
#include "pow.h"
#include "primitives/block.h"
#include "tinyformat.h"
Expand Down Expand Up @@ -155,6 +156,7 @@ class CBlockIndex
BLOCK_STAKE_MODIFIER = (1 << 2), // regenerated stake modifier
};


// proof-of-stake specific fields
uint256 GetBlockTrust() const;
uint64_t nStakeModifier; // hash modifier for proof-of-stake
Expand All @@ -164,6 +166,7 @@ class CBlockIndex
uint256 hashProofOfStake;
int64_t nMint;
int64_t nMoneySupply;
uint256 nStakeModifierV2;

//! block header
int nVersion;
Expand Down Expand Up @@ -199,6 +202,7 @@ class CBlockIndex
nMoneySupply = 0;
nFlags = 0;
nStakeModifier = 0;
nStakeModifierV2 = uint256();
Comment thread
random-zebra marked this conversation as resolved.
Outdated
nStakeModifierChecksum = 0;
prevoutStake.SetNull();
nStakeTime = 0;
Expand Down Expand Up @@ -233,22 +237,10 @@ class CBlockIndex
if(block.nVersion > 3)
nAccumulatorCheckpoint = block.nAccumulatorCheckpoint;

//Proof of Stake
bnChainTrust = uint256();
nMint = 0;
nMoneySupply = 0;
nFlags = 0;
nStakeModifier = 0;
nStakeModifierChecksum = 0;
hashProofOfStake = uint256();

if (block.IsProofOfStake()) {
SetProofOfStake();
prevoutStake = block.vtx[1].vin[0].prevout;
nStakeTime = block.nTime;
} else {
prevoutStake.SetNull();
nStakeTime = 0;
}
}

Expand Down Expand Up @@ -477,7 +469,14 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(nMint);
READWRITE(nMoneySupply);
READWRITE(nFlags);
READWRITE(nStakeModifier);

// v1/v2 modifier selection.
if (!Params().IsStakeModifierV2(nHeight)) {
READWRITE(nStakeModifier);
} else {
READWRITE(nStakeModifierV2);
}

if (IsProofOfStake()) {
READWRITE(prevoutStake);
READWRITE(nStakeTime);
Expand Down
32 changes: 22 additions & 10 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <assert.h>

#include <boost/assign/list_of.hpp>
#include <limits>


struct SeedSpec6 {
Expand Down Expand Up @@ -116,6 +117,17 @@ libzerocoin::ZerocoinParams* CChainParams::Zerocoin_Params(bool useModulusV1) co
return &ZCParamsDec;
}

bool CChainParams::HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t contextTime,
const int utxoFromBlockHeight, const uint32_t utxoFromBlockTime) const
{
// before stake modifier V2, the age required was 60 * 60 (1 hour) / not required on regtest
if (!IsStakeModifierV2(contextHeight))
return (NetworkID() == CBaseChainParams::REGTEST || (utxoFromBlockTime + 3600 <= contextTime));

// after stake modifier V2, we require the utxo to be nStakeMinDepth deep in the chain
return (contextHeight - utxoFromBlockHeight >= nStakeMinDepth);
}

class CMainParams : public CChainParams
{
public:
Expand All @@ -141,10 +153,11 @@ class CMainParams : public CChainParams
nRejectBlockOutdatedMajority = 10260; // 95%
nToCheckBlockUpgradeMajority = 10800; // Approximate expected amount of blocks in 7 days (1440*7.5)
nMinerThreads = 0;
nTargetTimespan = 1 * 60; // PIVX: 1 minute
nTargetSpacing = 1 * 60; // PIVX: 1 minute
nTargetSpacing = 1 * 60; // 1 minute
nMaturity = 100;
nStakeMinAge = 60 * 60; // PIVX: 1 hour
nStakeMinDepth = 600;
nFutureTimeDriftPoW = 7200;
nFutureTimeDriftPoS = 180;
nMasternodeCountDrift = 20;
nMaxMoneyOut = 21000000 * COIN;

Expand All @@ -165,7 +178,7 @@ class CMainParams : public CChainParams
nBlockDoubleAccumulated = 1050010;
nEnforceNewSporkKey = 1525158000; //!> Sporks signed after (GMT): Tuesday, May 1, 2018 7:00:00 AM GMT must use the new spork key
nRejectOldSporkKey = 1527811200; //!> Fully reject old spork key after (GMT): Friday, June 1, 2018 12:00:00 AM

nBlockStakeModifierlV2 = 1967000;
// Public coin spend enforcement
nPublicZCSpends = 1880000;

Expand Down Expand Up @@ -256,6 +269,7 @@ class CMainParams : public CChainParams
{
return data;
}

};
static CMainParams mainParams;

Expand All @@ -279,12 +293,12 @@ class CTestNetParams : public CMainParams
nRejectBlockOutdatedMajority = 5472; // 95%
nToCheckBlockUpgradeMajority = 5760; // 4 days
nMinerThreads = 0;
nTargetTimespan = 1 * 60; // PIVX: 1 day
nTargetSpacing = 1 * 60; // PIVX: 1 minute
nLastPOWBlock = 200;
nPivxBadBlockTime = 1489001494; // Skip nBit validation of Block 259201 per PR #915
nPivxBadBlocknBits = 0x1e0a20bd; // Skip nBit validation of Block 201 per PR #915
nMaturity = 15;
nStakeMinDepth = 100;
nMasternodeCountDrift = 4;
nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
nMaxMoneyOut = 43199500 * COIN;
Expand All @@ -299,7 +313,7 @@ class CTestNetParams : public CMainParams
nBlockZerocoinV2 = 444020; //!> The block that zerocoin v2 becomes active
nEnforceNewSporkKey = 1521604800; //!> Sporks signed after Wednesday, March 21, 2018 4:00:00 AM GMT must use the new spork key
nRejectOldSporkKey = 1522454400; //!> Reject old spork key after Saturday, March 31, 2018 12:00:00 AM GMT

nBlockStakeModifierlV2 = 1214000;
// Public coin spend enforcement
nPublicZCSpends = 1106100;

Expand Down Expand Up @@ -377,12 +391,11 @@ class CRegTestParams : public CTestNetParams
nRejectBlockOutdatedMajority = 950;
nToCheckBlockUpgradeMajority = 1000;
nMinerThreads = 1;
nTargetTimespan = 24 * 60 * 60; // PIVX: 1 day
nTargetSpacing = 1 * 60; // PIVX: 1 minutes
bnProofOfWorkLimit = ~uint256(0) >> 1;
nLastPOWBlock = 250;
nMaturity = 100;
nStakeMinAge = 0;
nStakeMinDepth = 0;
nMasternodeCountDrift = 4;
nModifierUpdateBlock = 0; //approx Mon, 17 Apr 2017 04:00:00 GMT
nMaxMoneyOut = 43199500 * COIN;
Expand All @@ -393,7 +406,7 @@ class CRegTestParams : public CTestNetParams
nBlockRecalculateAccumulators = 999999999; //Trigger a recalculation of accumulators
nBlockFirstFraudulent = 999999999; //First block that bad serials emerged
nBlockLastGoodCheckpoint = 999999999; //Last valid accumulator checkpoint

nBlockStakeModifierlV2 = std::numeric_limits<int>::max(); // max integer value (never switch on regtest)
// Public coin spend enforcement
nPublicZCSpends = 350;

Expand Down Expand Up @@ -470,7 +483,6 @@ class CUnitTestParams : public CMainParams, public CModifiableParams
};
static CUnitTestParams unitTestParams;


static CChainParams* pCurrentParams = 0;

CModifiableParams* ModifiableParams()
Expand Down
22 changes: 17 additions & 5 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class CChainParams
int RejectBlockOutdatedMajority() const { return nRejectBlockOutdatedMajority; }
int ToCheckBlockUpgradeMajority() const { return nToCheckBlockUpgradeMajority; }
int MaxReorganizationDepth() const { return nMaxReorganizationDepth; }
int StakeMinAge() const { return nStakeMinAge; }

/** Used if GenerateBitcoins is called with a negative number of threads */
int DefaultMinerThreads() const { return nMinerThreads; }
Expand All @@ -73,10 +72,19 @@ class CChainParams
bool SkipProofOfWorkCheck() const { return fSkipProofOfWorkCheck; }
/** Make standard checks */
bool RequireStandard() const { return fRequireStandard; }
int64_t TargetTimespan() const { return nTargetTimespan; }
int64_t TargetSpacing() const { return nTargetSpacing; }
int64_t Interval() const { return nTargetTimespan / nTargetSpacing; }

/** returns the coinbase maturity **/
int COINBASE_MATURITY() const { return nMaturity; }

/** returns the coinstake maturity (min depth required) **/
int COINSTAKE_MIN_DEPTH() const { return nStakeMinDepth; }
bool HasStakeMinAgeOrDepth(const int contextHeight, const uint32_t contextTime, const int utxoFromBlockHeight, const uint32_t utxoFromBlockTime) const;

/** returns the max future time (and drift in seconds) allowed for a block in the future **/
int FutureBlockTimeDrift(const bool isPoS) const { return isPoS ? nFutureTimeDriftPoS : nFutureTimeDriftPoW; }
uint32_t MaxFutureBlockTime(uint32_t time, const bool isPoS) const { return time + FutureBlockTimeDrift(isPoS); }

CAmount MaxMoneyOut() const { return nMaxMoneyOut; }
/** The masternode count that we will allow the see-saw reward payments to be off by */
int MasternodeCountDrift() const { return nMasternodeCountDrift; }
Expand Down Expand Up @@ -131,6 +139,7 @@ class CChainParams
int Zerocoin_StartTime() const { return nZerocoinStartTime; }
int Block_Enforce_Invalid() const { return nBlockEnforceInvalidUTXO; }
int Zerocoin_Block_V2_Start() const { return nBlockZerocoinV2; }
bool IsStakeModifierV2(const int nHeight) const { return nHeight >= nBlockStakeModifierlV2; }

// fake serial attack
int Zerocoin_Block_EndFakeSerial() const { return nFakeSerialBlockheightEnd; }
Expand All @@ -150,19 +159,21 @@ class CChainParams
std::vector<unsigned char> vAlertPubKey;
int nDefaultPort;
uint256 bnProofOfWorkLimit;
int nStakeMinAge;
int nMaxReorganizationDepth;
int nSubsidyHalvingInterval;
int nEnforceBlockUpgradeMajority;
int nRejectBlockOutdatedMajority;
int nToCheckBlockUpgradeMajority;
int64_t nTargetTimespan;
int64_t nTargetSpacing;
int nLastPOWBlock;
int64_t nPivxBadBlockTime;
unsigned int nPivxBadBlocknBits;
int nMasternodeCountDrift;
int nMaturity;
int nStakeMinDepth;
int nFutureTimeDriftPoW;
int nFutureTimeDriftPoS;

int nModifierUpdateBlock;
CAmount nMaxMoneyOut;
int nMinerThreads;
Expand Down Expand Up @@ -211,6 +222,7 @@ class CChainParams
int nBlockZerocoinV2;
int nBlockDoubleAccumulated;
int nPublicZCSpends;
int nBlockStakeModifierlV2;

// fake serial attack
int nFakeSerialBlockheightEnd = 0;
Expand Down
Loading