From ca6297be978cd077b7d5c6a82e101f3fc1cfaef5 Mon Sep 17 00:00:00 2001 From: Michi Lumin Date: Mon, 18 Oct 2021 20:46:59 -0600 Subject: [PATCH] Revert "Merge branch '1.14.5-dev' of http://github.com/dogecoin/dogecoin into 1.14.5-dev" This reverts commit 16761956ce2ccb9b994edf4a2fd79721010c23fd, reversing changes made to 1eede33ce81dbea5745cec6b731c9ca2a587e0bf. --- src/rpc/mining.cpp | 232 ++------------------------------------------- 1 file changed, 6 insertions(+), 226 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index ab9e38b26..387656baa 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -969,152 +969,6 @@ UniValue estimatesmartpriority(const JSONRPCRequest& request) /* ************************************************************************** */ /* Merge mining. */ -//MLUMIN: 10/2021 Add these functions back from 1.14 regression, attempt - -/** - * The variables below are used to keep track of created and not yet - * submitted auxpow blocks. Lock them to be sure even for multiple - * RPC threads running in parallel. - */ - -static CCriticalSection cs_auxblockCache; -LOCK(cs_auxblockCache); -static std::map mapNewBlock; -static std::vector> vNewBlockTemplate; - -void AuxMiningCheck() -{ - if(!g_connman) - throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); - - if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0 && !Params().MineBlocksOnDemand()) - throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Dogecoin is not connected!"); - - if (IsInitialBlockDownload() && !Params().MineBlocksOnDemand()) - throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, - "Dogecoin is downloading blocks..."); - - /* This should never fail, since the chain is already - past the point of merge-mining start. Check nevertheless. */ - { - LOCK(cs_main); - if (Params().GetConsensus(chainActive.Height() + 1).fAllowLegacyBlocks) - throw std::runtime_error("getauxblock method is not yet available"); - } -} - - -static -UniValue AuxMiningCreateBlock(const CScript& scriptPubKey) -{ - - AuxMiningCheck(); - LOCK(cs_auxblockCache); - - static unsigned nTransactionsUpdatedLast; - static const CBlockIndex* pindexPrev = nullptr; - static uint64_t nStart; - static CBlock* pblock = nullptr; - static unsigned nExtraNonce = 0; - - // Update block - { - LOCK(cs_main); - if (pindexPrev != chainActive.Tip() - || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast - && GetTime() - nStart > 60)) - { - if (pindexPrev != chainActive.Tip()) - { - // Clear old blocks since they're obsolete now. - mapNewBlock.clear(); - vNewBlockTemplate.clear(); - pblock = nullptr; - } - - // Create new block with nonce = 0 and extraNonce = 1 - std::unique_ptr newBlock - = BlockAssembler(Params()).CreateNewBlock(scriptPubKey,true); - if (!newBlock) - throw JSONRPCError(RPC_OUT_OF_MEMORY, "out of memory"); - - // Update state only when CreateNewBlock succeeded - nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - pindexPrev = chainActive.Tip(); - nStart = GetTime(); - - // Finalise it by setting the version and building the merkle root - IncrementExtraNonce(&newBlock->block, pindexPrev, nExtraNonce); - newBlock->block.SetAuxpowFlag(true); - - // Save - pblock = &newBlock->block; - mapNewBlock[pblock->GetHash()] = pblock; - vNewBlockTemplate.push_back(std::move(newBlock)); - } - } - - // At this point, pblock is always initialised: If we make it here - // without creating a new block above, it means that, in particular, - // pindexPrev == chainActive.Tip(). But for that to happen, we must - // already have created a pblock in a previous call, as pindexPrev is - // initialised only when pblock is. - assert(pblock); - - arith_uint256 target; - bool fNegative, fOverflow; - target.SetCompact(pblock->nBits, &fNegative, &fOverflow); - if (fNegative || fOverflow || target == 0) - throw std::runtime_error("invalid difficulty bits in block"); - - UniValue result(UniValue::VOBJ); - result.pushKV("hash", pblock->GetHash().GetHex()); - result.pushKV("chainid", pblock->GetChainId()); - result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex()); - result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->vout[0].nValue); - result.pushKV("bits", strprintf("%08x", pblock->nBits)); - result.pushKV("height", static_cast (pindexPrev->nHeight + 1)); - result.pushKV("_target", HexStr(BEGIN(target), END(target))); - - return result; -} - - -static -bool AuxMiningSubmitBlock(const std::string& hashHex, - const std::string& auxpowHex) -{ - - AuxMiningCheck(); - LOCK(cs_auxblockCache); - - uint256 hash; - hash.SetHex(hashHex); - - const std::map::iterator mit = mapNewBlock.find(hash); - if (mit == mapNewBlock.end()) - throw JSONRPCError(RPC_INVALID_PARAMETER, "block hash unknown"); - CBlock& block = *mit->second; - - const std::vector vchAuxPow = ParseHex(auxpowHex); - CDataStream ss(vchAuxPow, SER_GETHASH, PROTOCOL_VERSION); - CAuxPow pow; - ss >> pow; - block.SetAuxpow(new CAuxPow(pow)); - assert(block.GetHash() == hash); - - submitblock_StateCatcher sc(block.GetHash()); - RegisterValidationInterface(&sc); - std::shared_ptr shared_block - = std::make_shared(block); - bool fAccepted = ProcessNewBlock(Params(), shared_block, true, nullptr); - UnregisterValidationInterface(&sc); - - return fAccepted; -} - -//MLUMIN: 10/2021 - end section - UniValue getauxblockbip22(const JSONRPCRequest& request) { if (request.fHelp @@ -1157,10 +1011,6 @@ UniValue getauxblockbip22(const JSONRPCRequest& request) if (!coinbaseScript->reserveScript.size()) throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available (mining requires a wallet)"); - - //MLUMIN: 10/2021 - Call AuxMiningCheck(); instead. - AuxMiningCheck(); - /* if(!g_connman) throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled"); @@ -1170,33 +1020,25 @@ UniValue getauxblockbip22(const JSONRPCRequest& request) if (IsInitialBlockDownload() && !Params().MineBlocksOnDemand()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Dogecoin is downloading blocks..."); - - // This should never fail, since the chain is already - // past the point of merge-mining start. Check nevertheless. + + /* This should never fail, since the chain is already + past the point of merge-mining start. Check nevertheless. */ { LOCK(cs_main); if (Params().GetConsensus(chainActive.Height() + 1).fAllowLegacyBlocks) throw std::runtime_error("getauxblock method is not yet available"); } - */ - //MLUMIN: 10/2021 - Section end - // The variables below are used to keep track of created and not yet - // submitted auxpow blocks. Lock them to be sure even for multiple - // RPC threads running in parallel. - - //MLUMIN: 10/2021 - These have been moved above create/submit/checkaux. - /* + /* The variables below are used to keep track of created and not yet + submitted auxpow blocks. Lock them to be sure even for multiple + RPC threads running in parallel. */ static CCriticalSection cs_auxblockCache; LOCK(cs_auxblockCache); static std::map mapNewBlock; static std::vector> vNewBlockTemplate; - */ /* Create a new block? */ if (request.params.size() == 0) - - //MLUMIN 10/2021: Note, this should return AuxMiningCreateBlock(coinbaseScript->ReverseScript); { static unsigned nTransactionsUpdatedLast; static const CBlockIndex* pindexPrev = nullptr; @@ -1293,61 +1135,6 @@ UniValue getauxblockbip22(const JSONRPCRequest& request) return BIP22ValidationResult(sc.state); } -//MLUMIN: 10/2021 - test on replacing createauxblock - -UniValue createauxblock(const JSONRPCRequest& request) -{ - if (request.fHelp || request.params.size() != 1) - throw std::runtime_error( - "createauxblock
\n" - "\ncreate a new block and return information required to merge-mine it.\n" - "\nArguments:\n" - "1. address (string, required) specify coinbase transaction payout address\n" - "\nResult:\n" - "{\n" - " \"hash\" (string) hash of the created block\n" - " \"chainid\" (numeric) chain ID for this block\n" - " \"previousblockhash\" (string) hash of the previous block\n" - " \"coinbasevalue\" (numeric) value of the block's coinbase\n" - " \"bits\" (string) compressed target of the block\n" - " \"height\" (numeric) height of the block\n" - " \"_target\" (string) target in reversed byte order, deprecated\n" - "}\n" - "\nExamples:\n" - + HelpExampleCli("createauxblock", "\"address\"") - + HelpExampleRpc("createauxblock", "\"address\"") - ); - // Check coinbase payout address - CBitcoinAddress coinbaseAddress(request.params[0].get_str()); - if (!coinbaseAddress.IsValid()) - throw JSONRPCError(RPC_INVALID_PARAMETER,"Invalid coinbase payout address"); - const CScript scriptPubKey = GetScriptForDestination(coinbaseAddress.Get()); - return AuxMiningCreateBlock(scriptPubKey); -} - -UniValue submitauxblock(const JSONRPCRequest& request) -{ - if (request.fHelp || request.params.size() != 2) - throw std::runtime_error( - "submitauxblock \n" - "\nsubmit a solved auxpow for a previously block created by 'createauxblock'.\n" - "\nArguments:\n" - "1. hash (string, required) hash of the block to submit\n" - "2. auxpow (string, required) serialised auxpow found\n" - "\nResult:\n" - "xxxxx (boolean) whether the submitted block was correct\n" - "\nExamples:\n" - + HelpExampleCli("submitauxblock", "\"hash\" \"serialised auxpow\"") - + HelpExampleRpc("submitauxblock", "\"hash\" \"serialised auxpow\"") - ); - - return AuxMiningSubmitBlock(request.params[0].get_str(), - request.params[1].get_str()); -} - -//MLUMIN: 10/2021 End section. - - UniValue getauxblock(const JSONRPCRequest& request) { const UniValue response = getauxblockbip22(request); @@ -1372,13 +1159,6 @@ static const CRPCCommand commands[] = { "mining", "submitblock", &submitblock, true, {"hexdata","parameters"} }, { "mining", "getauxblock", &getauxblock, true, {"hash", "auxpow"} }, - //MLUMIN: 10/2021 add back in create/submit - { "mining", "createauxblock", &createauxblock, true, {"address"} }, - { "mining", "submitauxblock", &submitauxblock, true, {"hash", "auxpow"} }, - //MLUMIN: 10/2021 end section - - - { "generating", "generate", &generate, true, {"nblocks","maxtries","auxpow"} }, { "generating", "generatetoaddress", &generatetoaddress, true, {"nblocks","address","maxtries","auxpow"} },