Skip to content

Commit 9fd56f0

Browse files
committed
miner: always treat SegWit as active
The getblocktemplate RPC would check if SegWit has activated yet at the tip. This has been the case for more than five years.
1 parent 9fc563b commit 9fd56f0

File tree

2 files changed

+5
-35
lines changed

2 files changed

+5
-35
lines changed

src/rpc/mining.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,6 @@ static RPCHelpMan getblocktemplate()
826826
UpdateTime(&block, consensusParams, pindexPrev);
827827
block.nNonce = 0;
828828

829-
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration
830-
const bool fPreSegWit = !DeploymentActiveAfter(pindexPrev, chainman, Consensus::DEPLOYMENT_SEGWIT);
831-
832829
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
833830

834831
UniValue transactions(UniValue::VARR);
@@ -862,10 +859,6 @@ static RPCHelpMan getblocktemplate()
862859
int index_in_template = i - 1;
863860
entry.pushKV("fee", tx_fees.at(index_in_template));
864861
int64_t nTxSigOps{tx_sigops.at(index_in_template)};
865-
if (fPreSegWit) {
866-
CHECK_NONFATAL(nTxSigOps % WITNESS_SCALE_FACTOR == 0);
867-
nTxSigOps /= WITNESS_SCALE_FACTOR;
868-
}
869862
entry.pushKV("sigops", nTxSigOps);
870863
entry.pushKV("weight", GetTransactionWeight(tx));
871864

@@ -889,10 +882,9 @@ static RPCHelpMan getblocktemplate()
889882
// ! indicates a more subtle change to the block structure or generation transaction
890883
// Otherwise clients may assume the rule will not impact usage of the template as-is.
891884
aRules.push_back("csv");
892-
if (!fPreSegWit) {
893-
aRules.push_back("!segwit");
894-
aRules.push_back("taproot");
895-
}
885+
// BIP 145: the '!' rule prefix MUST be enabled on the "segwit" rule for templates including transactions with witness data.
886+
aRules.push_back("!segwit");
887+
aRules.push_back("taproot");
896888
if (consensusParams.signet_blocks) {
897889
// indicate to miner that they must understand signet rules
898890
// when attempting to mine with this template
@@ -955,17 +947,9 @@ static RPCHelpMan getblocktemplate()
955947
result.pushKV("noncerange", "00000000ffffffff");
956948
int64_t nSigOpLimit = MAX_BLOCK_SIGOPS_COST;
957949
int64_t nSizeLimit = MAX_BLOCK_SERIALIZED_SIZE;
958-
if (fPreSegWit) {
959-
CHECK_NONFATAL(nSigOpLimit % WITNESS_SCALE_FACTOR == 0);
960-
nSigOpLimit /= WITNESS_SCALE_FACTOR;
961-
CHECK_NONFATAL(nSizeLimit % WITNESS_SCALE_FACTOR == 0);
962-
nSizeLimit /= WITNESS_SCALE_FACTOR;
963-
}
964950
result.pushKV("sigoplimit", nSigOpLimit);
965951
result.pushKV("sizelimit", nSizeLimit);
966-
if (!fPreSegWit) {
967-
result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT);
968-
}
952+
result.pushKV("weightlimit", (int64_t)MAX_BLOCK_WEIGHT);
969953
result.pushKV("curtime", block.GetBlockTime());
970954
result.pushKV("bits", strprintf("%08x", block.nBits));
971955
result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));

test/functional/feature_segwit.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,18 @@ def add_options(self, parser):
8484
def set_test_params(self):
8585
self.setup_clean_chain = True
8686
self.num_nodes = 3
87-
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
87+
# This test tests SegWit post-activation
8888
self.extra_args = [
8989
[
9090
"-acceptnonstdtxn=1",
91-
"-testactivationheight=segwit@165",
9291
"-addresstype=legacy",
9392
],
9493
[
9594
"-acceptnonstdtxn=1",
96-
"-testactivationheight=segwit@165",
9795
"-addresstype=legacy",
9896
],
9997
[
10098
"-acceptnonstdtxn=1",
101-
"-testactivationheight=segwit@165",
10299
"-addresstype=legacy",
103100
],
104101
]
@@ -124,17 +121,6 @@ def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
124121
def run_test(self):
125122
self.generate(self.nodes[0], 161) # block 161
126123

127-
self.log.info("Verify sigops are counted in GBT with pre-BIP141 rules before the fork")
128-
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
129-
tmpl = self.nodes[0].getblocktemplate({'rules': ['segwit']})
130-
assert_equal(tmpl['sizelimit'], 1000000)
131-
assert 'weightlimit' not in tmpl
132-
assert_equal(tmpl['sigoplimit'], 20000)
133-
assert_equal(tmpl['transactions'][0]['hash'], txid)
134-
assert_equal(tmpl['transactions'][0]['sigops'], 2)
135-
assert '!segwit' not in tmpl['rules']
136-
self.generate(self.nodes[0], 1) # block 162
137-
138124
balance_presetup = self.nodes[0].getbalance()
139125
self.pubkey = []
140126
p2sh_ids = [] # p2sh_ids[NODE][TYPE] is an array of txids that spend to P2WPKH (TYPE=0) or P2WSH (TYPE=1) scripts to an address for NODE embedded in p2sh

0 commit comments

Comments
 (0)