From 6fccda8e55816a81e21f89ae54c92785242ee8f8 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Sun, 29 Mar 2015 21:06:30 +0300 Subject: [PATCH] Timestamp adjustment. There is a minimal limit for age. If input is younger than 30 days old, then move forward to the future until it will be sufficient for stake mining. --- src/kernel.cpp | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/kernel.cpp b/src/kernel.cpp index 4055314..7429a38 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -512,13 +512,10 @@ bool ScanForStakeKernelHash(MetaMap &mapMeta, uint32_t nBits, uint32_t nTime, ui // Scan given input for kernel solution bool ScanInputForStakeKernelHash(CTransaction &tx, uint32_t nOut, uint32_t nBits, uint32_t nSearchInterval, std::pair &solution) { + CTxDB txdb("r"); + CBlock block; CTxIndex txindex; - uint256 hashProofOfStake; - - int nTime = GetTime(); - - CTxDB txdb("r"); // Load transaction index item if (!txdb.ReadTxIndex(tx.GetHash(), txindex)) @@ -532,13 +529,17 @@ bool ScanInputForStakeKernelHash(CTransaction &tx, uint32_t nOut, uint32_t nBits if (!GetKernelStakeModifier(block.GetHash(), nStakeModifier)) return false; + uint32_t nTime = GetTime(); + // Only count coins meeting min age requirement + if (nStakeMinAge + block.nTime > nTime) + nTime += (nStakeMinAge + block.nTime - nTime); + // Transaction offset inside block uint32_t nTxOffset = txindex.pos.nTxPos - txindex.pos.nBlockPos; + int64_t nValueIn = tx.vout[nOut].nValue; - uint32_t nBlockTime = block.nTime; CBigNum bnTargetPerCoinDay; bnTargetPerCoinDay.SetCompact(nBits); - int64_t nValueIn = tx.vout[nOut].nValue; // Search forward in time from the given timestamp // Stopping search in case of shutting down @@ -551,10 +552,10 @@ bool ScanInputForStakeKernelHash(CTransaction &tx, uint32_t nOut, uint32_t nBits // Build kernel CDataStream ss(SER_GETHASH, 0); ss << nStakeModifier; - ss << nBlockTime << nTxOffset << tx.nTime << nOut << nTimeTx; + ss << block.nTime << nTxOffset << tx.nTime << nOut << nTimeTx; // Calculate kernel hash - hashProofOfStake = Hash(ss.begin(), ss.end()); + uint256 hashProofOfStake = Hash(ss.begin(), ss.end()); if (bnTargetProofOfStake >= CBigNum(hashProofOfStake)) { -- 1.7.1