Skip to content

Commit

Permalink
Merge pull request #750 from peercoin/develop
Browse files Browse the repository at this point in the history
0.14.0 changes
  • Loading branch information
backpacker69 committed Apr 17, 2024
2 parents d1a4676 + 4bca8a0 commit 59b8a3a
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 63 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2024)
define(_PEERCOIN_VERSION_MAJOR, 0)
define(_PEERCOIN_VERSION_MINOR, 13)
define(_PEERCOIN_VERSION_REVISION, 1)
define(_PEERCOIN_VERSION_MINOR, 14)
define(_PEERCOIN_VERSION_REVISION, 0)
define(_PEERCOIN_VERSION_BUILD, 0)
define(_PEERCOIN_VERSION_RC, 0)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down
14 changes: 12 additions & 2 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class CBlockIndex

// peercoin: proof-of-stake related block index fields
unsigned int nFlags{0}; // peercoin: block index flags
// peercoin: height of pos blocks only
unsigned int nHeightStake{0};
enum
{
BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block
Expand Down Expand Up @@ -395,8 +397,8 @@ class CBlockIndex

std::string ToString() const
{
return strprintf("CBlockIndex(nprev=%08x, "/*nFile=%d, */"nHeight=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016llx, nStakeModifierChecksum=%08x, hashProofOfStake=%s, prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)",
pprev, /*nFile, */nHeight,
return strprintf("CBlockIndex(nprev=%08x, "/*nFile=%d, */"nHeight=%d, nHeightStake=%d, nMint=%s, nMoneySupply=%s, nFlags=(%s)(%d)(%s), nStakeModifier=%016llx, nStakeModifierChecksum=%08x, hashProofOfStake=%s, prevoutStake=(%s), nStakeTime=%d merkle=%s, hashBlock=%s)",
pprev, /*nFile, */nHeight, nHeightStake,
FormatMoney(nMint), FormatMoney(nMoneySupply),
GeneratedStakeModifier() ? "MOD" : "-", GetStakeEntropyBit(), IsProofOfStake()? "PoS" : "PoW",
nStakeModifier, nStakeModifierChecksum,
Expand Down Expand Up @@ -511,6 +513,7 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(obj.nMint);
READWRITE(obj.nMoneySupply);
READWRITE(obj.nFlags);
READWRITE(obj.nHeightStake);
READWRITE(obj.nStakeModifier);
if (obj.nFlags & BLOCK_PROOF_OF_STAKE)
{
Expand Down Expand Up @@ -596,6 +599,13 @@ class CChain
return int(vChain.size()) - 1;
}

/** Return height of the chain counting only proof of stake blocks */

int HeightStake() const
{
return vChain.size() > 0 ? vChain[vChain.size() - 1]->nHeightStake : 0;
}

/** Set/initialize a chain with a given tip. */
void SetTip(CBlockIndex& block);

Expand Down
21 changes: 20 additions & 1 deletion src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const unsigned int nProtocolV10TestSwitchTime = 1625140800; // Thu 1 Jul 12:00:
// Protocol switch time for v12 kernel protocol
const unsigned int nProtocolV12SwitchTime = 1700276331; // Sat 18 Nov 02:58:51 UTC 2023
const unsigned int nProtocolV12TestSwitchTime = 1671060214; // Wed 14 Dec 11:23:34 UTC 2022
// Protocol switch time for v14 kernel protocol
const unsigned int nProtocolV14SwitchTime = 1717416000; // Mon 3 Jun 12:00:00 UTC 2024
const unsigned int nProtocolV14TestSwitchTime = 1710720000; // Mon 18 Mar 00:00:00 UTC 2024

// Hard checkpoints of stake modifiers to ensure they are deterministic
static std::map<int, unsigned int> mapStakeModifierCheckpoints =
Expand Down Expand Up @@ -150,7 +153,7 @@ bool IsProtocolV10(unsigned int nTime)
return (nTime >= (Params().NetworkIDString() != CBaseChainParams::MAIN ? nProtocolV10TestSwitchTime : nProtocolV10SwitchTime));
}

// Whether a given timestamp is subject to new v10 protocol
// Whether a given block is subject to new v12 protocol
bool IsProtocolV12(const CBlockIndex* pindexPrev)
{
if (Params().NetworkIDString() == CBaseChainParams::REGTEST)
Expand All @@ -159,6 +162,22 @@ bool IsProtocolV12(const CBlockIndex* pindexPrev)
return (pindexPrev->nTime >= (Params().NetworkIDString() != CBaseChainParams::MAIN ? nProtocolV12TestSwitchTime : nProtocolV12SwitchTime));
}

// Whether a given block is subject to new v14 protocol
bool IsProtocolV14(const CBlockIndex* pindexPrev)
{
if (Params().NetworkIDString() == CBaseChainParams::REGTEST)
return true;

if (pindexPrev->nTime < (Params().NetworkIDString() != CBaseChainParams::MAIN ? nProtocolV14TestSwitchTime : nProtocolV14SwitchTime))
return false;

if ((Params().NetworkIDString() == CBaseChainParams::MAIN && IsSuperMajority(5, pindexPrev, 750, 1000)) ||
(Params().NetworkIDString() != CBaseChainParams::MAIN && IsSuperMajority(5, pindexPrev, 75, 100)))
return true;

return false;
}

// Get the last stake modifier and its generation time from a given block
static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64_t& nStakeModifier, int64_t& nModifierTime)
{
Expand Down
2 changes: 2 additions & 0 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ bool IsProtocolV09(unsigned int nTimeTx);
bool IsProtocolV10(unsigned int nTimeTx);
// Whether a given block is subject to new v12 protocol
bool IsProtocolV12(const CBlockIndex* pindexPrev);
// Whether a given block is subject to new v14 protocol
bool IsProtocolV14(const CBlockIndex* pindexPrev);

// Compute the hash modifier for proof-of-stake
bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStakeModifier, bool& fGeneratedStakeModifier, Chainstate& chainstate);
Expand Down
1 change: 1 addition & 0 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockInde
if (miPrev != m_block_index.end()) {
pindexNew->pprev = &(*miPrev).second;
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
pindexNew->nHeightStake = pindexNew->pprev->nHeightStake + (block.nFlags & CBlockIndex::BLOCK_PROOF_OF_STAKE);
pindexNew->BuildSkip();
}
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
Expand Down

0 comments on commit 59b8a3a

Please sign in to comment.