Skip to content

Commit 59b8a3a

Browse files
authored
Merge pull request #750 from peercoin/develop
0.14.0 changes
2 parents d1a4676 + 4bca8a0 commit 59b8a3a

File tree

14 files changed

+328
-63
lines changed

14 files changed

+328
-63
lines changed

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ define(_CLIENT_VERSION_RC, 0)
66
define(_CLIENT_VERSION_IS_RELEASE, true)
77
define(_COPYRIGHT_YEAR, 2024)
88
define(_PEERCOIN_VERSION_MAJOR, 0)
9-
define(_PEERCOIN_VERSION_MINOR, 13)
10-
define(_PEERCOIN_VERSION_REVISION, 1)
9+
define(_PEERCOIN_VERSION_MINOR, 14)
10+
define(_PEERCOIN_VERSION_REVISION, 0)
1111
define(_PEERCOIN_VERSION_BUILD, 0)
1212
define(_PEERCOIN_VERSION_RC, 0)
1313
define(_COPYRIGHT_HOLDERS,[The %s developers])

src/chain.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ class CBlockIndex
222222

223223
// peercoin: proof-of-stake related block index fields
224224
unsigned int nFlags{0}; // peercoin: block index flags
225+
// peercoin: height of pos blocks only
226+
unsigned int nHeightStake{0};
225227
enum
226228
{
227229
BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block
@@ -395,8 +397,8 @@ class CBlockIndex
395397

396398
std::string ToString() const
397399
{
398-
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)",
399-
pprev, /*nFile, */nHeight,
400+
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)",
401+
pprev, /*nFile, */nHeight, nHeightStake,
400402
FormatMoney(nMint), FormatMoney(nMoneySupply),
401403
GeneratedStakeModifier() ? "MOD" : "-", GetStakeEntropyBit(), IsProofOfStake()? "PoS" : "PoW",
402404
nStakeModifier, nStakeModifierChecksum,
@@ -511,6 +513,7 @@ class CDiskBlockIndex : public CBlockIndex
511513
READWRITE(obj.nMint);
512514
READWRITE(obj.nMoneySupply);
513515
READWRITE(obj.nFlags);
516+
READWRITE(obj.nHeightStake);
514517
READWRITE(obj.nStakeModifier);
515518
if (obj.nFlags & BLOCK_PROOF_OF_STAKE)
516519
{
@@ -596,6 +599,13 @@ class CChain
596599
return int(vChain.size()) - 1;
597600
}
598601

602+
/** Return height of the chain counting only proof of stake blocks */
603+
604+
int HeightStake() const
605+
{
606+
return vChain.size() > 0 ? vChain[vChain.size() - 1]->nHeightStake : 0;
607+
}
608+
599609
/** Set/initialize a chain with a given tip. */
600610
void SetTip(CBlockIndex& block);
601611

src/kernel.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const unsigned int nProtocolV10TestSwitchTime = 1625140800; // Thu 1 Jul 12:00:
4949
// Protocol switch time for v12 kernel protocol
5050
const unsigned int nProtocolV12SwitchTime = 1700276331; // Sat 18 Nov 02:58:51 UTC 2023
5151
const unsigned int nProtocolV12TestSwitchTime = 1671060214; // Wed 14 Dec 11:23:34 UTC 2022
52+
// Protocol switch time for v14 kernel protocol
53+
const unsigned int nProtocolV14SwitchTime = 1717416000; // Mon 3 Jun 12:00:00 UTC 2024
54+
const unsigned int nProtocolV14TestSwitchTime = 1710720000; // Mon 18 Mar 00:00:00 UTC 2024
5255

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

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

165+
// Whether a given block is subject to new v14 protocol
166+
bool IsProtocolV14(const CBlockIndex* pindexPrev)
167+
{
168+
if (Params().NetworkIDString() == CBaseChainParams::REGTEST)
169+
return true;
170+
171+
if (pindexPrev->nTime < (Params().NetworkIDString() != CBaseChainParams::MAIN ? nProtocolV14TestSwitchTime : nProtocolV14SwitchTime))
172+
return false;
173+
174+
if ((Params().NetworkIDString() == CBaseChainParams::MAIN && IsSuperMajority(5, pindexPrev, 750, 1000)) ||
175+
(Params().NetworkIDString() != CBaseChainParams::MAIN && IsSuperMajority(5, pindexPrev, 75, 100)))
176+
return true;
177+
178+
return false;
179+
}
180+
162181
// Get the last stake modifier and its generation time from a given block
163182
static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64_t& nStakeModifier, int64_t& nModifierTime)
164183
{

src/kernel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ bool IsProtocolV09(unsigned int nTimeTx);
4040
bool IsProtocolV10(unsigned int nTimeTx);
4141
// Whether a given block is subject to new v12 protocol
4242
bool IsProtocolV12(const CBlockIndex* pindexPrev);
43+
// Whether a given block is subject to new v14 protocol
44+
bool IsProtocolV14(const CBlockIndex* pindexPrev);
4345

4446
// Compute the hash modifier for proof-of-stake
4547
bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStakeModifier, bool& fGeneratedStakeModifier, Chainstate& chainstate);

src/node/blockstorage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockInde
100100
if (miPrev != m_block_index.end()) {
101101
pindexNew->pprev = &(*miPrev).second;
102102
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
103+
pindexNew->nHeightStake = pindexNew->pprev->nHeightStake + (block.nFlags & CBlockIndex::BLOCK_PROOF_OF_STAKE);
103104
pindexNew->BuildSkip();
104105
}
105106
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);

0 commit comments

Comments
 (0)