From 05cbc86a009a8ebcf6a5ab7b74ee2465cfea89f0 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 13:43:51 -0400 Subject: [PATCH] Fix bug where GetNextWorkRequired did not know about randomx --- src/hush_defs.h | 2 +- src/miner.cpp | 10 ++++++++++ src/pow.cpp | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/hush_defs.h b/src/hush_defs.h index 4d8bd62b8..c4a0b5425 100644 --- a/src/hush_defs.h +++ b/src/hush_defs.h @@ -568,7 +568,7 @@ extern int32_t ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER, extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD; extern int32_t ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER,ASSETCHAINS_BLOCKTIME; extern uint64_t ASSETCHAINS_TIMELOCKGTE; -extern uint32_t ASSETCHAINS_ALGO,ASSETCHAINS_EQUIHASH,HUSH_INITDONE; +extern uint32_t ASSETCHAINS_ALGO,ASSETCHAINS_EQUIHASH,ASSETCHAINS_RANDOMX, HUSH_INITDONE; extern int32_t HUSH_MININGTHREADS,HUSH_LONGESTCHAIN,ASSETCHAINS_SEED,IS_HUSH_NOTARY,USE_EXTERNAL_PUBKEY,HUSH_CHOSEN_ONE,HUSH_ON_DEMAND,HUSH_PASSPORT_INITDONE,ASSETCHAINS_STAKED,HUSH_NSPV; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; diff --git a/src/miner.cpp b/src/miner.cpp index ea6a298d9..392d9aaa4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -391,6 +391,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + fprintf(stderr,"%s: computing priority with nTxSize=%u\n", __func__, nTxSize); dPriority = tx.ComputePriority(dPriority, nTxSize); uint256 hash = tx.GetHash(); @@ -436,6 +437,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); } } + fprintf(stderr,"%s: done adding txs from mempool\n", __func__); // Collect transactions into block int64_t interest; @@ -447,13 +449,18 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + fprintf(stderr,"%s: compared txs with fSortedByFee=%d\n", __func__, fSortedByFee); + while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); + fprintf(stderr,"%s: grabbed first tx from priority queue\n", __func__); + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + fprintf(stderr,"%s: compared first tx from priority queue\n", __func__); vecPriority.pop_back(); // Size limits @@ -591,10 +598,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; + fprintf(stderr,"%s: nLastBlockTx=%lu , nLastBlockSize=%lu\n", __func__, nLastBlockTx, nLastBlockSize); + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); else blocktime = 1 + std::max((int64_t)(pindexPrev->nTime+1), GetTime()); //pblock->nTime = blocktime + 1; + fprintf(stderr,"%s: calling GetNextWorkRequired\n", __func__); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); diff --git a/src/pow.cpp b/src/pow.cpp index 143ee71c0..757929a19 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -297,8 +297,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexLast->GetHeight() == 340000) { LogPrintf("%s: Using blocktime=%d\n",__func__,ASSETCHAINS_BLOCKTIME); } - if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) + //if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) + if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_ALGO != ASSETCHAINS_RANDOMX) { + fprintf(stderr,"%s: using lwma for next work\n",__func__); return lwmaGetNextWorkRequired(pindexLast, pblock, params); + } arith_uint256 bnLimit; if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) @@ -500,7 +503,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; } - if(fDebug) + //if(fDebug) fprintf(stderr,"%s: nbits=%d\n", __func__, nbits); return(nbits); }