Skip to content

Commit 160f895

Browse files
committed
Bugfix: Use pre-BIP141 sigops until segwit activates
1 parent 6e6ab2c commit 160f895

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/rpc/mining.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
546546
UpdateTime(pblock, consensusParams, pindexPrev);
547547
pblock->nNonce = 0;
548548

549+
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
550+
const bool fPreSegWit = (THRESHOLD_ACTIVE != VersionBitsState(pindexPrev, consensusParams, Consensus::DEPLOYMENT_SEGWIT, versionbitscache));
551+
549552
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
550553

551554
UniValue transactions(UniValue::VARR);
@@ -574,7 +577,12 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
574577

575578
int index_in_template = i - 1;
576579
entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template]));
577-
entry.push_back(Pair("sigops", pblocktemplate->vTxSigOpsCost[index_in_template]));
580+
int64_t nTxSigOps = pblocktemplate->vTxSigOpsCost[index_in_template];
581+
if (fPreSegWit) {
582+
assert(nTxSigOps % WITNESS_SCALE_FACTOR == 0);
583+
nTxSigOps /= WITNESS_SCALE_FACTOR;
584+
}
585+
entry.push_back(Pair("sigops", nTxSigOps));
578586
entry.push_back(Pair("weight", GetTransactionWeight(tx)));
579587

580588
transactions.push_back(entry);
@@ -657,7 +665,12 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
657665
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
658666
result.push_back(Pair("mutable", aMutable));
659667
result.push_back(Pair("noncerange", "00000000ffffffff"));
660-
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS_COST));
668+
int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
669+
if (fPreSegWit) {
670+
assert(nSigOpLimit % WITNESS_SCALE_FACTOR == 0);
671+
nSigOpLimit /= WITNESS_SCALE_FACTOR;
672+
}
673+
result.push_back(Pair("sigoplimit", nSigOpLimit));
661674
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SERIALIZED_SIZE));
662675
result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT));
663676
result.push_back(Pair("curtime", pblock->GetBlockTime()));

0 commit comments

Comments
 (0)