364907079e4dafb5314c632ddf59157ded0bc563
[novacoin.git] / src / kernel.h
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
6
7 #include "uint256.h"
8
9 class CBlock;
10 class CBlockIndex;
11 class CTransaction;
12 class COutPoint;
13
14 extern uint32_t nStakeMinAge;
15 extern uint32_t nStakeMaxAge;
16
17 // ChainDB upgrade time
18 extern uint32_t nModifierUpgradeTime;
19
20 // MODIFIER_INTERVAL: time to elapse before new modifier is computed
21 extern uint32_t nModifierInterval;
22
23 // MODIFIER_INTERVAL_RATIO:
24 // ratio of group interval length between the last group and the first group
25 static const int MODIFIER_INTERVAL_RATIO = 3;
26
27 // Whether the given block is subject to new modifier protocol
28 bool IsFixedModifierInterval(uint32_t nTimeBlock);
29
30 // Compute the hash modifier for proof-of-stake
31 bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStakeModifier, bool& fGeneratedStakeModifier);
32
33 // The stake modifier used to hash for a stake kernel is chosen as the stake
34 // modifier about a selection interval later than the coin generating the kernel
35 bool GetKernelStakeModifier(const uint256 &hashBlockFrom, uint64_t& nStakeModifier);
36
37 // Check whether stake kernel meets hash target
38 // Sets hashProofOfStake on success return
39 bool CheckStakeKernelHash(uint32_t nBits, const CBlock& blockFrom, uint32_t nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, uint32_t nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
40
41 // Scan given kernel for solutions
42 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
44 // Check kernel hash target and coinstake signature
45 // Sets hashProofOfStake on success return
46 bool CheckProofOfStake(const CTransaction& tx, uint32_t nBits, uint256& hashProofOfStake, uint256& targetProofOfStake);
47
48 // Get stake modifier checksum
49 uint32_t GetStakeModifierChecksum(const CBlockIndex* pindex);
50
51 // Check stake modifier hard checkpoints
52 bool CheckStakeModifierCheckpoints(int nHeight, uint32_t nStakeModifierChecksum);
53
54 // Get time weight using supplied timestamps
55 inline int64_t GetWeight(int64_t nIntervalBeginning, int64_t nIntervalEnd)
56 {
57     // Kernel hash weight starts from 0 at the 30-day min age
58     // this change increases active coins participating the hash and helps
59     // to secure the network when proof-of-stake difficulty is low
60     //
61     // Maximum TimeWeight is 90 days.
62
63     return std::min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64_t)nStakeMaxAge);
64 }
65
66 #endif // PPCOIN_KERNEL_H