Skip to content

Commit aa791e2

Browse files
committed
Merge #9619: Bugfix: RPC/Mining: GBT should return 1 MB sizelimit before segwit activates
279f944 QA: Test GBT size/weight limit values (Luke Dashjr) 9fc7f0b Bugfix: RPC/Mining: GBT should return 1 MB sizelimit before segwit activates (Luke Dashjr)
2 parents 2dad022 + 279f944 commit aa791e2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

qa/rpc-tests/segwit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ def run_test(self):
130130
print("Verify sigops are counted in GBT with pre-BIP141 rules before the fork")
131131
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
132132
tmpl = self.nodes[0].getblocktemplate({})
133+
assert(tmpl['sizelimit'] == 1000000)
134+
assert('weightlimit' not in tmpl)
133135
assert(tmpl['sigoplimit'] == 20000)
134136
assert(tmpl['transactions'][0]['hash'] == txid)
135137
assert(tmpl['transactions'][0]['sigops'] == 2)
136138
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']})
139+
assert(tmpl['sizelimit'] == 1000000)
140+
assert('weightlimit' not in tmpl)
137141
assert(tmpl['sigoplimit'] == 20000)
138142
assert(tmpl['transactions'][0]['hash'] == txid)
139143
assert(tmpl['transactions'][0]['sigops'] == 2)
@@ -241,6 +245,8 @@ def run_test(self):
241245
print("Verify sigops are counted in GBT with BIP141 rules after the fork")
242246
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
243247
tmpl = self.nodes[0].getblocktemplate({'rules':['segwit']})
248+
assert(tmpl['sizelimit'] >= 3999577) # actual maximum size is lower due to minimum mandatory non-witness data
249+
assert(tmpl['weightlimit'] == 4000000)
244250
assert(tmpl['sigoplimit'] == 80000)
245251
assert(tmpl['transactions'][0]['txid'] == txid)
246252
assert(tmpl['transactions'][0]['sigops'] == 8)
@@ -250,6 +256,8 @@ def run_test(self):
250256
try:
251257
tmpl = self.nodes[0].getblocktemplate({})
252258
assert(len(tmpl['transactions']) == 1) # Doesn't include witness tx
259+
assert(tmpl['sizelimit'] == 1000000)
260+
assert('weightlimit' not in tmpl)
253261
assert(tmpl['sigoplimit'] == 20000)
254262
assert(tmpl['transactions'][0]['hash'] == txid)
255263
assert(tmpl['transactions'][0]['sigops'] == 2)

src/rpc/mining.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,12 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
676676
nSigOpLimit /= WITNESS_SCALE_FACTOR;
677677
}
678678
result.push_back(Pair("sigoplimit", nSigOpLimit));
679-
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SERIALIZED_SIZE));
680-
result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT));
679+
if (fPreSegWit) {
680+
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_BASE_SIZE));
681+
} else {
682+
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SERIALIZED_SIZE));
683+
result.push_back(Pair("weightlimit", (int64_t)MAX_BLOCK_WEIGHT));
684+
}
681685
result.push_back(Pair("curtime", pblock->GetBlockTime()));
682686
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
683687
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));

0 commit comments

Comments
 (0)