Skip to content

Commit 23e8c70

Browse files
committed
Merge bitcoin/bitcoin#24421: miner: always assume we can build witness blocks
40e871d [miner] always assume we can create witness blocks (glozow) Pull request description: Given the low possibility of a reorg reverting the segwit soft fork, there is no longer a need to check whether segwit is active to see if it's okay to add to the block template (see also #23512, #21009, etc). `TestBlockValidity()` is also run on the block template at the end of `CreateNewBlock()`, so any invalid block would be caught there. ACKs for top commit: gruve-p: ACK bitcoin/bitcoin@40e871d jnewbery: utACK 40e871d, although I disagree about changing the test for segwit transaction in mempool before activagtion, instead of just removing it: bitcoin/bitcoin#24421 (comment). achow101: ACK 40e871d theStack: Code-review ACK 40e871d Tree-SHA512: bf4860bf2bed8339622d05228d11d60286edb0c32a9a3c434b8d154913c07ea56e50649f4af7009c2a1c6a58a81d2299ab43b41a6f16dee7d08cc89cc1603019
2 parents bb0b39c + 40e871d commit 23e8c70

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

src/node/miner.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ void BlockAssembler::resetBlock()
9797
// Reserve space for coinbase tx
9898
nBlockWeight = 4000;
9999
nBlockSigOpsCost = 400;
100-
fIncludeWitness = false;
101100

102101
// These counters do not include coinbase tx
103102
nBlockTx = 0;
@@ -137,17 +136,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
137136
pblock->nTime = GetAdjustedTime();
138137
m_lock_time_cutoff = pindexPrev->GetMedianTimePast();
139138

140-
// Decide whether to include witness transactions
141-
// This is only needed in case the witness softfork activation is reverted
142-
// (which would require a very deep reorganization).
143-
// Note that the mempool would accept transactions with witness data before
144-
// the deployment is active, but we would only ever mine blocks after activation
145-
// unless there is a massive block reorganization with the witness softfork
146-
// not activated.
147-
// TODO: replace this with a call to main to assess validity of a mempool
148-
// transaction (which in most cases can be a no-op).
149-
fIncludeWitness = DeploymentActiveAfter(pindexPrev, chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT);
150-
151139
int nPackagesSelected = 0;
152140
int nDescendantsUpdated = 0;
153141
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
@@ -215,17 +203,12 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
215203

216204
// Perform transaction-level checks before adding to block:
217205
// - transaction finality (locktime)
218-
// - premature witness (in case segwit transactions are added to mempool before
219-
// segwit activation)
220206
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package) const
221207
{
222208
for (CTxMemPool::txiter it : package) {
223209
if (!IsFinalTx(it->GetTx(), nHeight, m_lock_time_cutoff)) {
224210
return false;
225211
}
226-
if (!fIncludeWitness && it->GetTx().HasWitness()) {
227-
return false;
228-
}
229212
}
230213
return true;
231214
}

src/node/miner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class BlockAssembler
132132
std::unique_ptr<CBlockTemplate> pblocktemplate;
133133

134134
// Configuration parameters for the block size
135-
bool fIncludeWitness;
136135
unsigned int nBlockMaxWeight;
137136
CFeeRate blockMinFeeRate;
138137

test/functional/feature_segwit.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,9 @@ def success_mine(self, node, txid, sign, redeem_script=""):
117117
assert_equal(len(node.getblock(block[0])["tx"]), 2)
118118
self.sync_blocks()
119119

120-
def skip_mine(self, node, txid, sign, redeem_script=""):
120+
def fail_mine(self, node, txid, sign, redeem_script=""):
121121
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
122-
block = self.generate(node, 1)
123-
assert_equal(len(node.getblock(block[0])["tx"]), 1)
124-
self.sync_blocks()
122+
assert_raises_rpc_error(-1, "unexpected witness data found", self.generate, node, 1)
125123

126124
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
127125
assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script)
@@ -197,21 +195,21 @@ def run_test(self):
197195
assert_equal(self.nodes[1].getbalance(), 20 * Decimal("49.999"))
198196
assert_equal(self.nodes[2].getbalance(), 20 * Decimal("49.999"))
199197

200-
self.generate(self.nodes[0], 260) # block 423
198+
self.generate(self.nodes[0], 264) # block 427
201199

202-
self.log.info("Verify witness txs are skipped for mining before the fork")
203-
self.skip_mine(self.nodes[2], wit_ids[NODE_2][P2WPKH][0], True) # block 424
204-
self.skip_mine(self.nodes[2], wit_ids[NODE_2][P2WSH][0], True) # block 425
205-
self.skip_mine(self.nodes[2], p2sh_ids[NODE_2][P2WPKH][0], True) # block 426
206-
self.skip_mine(self.nodes[2], p2sh_ids[NODE_2][P2WSH][0], True) # block 427
200+
self.log.info("Verify witness txs cannot be mined before the fork")
201+
self.fail_mine(self.nodes[2], wit_ids[NODE_2][P2WPKH][0], True)
202+
self.fail_mine(self.nodes[2], wit_ids[NODE_2][P2WSH][0], True)
203+
self.fail_mine(self.nodes[2], p2sh_ids[NODE_2][P2WPKH][0], True)
204+
self.fail_mine(self.nodes[2], p2sh_ids[NODE_2][P2WSH][0], True)
207205

208206
self.log.info("Verify unsigned p2sh witness txs without a redeem script are invalid")
209207
self.fail_accept(self.nodes[2], "mandatory-script-verify-flag-failed (Operation not valid with the current stack size)", p2sh_ids[NODE_2][P2WPKH][1], sign=False)
210208
self.fail_accept(self.nodes[2], "mandatory-script-verify-flag-failed (Operation not valid with the current stack size)", p2sh_ids[NODE_2][P2WSH][1], sign=False)
211209

212-
self.generate(self.nodes[2], 4) # blocks 428-431
210+
self.generate(self.nodes[0], 4) # blocks 428-431
213211

214-
self.log.info("Verify previous witness txs skipped for mining can now be mined")
212+
self.log.info("Verify previous witness txs can now be mined")
215213
assert_equal(len(self.nodes[2].getrawmempool()), 4)
216214
blockhash = self.generate(self.nodes[2], 1)[0] # block 432 (first block with new rules; 432 = 144 * 3)
217215
assert_equal(len(self.nodes[2].getrawmempool()), 0)

0 commit comments

Comments
 (0)