From: CryptoManiac Date: Sun, 6 Dec 2015 23:41:59 +0000 (+0300) Subject: Add checkpoint + Reject blocks from the distant future X-Git-Tag: nvc-v0.5.5~1 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=fe3160e5c4a0046b4f97ec6d32d280aaa6ecc74c Add checkpoint + Reject blocks from the distant future --- diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index e6b7ab4..68c427f 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -30,6 +30,7 @@ namespace Checkpoints ( 149000, std::make_pair(uint256("0x7a24acfcadcf43054e7f7d9f273522c0dfc5791ba4006e0273e7521a8d36c525"), 1420872125) ) ( 160000, std::make_pair(uint256("0x000000000001cb1133043d38d077c0e93f66c8b2566779f10f182137d1e34a68"), 1425150237) ) ( 200000, std::make_pair(uint256("0x0000000000029f8bbf66e6ea6f3e5db55009404aae0fe395a53dd33142b2bff2"), 1441127233) ) + ( 221046, std::make_pair(uint256("0x000000000005487dee17d16e9ed726b6dcc119bc89be5641facaea8f5b742cf6"), 1449428373) ) ; // TestNet has no checkpoints diff --git a/src/main.cpp b/src/main.cpp index 7d0ce98..b857739 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2335,10 +2335,19 @@ bool CBlock::AcceptBlock() if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake())) return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake")); + int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); + int nMaxOffset = 12 * 3600; // 12 hours + if (pindexPrev->nTime < 1450569600) + nMaxOffset = 7 * 86400; // One week until 20 Dec, 2015 + // Check timestamp against prev - if (GetBlockTime() <= pindexPrev->GetMedianTimePast() || FutureDrift(GetBlockTime()) < pindexPrev->GetBlockTime()) + if (GetBlockTime() <= nMedianTimePast || FutureDrift(GetBlockTime()) < pindexPrev->GetBlockTime()) return error("AcceptBlock() : block's timestamp is too early"); + // Don't accept blocks with future timestamps + if (pindexPrev->nHeight > 1 && nMedianTimePast + nMaxOffset < GetBlockTime()) + return error("AcceptBlock() : block's timestamp is too far in the future"); + // Check that all transactions are finalized BOOST_FOREACH(const CTransaction& tx, vtx) if (!tx.IsFinal(nHeight, GetBlockTime()))