@@ -94,6 +94,7 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams)
94
94
nBlockMaxCost = nBlockMaxSize * WITNESS_SCALE_FACTOR;
95
95
}
96
96
}
97
+
97
98
// Limit cost to between 4K and MAX_BLOCK_COST-4K for sanity:
98
99
nBlockMaxCost = std::max ((unsigned int )4000 , std::min ((unsigned int )(MAX_BLOCK_COST-4000 ), nBlockMaxCost));
99
100
// Limit size to between 1K and MAX_BLOCK_SERIALIZED_SIZE-1K for sanity:
@@ -167,13 +168,7 @@ CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
167
168
fIncludeWitness = IsWitnessEnabled (pindexPrev, chainparams.GetConsensus ());
168
169
169
170
addPriorityTxs ();
170
- if (fNeedSizeAccounting ) {
171
- // addPackageTxs (the CPFP-based algorithm) cannot deal with size based
172
- // accounting, so fall back to the old algorithm.
173
- addScoreTxs ();
174
- } else {
175
- addPackageTxs ();
176
- }
171
+ addPackageTxs ();
177
172
178
173
nLastBlockTx = nBlockTx;
179
174
nLastBlockSize = nBlockSize;
@@ -243,11 +238,19 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
243
238
244
239
// Block size and sigops have already been tested. Check that all transactions
245
240
// are final.
246
- bool BlockAssembler::TestPackageFinality (const CTxMemPool::setEntries& package)
241
+ bool BlockAssembler::TestPackageFinalityAndSerializedSize (const CTxMemPool::setEntries& package)
247
242
{
243
+ uint64_t nPotentialBlockSize = nBlockSize; // only used with fNeedSizeAccounting
248
244
BOOST_FOREACH (const CTxMemPool::txiter it, package) {
249
245
if (!IsFinalTx (it->GetTx (), nHeight, nLockTimeCutoff))
250
246
return false ;
247
+ if (fNeedSizeAccounting ) {
248
+ uint64_t nTxSize = ::GetSerializeSize (it->GetTx (), SER_NETWORK, PROTOCOL_VERSION);
249
+ if (nPotentialBlockSize + nTxSize >= nBlockMaxSize) {
250
+ return false ;
251
+ }
252
+ nPotentialBlockSize += nTxSize;
253
+ }
251
254
}
252
255
return true ;
253
256
}
@@ -539,7 +542,7 @@ void BlockAssembler::addPackageTxs()
539
542
ancestors.insert (iter);
540
543
541
544
// Test if all tx's are Final
542
- if (!TestPackageFinality (ancestors)) {
545
+ if (!TestPackageFinalityAndSerializedSize (ancestors)) {
543
546
if (fUsingModified ) {
544
547
mapModifiedTx.get <ancestor_score>().erase (modit);
545
548
failedTx.insert (iter);
@@ -573,6 +576,7 @@ void BlockAssembler::addPriorityTxs()
573
576
return ;
574
577
}
575
578
579
+ bool fSizeAccounting = fNeedSizeAccounting ;
576
580
fNeedSizeAccounting = true ;
577
581
578
582
// This vector will be sorted into a priority queue:
@@ -624,7 +628,7 @@ void BlockAssembler::addPriorityTxs()
624
628
// If now that this txs is added we've surpassed our desired priority size
625
629
// or have dropped below the AllowFreeThreshold, then we're done adding priority txs
626
630
if (nBlockSize >= nBlockPrioritySize || !AllowFree (actualPriority)) {
627
- return ;
631
+ break ;
628
632
}
629
633
630
634
// This tx was successfully added, so
@@ -640,6 +644,7 @@ void BlockAssembler::addPriorityTxs()
640
644
}
641
645
}
642
646
}
647
+ fNeedSizeAccounting = fSizeAccounting ;
643
648
}
644
649
645
650
void IncrementExtraNonce (CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int & nExtraNonce)
0 commit comments