diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 15925feee..31ee16b3e 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/coins.cpp b/src/coins.cpp index 30286f904..2fd175759 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -529,7 +529,10 @@ unsigned int CCoinsViewCache::GetCacheSize() const { const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input) const { const CCoins* coins = AccessCoins(input.prevout.hash); + fprintf(stderr, "GetOutputFor: input=%s", input.ToString().c_str()); + fprintf(stderr, "GetOutputFor: prevout n=%d,txid=%s\n", input.prevout.n, input.prevout.hash.ToString().c_str()); assert(coins && coins->IsAvailable(input.prevout.n)); + fprintf(stderr, "GetOutputFor: IsAvailable\n"); return coins->vout[input.prevout.n]; } diff --git a/src/coins.h b/src/coins.h index 5e48449af..b5023dbda 100644 --- a/src/coins.h +++ b/src/coins.h @@ -245,6 +245,9 @@ public: //! check whether a particular output is still available bool IsAvailable(unsigned int nPos) const { + //fprintf(stderr,"IsAvailable(nPos=%d), vout.size()=%li, vout[%d].IsNull()=%d", nPos, vout.size(), nPos, vout[nPos].IsNull() ); + //fprintf(stderr,"IsAvailable(nPos=%d), vout.size()=%li, vout[%d]=%d", nPos, vout.size(), nPos, vout[nPos] ); + fprintf(stderr,"IsAvailable(nPos=%d), vout.size()=%li", nPos, vout.size() ); return (nPos < vout.size() && !vout[nPos].IsNull()); } 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 cfe59056b..5aa7ad531 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -3,7 +3,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 - /****************************************************************************** * 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 448856549..a27bb59f2 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 deb06d382..1204b336b 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 98f34227c..b48537f2b 100644 --- a/src/hush_notary.h +++ b/src/hush_notary.h @@ -196,14 +196,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 a80e191e5..665338716 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 The Hush 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 /****************************************************************************** @@ -949,9 +949,7 @@ int32_t dragon_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian case 4: *(uint32_t *)endianedp = (uint32_t)x; break; case 8: *(uint64_t *)endianedp = (uint64_t)x; break; } - } - else - { + } else { x = 0; switch ( len ) { @@ -1443,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); @@ -1464,11 +1462,11 @@ uint16_t komodo_userpass(char *userpass,char *symbol) return(port); } -uint32_t komodo_assetmagic(char *symbol,uint64_t supply,uint8_t *extraptr,int32_t extralen) +#define HUSH_MAGIC 0xd394d36e + +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,"KMD") == 0 ) - return(0x8de4eef9); len = dragon_rwnum(1,&buf[len],sizeof(supply),(void *)&supply); strcpy((char *)&buf[len],symbol); len += strlen(symbol); @@ -1476,55 +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 (uint64_t)90*1000*1000000 ) { - fprintf(stderr,"-ac_supply must be less than 90 billion\n"); + fprintf(stderr,"-ac_supply must be less than 90 billion, derpz\n"); StartShutdown(); } - fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY); + if(fDebug) + fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY); - ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); + ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); - ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); - ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); - ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); - ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); - ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); - ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0); - //fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); - if ( ASSETCHAINS_CBOPRET != 0 ) - { + ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); + ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); + ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + ASSETCHAINS_CBOPRET = GetArg("-ac_cbopret",0); + ASSETCHAINS_CBMATURITY = GetArg("-ac_cbmaturity",0); + ASSETCHAINS_ADAPTIVEPOW = GetArg("-ac_adaptivepow",0); + if(fDebug) + fprintf(stderr,"ASSETCHAINS_CBOPRET.%llx\n",(long long)ASSETCHAINS_CBOPRET); + if ( ASSETCHAINS_CBOPRET != 0 ) { SplitStr(GetArg("-ac_prices",""), ASSETCHAINS_PRICES); if ( ASSETCHAINS_PRICES.size() > 0 ) ASSETCHAINS_CBOPRET |= 4; @@ -2088,14 +2084,12 @@ void hush_args(char *argv0) StartShutdown(); } - + // HUSH will always be The First Pure Sapling Coin, no Sprout JoinSplits in our history! ;) ASSETCHAINS_SAPLING = GetArg("-ac_sapling", -1); if (ASSETCHAINS_SAPLING == -1) { ASSETCHAINS_OVERWINTER = GetArg("-ac_overwinter", -1); - } - else - { + } else { ASSETCHAINS_OVERWINTER = GetArg("-ac_overwinter", ASSETCHAINS_SAPLING); } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) @@ -2121,9 +2115,7 @@ void hush_args(char *argv0) { ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); - } - else - { + } else { printf("ASSETCHAINS_FOUNDERS_REWARD set to %ld\n", ASSETCHAINS_FOUNDERS_REWARD); } /*else if ( ASSETCHAINS_SELFIMPORT.size() == 0 ) @@ -2132,9 +2124,7 @@ void hush_args(char *argv0) printf("-ac_perc must be set with -ac_pubkey\n"); }*/ } - } - else - { + } else { if ( ASSETCHAINS_COMMISSION != 0 ) { ASSETCHAINS_COMMISSION = 0; @@ -2147,23 +2137,26 @@ void hush_args(char *argv0) } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || KOMODO_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 || nonz > 0 || ASSETCHAINS_CCLIB.size() > 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 || ASSETCHAINS_NOTARY_PAY[0] != 0 || ASSETCHAINS_BLOCKTIME != 60 || ASSETCHAINS_CBOPRET != 0 || Mineropret.size() != 0 || (ASSETCHAINS_NK[0] != 0 && ASSETCHAINS_NK[1] != 0) || HUSH_SNAPSHOT_INTERVAL != 0 || ASSETCHAINS_EARLYTXIDCONTRACT != 0 || ASSETCHAINS_CBMATURITY != 0 || ASSETCHAINS_ADAPTIVEPOW != 0 ) { - fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); + if(fDebug) + fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; // if we have one era, this should create the same data structure as it used to, same if we increase _MAX_ERAS for ( int i = 0; i <= ASSETCHAINS_LASTERA; i++ ) { - printf("ERA%u: end.%llu reward.%llu halving.%llu decay.%llu notarypay.%llu\n", i, + if (fDebug) { + printf("ERA%u: end.%llu reward.%llu halving.%llu decay.%llu notarypay.%llu\n", i, (long long)ASSETCHAINS_ENDSUBSIDY[i], (long long)ASSETCHAINS_REWARD[i], (long long)ASSETCHAINS_HALVING[i], (long long)ASSETCHAINS_DECAY[i], (long long)ASSETCHAINS_NOTARY_PAY[i]); + } - // TODO: Verify that we don't overrun extrabuf here, which is a 256 byte buffer + // TODO: Verify that we don't overrun extrabuf here, which is a 32KB byte buffer extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY[i]),(void *)&ASSETCHAINS_ENDSUBSIDY[i]); extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD[i]),(void *)&ASSETCHAINS_REWARD[i]); extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING[i]),(void *)&ASSETCHAINS_HALVING[i]); @@ -2205,6 +2198,7 @@ void hush_args(char *argv0) extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(tmp),(void *)&tmp); if ( ASSETCHAINS_FOUNDERS > 1 ) extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); + // NOTE: Hush does not use this, we use -ac_script to implement our FR -- Duke if ( ASSETCHAINS_FOUNDERS_REWARD != 0 ) { fprintf(stderr, "set founders reward.%lld\n",(long long)ASSETCHAINS_FOUNDERS_REWARD); @@ -2232,9 +2226,10 @@ void hush_args(char *argv0) extraptr[extralen++] = 'c'; if ( ASSETCHAINS_MARMARA != 0 ) extraptr[extralen++] = ASSETCHAINS_MARMARA; -fprintf(stderr,"extralen.%d before disable bits\n",extralen); - if ( nonz > 0 ) - { + + fprintf(stderr,"extralen.%d before disable bits\n",extralen); + + if ( nonz > 0 ) { memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); extralen += sizeof(disablebits); } @@ -2247,8 +2242,12 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); } fprintf(stderr," <- CCLIB name\n"); } - if ( ASSETCHAINS_BLOCKTIME != 60 ) + // is this not being run correctly? + if ( ASSETCHAINS_BLOCKTIME != 60 ) { extralen += dragon_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_BLOCKTIME),(void *)&ASSETCHAINS_BLOCKTIME); + fprintf(stderr,"%s: ASSETCHAINS_BLOCKTIME=%d, extralen=%d\n", __func__, ASSETCHAINS_BLOCKTIME, extralen); + } + if ( Mineropret.size() != 0 ) { for (i=0; i= 0 && baseid < 32 ) { //komodo_maxallowed(baseid); - printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); + if(fDebug) + printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); } if ( ASSETCHAINS_CC >= HUSH_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; if ( KOMODO_BIT63SET(MAX_MONEY) != 0 ) MAX_MONEY = KOMODO_MAXNVALUE; - fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); + if(fDebug) + fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,SMART_CHAIN_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - uint16_t tmpport = komodo_port(SMART_CHAIN_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); + uint16_t tmpport = hush_port(SMART_CHAIN_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); if ( GetArg("-port",0) != 0 ) { ASSETCHAINS_P2PPORT = GetArg("-port",0); + if(fDebug) fprintf(stderr,"set p2pport.%u\n",ASSETCHAINS_P2PPORT); } else ASSETCHAINS_P2PPORT = tmpport; @@ -2343,8 +2345,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); extern int COINBASE_MATURITY; if ( strcmp(SMART_CHAIN_SYMBOL,"KMD") == 0 ) { - fprintf(stderr,"cant have assetchain named KMD\n"); - StartShutdown(); + fprintf(stderr,"Oh hellz yezzz\n"); } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,SMART_CHAIN_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; @@ -2371,6 +2372,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); magicstr[8] = 0; #ifndef FROM_CLI sprintf(fname,"%s_7776",SMART_CHAIN_SYMBOL); + // TODO: why are we doing this again? Most users do not need this if ( (fp= fopen(fname,"wb")) != 0 ) { int8_t notarypay = 0; @@ -2394,9 +2396,7 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); fprintf(stderr,"smart utxo CC contract %d will activate at height.%d\n",(int32_t)ccEnablesHeight[0],(int32_t)ccEnablesHeight[1]); } } - } - else - { + } else { char fname[512],username[512],password[4096]; int32_t iter; FILE *fp; ASSETCHAINS_P2PPORT = 7770; ASSETCHAINS_RPCPORT = 7771; @@ -2439,75 +2439,20 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); //fprintf(stderr,"(%s) port.%u chain params initialized\n",SMART_CHAIN_SYMBOL,BITCOIND_RPCPORT); - // Set cc enables for all existing ac_cc chains here. - if ( strcmp("AXO",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("CCL",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - CCENABLE(EVAL_TOKENS); - CCENABLE(EVAL_HEIR); - } - if ( strcmp("COQUI",SMART_CHAIN_SYMBOL) == 0 ) - { - CCDISABLEALL; - CCENABLE(EVAL_DICE); - CCENABLE(EVAL_CHANNELS); - CCENABLE(EVAL_ORACLES); - CCENABLE(EVAL_ASSETS); - CCENABLE(EVAL_TOKENS); - } - if ( strcmp("DION",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - - if ( strcmp("EQL",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("ILN",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("OUR",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("ZEXO",SMART_CHAIN_SYMBOL) == 0 ) - { - // No CCs used on this chain yet. - CCDISABLEALL; - } - if ( strcmp("SEC",SMART_CHAIN_SYMBOL) == 0 ) - { - CCDISABLEALL; - CCENABLE(EVAL_ASSETS); - CCENABLE(EVAL_TOKENS); - CCENABLE(EVAL_ORACLES); - } - if ( strcmp("KMDICE",SMART_CHAIN_SYMBOL) == 0 ) - { - CCDISABLEALL; - CCENABLE(EVAL_FAUCET); - CCENABLE(EVAL_DICE); - CCENABLE(EVAL_ORACLES); + // Set custom cc rulse for chains here + if ( strcmp("HUSH3",SMART_CHAIN_SYMBOL) == 0 ) { + // Disable all CC's + if(GetArg("-ac_disable_cc",false)) { + CCDISABLEALL; + } } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); HUSH_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); - if ( SMART_CHAIN_SYMBOL[0] == 0 || strcmp(SMART_CHAIN_SYMBOL,"SUPERNET") == 0 || strcmp(SMART_CHAIN_SYMBOL,"DEX") == 0 || strcmp(SMART_CHAIN_SYMBOL,"COQUI") == 0 || strcmp(SMART_CHAIN_SYMBOL,"PIRATE") == 0 || strcmp(SMART_CHAIN_SYMBOL,"KMDICE") == 0 ) + if ( strcmp(SMART_CHAIN_SYMBOL,"CA333LIES") == 0 ) HUSH_EXTRASATOSHI = 1; } -void komodo_nameset(char *symbol,char *dest,char *source) +void hush_nameset(char *symbol,char *dest,char *source) { if ( source[0] == 0 ) { strcpy(symbol,(char *)"HUSH3"); @@ -2521,7 +2466,7 @@ void komodo_nameset(char *symbol,char *dest,char *source) struct hush_state *hush_stateptrget(char *base) { int32_t baseid; - if ( base == 0 || base[0] == 0 || strcmp(base,(char *)"KMD") == 0 ) + if ( base == 0 || base[0] == 0 || strcmp(base,(char *)"KYCSELLOUTS") == 0 ) return(&KOMODO_STATES[33]); else if ( (baseid= komodo_baseid(base)) >= 0 ) return(&KOMODO_STATES[baseid+1]); @@ -2531,7 +2476,7 @@ struct hush_state *hush_stateptrget(char *base) struct hush_state *hush_stateptr(char *symbol,char *dest) { int32_t baseid; - komodo_nameset(symbol,dest,SMART_CHAIN_SYMBOL); + hush_nameset(symbol,dest,SMART_CHAIN_SYMBOL); return(hush_stateptrget(symbol)); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5f0c6c6b2..febeef177 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1005,7 +1005,7 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) 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 i,j,notaryid=0,minerid,limit,nid; uint8_t destpubkey33[33]; - komodo_chosennotary(¬aryid,height,pubkey33,blocktimes[0]); + hush_chosennotary(¬aryid,height,pubkey33,blocktimes[0]); if ( height >= 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 771300b7d..356deb613 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -1,8 +1,7 @@ -// Copyright (c) 2016 The Zcash developers // Copyright (c) 2016-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 b1e46f5df..0db996bbc 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 c0372d549..ec35a1148 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 2b3b6b3af..6590ed9b7 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 cf2d818d8..a0eb5418f 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()