X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fkernel.cpp;h=bd1cdf302ce68f7f9fc396f8ce42b2bac6744a65;hb=8d43f1482a14263a76c039c227c4383580dcc1db;hp=959bd100ae1892b022148ca4d2842a11ca02e735;hpb=2c37da26ee5dde9e7c41d7f891a36e3081dc1e66;p=novacoin.git diff --git a/src/kernel.cpp b/src/kernel.cpp index 959bd10..bd1cdf3 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -23,6 +23,9 @@ static std::map mapStakeModifierCheckpoints = ( 37092, 0xd230afccu ) ( 44200, 0x05370164u ) ( 65000, 0xc8e7be6au ) + ( 68600, 0x73a8cc4cu ) + ( 92161, 0xe21a911au ) + ( 98661, 0xd20c44d4u ) ; // Hard checkpoints of stake modifiers to ensure they are deterministic (testNet) @@ -31,6 +34,18 @@ static std::map mapStakeModifierCheckpointsTestNet = ( 0, 0x0e00670bu ) ; +// Get time weight +int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd) +{ + // Kernel hash weight starts from 0 at the 30-day min age + // this change increases active coins participating the hash and helps + // to secure the network when proof-of-stake difficulty is low + // + // Maximum TimeWeight is 90 days. + + return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64)nStakeMaxAge); +} + // Get the last stake modifier and its generation time from a given block static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64& nStakeModifier, int64& nModifierTime) { @@ -275,17 +290,9 @@ bool CheckStakeKernelHash(unsigned int nBits, const CBlock& blockFrom, unsigned bnTargetPerCoinDay.SetCompact(nBits); int64 nValueIn = txPrev.vout[prevout.n].nValue; - int64 nTimeWeight; uint256 hashBlockFrom = blockFrom.GetHash(); - // Kernel hash weight starts from 0 at the 30-day min age - // this change increases active coins participating the hash and helps - // to secure the network when proof-of-stake difficulty is low - // - // Maximum TimeWeight is 90 days. - nTimeWeight = min((int64)nTimeTx - txPrev.nTime - nStakeMinAge, (int64)nStakeMaxAge); - - CBigNum bnCoinDayWeight = CBigNum(nValueIn) * nTimeWeight / COIN / (24 * 60 * 60); + CBigNum bnCoinDayWeight = CBigNum(nValueIn) * GetWeight((int64)txPrev.nTime, (int64)nTimeTx) / COIN / (24 * 60 * 60); targetProofOfStake = (bnCoinDayWeight * bnTargetPerCoinDay).getuint256(); // Calculate hash @@ -347,10 +354,6 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hash if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex)) return tx.DoS(1, error("CheckProofOfStake() : INFO: read txPrev failed")); // previous transaction not in main chain, may occur during initial download -#ifndef USE_LEVELDB - txdb.Close(); -#endif - // Verify signature if (!VerifySignature(txPrev, tx, 0, true, 0)) return tx.DoS(100, error("CheckProofOfStake() : VerifySignature failed on coinstake %s", tx.GetHash().ToString().c_str())); @@ -366,13 +369,6 @@ bool CheckProofOfStake(const CTransaction& tx, unsigned int nBits, uint256& hash return true; } -// Check whether the coinstake timestamp meets protocol -bool CheckCoinStakeTimestamp(int64 nTimeBlock, int64 nTimeTx) -{ - // v0.3 protocol - return (nTimeBlock == nTimeTx); -} - // Get stake modifier checksum unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex) {