Skip to content

Commit

Permalink
rpc: Allow to call GBT before SegWit activation
Browse files Browse the repository at this point in the history
  • Loading branch information
lateminer committed Oct 28, 2023
1 parent baa5903 commit f483a77
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CBlockTemplate> 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))
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f483a77

Please sign in to comment.