File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -416,6 +416,13 @@ void BlockAssembler::addPackageTxs()
416
416
417
417
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx .get <ancestor_score>().begin ();
418
418
CTxMemPool::txiter iter;
419
+
420
+ // Limit the number of attempts to add transactions to the block when it is
421
+ // close to full; this is just a simple heuristic to finish quickly if the
422
+ // mempool has a lot of entries.
423
+ const int64_t MAX_CONSECUTIVE_FAILURES = 1000 ;
424
+ int64_t nConsecutiveFailed = 0 ;
425
+
419
426
while (mi != mempool.mapTx .get <ancestor_score>().end () || !mapModifiedTx.empty ())
420
427
{
421
428
// First try to find a new transaction in mapTx to evaluate.
@@ -477,6 +484,14 @@ void BlockAssembler::addPackageTxs()
477
484
mapModifiedTx.get <ancestor_score>().erase (modit);
478
485
failedTx.insert (iter);
479
486
}
487
+
488
+ ++nConsecutiveFailed;
489
+
490
+ if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
491
+ nBlockMaxWeight - 4000 ) {
492
+ // Give up if we're close to full and haven't succeeded in a while
493
+ break ;
494
+ }
480
495
continue ;
481
496
}
482
497
@@ -497,6 +512,9 @@ void BlockAssembler::addPackageTxs()
497
512
continue ;
498
513
}
499
514
515
+ // This transaction will make it in; reset the failed counter.
516
+ nConsecutiveFailed = 0 ;
517
+
500
518
// Package can be added. Sort the entries in a valid order.
501
519
std::vector<CTxMemPool::txiter> sortedEntries;
502
520
SortForBlock (ancestors, iter, sortedEntries);
You can’t perform that action at this time.
0 commit comments