Skip to content

Commit 6dd4bc2

Browse files
committed
Exclude witness transactions in addPackageTxs() pre-segwit activation
1 parent f15c2cd commit 6dd4bc2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/miner.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,19 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
236236
return true;
237237
}
238238

239-
// Block size and sigops have already been tested. Check that all transactions
240-
// are final.
241-
bool BlockAssembler::TestPackageFinalityAndSerializedSize(const CTxMemPool::setEntries& package)
239+
// Perform transaction-level checks before adding to block:
240+
// - transaction finality (locktime)
241+
// - premature witness (in case segwit transactions are added to mempool before
242+
// segwit activation)
243+
// - serialized size (in case -blockmaxsize is in use)
244+
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package)
242245
{
243246
uint64_t nPotentialBlockSize = nBlockSize; // only used with fNeedSizeAccounting
244247
BOOST_FOREACH (const CTxMemPool::txiter it, package) {
245248
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
246249
return false;
250+
if (!fIncludeWitness && !it->GetTx().wit.IsNull())
251+
return false;
247252
if (fNeedSizeAccounting) {
248253
uint64_t nTxSize = ::GetSerializeSize(it->GetTx(), SER_NETWORK, PROTOCOL_VERSION);
249254
if (nPotentialBlockSize + nTxSize >= nBlockMaxSize) {
@@ -542,7 +547,7 @@ void BlockAssembler::addPackageTxs()
542547
ancestors.insert(iter);
543548

544549
// Test if all tx's are Final
545-
if (!TestPackageFinalityAndSerializedSize(ancestors)) {
550+
if (!TestPackageTransactions(ancestors)) {
546551
if (fUsingModified) {
547552
mapModifiedTx.get<ancestor_score>().erase(modit);
548553
failedTx.insert(iter);

src/miner.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,11 @@ class BlockAssembler
192192
void onlyUnconfirmed(CTxMemPool::setEntries& testSet);
193193
/** Test if a new package would "fit" in the block */
194194
bool TestPackage(uint64_t packageSize, int64_t packageSigOpsCost);
195-
/** Test if a set of transactions are all final */
196-
bool TestPackageFinalityAndSerializedSize(const CTxMemPool::setEntries& package);
195+
/** Perform checks on each transaction in a package:
196+
* locktime, premature-witness, serialized size (if necessary)
197+
* These checks should always succeed, and they're here
198+
* only as an extra check in case of suboptimal node configuration */
199+
bool TestPackageTransactions(const CTxMemPool::setEntries& package);
197200
/** Return true if given transaction from mapTx has already been evaluated,
198201
* or if the transaction's cached data in mapTx is incorrect. */
199202
bool SkipMapTxEntry(CTxMemPool::txiter it, indexed_modified_transaction_set &mapModifiedTx, CTxMemPool::setEntries &failedTx);

0 commit comments

Comments
 (0)