From 9f92bdd7dc136d73d0dbd7b5d245a5cb70bdce88 Mon Sep 17 00:00:00 2001 From: Duke Date: Mon, 19 Jun 2023 09:32:32 -0400 Subject: [PATCH] Decentralized Devtax --- src/hush_bitcoind.h | 5 +++++ src/hush_defs.h | 3 +++ src/hush_globals.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/hush_utils.h | 2 ++ src/miner.cpp | 3 +++ src/rpc/mining.cpp | 2 ++ 6 files changed, 65 insertions(+) diff --git a/src/hush_bitcoind.h b/src/hush_bitcoind.h index b09c756ad..215181547 100644 --- a/src/hush_bitcoind.h +++ b/src/hush_bitcoind.h @@ -30,6 +30,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi bool EnsureWalletIsAvailable(bool avoidException); extern bool fRequestShutdown; extern CScript HUSH_EARLYTXID_SCRIPTPUB; +extern std::string scriptpub_for_height(uint32_t nHeight); uint32_t hush_heightstamp(int32_t height); @@ -1548,6 +1549,8 @@ bool hush_appendACscriptpub() static bool didinit = false; if ( didinit ) return didinit; + // HUSH doesn't use earlytxid so we do not need this in this function + //ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(height); if ( ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] == 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] == 51 ) { CTransaction tx; uint256 blockhash; @@ -1616,6 +1619,7 @@ int64_t hush_checkcommission(CBlock *pblock,int32_t height) if(fDebug) fprintf(stderr,"%s at height=%d\n",__func__,height); int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0; static bool didinit = false; + ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(height); if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 ) { checktoshis = the_commission(pblock,height); @@ -1728,6 +1732,7 @@ int32_t hush_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( failed == 0 && ASSETCHAINS_COMMISSION != 0 ) { if ( height == 1 ) { + ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(height); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 ) { int32_t scriptlen; uint8_t scripthex[10000]; script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0]; diff --git a/src/hush_defs.h b/src/hush_defs.h index 8ae77797e..672d3cec3 100644 --- a/src/hush_defs.h +++ b/src/hush_defs.h @@ -54,6 +54,9 @@ const uint32_t nHushHardforkHeight2 = 245055; // This height begins Hush DPoW from Hush notaries const uint32_t nHushHardforkHeight3 = 340420; +// This height begins Hush Decentralized Devtax +const uint32_t nHushHardforkHeight4 = 99999999; // TODO + const uint32_t nHushHardforkTimestamp = 1580303652; // Jan 29nd 1pm GMT const uint32_t nHushHardforkTimestamp2 = 1594425600; // Jul 11th 12a GMT diff --git a/src/hush_globals.h b/src/hush_globals.h index e307f774c..5b6df753b 100644 --- a/src/hush_globals.h +++ b/src/hush_globals.h @@ -280,3 +280,53 @@ uint64_t hush_current_supply(uint32_t nHeight) //fprintf(stderr,"cur_money %.8f\n",(double)cur_money/COIN); return(cur_money); } + +//TODO: production scriptpubs +std::string DEVTAX_SCRIPTPUBS[20] = { +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac", +"76a914f70a2e3df98d2befba431dfe01d4eaa3e418f68488ac", +"76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac" + }; + +// this is a deterministic consensus-changing function. All miners must be able +// to predict the scriptpub for the next block +std::string scriptpub_for_height(uint32_t nHeight) { + bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; + bool istush3 = strncmp(SMART_CHAIN_SYMBOL, "TUSH3",5) == 0 ? true : false; + // Fork height for HUSH3 mainnet needs to be decided just before code is merged + // Since it requires all full nodes on the network to have enough time to update. + // For testing, we choose an early blockheight so we can observe the value changing + // from the old fixed value to the new values which cycle + const int DEVTAX_FORK_HEIGHT = ishush3 ? nHushHardforkHeight4 : 5; + + // Decentralized devtax is height-activated + if (nHeight >= DEVTAX_FORK_HEIGHT) { + if (ishush3 || istush3) { + // devtax_scriptpubs is an array of length 20 with 20 different scriptpubs + int NUM_SCRIPTPUBS = 20; + return DEVTAX_SCRIPTPUBS[ nHeight % NUM_SCRIPTPUBS ]; + } else { + // if this is not HUSH3 or a testchain for HUSH3, return it unchanged + return ASSETCHAINS_SCRIPTPUB; + } + } + // return default unchanged if we are less than fork height + return ASSETCHAINS_SCRIPTPUB; +} diff --git a/src/hush_utils.h b/src/hush_utils.h index 233028898..3b1e55e34 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1952,6 +1952,8 @@ void hush_args(char *argv0) ASSETCHAINS_SAPLING = 1; // this corresponds to FR address RHushEyeDm7XwtaTWtyCbjGQumYyV8vMjn ASSETCHAINS_SCRIPTPUB = "76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac"; + // we do not want to change the magic of HUSH3 mainnet so we do not call scriptpub_for_height() here, + // instead we call it whenever ASSETCHAINS_SCRIPTPUB is used later on // Over-ride HUSH3 values from CLI params. Changing our blocktime to 75s changes things ASSETCHAINS_REWARD[0] = 0; diff --git a/src/miner.cpp b/src/miner.cpp index ee85a52eb..2cd5da22b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,6 +120,7 @@ public: extern int8_t ASSETCHAINS_ADAPTIVEPOW; extern uint32_t ASSETCHAINS_RANDOMX; extern bool fRandomXDebug; +extern std::string scriptpub_for_height(uint32_t nHeight); void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { @@ -630,6 +631,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->vtx[0] = txNew; + ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(nHeight); if ( nHeight > 1 && SMART_CHAIN_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD != 0) && (commission= the_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; @@ -819,6 +821,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len; // fprintf(stderr,"%s: with nHeight=%d\n", __func__, nHeight); + ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(nHeight); if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index f422f9287..0e0758432 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1036,6 +1036,8 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp, const CPubKey& mypk UniValue result(UniValue::VOBJ); result.push_back(Pair("miner", ValueFromAmount(nReward))); + // the value of ASSETCHAINS_SCRIPTPUB is not used here, this is just a check if it exists + // so we don't need to call scriptpub_for_height() if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_FOUNDERS == 0 && ASSETCHAINS_COMMISSION != 0 )