@@ -311,15 +311,15 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
311311 " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n "
312312 " https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n " ,
313313 {
314- {" template_request" , RPCArg::Type::OBJ, /* opt */ true , /* default_val */ " " , " A json object in the following spec" ,
314+ {" template_request" , RPCArg::Type::OBJ, /* opt */ false , /* default_val */ " " , " A json object in the following spec" ,
315315 {
316316 {" mode" , RPCArg::Type::STR, /* opt */ true , /* default_val */ " " , " This must be set to \" template\" , \" proposal\" (see BIP 23), or omitted" },
317317 {" capabilities" , RPCArg::Type::ARR, /* opt */ true , /* default_val */ " " , " A list of strings" ,
318318 {
319319 {" support" , RPCArg::Type::STR, /* opt */ true , /* default_val */ " " , " client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'" },
320320 },
321321 },
322- {" rules" , RPCArg::Type::ARR, /* opt */ true , /* default_val */ " " , " A list of strings" ,
322+ {" rules" , RPCArg::Type::ARR, /* opt */ false , /* default_val */ " " , " A list of strings" ,
323323 {
324324 {" support" , RPCArg::Type::STR, /* opt */ true , /* default_val */ " " , " client side supported softfork deployment" },
325325 },
@@ -503,21 +503,17 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
503503 }
504504
505505 const struct VBDeploymentInfo & segwit_info = VersionBitsDeploymentInfo[Consensus::DEPLOYMENT_SEGWIT];
506- // If the caller is indicating segwit support, then allow CreateNewBlock()
507- // to select witness transactions, after segwit activates (otherwise
508- // don't).
509- bool fSupportsSegwit = setClientRules. find (segwit_info. name ) != setClientRules. end ();
506+ // GBT must be called with ' segwit' set in the rules
507+ if (setClientRules. count (segwit_info. name ) != 1 ) {
508+ throw JSONRPCError (RPC_INVALID_PARAMETER, " getblocktemplate must be called with the segwit rule set (call with { \" rules \" : [ \" segwit \" ]}) " );
509+ }
510510
511511 // Update block
512512 static CBlockIndex* pindexPrev;
513513 static int64_t nStart;
514514 static std::unique_ptr<CBlockTemplate> pblocktemplate;
515- // Cache whether the last invocation was with segwit support, to avoid returning
516- // a segwit-block to a non-segwit caller.
517- static bool fLastTemplateSupportsSegwit = true ;
518515 if (pindexPrev != chainActive.Tip () ||
519- (mempool.GetTransactionsUpdated () != nTransactionsUpdatedLast && GetTime () - nStart > 5 ) ||
520- fLastTemplateSupportsSegwit != fSupportsSegwit )
516+ (mempool.GetTransactionsUpdated () != nTransactionsUpdatedLast && GetTime () - nStart > 5 ))
521517 {
522518 // Clear pindexPrev so future calls make a new block, despite any failures from here on
523519 pindexPrev = nullptr ;
@@ -526,11 +522,10 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
526522 nTransactionsUpdatedLast = mempool.GetTransactionsUpdated ();
527523 CBlockIndex* pindexPrevNew = chainActive.Tip ();
528524 nStart = GetTime ();
529- fLastTemplateSupportsSegwit = fSupportsSegwit ;
530525
531526 // Create new block
532527 CScript scriptDummy = CScript () << OP_TRUE;
533- pblocktemplate = BlockAssembler (Params ()).CreateNewBlock (scriptDummy, fSupportsSegwit );
528+ pblocktemplate = BlockAssembler (Params ()).CreateNewBlock (scriptDummy);
534529 if (!pblocktemplate)
535530 throw JSONRPCError (RPC_OUT_OF_MEMORY, " Out of memory" );
536531
@@ -682,7 +677,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
682677 result.pushKV (" bits" , strprintf (" %08x" , pblock->nBits ));
683678 result.pushKV (" height" , (int64_t )(pindexPrev->nHeight +1 ));
684679
685- if (!pblocktemplate->vchCoinbaseCommitment .empty () && fSupportsSegwit ) {
680+ if (!pblocktemplate->vchCoinbaseCommitment .empty ()) {
686681 result.pushKV (" default_witness_commitment" , HexStr (pblocktemplate->vchCoinbaseCommitment .begin (), pblocktemplate->vchCoinbaseCommitment .end ()));
687682 }
688683
0 commit comments