mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-23 22:19:39 +01:00
Merge #10006: [0.14 backport] Don't require segwit in getblocktemplate for segwit signalling or mining
2cd2cd5Test transaction selection when gbt called without segwit support (Suhas Daftuar)569596cDon't require segwit in getblocktemplate for segwit signalling or mining (Suhas Daftuar) Tree-SHA512: bf2672287713e5adc7e851791207e17490679f941d0b9ed38467ffede3aa3000d229151b8ae54323fc8037e0a8569b2fd910ec19f034fb85d9142289648793c3
This commit is contained in:
@@ -127,7 +127,7 @@ void BlockAssembler::resetBlock()
|
||||
blockFinished = false;
|
||||
}
|
||||
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx)
|
||||
{
|
||||
resetBlock();
|
||||
|
||||
@@ -165,7 +165,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
// -promiscuousmempoolflags is used.
|
||||
// TODO: replace this with a call to main to assess validity of a mempool
|
||||
// transaction (which in most cases can be a no-op).
|
||||
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus());
|
||||
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus()) && fMineWitnessTx;
|
||||
|
||||
addPriorityTxs();
|
||||
addPackageTxs();
|
||||
|
||||
@@ -165,7 +165,7 @@ private:
|
||||
public:
|
||||
BlockAssembler(const CChainParams& chainparams);
|
||||
/** Construct a new block template with coinbase to scriptPubKeyIn */
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true);
|
||||
|
||||
private:
|
||||
// utility functions
|
||||
|
||||
@@ -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?
|
||||
}
|
||||
|
||||
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
|
||||
static CBlockIndex* pindexPrev;
|
||||
static int64_t nStart;
|
||||
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() ||
|
||||
(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
|
||||
pindexPrev = nullptr;
|
||||
@@ -533,10 +543,11 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
CBlockIndex* pindexPrevNew = chainActive.Tip();
|
||||
nStart = GetTime();
|
||||
fLastTemplateSupportsSegwit = fSupportsSegwit;
|
||||
|
||||
// Create new block
|
||||
CScript scriptDummy = CScript() << OP_TRUE;
|
||||
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(scriptDummy);
|
||||
pblocktemplate = BlockAssembler(Params()).CreateNewBlock(scriptDummy, fSupportsSegwit);
|
||||
if (!pblocktemplate)
|
||||
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("height", (int64_t)(pindexPrev->nHeight+1)));
|
||||
|
||||
const struct BIP9DeploymentInfo& segwit_info = VersionBitsDeploymentInfo[Consensus::DEPLOYMENT_SEGWIT];
|
||||
if (!pblocktemplate->vchCoinbaseCommitment.empty() && setClientRules.find(segwit_info.name) != setClientRules.end()) {
|
||||
if (!pblocktemplate->vchCoinbaseCommitment.empty() && fSupportsSegwit) {
|
||||
result.push_back(Pair("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION
|
||||
},
|
||||
{
|
||||
/*.name =*/ "segwit",
|
||||
/*.gbt_force =*/ false,
|
||||
/*.gbt_force =*/ true,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user