Merge pull request #6466 from nuttycom/cleanup/params_const_correctness
Improve CChainParams const correctness.
This commit is contained in:
commit
38f7ed3ce4
|
@ -777,14 +777,14 @@ public:
|
|||
};
|
||||
static CRegTestParams regTestParams;
|
||||
|
||||
static CChainParams *pCurrentParams = 0;
|
||||
static const CChainParams* pCurrentParams = nullptr;
|
||||
|
||||
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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<std::string> r = read_lines(temp);
|
||||
EXPECT_EQ(r.size(), 1u);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue