@ -519,12 +519,22 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
// TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
// TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
}
}
const struct BIP9DeploymentInfo & segwit_info = VersionBitsDeploymentInfo [ Consensus : : DEPLOYMENT_SEGWIT ] ;
// If the caller is indicating segwit support, then allow CreateNewBlock()
// to select witness transactions, after segwit activates (otherwise
// don't).
bool fSupportsSegwit = setClientRules . find ( segwit_info . name ) ! = setClientRules . end ( ) ;
// Update block
// Update block
static CBlockIndex * pindexPrev ;
static CBlockIndex * pindexPrev ;
static int64_t nStart ;
static int64_t nStart ;
static std : : unique_ptr < CBlockTemplate > pblocktemplate ;
static std : : unique_ptr < CBlockTemplate > pblocktemplate ;
// Cache whether the last invocation was with segwit support, to avoid returning
// a segwit-block to a non-segwit caller.
static bool fLastTemplateSupportsSegwit = true ;
if ( pindexPrev ! = chainActive . Tip ( ) | |
if ( pindexPrev ! = chainActive . Tip ( ) | |
( mempool . GetTransactionsUpdated ( ) ! = nTransactionsUpdatedLast & & GetTime ( ) - nStart > 5 ) )
( mempool . GetTransactionsUpdated ( ) ! = nTransactionsUpdatedLast & & GetTime ( ) - nStart > 5 ) | |
fLastTemplateSupportsSegwit ! = fSupportsSegwit )
{
{
// Clear pindexPrev so future calls make a new block, despite any failures from here on
// Clear pindexPrev so future calls make a new block, despite any failures from here on
pindexPrev = nullptr ;
pindexPrev = nullptr ;
@ -533,10 +543,11 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
nTransactionsUpdatedLast = mempool . GetTransactionsUpdated ( ) ;
nTransactionsUpdatedLast = mempool . GetTransactionsUpdated ( ) ;
CBlockIndex * pindexPrevNew = chainActive . Tip ( ) ;
CBlockIndex * pindexPrevNew = chainActive . Tip ( ) ;
nStart = GetTime ( ) ;
nStart = GetTime ( ) ;
fLastTemplateSupportsSegwit = fSupportsSegwit ;
// Create new block
// Create new block
CScript scriptDummy = CScript ( ) < < OP_TRUE ;
CScript scriptDummy = CScript ( ) < < OP_TRUE ;
pblocktemplate = BlockAssembler ( Params ( ) ) . CreateNewBlock ( scriptDummy ) ;
pblocktemplate = BlockAssembler ( Params ( ) ) . CreateNewBlock ( scriptDummy , fSupportsSegwit ) ;
if ( ! pblocktemplate )
if ( ! pblocktemplate )
throw JSONRPCError ( RPC_OUT_OF_MEMORY , " Out of memory " ) ;
throw JSONRPCError ( RPC_OUT_OF_MEMORY , " Out of memory " ) ;
@ -686,8 +697,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
result . push_back ( Pair ( " bits " , strprintf ( " %08x " , pblock - > nBits ) ) ) ;
result . push_back ( Pair ( " bits " , strprintf ( " %08x " , pblock - > nBits ) ) ) ;
result . push_back ( Pair ( " height " , ( int64_t ) ( pindexPrev - > nHeight + 1 ) ) ) ;
result . push_back ( Pair ( " height " , ( int64_t ) ( pindexPrev - > nHeight + 1 ) ) ) ;
const struct BIP9DeploymentInfo & segwit_info = VersionBitsDeploymentInfo [ Consensus : : DEPLOYMENT_SEGWIT ] ;
if ( ! pblocktemplate - > vchCoinbaseCommitment . empty ( ) & & fSupportsSegwit ) {
if ( ! pblocktemplate - > vchCoinbaseCommitment . empty ( ) & & setClientRules . find ( segwit_info . name ) ! = setClientRules . end ( ) ) {
result . push_back ( Pair ( " default_witness_commitment " , HexStr ( pblocktemplate - > vchCoinbaseCommitment . begin ( ) , pblocktemplate - > vchCoinbaseCommitment . end ( ) ) ) ) ;
result . push_back ( Pair ( " default_witness_commitment " , HexStr ( pblocktemplate - > vchCoinbaseCommitment . begin ( ) , pblocktemplate - > vchCoinbaseCommitment . end ( ) ) ) ) ;
}
}