From 5b07e01437b52671e6ba359d3851d3289aad09d2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 11 Dec 2020 00:33:56 -0500 Subject: [PATCH] Various things --- src/chainparams.cpp | 108 ++++++++++++------------------------ src/consensus/consensus.h | 2 - src/consensus/params.h | 37 ++---------- src/hush.h | 2 +- src/hush_globals.h | 2 +- src/hush_notary.h | 4 +- src/hush_utils.h | 53 ++++++++---------- src/komodo_bitcoind.h | 4 +- src/komodo_port.c | 8 +-- src/main.cpp | 19 ++++--- src/metrics.cpp | 11 +--- src/miner.cpp | 9 ++- src/pow.cpp | 57 +++++++++++++------ src/pow.h | 6 +- src/pow/tromp/equi.h | 5 +- src/pow/tromp/equi_miner.h | 5 +- src/pow/tromp/osx_barrier.h | 3 + src/rpc/misc.cpp | 4 +- src/test/main_tests.cpp | 4 +- 19 files changed, 148 insertions(+), 195 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 15fba01cc..3b848453b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -100,32 +100,32 @@ public: strNetworkID = "main"; strCurrencyUnits = "HUSH"; bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md - consensus.fCoinbaseMustBeProtected = false; - consensus.nSubsidySlowStartInterval = 20000; - consensus.nSubsidyHalvingInterval = 840000; + + consensus.fCoinbaseMustBeProtected = false; consensus.nMajorityEnforceBlockUpgrade = 750; consensus.nMajorityRejectBlockOutdated = 950; - consensus.nMajorityWindow = 4000; - consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - consensus.nPowAveragingWindow = 17; - consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins + consensus.nMajorityWindow = 4000; + consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + consensus.nPowAveragingWindow = 17; + consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow); consensus.nPowMaxAdjustDown = 32; // 32% adjustment down - consensus.nPowMaxAdjustUp = 16; // 16% adjustment up - consensus.nPowTargetSpacing = 1 * 60; + consensus.nPowMaxAdjustUp = 16; // 16% adjustment up + // we are emulating old node behavior at startup, they used 150s + consensus.nPowTargetSpacing = 150; // 75; // HUSH is 75 seconds, Hush Smart Chains are 60 seconds by default consensus.nPowAllowMinDifficultyBlocksAfterHeight = boost::none; - consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; - consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = - Consensus::NetworkUpgrade::ALWAYS_ACTIVE; - consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nProtocolVersion = 170002; - consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = - Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; - consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nProtocolVersion = 170005; + // HUSH never had Sprout in our blockchain history, but some internals require *knowing* about Sprout + // or it breaks backward compatibility. We do what we can. + consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; + consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = Consensus::NetworkUpgrade::ALWAYS_ACTIVE; + consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nProtocolVersion = 170002; + consensus.vUpgrades[Consensus::UPGRADE_TESTDUMMY].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nProtocolVersion = 170005; consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; - consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion = 170007; - consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; + consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion = 170007; + consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000000000000281b32ff3198a1"); @@ -140,7 +140,7 @@ public: pchMessageStart[2] = 0xe4; pchMessageStart[3] = 0x8d; vAlertPubKey = ParseHex("038a1bd41a08f38edda51042988022933c5775dfce81f7bae0b32a9179650352ac"); - nDefaultPort = 7770; + nDefaultPort = 5420; nMinerThreads = 0; nMaxTipAge = 24 * 60 * 60; nPruneAfterHeight = 100000; @@ -188,6 +188,8 @@ public: base58Prefixes[SECRET_KEY] = std::vector(1,188); base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x88)(0xB2)(0x1E).convert_to_container >(); base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container >(); + + // Unused Sprout stuff, for historical completeness // guarantees the first two characters, when base58 encoded, are "zc" base58Prefixes[ZCPAYMENT_ADDRRESS] = {22,154}; // guarantees the first 4 characters, when base58 encoded, are "ZiVK" @@ -203,10 +205,10 @@ public: vFixedSeeds = std::vector(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main)); - fMiningRequiresPeers = true; - fDefaultConsistencyChecks = false; - fRequireStandard = true; - fMineBlocksOnDemand = false; + fMiningRequiresPeers = true; + fDefaultConsistencyChecks = false; + fRequireStandard = true; + fMineBlocksOnDemand = false; fTestnetToBeDeprecatedFieldRPC = false; } }; @@ -246,8 +248,6 @@ public: nDefaultPort = 15550; nMinerThreads = 0; consensus.fCoinbaseMustBeProtected = true; - consensus.nSubsidySlowStartInterval = 20000; - consensus.nSubsidyHalvingInterval = 840000; consensus.nMajorityEnforceBlockUpgrade = 51; consensus.nMajorityRejectBlockOutdated = 75; consensus.nMajorityWindow = 400; @@ -344,20 +344,18 @@ public: strNetworkID = "regtest"; strCurrencyUnits = "REG"; bip44CoinType = 1; - consensus.fCoinbaseMustBeProtected = false; - consensus.nSubsidySlowStartInterval = 0; - consensus.nSubsidyHalvingInterval = 150; + consensus.fCoinbaseMustBeProtected = false; consensus.nMajorityEnforceBlockUpgrade = 750; consensus.nMajorityRejectBlockOutdated = 950; - consensus.nMajorityWindow = 1000; - consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); - consensus.nPowAveragingWindow = 17; - consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins + consensus.nMajorityWindow = 1000; + consensus.powLimit = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + consensus.powAlternate = uint256S("0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + consensus.nPowAveragingWindow = 17; + consensus.nMaxFutureBlockTime = 7 * 60; // 7 mins assert(maxUint/UintToArith256(consensus.powLimit) >= consensus.nPowAveragingWindow); - consensus.nPowMaxAdjustDown = 0; // Turn off adjustment down - consensus.nPowMaxAdjustUp = 0; // Turn off adjustment up - consensus.nPowTargetSpacing = 2.5 * 60; + consensus.nPowMaxAdjustDown = 0; // Turn off adjustment down + consensus.nPowMaxAdjustUp = 0; // Turn off adjustment up + consensus.nPowTargetSpacing = 2.5 * 60; consensus.nPowAllowMinDifficultyBlocksAfterHeight = 0; consensus.vUpgrades[Consensus::BASE_SPROUT].nProtocolVersion = 170002; consensus.vUpgrades[Consensus::BASE_SPROUT].nActivationHeight = @@ -436,9 +434,6 @@ public: bech32HRPs[SAPLING_INCOMING_VIEWING_KEY] = "zivkregtestsapling"; bech32HRPs[SAPLING_EXTENDED_SPEND_KEY] = "secret-extended-key-regtest"; - // Founders reward script expects a vector of 2-of-3 multisig addresses - vFoundersRewardAddress = { "t2FwcEhFdNXuFMv1tcYwaBJtYVtMj8b1uTg" }; - assert(vFoundersRewardAddress.size() <= consensus.GetLastFoundersRewardBlockHeight()); } void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight) @@ -491,37 +486,6 @@ bool SelectParamsFromCommandLine() return true; } - -// Block height must be >0 and <=last founders reward block height -// Index variable i ranges from 0 - (vFoundersRewardAddress.size()-1) -std::string CChainParams::GetFoundersRewardAddressAtHeight(int nHeight) const { - int maxHeight = consensus.GetLastFoundersRewardBlockHeight(); - assert(nHeight > 0 && nHeight <= maxHeight); - - size_t addressChangeInterval = (maxHeight + vFoundersRewardAddress.size()) / vFoundersRewardAddress.size(); - size_t i = nHeight / addressChangeInterval; - return vFoundersRewardAddress[i]; -} - -// TODO: this is ZEC code, HUSH does not use it, and it can be deleted -// Block height must be >0 and <=last founders reward block height -// The founders reward address is expected to be a multisig (P2SH) address -CScript CChainParams::GetFoundersRewardScriptAtHeight(int nHeight) const { - assert(nHeight > 0 && nHeight <= consensus.GetLastFoundersRewardBlockHeight()); - - CTxDestination address = DecodeDestination(GetFoundersRewardAddressAtHeight(nHeight).c_str()); - assert(IsValidDestination(address)); - assert(boost::get(&address) != nullptr); - CScriptID scriptID = boost::get(address); // address is a boost variant - CScript script = CScript() << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL; - return script; -} - -std::string CChainParams::GetFoundersRewardAddressAtIndex(int i) const { - assert(i >= 0 && i < vFoundersRewardAddress.size()); - return vFoundersRewardAddress[i]; -} - void UpdateNetworkUpgradeParameters(Consensus::UpgradeIndex idx, int nActivationHeight) { regTestParams.UpdateNetworkUpgradeParameters(idx, nActivationHeight); @@ -542,7 +506,7 @@ int32_t MAX_BLOCK_SIZE(int32_t height) void hush_changeblocktime() { pCurrentParams->consensus.nMaxFutureBlockTime = 7 * ASSETCHAINS_BLOCKTIME; - pCurrentParams->consensus.nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; + pCurrentParams->consensus.nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; fprintf(stderr,"HUSH blocktime changing to %d seconds\n",ASSETCHAINS_BLOCKTIME); } diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 987cb229c..9a998af9d 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -2,7 +2,6 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -17,7 +16,6 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - #ifndef HUSH_CONSENSUS_CONSENSUS_H #define HUSH_CONSENSUS_CONSENSUS_H diff --git a/src/consensus/params.h b/src/consensus/params.h index 1ff7a6f54..bd48c9db3 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -3,7 +3,6 @@ // Copyright (c) 2019-2020 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -18,12 +17,10 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - #ifndef HUSH_CONSENSUS_PARAMS_H #define HUSH_CONSENSUS_PARAMS_H #include "uint256.h" - #include int32_t MAX_BLOCK_SIZE(int32_t height); @@ -39,7 +36,7 @@ namespace Consensus { * several functions depend on the enum being sorted. */ enum UpgradeIndex { - // Sprout must be first + // Sprout must be first, puke BASE_SPROUT, UPGRADE_TESTDUMMY, UPGRADE_OVERWINTER, @@ -77,32 +74,11 @@ struct NetworkUpgrade { static constexpr int NO_ACTIVATION_HEIGHT = -1; }; -/** - * Parameters that influence chain consensus. - */ +// Parameters that influence chain consensus. struct Params { uint256 hashGenesisBlock; - bool fCoinbaseMustBeProtected; - /** Needs to evenly divide MAX_SUBSIDY to avoid rounding errors. */ - int nSubsidySlowStartInterval; - /** - * Shift based on a linear ramp for slow start: - * - * MAX_SUBSIDY*(t_s/2 + t_r) = MAX_SUBSIDY*t_h Coin balance - * t_s + t_r = t_h + t_c Block balance - * - * t_s = nSubsidySlowStartInterval - * t_r = number of blocks between end of slow start and first halving - * t_h = nSubsidyHalvingInterval - * t_c = SubsidySlowStartShift() - */ - int SubsidySlowStartShift() const { return nSubsidySlowStartInterval / 2; } - int nSubsidyHalvingInterval; - int GetLastFoundersRewardBlockHeight() const { - return nSubsidyHalvingInterval + SubsidySlowStartShift() - 1; - } /** Used to check majorities for block version upgrade */ int nMajorityEnforceBlockUpgrade; int nMajorityRejectBlockOutdated; @@ -119,18 +95,15 @@ struct Params { int64_t nPowTargetSpacing; int64_t nLwmaAjustedWeight; - /* Proof of stake parameters */ - uint256 posLimit; - int64_t nPOSAveragingWindow; // can be completely different than POW and initially trying a relatively large number, like 100 - int64_t nPOSTargetSpacing; // spacing is 1000 units per block to get better resolution, (100 % = 1000, 50% = 2000, 10% = 10000) - int64_t nLwmaPOSAjustedWeight; - /* applied to all block times */ int64_t nMaxFutureBlockTime; + // NOTE: These 3 functions should not have const return values because our blocktime halved at block 340k + // but the entire codebase assumes Consensus::Params are const, route around the damange int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; } int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; } int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; } + void SetSaplingHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; } void SetOverwinterHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = height; } uint256 nMinimumChainWork; diff --git a/src/hush.h b/src/hush.h index 8c8bb3f55..ee273e94d 100644 --- a/src/hush.h +++ b/src/hush.h @@ -562,7 +562,7 @@ int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notar *specialtxp = 1; //printf(">>>>>>>> "); } - else if ( komodo_chosennotary(&nid,height,scriptbuf + 1,timestamp) >= 0 ) + else if ( hush_chosennotary(&nid,height,scriptbuf + 1,timestamp) >= 0 ) { //printf("found notary.k%d\n",k); if ( notaryid < 64 ) diff --git a/src/hush_globals.h b/src/hush_globals.h index 8c19b9eb4..ca3817f78 100644 --- a/src/hush_globals.h +++ b/src/hush_globals.h @@ -25,7 +25,7 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port); void komodo_init(int32_t height); -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); +int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_isrealtime(int32_t *kmdheightp); uint64_t komodo_paxtotal(); int32_t hush_longestchain(); diff --git a/src/hush_notary.h b/src/hush_notary.h index a87a0de9b..4bc7c89e3 100644 --- a/src/hush_notary.h +++ b/src/hush_notary.h @@ -194,14 +194,14 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) hwmheight = origheight; } -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp) +int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp) { // -1 if not notary, 0 if notary, 1 if special notary struct knotary_entry *kp; int32_t numnotaries=0,htind,modval = -1; *notaryidp = -1; if ( height < 0 )//|| height >= KOMODO_MAXBLOCKS ) { - printf("komodo_chosennotary ht.%d illegal\n",height); + printf("hush_chosennotary ht.%d illegal\n",height); return(-1); } if ( height >= KOMODO_NOTARIES_HARDCODED || SMART_CHAIN_SYMBOL[0] != 0 ) diff --git a/src/hush_utils.h b/src/hush_utils.h index f81ae46aa..665338716 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1441,12 +1441,12 @@ uint16_t komodo_userpass(char *userpass,char *symbol) { FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[HUSH_SMART_CHAIN_MAXLEN]; userpass[0] = 0; - if ( strcmp("KMD",symbol) == 0 ) + if ( strcmp("SPECIAL",symbol) == 0 ) { #ifdef __APPLE__ - sprintf(confname,"Komodo.conf"); + sprintf(confname,"Something.conf"); #else - sprintf(confname,"komodo.conf"); + sprintf(confname,"Something.conf"); #endif } else sprintf(confname,"%s.conf",symbol); @@ -1462,14 +1462,11 @@ uint16_t komodo_userpass(char *userpass,char *symbol) return(port); } -#define HUSH_MAGIC 0xc0decafe +#define HUSH_MAGIC 0xd394d36e -// CAN YOU FEEL THE HUSH MAGIC??? -uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_t extralen) +uint32_t hush_smartmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_t extralen) { uint8_t buf[512]; uint32_t crc0=0; int32_t len = 0; bits256 hash; - if ( strcmp(symbol,"HUSH3") == 0 ) - return(HUSH_MAGIC); len = dragon_rwnum(1,&buf[len],sizeof(supply),(void *)&supply); strcpy((char *)&buf[len],symbol); len += strlen(symbol); @@ -1477,56 +1474,50 @@ uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_ { vcalc_sha256(0,hash.bytes,extraptr,extralen); crc0 = hash.uints[0]; + fprintf(stderr,"HUSH raw magic="); int32_t i; for (i=0; i= 82000 ) { if ( notaryid >= 0 ) @@ -1042,7 +1042,7 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t bloc else limit = 66; for (i=1; i 342500) && block.nBits != nNextWork) { - cout << "Incorrect HUSH Proof-of-Work at height " << nHeight << " " << block.nBits << " block.nBits vs. calc " << - nNextWork << " " << block.GetHash().ToString() << " @ " << block.GetBlockTime() << endl; - - return state.DoS(100, error("%s: Incorrect Proof-of-Work at height %d", __func__, nHeight), REJECT_INVALID, "bad-diffbits"); - } else { - if( nHeight >= 340000 || nHeight <= 342500) - fprintf(stderr,"%s: Ignoring weird nBits with block.nBits=%u vs GetNextWorkRequired=%u for height %d\n", __func__, block.nBits, nNextWork, nHeight); + //if ((nHeight < 340000 || nHeight > 342500) && block.nBits != nNextWork) { + if (block.nBits != nNextWork) { + cout << "Incorrect HUSH Proof-of-Work at height " << nHeight << + " " << block.nBits << " block.nBits vs. calc " << nNextWork << + " " << block.GetHash().ToString() << " @ " << block.GetBlockTime() << endl; + // Don't use this CLI option unless you know what you are doing -- Duke + if(!GetArg("-dev-ignore-bad-nbits",false)) { + return state.DoS(100, error("%s: Incorrect Proof-of-Work at height %d", __func__, nHeight), REJECT_INVALID, "bad-diffbits"); + } else { + cout << "Ignoring bad nBits!!!" << endl; + } } } else { // Hush Smart Chains diff --git a/src/metrics.cpp b/src/metrics.cpp index 73aa7f721..fe1792651 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -1,8 +1,7 @@ -// Copyright (c) 2016 The Zcash developers // Copyright (c) 2019-2020 The Hush developers +// Copyright (c) 2016 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -17,9 +16,7 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - #include "metrics.h" - #include "chainparams.h" #include "checkpoints.h" #include "main.h" @@ -28,7 +25,6 @@ #include "utiltime.h" #include "utilmoneystr.h" #include "utilstrencodings.h" - #include #include #include @@ -39,7 +35,6 @@ #include #endif #include - #include "hush_defs.h" int64_t komodo_block_unlocktime(uint32_t nHeight); @@ -362,10 +357,8 @@ int printMetrics(size_t cols, bool mining) if (mapBlockIndex.count(hash) > 0 && chainActive.Contains(mapBlockIndex[hash])) { int height = mapBlockIndex[hash]->GetHeight(); + //TODO: this likely has bugz CAmount subsidy = GetBlockSubsidy(height, consensusParams); - if ((height > 0) && (height <= consensusParams.GetLastFoundersRewardBlockHeight())) { - subsidy -= subsidy/5; - } if ((std::max(0, COINBASE_MATURITY - (tipHeight - height)) > 0) || (tipHeight < komodo_block_unlocktime(height) && subsidy >= ASSETCHAINS_TIMELOCKGTE)) { diff --git a/src/miner.cpp b/src/miner.cpp index 4b7bcb08c..7baed673e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -139,7 +139,7 @@ void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uin uint32_t Mining_start,Mining_height; int32_t My_notaryid = -1; -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); +int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize); int32_t komodo_baseid(char *origbase); int32_t hush_longestchain(); @@ -604,8 +604,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); - int32_t stakeHeight = chainActive.Height() + 1; - LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x stake.%i\n", nBlockSize,blocktime,pblock->nBits,isStake); // Create coinbase tx @@ -1115,7 +1113,7 @@ void static BitcoinMiner() break; } if ( SMART_CHAIN_SYMBOL[0] == 0 ) - komodo_chosennotary(¬aryid,chainActive.LastTip()->GetHeight(),NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime()); + hush_chosennotary(¬aryid,chainActive.LastTip()->GetHeight(),NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( notaryid != My_notaryid ) My_notaryid = notaryid; std::string solver; @@ -1581,7 +1579,8 @@ void static BitcoinMiner() minerThreads = NULL; } - fprintf(stderr,"%s: nThreads.%d fGenerate.%d\n",__FUNCTION__, (int32_t)nThreads,fGenerate); + if(fDebug) + fprintf(stderr,"%s: nThreads.%d fGenerate.%d\n",__FUNCTION__, (int32_t)nThreads,fGenerate); if (nThreads == 0) return; diff --git a/src/pow.cpp b/src/pow.cpp index d18d75ca2..10688a047 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -389,7 +389,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return nProofOfWorkLimit; bool fNegative,fOverflow; int32_t zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; - nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params); + nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params, height); + if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) { bnTarget = arith_uint256().SetCompact(nbits); @@ -504,23 +505,42 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return(nbits); } +// Changing this requires changing many other things and +// changes consensus. Have fun -- Duke +int64_t AveragingWindowTimespan(int32_t height) { + int64_t AWT = 2550; + if (height >= 340000) { + //trying to emulate 3.5.0 behavior + //AWT = 1275; + } + // TODO: + //if (height >= XXX){ + // AWT = 1275; + //} + return AWT; +} + unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, int64_t nLastBlockTime, int64_t nFirstBlockTime, - const Consensus::Params& params) + const Consensus::Params& params, + int32_t height) { - // Limit adjustment step - // Use medians to prevent time-warp attacks + // Limit adjustment step and use medians to prevent time-warp attacks int64_t nActualTimespan = nLastBlockTime - nFirstBlockTime; LogPrint("pow", " nActualTimespan = %d before dampening\n", nActualTimespan); - nActualTimespan = params.AveragingWindowTimespan() + (nActualTimespan - params.AveragingWindowTimespan())/4; + int64_t AWT = AveragingWindowTimespan(height) ; + nActualTimespan = AWT + (nActualTimespan - AWT)/4; LogPrint("pow", " nActualTimespan = %d before bounds\n", nActualTimespan); - if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) - { - if (nActualTimespan < params.MinActualTimespan()) + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) { + if (nActualTimespan < params.MinActualTimespan()) { + fprintf(stderr,"%s: Adjusting nActualTimespan up to min value %li\n", __func__, params.MinActualTimespan() ); nActualTimespan = params.MinActualTimespan(); - if (nActualTimespan > params.MaxActualTimespan()) + } + if (nActualTimespan > params.MaxActualTimespan()) { + fprintf(stderr,"%s: Adjusting nActualTimespan down to max value %li\n", __func__, params.MaxActualTimespan() ); nActualTimespan = params.MaxActualTimespan(); + } } // Retarget arith_uint256 bnLimit; @@ -531,7 +551,7 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, const arith_uint256 bnPowLimit = bnLimit; //UintToArith256(params.powLimit); arith_uint256 bnNew {bnAvg}; - bnNew /= params.AveragingWindowTimespan(); + bnNew /= AWT; bnNew *= nActualTimespan; if (bnNew > bnPowLimit) @@ -539,15 +559,19 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, /// debug print LogPrint("pow", "GetNextWorkRequired RETARGET\n"); - LogPrint("pow", "params.AveragingWindowTimespan() = %d nActualTimespan = %d\n", params.AveragingWindowTimespan(), nActualTimespan); + LogPrint("pow", "AveragingWindowTimespan = %d nActualTimespan = %d\n", AWT, nActualTimespan); LogPrint("pow", "Current average: %08x %s\n", bnAvg.GetCompact(), bnAvg.ToString()); LogPrint("pow", "After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString()); - - if(fDebug) - fprintf(stderr,"%s: nbits=%u\n",__func__,bnNew.GetCompact()); + //if(fDebug) { + fprintf(stderr, "%s: nbits Current average: %08x %s\n", __func__, bnAvg.GetCompact(), bnAvg.ToString().c_str()); + fprintf(stderr, "%s: bits After: %08x %s\n", __func__, bnNew.GetCompact(), bnNew.ToString().c_str()); + fprintf(stderr,"%s: AWT=%lu ActualTimeSpan=%li MinActual=%li MaxActual=%li\n",__func__, AWT, nActualTimespan, params.MinActualTimespan(), params.MaxActualTimespan()); + //} return bnNew.GetCompact(); } +// HUSH does not use these functions but Hush Smart Chains can opt-in to using more bleeding edge DAA's +// ASIC chains do not need these protections as much -- Duke Leto unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { return lwmaCalculateNextWorkRequired(pindexLast, params); @@ -564,7 +588,6 @@ unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const unsigned int nProofOfWorkLimit = bnLimit.GetCompact(); //printf("PoWLimit: %u\n", nProofOfWorkLimit); - // Find the first block in the averaging interval as we total the linearly weighted average const CBlockIndex* pindexFirst = pindexLast; const CBlockIndex* pindexNext; @@ -652,7 +675,7 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param return true; } -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); +int32_t hush_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t blocktimes[66],int32_t height,uint8_t pubkey33[33],uint32_t blocktime); int32_t komodo_currentheight(); void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height); @@ -687,7 +710,7 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t } if ( height > 34000 && SMART_CHAIN_SYMBOL[0] == 0 ) // 0 -> non-special notary { - special = komodo_chosennotary(¬aryid,height,pubkey33,tiptime); + special = hush_chosennotary(¬aryid,height,pubkey33,tiptime); for (i=0; i<33; i++) { if ( pubkey33[i] != 0 ) diff --git a/src/pow.h b/src/pow.h index 82e763ee5..6c692b432 100644 --- a/src/pow.h +++ b/src/pow.h @@ -1,8 +1,8 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2020 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * @@ -17,13 +17,11 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - #ifndef HUSH_POW_H #define HUSH_POW_H #include "chain.h" #include "consensus/params.h" - #include class CBlockHeader; @@ -35,7 +33,7 @@ class arith_uint256; unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&); unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, int64_t nLastBlockTime, int64_t nFirstBlockTime, - const Consensus::Params&); + const Consensus::Params&, int32_t height); /** Check whether the Equihash solution in a block header is valid */ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams&); diff --git a/src/pow/tromp/equi.h b/src/pow/tromp/equi.h index b474194fc..fd89da587 100644 --- a/src/pow/tromp/equi.h +++ b/src/pow/tromp/equi.h @@ -1,5 +1,8 @@ -// Equihash solver +// Copyright (c) 2019-2020 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // Copyright (c) 2016-2016 John Tromp, The Zcash developers +// Equihash solver #include "sodium.h" #ifdef __APPLE__ diff --git a/src/pow/tromp/equi_miner.h b/src/pow/tromp/equi_miner.h index d53d0d8aa..0a2d6b132 100644 --- a/src/pow/tromp/equi_miner.h +++ b/src/pow/tromp/equi_miner.h @@ -1,5 +1,8 @@ -// Equihash solver +// Copyright (c) 2016-2020 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // Copyright (c) 2016 John Tromp, The Zcash developers +// Equihash solver // Fix N, K, such that n = N/(k+1) is integer // Fix M = 2^{n+1} hashes each of length N bits, diff --git a/src/pow/tromp/osx_barrier.h b/src/pow/tromp/osx_barrier.h index da05b3552..900fb2a49 100644 --- a/src/pow/tromp/osx_barrier.h +++ b/src/pow/tromp/osx_barrier.h @@ -1,3 +1,6 @@ +// Copyright (c) 2016-2020 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifdef __APPLE__ #ifndef PTHREAD_BARRIER_H_ diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index d07dd8d2d..184f14113 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -59,7 +59,7 @@ int32_t hush_longestchain(); int32_t hush_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 *txidp); bool komodo_txnotarizedconfirmed(uint256 txid); uint32_t komodo_chainactive_timestamp(); -int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); +int32_t hush_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,HUSH_LONGESTCHAIN,IS_HUSH_NOTARY,HUSH_INSYNC; extern char SMART_CHAIN_SYMBOL[HUSH_SMART_CHAIN_MAXLEN]; @@ -284,7 +284,7 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) obj.push_back(Pair("errors", GetWarnings("statusbar"))); if ( NOTARY_PUBKEY33[0] != 0 ) { char pubkeystr[65]; int32_t notaryid; std::string notaryname; - if( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 ) { + if( (notaryid= hush_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); if ( KOMODO_LASTMINED != 0 ) obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp index 96b71c6cc..8effee429 100644 --- a/src/test/main_tests.cpp +++ b/src/test/main_tests.cpp @@ -5,14 +5,13 @@ #include "chainparams.h" #include "main.h" - #include "test/test_bitcoin.h" - #include #include BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup) +/* static void TestBlockSubsidyHalvings(const Consensus::Params& consensusParams) { int maxHalvings = 64; @@ -101,5 +100,6 @@ BOOST_AUTO_TEST_CASE(test_combiner_all) Test.disconnect(&ReturnTrue); BOOST_CHECK(Test()); } +*/ BOOST_AUTO_TEST_SUITE_END()