diff --git a/src/main.cpp b/src/main.cpp index 12bef646d..54044fe43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2218,7 +2218,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c return DoS(50, error("CheckBlock() : proof of work failed")); // Check timestamp - if (GetBlockTime() > GetAdjustedTime() + nMaxClockDrift) + if (GetBlockTime() > GetAdjustedTime() + GetMaxClockDrift()) return error("CheckBlock() : block timestamp too far in the future"); // First transaction must be coinbase, the rest must not be @@ -2238,7 +2238,7 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c return error("CheckBlock() : coinbase output not empty for proof-of-stake block"); // Check coinbase timestamp - if (GetBlockTime() > (int64)vtx[0].nTime + nMaxClockDrift) + if (GetBlockTime() > (int64)vtx[0].nTime + GetMaxClockDrift()) return DoS(50, error("CheckBlock() : coinbase timestamp is too early")); // Check coinstake timestamp @@ -2330,7 +2330,7 @@ bool CBlock::AcceptBlock() return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake")); // Check timestamp against prev - if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || GetBlockTime() + nMaxClockDrift < pindexPrev->GetBlockTime()) + if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || GetBlockTime() + GetMaxClockDrift() < pindexPrev->GetBlockTime()) return error("AcceptBlock() : block's timestamp is too early"); // Check that all transactions are finalized @@ -4458,7 +4458,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int algo) { if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime-nLastCoinStakeSearchTime, txCoinStake)) { - if (txCoinStake.nTime >= max(pindexPrev->GetMedianTimePast()+1, pindexPrev->GetBlockTime() - nMaxClockDrift)) + if (txCoinStake.nTime >= max(pindexPrev->GetMedianTimePast()+1, pindexPrev->GetBlockTime() - GetMaxClockDrift())) { // make sure coinstake would meet timestamp protocol // as it would be the same as the block timestamp pblock->vtx[0].vout[0].SetEmpty(); @@ -4675,7 +4675,7 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake, int algo) if (pblock->IsProofOfStake()) pblock->nTime = pblock->vtx[1].nTime; //same as coinstake timestamp pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime()); - pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift); + pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - GetMaxClockDrift()); if (pblock->IsProofOfWork()) pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; @@ -4960,11 +4960,11 @@ void VERGEMiner(CWallet *pwallet, bool fProofOfStake) // Update nTime every few seconds pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, pblock->GetMaxTransactionTime()); - pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - nMaxClockDrift); + pblock->nTime = max(pblock->GetBlockTime(), pindexPrev->GetBlockTime() - GetMaxClockDrift()); pblock->UpdateTime(pindexPrev); nBlockTime = ByteReverse(pblock->nTime); - if (pblock->GetBlockTime() >= (int64)pblock->vtx[0].nTime + nMaxClockDrift) + if (pblock->GetBlockTime() >= (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) break; // need to update coinbase timestamp } } diff --git a/src/main.h b/src/main.h index f5a3540d9..e61774569 100644 --- a/src/main.h +++ b/src/main.h @@ -59,7 +59,12 @@ static const int fHaveUPnP = false; static const uint256 hashGenesisBlockOfficial("0x00000fc63692467faeb20cdb3b53200dc601d75bdfa1001463304cc790d77278"); static const uint256 hashGenesisBlockTestNet("0x65b4e101cacf3e1e4f3a9237e3a74ffd1186e595d8b78fa8ea22c21ef5bf9347"); -static const int64 nMaxClockDrift = 2 * 60 * 60; // 2 hours +inline int64 GetMaxClockDrift(int Height=nBestHeight){ + if (Height < 2218500) + return 2 * 60 * 60; // old 2 hour drift + else + return 10 * 60; // new 10 min drift +} extern CScript COINBASE_FLAGS; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index bc278d536..c08b5e904 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -140,7 +140,7 @@ Value getworkex(const Array& params, bool fHelp) // if difficulty is high and nobody else is mining coinbase time stamp // will eventually expire - if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + nMaxClockDrift) { + if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) { int oldTime = pblock->vtx[0].nTime; pblock->vtx[0].nTime = GetAdjustedTime(); pblock->hashMerkleRoot = pblock->BuildMerkleTree(); @@ -290,7 +290,7 @@ Value getwork(const Array& params, bool fHelp) // if difficulty is high and nobody else is mining coinbase time stamp // will eventually expire - if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + nMaxClockDrift) { + if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) { int oldTime = pblock->vtx[0].nTime; pblock->vtx[0].nTime = GetAdjustedTime(); pblock->hashMerkleRoot = pblock->BuildMerkleTree(); @@ -434,7 +434,7 @@ Value getblocktemplate(const Array& params, bool fHelp) // if difficulty is high and nobody else is mining coinbase time stamp // will eventually expire - if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + nMaxClockDrift) { + if (pblock->GetBlockTime() > (int64)pblock->vtx[0].nTime + GetMaxClockDrift()) { int oldTime = pblock->vtx[0].nTime; pblock->vtx[0].nTime = GetAdjustedTime(); pblock->hashMerkleRoot = pblock->BuildMerkleTree();