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