From 1021455845b12a1e3095fed16b5e56f940e34a96 Mon Sep 17 00:00:00 2001 From: miketout Date: Thu, 11 Oct 2018 14:23:14 -0700 Subject: [PATCH] Fix negative height issues for pruning cheat lists --- src/chainparams.cpp | 16 +--------------- src/cheatcatcher.cpp | 4 ++-- src/consensus/upgrades.cpp | 4 ++++ src/komodo_globals.h | 3 +-- src/komodo_utils.h | 4 +++- src/main.cpp | 3 ++- src/miner.cpp | 14 ++++++++++++++ src/wallet-utility.cpp | 2 +- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 52ea0fa0b..792521cb2 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -267,21 +267,6 @@ void *chainparams_commandline(void *ptr) mainParams.consensus.nLwmaPOSAjustedWeight = 46531; } - if (VERUS_CHEATCATCHER.size() == 77) - { - // if we are supposed to catch stake cheaters, there must be a valid sapling parameter, store the Sapling address here - extern boost::optional cheatCatcher; - libzcash::PaymentAddress addr = DecodePaymentAddress(mapArgs["-cheatcatcher"]); - if (IsValidPaymentAddress(addr)) - { - cheatCatcher = boost::get(addr); - } - else - { - fprintf(stderr, "-cheatcatcher parameter is invalid Sapling payment address"); - } - } - // only require coinbase protection on Verus from the Komodo family of coins if (strcmp(ASSETCHAINS_SYMBOL,"VRSC") == 0) { @@ -734,6 +719,7 @@ bool SelectParamsFromCommandLine() return false; SelectParams(network); + return true; } diff --git a/src/cheatcatcher.cpp b/src/cheatcatcher.cpp index 3bac5413b..4008c34a2 100644 --- a/src/cheatcatcher.cpp +++ b/src/cheatcatcher.cpp @@ -23,11 +23,11 @@ boost::optional cheatCatcher; uint32_t CCheatList::Prune(uint32_t height) { - uint32_t count; + uint32_t count = 0; pair::iterator, multimap::iterator> range; vector toPrune; - if (NetworkUpgradeActive(height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) + if (height > 0 && NetworkUpgradeActive(height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { LOCK(cs_cheat); for (auto it = orderedCheatCandidates.begin(); it != orderedCheatCandidates.end() && it->second.height <= height; it--) diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index 04be05cdf..5f484e949 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -38,6 +38,10 @@ UpgradeState NetworkUpgradeState( const Consensus::Params& params, Consensus::UpgradeIndex idx) { + if (nHeight < 0) + { + printf("height: %d", nHeight); + } assert(nHeight >= 0); assert(idx >= Consensus::BASE_SPROUT && idx < Consensus::MAX_NETWORK_UPGRADES); auto nActivationHeight = params.vUpgrades[idx].nActivationHeight; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 14d86d956..ddea32be7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,10 +46,9 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = 0,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; +std::string VERUS_CHEATCATCHER, NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; bool VERUS_MINTBLOCKS; -std::string VERUS_CHEATCATCHER; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8fde211b0..f3496b132 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1645,6 +1645,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; +extern std::string VERUS_CHEATCATCHER; void komodo_args(char *argv0) { @@ -1661,7 +1662,8 @@ void komodo_args(char *argv0) else KOMODO_MININGTHREADS = 0; VERUS_MINTBLOCKS = GetBoolArg("-mint", false); - VERUS_CHEATCATCHER = mapArgs["-cheatcatcher"].size(); + + VERUS_CHEATCATCHER = GetArg("-cheatcatcher", ""); if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); diff --git a/src/main.cpp b/src/main.cpp index 4fff65c2b..9dae7d323 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5005,7 +5005,8 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo // when we succeed here, we prune all cheat candidates in the cheat list to 250 blocks ago, as they should be used or not // useful by then - cheatList.Prune(height - 250); + if ((height - 250) > 1) + cheatList.Prune(height - 250); return true; } diff --git a/src/miner.cpp b/src/miner.cpp index 80e89da5e..f075498b6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1876,6 +1876,20 @@ void static BitcoinMiner() void GenerateBitcoins(bool fGenerate, int nThreads) #endif { + // if we are supposed to catch stake cheaters, there must be a valid sapling parameter, we need it at + // initialization, and this is the first time we can get it. store the Sapling address here + extern boost::optional cheatCatcher; + extern std::string VERUS_CHEATCATCHER; + libzcash::PaymentAddress addr = DecodePaymentAddress(VERUS_CHEATCATCHER); + if (VERUS_CHEATCATCHER.size() > 0 && IsValidPaymentAddress(addr)) + { + cheatCatcher = boost::get(addr); + } + else + { + fprintf(stderr, "-cheatcatcher parameter is invalid Sapling payment address"); + } + static boost::thread_group* minerThreads = NULL; if (nThreads < 0) diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index e9dd9045f..c10459b0f 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -24,7 +24,7 @@ int32_t VERUS_BLOCK_POSUNITS = 1000; int32_t ASSETCHAINS_OVERWINTER = 227520 - 120; int32_t ASSETCHAINS_SAPLING = 227520; boost::optional cheatCatcher; -std::string VERUS_CHEATCATCHER; +std::string VERUS_CHEATCATCHER = ""; unsigned int MAX_BLOCK_SIGOPS = 20000;