From: alex Date: Wed, 28 Aug 2013 19:00:51 +0000 (+0400) Subject: Replace -nosynccheckpoints with a new -cppolicy=mode option X-Git-Tag: v0.4.4.4~5 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=d442c8e26cc71979b12cbfbbf4af14460e206995 Replace -nosynccheckpoints with a new -cppolicy=mode option 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. --- diff --git a/src/checkpoints.h b/src/checkpoints.h index 1074cd2..1585126 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -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); diff --git a/src/init.cpp b/src/init.cpp index babe715..9dfdc63 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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= " + _("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= " + _("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; diff --git a/src/main.cpp b/src/main.cpp index 332832e..4f6d71f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 diff --git a/src/main.h b/src/main.h index f7918fc..666745d 100644 --- a/src/main.h +++ b/src/main.h @@ -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; diff --git a/src/qt/locale/bitcoin_en.ts b/src/qt/locale/bitcoin_en.ts index 20cebb3..a8f6a60 100644 --- a/src/qt/locale/bitcoin_en.ts +++ b/src/qt/locale/bitcoin_en.ts @@ -2350,8 +2350,8 @@ Address: %4 - Disable sync checkpoints (default: 0) - Disable sync checkpoints (default: 0) + Sync checkpoints policy (default: strict) + Sync checkpoints policy (default: strict) diff --git a/src/qt/locale/bitcoin_ru.ts b/src/qt/locale/bitcoin_ru.ts index 66fe88b..6ef6a75 100644 --- a/src/qt/locale/bitcoin_ru.ts +++ b/src/qt/locale/bitcoin_ru.ts @@ -2362,8 +2362,8 @@ Address: %4 - Disable sync checkpoints (default: 0) - Отключить синхронизированные метки (по умолчанию: 0) + Sync checkpoints policy (default: strict) + Политика синхронизированных меток (по умолчанию: strict) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c47edd5..fae3e45 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -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));