Commit ffd0e8ba authored by presstab's avatar presstab
Browse files

Add PoS to CBlock and Header

parent cf1f2d66
Showing with 35 additions and 3 deletions
+35 -3
......@@ -125,7 +125,10 @@ public:
nMinerThreads = 0;
nTargetTimespan = 14 * 24 * 60 * 60; // Crown: 2 weeks
nTargetSpacing = 1 * 60; // Crown: 1 minutes
nMaxTipAge = 6 * 60 * 60;
nMaxTipAge = 6 * 60 * 60;
nAuxpowChainId = 20;
nPoSChainId = 22;
/**
* Build the genesis block. Note that the output of the genesis coinbase cannot
......
......@@ -84,7 +84,9 @@ public:
int64_t StartMasternodePayments() const { return nStartMasternodePayments; }
CBaseChainParams::Network NetworkID() const { return networkID; }
/* Return the auxpow chain ID. */
inline int32_t AuxpowChainId () const { return 20; }
inline int32_t AuxpowChainId () const { return nAuxpowChainId; }
int32_t PoSChainId () const { return nPoSChainId; }
int PoSStartHeight() const { return nBlockPoSStart; }
/* Return start height of auxpow and the retarget interval change. */
virtual int AuxpowStartHeight() const = 0;
/* Return whether or not to enforce strict chain ID checks. */
......@@ -127,6 +129,9 @@ protected:
std::string strLegacySignerDummyAddress;
std::string strDevfundAddress;
int64_t nStartMasternodePayments;
int32_t nAuxpowChainId;
int32_t nPoSChainId;
int nBlockPoSStart;
};
/**
......
......@@ -108,7 +108,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
txNew.vout[0].scriptPubKey = scriptPubKeyIn;
/* Initialise the block version. */
const int32_t nChainId = Params().AuxpowChainId();
int32_t nChainId = Params().AuxpowChainId();
if (chainActive.Height() > Params().PoSStartHeight())
nChainId = Params().PoSChainId();
pblock->nVersion.SetBaseVersion(CBlockHeader::CURRENT_VERSION, nChainId);
......
......@@ -24,6 +24,11 @@ void CBlockHeader::SetAuxpow (CAuxPow* apow)
}
}
void CBlockHeader::SetProofOfStake(bool fProofOfStake)
{
nVersion.SetProofOfStake(fProofOfStake);
}
uint256 CBlock::BuildMerkleTree(bool* fMutated) const
{
/* WARNING! If you're reading this because you're learning about crypto
......
......@@ -75,6 +75,8 @@ public:
*/
void SetAuxpow (CAuxPow* apow);
void SetProofOfStake(bool fProofOfStake);
};
class CBlock : public CBlockHeader
......
......@@ -21,6 +21,7 @@ private:
/* Modifiers to the version. */
static const int32_t VERSION_AUXPOW = (1 << 8);
static const int32_t VERSION_POS_START = (1 << 9);
/** Bits above are reserved for the auxpow chain ID. */
static const int32_t VERSION_CHAIN_START = (1 << 16);
......@@ -123,6 +124,19 @@ public:
nVersion &= ~VERSION_AUXPOW;
}
inline bool IsProofOfStake() const
{
return nVersion & VERSION_POS_START;
}
inline void SetProofOfStake(bool fProofOfStake)
{
if (fProofOfStake)
nVersion |= VERSION_POS_START;
else
nVersion &= ~VERSION_POS_START;
}
/**
* Check whether this is a "legacy" block without chain ID.
* @return True iff it is.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment