Fix miner issues
[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 "main.h"
8 #include "wallet.h"
9
10 // ChainDB upgrade time
11 extern unsigned int nModifierUpgradeTime;
12
13 // MODIFIER_INTERVAL: time to elapse before new modifier is computed
14 extern const unsigned int nModifierInterval;
15
16 extern bool fCoinsDataActual;
17
18 // MODIFIER_INTERVAL_RATIO:
19 // ratio of group interval length between the last group and the first group
20 static const int MODIFIER_INTERVAL_RATIO = 3;
21
22 // Whether the given block is subject to new modifier protocol
23 bool IsFixedModifierInterval(unsigned int nTimeBlock);
24
25 // Compute the hash modifier for proof-of-stake
26 bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64& nStakeModifier, bool& fGeneratedStakeModifier);
27
28 // The stake modifier used to hash for a stake kernel is chosen as the stake
29 // modifier about a selection interval later than the coin generating the kernel
30 bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier);
31
32 // Check whether stake kernel meets hash target
33 // Sets hashProofOfStake on success return
34 bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned int nTxPrevOffset, const CTransaction& txPrev, const COutPoint& prevout, unsigned int nTimeTx, uint256& hashProofOfStake, uint256& targetProofOfStake, bool fPrintProofOfStake=false);
35
36 // Coins scanning options
37 typedef struct KernelSearchSettings {
38     unsigned int nBits;           // Packed difficulty
39     unsigned int nTime;           // Basic time
40     unsigned int nOffset;         // Offset inside CoinsSet (isn't used yet)
41     unsigned int nLimit;          // Coins to scan (isn't used yet)
42     unsigned int nSearchInterval; // Number of seconds allowed to go into the past
43 } KernelSearchSettings;
44
45 typedef std::set<std::pair<const CWalletTx*,unsigned int> > CoinsSet;
46
47 // Preloaded coins metadata
48 // txid => ((txindex, (tx, vout.n)), (block, modifier))
49 typedef std::map<std::pair<uint256, unsigned int>, std::pair<std::pair<CTxIndex, std::pair<const CWalletTx*,unsigned int> >, std::pair<CBlock, uint64> > > MetaMap;
50
51 // Scan given coins set for kernel solution
52 bool ScanForStakeKernelHash(MetaMap &mapMeta, KernelSearchSettings &settings, CoinsSet::value_type &kernelcoin, unsigned int &nTimeTx, unsigned int &nBlockTime);
53
54 // Check kernel hash target and coinstake signature
55 // Sets hashProofOfStake on success return
56 bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hashProofOfStake, uint256& targetProofOfStake);
57
58 // Get stake modifier checksum
59 unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex);
60
61 // Check stake modifier hard checkpoints
62 bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierChecksum);
63
64 // Get time weight using supplied timestamps
65 int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd);
66
67 #endif // PPCOIN_KERNEL_H