From e920c68b5e82e9cb7b044102d0835ff609ad52da Mon Sep 17 00:00:00 2001 From: IntegralTeam V Date: Wed, 11 Sep 2019 16:25:47 +0700 Subject: [PATCH] add proofOfStake --- src/chain.h | 18 +++++++++++++++++- src/miner.cpp | 3 +++ src/pos.cpp | 6 ------ src/pos.h | 4 ---- src/primitives/block.cpp | 2 ++ src/primitives/block.h | 18 ++++++++++++++---- src/txdb.cpp | 4 ++++ 7 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/chain.h b/src/chain.h index 4cc4847d3e1..26c303c38d8 100644 --- a/src/chain.h +++ b/src/chain.h @@ -209,6 +209,10 @@ class CBlockIndex nSequenceId = 0; nTimeMax = 0; + // PoS + proofOfStakeBody = boost::optional{}; + stakeModifier = uint256{}; + nVersion = 0; hashMerkleRoot = uint256(); nTime = 0; @@ -230,6 +234,8 @@ class CBlockIndex nTime = block.nTime; nBits = block.nBits; nNonce = block.nNonce; + stakeModifier = block.stakeModifier; + proofOfStakeBody = block.proofOfStakeBody; } FlatFilePos GetBlockPos() const { @@ -260,6 +266,8 @@ class CBlockIndex block.nTime = nTime; block.nBits = nBits; block.nNonce = nNonce; + block.stakeModifier = stakeModifier; + block.proofOfStakeBody = proofOfStakeBody; return block; } @@ -305,8 +313,9 @@ class CBlockIndex std::string ToString() const { - return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)", + return strprintf("CBlockIndex(pprev=%p, nHeight=%d, stakeModifier=(%s), merkle=%s, hashBlock=%s)", pprev, nHeight, + stakeModifier.ToString(), hashMerkleRoot.ToString(), GetBlockHash().ToString()); } @@ -386,6 +395,11 @@ class CDiskBlockIndex : public CBlockIndex if (nStatus & BLOCK_HAVE_UNDO) READWRITE(VARINT(nUndoPos)); + //PoS serialization + CBlockHeader::PoS loc_proofOfStake = proofOfStakeBody ? *proofOfStakeBody : CBlockHeader::PoS{}; + READWRITE(loc_proofOfStake); + proofOfStakeBody = loc_proofOfStake; + // block header READWRITE(this->nVersion); READWRITE(hashPrev); @@ -404,6 +418,8 @@ class CDiskBlockIndex : public CBlockIndex block.nTime = nTime; block.nBits = nBits; block.nNonce = nNonce; + block.stakeModifier = stakeModifier; + block.proofOfStakeBody = proofOfStakeBody; return block.GetHash(); } diff --git a/src/miner.cpp b/src/miner.cpp index 015645c9c66..63ed457ca2d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include