diff --git a/src/hush_bitcoind.h b/src/hush_bitcoind.h index 215181547..15a0ed3fc 100644 --- a/src/hush_bitcoind.h +++ b/src/hush_bitcoind.h @@ -30,7 +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); +extern std::string devtax_scriptpub_for_height(uint32_t nHeight); uint32_t hush_heightstamp(int32_t height); @@ -1550,7 +1550,7 @@ bool hush_appendACscriptpub() if ( didinit ) return didinit; // HUSH doesn't use earlytxid so we do not need this in this function - //ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(height); + //ASSETCHAINS_SCRIPTPUB = devtax_scriptpub_for_height(height); if ( ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] == 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] == 51 ) { CTransaction tx; uint256 blockhash; @@ -1619,7 +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); + ASSETCHAINS_SCRIPTPUB = devtax_scriptpub_for_height(height); if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD != 0 ) { checktoshis = the_commission(pblock,height); @@ -1732,7 +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); + ASSETCHAINS_SCRIPTPUB = devtax_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_globals.h b/src/hush_globals.h index 5b6df753b..00d31f113 100644 --- a/src/hush_globals.h +++ b/src/hush_globals.h @@ -281,33 +281,35 @@ uint64_t hush_current_supply(uint32_t nHeight) 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" - }; +// the number of different devtax addresses/scriptpubs +const uint32_t DEVTAX_NUM = 20; +//TODO: production data +std::string DEVTAX_DATA[DEVTAX_NUM][2] = { +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "76a914941907aa5f85952bc8deff20f1e50aa676a2d8dd88ac"}, +{"RNnG51zYfnHk4dpNdVjjRGZ1RcV4cuMa95", "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) { +std::string devtax_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 @@ -319,14 +321,37 @@ std::string scriptpub_for_height(uint32_t nHeight) { // 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 ]; + return DEVTAX_DATA[ nHeight % DEVTAX_NUM ][1]; } else { - // if this is not HUSH3 or a testchain for HUSH3, return it unchanged - return ASSETCHAINS_SCRIPTPUB; + // 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; } + +// this is only used by getblocktemplate, so it cannot change consensus of +// blocks < DEVTAX_FORK_HEIGHT but it will affect consensus of later blocks +std::string devtax_address_for_height(uint32_t nHeight) { + const std::string legacy_devtax_address = "RHushEyeDm7XwtaTWtyCbjGQumYyV8vMjn"; + 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) { + return DEVTAX_DATA[ nHeight % DEVTAX_NUM ][2]; + } else { + // if this is not HUSH3 or TUSH3, return legacy + return legacy_devtax_address; + } + } + // return default unchanged if we are less than fork height + return legacy_devtax_address; +} diff --git a/src/hush_utils.h b/src/hush_utils.h index 3b1e55e34..e32fbc4e5 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1952,7 +1952,7 @@ 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, + // we do not want to change the magic of HUSH3 mainnet so we do not call devtax_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 diff --git a/src/miner.cpp b/src/miner.cpp index 2cd5da22b..88efdce87 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -120,7 +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); +extern std::string devtax_scriptpub_for_height(uint32_t nHeight); void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { @@ -631,7 +631,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->vtx[0] = txNew; - ASSETCHAINS_SCRIPTPUB = scriptpub_for_height(nHeight); + ASSETCHAINS_SCRIPTPUB = devtax_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; @@ -821,7 +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); + ASSETCHAINS_SCRIPTPUB = devtax_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 0e0758432..beea9dad7 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -50,6 +50,8 @@ using namespace std; #include "hush_defs.h" extern int32_t ASSETCHAINS_FOUNDERS; +extern std::string devtax_scriptpub_for_height(uint32_t height); +extern std::string devtax_address_for_height(uint32_t height); uint64_t the_commission(const CBlock *pblock,int32_t height); int32_t hush_blockload(CBlock& block,CBlockIndex *pindex); arith_uint256 hush_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); @@ -161,7 +163,6 @@ UniValue getnetworkhashps(const UniValue& params, bool fHelp, const CPubKey& myp } #ifdef ENABLE_MINING -extern bool VERUS_MINTBLOCKS; UniValue getgenerate(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (fHelp || params.size() != 0) @@ -570,9 +571,6 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp " }\n" " ,...\n" " ],\n" -// " \"coinbaseaux\" : { (json object) data that should be included in the coinbase's scriptSig content\n" -// " \"flags\" : \"flags\" (string) \n" -// " },\n" // " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in Satoshis)\n" " \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n" " \"target\" : \"xxxx\", (string) The hash target\n" @@ -801,19 +799,23 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp int index_in_template = i - 1; entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template])); entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template])); + uint32_t nHeight = chainActive.LastTip()->GetHeight()+1; if (tx.IsCoinBase() && coinbasetxn == true ) { // Show founders' reward if it is required if (ASSETCHAINS_FOUNDERS && pblock->vtx[0].vout.size() > 1) { // Correct this if GetBlockTemplate changes the order entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); + entry.push_back(Pair("foundersrewardaddress", devtax_address_for_height(nHeight))); + entry.push_back(Pair("foundersrewardscriptpub", devtax_scriptpub_for_height(nHeight))); } - CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->GetHeight()+1, Params().GetConsensus()); + CAmount nReward = GetBlockSubsidy(nHeight, Params().GetConsensus()); entry.push_back(Pair("coinbasevalue", nReward)); entry.push_back(Pair("required", true)); txCoinbase = entry; - } else + } else { transactions.push_back(entry); + } } UniValue aux(UniValue::VOBJ); @@ -839,7 +841,6 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp, const CPubKey& myp assert(txCoinbase.isObject()); result.push_back(Pair("coinbasetxn", txCoinbase)); } // else { - // result.push_back(Pair("coinbaseaux", aux)); // result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); //} result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); @@ -1037,7 +1038,7 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp, const CPubKey& mypk 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() + // so we don't need to call devtax_scriptpub_for_height() if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_FOUNDERS == 0 && ASSETCHAINS_COMMISSION != 0 )