1 // Copyright (c) 2012-2013 The PPCoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 #ifndef PPCOIN_KERNEL_H
5 #define PPCOIN_KERNEL_H
13 extern unsigned int nStakeMaxAge;
14 extern unsigned int nStakeMinAge;
16 // ChainDB upgrade time
17 extern unsigned int nModifierUpgradeTime;
19 // MODIFIER_INTERVAL: time to elapse before new modifier is computed
20 extern unsigned int nModifierInterval;
22 // MODIFIER_INTERVAL_RATIO:
23 // ratio of group interval length between the last group and the first group
24 static const int MODIFIER_INTERVAL_RATIO = 3;
26 // Whether the given block is subject to new modifier protocol
27 bool IsFixedModifierInterval(unsigned int nTimeBlock);
29 // Compute the hash modifier for proof-of-stake
30 bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStakeModifier, bool& fGeneratedStakeModifier);
32 // The stake modifier used to hash for a stake kernel is chosen as the stake
33 // modifier about a selection interval later than the coin generating the kernel
34 bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier);
36 // Check whether stake kernel meets hash target
37 // Sets hashProofOfStake on success return
38 bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
40 // Scan given kernel for solutions
41 bool ScanKernelForward(unsigned char *kernel, uint32_t nBits, uint32_t nInputTxTime, int64_t nValueIn, std::pair<uint32_t, uint32_t> &SearchInterval, std::vector<std::pair<uint256, uint32_t> > &solutions);
43 // Check kernel hash target and coinstake signature
44 // Sets hashProofOfStake on success return
45 bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake);
47 // Get stake modifier checksum
48 uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex);
50 // Check stake modifier hard checkpoints
51 bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum);
53 // Get time weight using supplied timestamps
54 inline int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd)
56 // Kernel hash weight starts from 0 at the 30-day min age
57 // this change increases active coins participating the hash and helps
58 // to secure the network when proof-of-stake difficulty is low
60 // Maximum TimeWeight is 90 days.
62 return std::min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64_t)nStakeMaxAge);
65 #endif // PPCOIN_KERNEL_H