From f483a77298b4626def238837a5efb0d621aa63b2 Mon Sep 17 00:00:00 2001 From: lateminer <9951982+lateminer@users.noreply.github.com> Date: Fri, 27 Oct 2023 21:34:31 +0200 Subject: [PATCH] rpc: Allow to call GBT before SegWit activation --- src/rpc/mining.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 186f02965c..acedc65f10 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -740,15 +740,19 @@ static RPCHelpMan getblocktemplate() throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the signet rule set (call with {\"rules\": [\"segwit\", \"signet\"]})"); } - // GBT must be called with 'segwit' set in the rules - if (setClientRules.count("segwit") != 1) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})"); - } - // Update block static CBlockIndex* pindexPrev; static int64_t time_start; static std::unique_ptr pblocktemplate; + + // NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration + const bool fPreSegWit = !DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT); + + // GBT must be called with 'segwit' set in the rules + if (!fPreSegWit && setClientRules.count("segwit") != 1) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "getblocktemplate must be called with the segwit rule set (call with {\"rules\": [\"segwit\"]})"); + } + if (pindexPrev != active_chain.Tip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - time_start > 5)) { @@ -776,9 +780,6 @@ static RPCHelpMan getblocktemplate() UpdateTime(pblock, consensusParams, pindexPrev); pblock->nNonce = 0; - // NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration - const bool fPreSegWit = !DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT); - UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal"); UniValue transactions(UniValue::VARR);