diff --git a/src/chainparams.cpp b/src/chainparams.cpp index e7a96a42a..3b3cce6b3 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -777,14 +777,14 @@ public: }; static CRegTestParams regTestParams; -static CChainParams *pCurrentParams = 0; +static const CChainParams* pCurrentParams = nullptr; -const CChainParams &Params() { +const CChainParams& Params() { assert(pCurrentParams); return *pCurrentParams; } -CChainParams& Params(const std::string& chain) +const CChainParams& Params(const std::string& chain) { if (chain == CBaseChainParams::MAIN) return mainParams; diff --git a/src/chainparams.h b/src/chainparams.h index 74a1323fb..632c4c486 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -128,7 +128,7 @@ const CChainParams &Params(); /** * @returns CChainParams for the given BIP70 chain name. */ -CChainParams& Params(const std::string& chain); +const CChainParams& Params(const std::string& chain); /** * Sets the params returned by Params() to those for the given BIP70 chain name. diff --git a/src/deprecation.cpp b/src/deprecation.cpp index 1dd4c4fe1..28df90062 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -9,7 +9,6 @@ #include "init.h" #include "ui_interface.h" #include "util/system.h" -#include "chainparams.h" // Flags that enable deprecated functionality. bool fEnableGbtOldHashes = true; @@ -34,10 +33,9 @@ int64_t EstimatedNodeDeprecationTime(const CClock& clock, int nHeight) { return clock.GetTime() + (blocksToDeprecation * Consensus::POST_BLOSSOM_POW_TARGET_SPACING); } -void EnforceNodeDeprecation(int nHeight, bool forceLogging, bool fThread) { - +void EnforceNodeDeprecation(const CChainParams& params, int nHeight, bool forceLogging, bool fThread) { // Do not enforce deprecation in regtest or on testnet - std::string networkID = Params().NetworkIDString(); + std::string networkID = params.NetworkIDString(); if (networkID != "main") return; int blocksToDeprecation = DEPRECATION_HEIGHT - nHeight; diff --git a/src/deprecation.h b/src/deprecation.h index 3e939a837..60f0506ad 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -5,6 +5,7 @@ #ifndef ZCASH_DEPRECATION_H #define ZCASH_DEPRECATION_H +#include "chainparams.h" #include "consensus/params.h" #include "util/time.h" @@ -78,7 +79,7 @@ int64_t EstimatedNodeDeprecationTime(const CClock& clock, int nHeight); * * fThread means run -alertnotify in a free-running thread. */ -void EnforceNodeDeprecation(int nHeight, bool forceLogging=false, bool fThread=true); +void EnforceNodeDeprecation(const CChainParams& params, int nHeight, bool forceLogging=false, bool fThread=true); /** * Checks config options for enabling and/or disabling of deprecated diff --git a/src/gtest/test_deprecation.cpp b/src/gtest/test_deprecation.cpp index fe8e1e25f..4c1ccd3bf 100644 --- a/src/gtest/test_deprecation.cpp +++ b/src/gtest/test_deprecation.cpp @@ -39,7 +39,7 @@ protected: uiInterface.ThreadSafeMessageBox.disconnect_all_slots(); uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, &mock_, _1, _2, _3)); SelectParams(CBaseChainParams::MAIN); - + } void TearDown() override { @@ -64,61 +64,61 @@ protected: TEST_F(DeprecationTest, NonDeprecatedNodeKeepsRunning) { EXPECT_FALSE(ShutdownRequested()); - EnforceNodeDeprecation(DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT - 1); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT - 1); EXPECT_FALSE(ShutdownRequested()); } TEST_F(DeprecationTest, NodeNearDeprecationIsWarned) { EXPECT_FALSE(ShutdownRequested()); EXPECT_CALL(mock_, ThreadSafeMessageBox(::testing::_, "", CClientUIInterface::MSG_WARNING)); - EnforceNodeDeprecation(DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT); EXPECT_FALSE(ShutdownRequested()); } TEST_F(DeprecationTest, NodeNearDeprecationWarningIsNotDuplicated) { EXPECT_FALSE(ShutdownRequested()); - EnforceNodeDeprecation(DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT + 1); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT + 1); EXPECT_FALSE(ShutdownRequested()); } TEST_F(DeprecationTest, NodeNearDeprecationWarningIsRepeatedOnStartup) { EXPECT_FALSE(ShutdownRequested()); EXPECT_CALL(mock_, ThreadSafeMessageBox(::testing::_, "", CClientUIInterface::MSG_WARNING)); - EnforceNodeDeprecation(DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT + 1, true); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT + 1, true); EXPECT_FALSE(ShutdownRequested()); } TEST_F(DeprecationTest, DeprecatedNodeShutsDown) { EXPECT_FALSE(ShutdownRequested()); EXPECT_CALL(mock_, ThreadSafeMessageBox(::testing::_, "", CClientUIInterface::MSG_ERROR)); - EnforceNodeDeprecation(DEPRECATION_HEIGHT); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT); EXPECT_TRUE(ShutdownRequested()); } TEST_F(DeprecationTest, DeprecatedNodeErrorIsNotDuplicated) { EXPECT_FALSE(ShutdownRequested()); - EnforceNodeDeprecation(DEPRECATION_HEIGHT + 1); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT + 1); EXPECT_TRUE(ShutdownRequested()); } TEST_F(DeprecationTest, DeprecatedNodeErrorIsRepeatedOnStartup) { EXPECT_FALSE(ShutdownRequested()); EXPECT_CALL(mock_, ThreadSafeMessageBox(::testing::_, "", CClientUIInterface::MSG_ERROR)); - EnforceNodeDeprecation(DEPRECATION_HEIGHT + 1, true); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT + 1, true); EXPECT_TRUE(ShutdownRequested()); } TEST_F(DeprecationTest, DeprecatedNodeIgnoredOnRegtest) { SelectParams(CBaseChainParams::REGTEST); EXPECT_FALSE(ShutdownRequested()); - EnforceNodeDeprecation(DEPRECATION_HEIGHT+1); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT+1); EXPECT_FALSE(ShutdownRequested()); } TEST_F(DeprecationTest, DeprecatedNodeIgnoredOnTestnet) { SelectParams(CBaseChainParams::TESTNET); EXPECT_FALSE(ShutdownRequested()); - EnforceNodeDeprecation(DEPRECATION_HEIGHT+1); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT+1); EXPECT_FALSE(ShutdownRequested()); } @@ -129,7 +129,7 @@ TEST_F(DeprecationTest, AlertNotify) { mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string(); EXPECT_CALL(mock_, ThreadSafeMessageBox(::testing::_, "", CClientUIInterface::MSG_WARNING)); - EnforceNodeDeprecation(DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT, false, false); + EnforceNodeDeprecation(Params(), DEPRECATION_HEIGHT - DEPRECATION_WARN_LIMIT, false, false); std::vector r = read_lines(temp); EXPECT_EQ(r.size(), 1u); diff --git a/src/main.cpp b/src/main.cpp index 5daaf90cb..430c75bd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4121,7 +4121,7 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams, // Increment the count of `ConnectTip` calls. nConnectedSequence += 1; - EnforceNodeDeprecation(pindexNew->nHeight); + EnforceNodeDeprecation(chainparams, pindexNew->nHeight); int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); @@ -5676,7 +5676,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip())); - EnforceNodeDeprecation(chainActive.Height(), true); + EnforceNodeDeprecation(chainparams, chainActive.Height(), true); return true; }