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 @@ -358,6 +358,13 @@ void BlockAssembler::addPackageTxs()
358
358
359
359
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx .get <ancestor_score>().begin ();
360
360
CTxMemPool::txiter iter;
361
+
362
+ // Limit the number of attempts to add transactions to the block when it is
363
+ // close to full; this is just a simple heuristic to finish quickly if the
364
+ // mempool has a lot of entries.
365
+ const int64_t MAX_CONSECUTIVE_FAILURES = 1000 ;
366
+ int64_t nConsecutiveFailed = 0 ;
367
+
361
368
while (mi != mempool.mapTx .get <ancestor_score>().end () || !mapModifiedTx.empty ())
362
369
{
363
370
// First try to find a new transaction in mapTx to evaluate.
@@ -419,6 +426,14 @@ void BlockAssembler::addPackageTxs()
419
426
mapModifiedTx.get <ancestor_score>().erase (modit);
420
427
failedTx.insert (iter);
421
428
}
429
+
430
+ ++nConsecutiveFailed;
431
+
432
+ if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
433
+ nBlockMaxWeight - 4000 ) {
434
+ // Give up if we're close to full and haven't succeeded in a while
435
+ break ;
436
+ }
422
437
continue ;
423
438
}
424
439
@@ -439,6 +454,9 @@ void BlockAssembler::addPackageTxs()
439
454
continue ;
440
455
}
441
456
457
+ // This transaction will make it in; reset the failed counter.
458
+ nConsecutiveFailed = 0 ;
459
+
442
460
// Package can be added. Sort the entries in a valid order.
443
461
std::vector<CTxMemPool::txiter> sortedEntries;
444
462
SortForBlock (ancestors, iter, sortedEntries);
You can’t perform that action at this time.
0 commit comments