Add checkpoint + Reject blocks from the distant future
authorCryptoManiac <balthazar@yandex.ru>
Sun, 6 Dec 2015 23:41:59 +0000 (02:41 +0300)
committerCryptoManiac <balthazar@yandex.ru>
Mon, 7 Dec 2015 00:25:28 +0000 (03:25 +0300)
src/checkpoints.cpp
src/main.cpp

index e6b7ab4..68c427f 100644 (file)
@@ -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
index 7d0ce98..b857739 100644 (file)
@@ -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()))