Replace -nosynccheckpoints with a new -cppolicy=mode option
authoralex <alex@alex-VirtualBox.(none)>
Wed, 28 Aug 2013 19:00:51 +0000 (23:00 +0400)
committeralex <alex@alex-VirtualBox.(none)>
Wed, 28 Aug 2013 19:00:51 +0000 (23:00 +0400)
Possible values:

* strict - default mode, verify blocks to satisfy syncronized checkpoints, and reject if necessary;
* advisory - verify blocks to satisfy syncronized checkpoints, and display warning if necessary;
* permissive - don't perform any checkings.

src/checkpoints.h
src/init.cpp
src/main.cpp
src/main.h
src/qt/locale/bitcoin_en.ts
src/qt/locale/bitcoin_ru.ts
src/rpcblockchain.cpp

index 1074cd2..1585126 100644 (file)
@@ -19,6 +19,17 @@ class CSyncCheckpoint;
  */
 namespace Checkpoints
 {
+    /** Checkpointing mode */
+    enum CPMode
+    {
+        // Scrict checkpoints policy, perform conflicts verification and resolve conflicts
+        STRICT = 0,
+        // Advisory checkpoints policy, perform conflicts verification but don't try to resolve them
+        ADVISORY = 1,
+        // Permissive checkpoints policy, don't perform any checking
+        PERMISSIVE = 2,
+    };
+
     // Returns true if block passes checkpoint checks
     bool CheckHardened(int nHeight, const uint256& hash);
 
index babe715..9dfdc63 100644 (file)
@@ -29,6 +29,7 @@ CClientUIInterface uiInterface;
 std::string strWalletFileName;
 unsigned int nNodeLifespan;
 unsigned int nDerivationMethodIndex;
+enum Checkpoints::CPMode CheckpointsMode;
 
 //////////////////////////////////////////////////////////////////////////////
 //
@@ -246,7 +247,7 @@ std::string HelpMessage()
         "  -listen                " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n" +
         "  -bind=<addr>           " + _("Bind to given address. Use [host]:port notation for IPv6") + "\n" +
         "  -dnsseed               " + _("Find peers using DNS lookup (default: 1)") + "\n" +
-        "  -nosynccheckpoints     " + _("Disable sync checkpoints (default: 0)") + "\n" +
+        "  -cppolicy              " + _("Sync checkpoints policy (default: strict)") + "\n" +
         "  -stakepooledkeys       " + _("Use pooled pubkeys for the last coinstake output (default: 0)") + "\n" +
         "  -derivationmethod      " + _("Which key derivation method to use by default (default: sha512)") + "\n" +
         "  -banscore=<n>          " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" +
@@ -358,6 +359,18 @@ bool AppInit2()
     nNodeLifespan = GetArg("-addrlifespan", 7);
     fStakeUsePooledKeys = GetBoolArg("-stakepooledkeys", false);
 
+    CheckpointsMode = Checkpoints::STRICT;
+    std::string strCpMode = GetArg("-cppolicy", "strict");
+
+    if(strCpMode == "strict")
+        CheckpointsMode = Checkpoints::STRICT;
+
+    if(strCpMode == "advisory")
+        CheckpointsMode = Checkpoints::ADVISORY;
+
+    if(strCpMode == "permissive")
+        CheckpointsMode = Checkpoints::PERMISSIVE;
+
     if(GetArg("-derivationmethod", "sha512") == "scrypt+sha512")
         nDerivationMethodIndex = 1;
 
index 332832e..4f6d71f 100644 (file)
@@ -75,6 +75,7 @@ const string strMessageMagic = "NovaCoin Signed Message:\n";
 // Settings
 int64 nTransactionFee = MIN_TX_FEE;
 bool fStakeUsePooledKeys = false;
+extern enum Checkpoints::CPMode CheckpointsMode;
 
 //////////////////////////////////////////////////////////////////////////////
 //
@@ -2256,10 +2257,15 @@ bool CBlock::AcceptBlock()
     if (!Checkpoints::CheckHardened(nHeight, hash))
         return DoS(100, error("AcceptBlock() : rejected by hardened checkpoint lock-in at %d", nHeight));
 
+    bool cpSatisfies = Checkpoints::CheckSync(hash, pindexPrev);
+
     // Check that the block satisfies synchronized checkpoint
-    if (!GetBoolArg("-nosynccheckpoints", false) && !Checkpoints::CheckSync(hash, pindexPrev))
+    if (CheckpointsMode == Checkpoints::STRICT && !cpSatisfies)
         return error("AcceptBlock() : rejected by synchronized checkpoint");
 
+    if (CheckpointsMode == Checkpoints::ADVISORY && !cpSatisfies)
+        strMiscWarning = _("WARNING: syncronized checkpoint violation detected, but skipped!");
+
     // Enforce rule that the coinbase starts with serialized block height
     CScript expect = CScript() << nHeight;
     if (vtx[0].vin[0].scriptSig.size() < expect.size() ||
@@ -2964,18 +2970,19 @@ string GetWarnings(string strFor)
 
     // * Should not enter safe mode for longer invalid chain
     // * If sync-checkpoint is too old do not enter safe mode
-    // * Do not display warning if -nosynccheckpoints specified
-    if (!GetBoolArg("-nosynccheckpoints", false) && Checkpoints::IsSyncCheckpointTooOld(60 * 60 * 24 * 10) && !fTestNet && !IsInitialBlockDownload())
+    // * Display warning only in the STRICT mode
+    if (CheckpointsMode == Checkpoints::STRICT && Checkpoints::IsSyncCheckpointTooOld(60 * 60 * 24 * 10) &&
+        !fTestNet && !IsInitialBlockDownload())
     {
         nPriority = 100;
-        strStatusBar = "WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers.";
+        strStatusBar = _("WARNING: Checkpoint is too old. Wait for block chain to download, or notify developers.");
     }
 
     // ppcoin: if detected invalid checkpoint enter safe mode
     if (Checkpoints::hashInvalidCheckpoint != 0)
     {
         nPriority = 3000;
-        strStatusBar = strRPC = "WARNING: Invalid checkpoint found! Displayed transactions may not be correct! You may need to upgrade, or notify developers.";
+        strStatusBar = strRPC = _("WARNING: Invalid checkpoint found! Displayed transactions may not be correct! You may need to upgrade, or notify developers.");
     }
 
     // Alerts
index f7918fc..666745d 100644 (file)
@@ -94,7 +94,6 @@ extern unsigned int nDerivationMethodIndex;
 // Minimum disk space required - used in CheckDiskSpace()
 static const uint64 nMinDiskSpace = 52428800;
 
-
 class CReserveKey;
 class CTxDB;
 class CTxIndex;
index 20cebb3..a8f6a60 100644 (file)
@@ -2350,8 +2350,8 @@ Address: %4
     </message>
     <message>
         <location line="+4"/>
-        <source>Disable sync checkpoints (default: 0)</source>
-        <translation>Disable sync checkpoints (default: 0)</translation>
+        <source>Sync checkpoints policy (default: strict)</source>
+        <translation>Sync checkpoints policy (default: strict)</translation>
     </message>
     <message>
         <location line="+5"/>
index 66fe88b..6ef6a75 100644 (file)
@@ -2362,8 +2362,8 @@ Address: %4
     </message>
     <message>
         <location line="+4"/>
-        <source>Disable sync checkpoints (default: 0)</source>
-        <translation>Отключить синхронизированные метки (по умолчанию: 0)</translation>
+        <source>Sync checkpoints policy (default: strict)</source>
+        <translation>Политика синхронизированных меток (по умолчанию: strict)</translation>
     </message>
     <message>
         <location line="+5"/>
index c47edd5..fae3e45 100644 (file)
@@ -234,9 +234,10 @@ Value getcheckpoint(const Array& params, bool fHelp)
     CBlockIndex* pindexCheckpoint;
 
     result.push_back(Pair("synccheckpoint", Checkpoints::hashSyncCheckpoint.ToString().c_str()));
-    pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint];        
+    pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint];
     result.push_back(Pair("height", pindexCheckpoint->nHeight));
     result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str()));
+    result.push_back(Pair("policy", GetArg("-cppolicy", "strict").c_str()));
     if (mapArgs.count("-checkpointkey"))
         result.push_back(Pair("checkpointmaster", true));