Mining: return early when block is almost full
Github-Pull: #9959
Rebased-From: eed816af6c
This commit is contained in:
parent
b768202695
commit
b5c3440b05
|
@ -416,6 +416,13 @@ void BlockAssembler::addPackageTxs()
|
||||||
|
|
||||||
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
|
CTxMemPool::indexed_transaction_set::index<ancestor_score>::type::iterator mi = mempool.mapTx.get<ancestor_score>().begin();
|
||||||
CTxMemPool::txiter iter;
|
CTxMemPool::txiter iter;
|
||||||
|
|
||||||
|
// Limit the number of attempts to add transactions to the block when it is
|
||||||
|
// close to full; this is just a simple heuristic to finish quickly if the
|
||||||
|
// mempool has a lot of entries.
|
||||||
|
const int64_t MAX_CONSECUTIVE_FAILURES = 1000;
|
||||||
|
int64_t nConsecutiveFailed = 0;
|
||||||
|
|
||||||
while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty())
|
while (mi != mempool.mapTx.get<ancestor_score>().end() || !mapModifiedTx.empty())
|
||||||
{
|
{
|
||||||
// First try to find a new transaction in mapTx to evaluate.
|
// First try to find a new transaction in mapTx to evaluate.
|
||||||
|
@ -477,6 +484,14 @@ void BlockAssembler::addPackageTxs()
|
||||||
mapModifiedTx.get<ancestor_score>().erase(modit);
|
mapModifiedTx.get<ancestor_score>().erase(modit);
|
||||||
failedTx.insert(iter);
|
failedTx.insert(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++nConsecutiveFailed;
|
||||||
|
|
||||||
|
if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
|
||||||
|
nBlockMaxWeight - 4000) {
|
||||||
|
// Give up if we're close to full and haven't succeeded in a while
|
||||||
|
break;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,6 +512,9 @@ void BlockAssembler::addPackageTxs()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This transaction will make it in; reset the failed counter.
|
||||||
|
nConsecutiveFailed = 0;
|
||||||
|
|
||||||
// Package can be added. Sort the entries in a valid order.
|
// Package can be added. Sort the entries in a valid order.
|
||||||
std::vector<CTxMemPool::txiter> sortedEntries;
|
std::vector<CTxMemPool::txiter> sortedEntries;
|
||||||
SortForBlock(ancestors, iter, sortedEntries);
|
SortForBlock(ancestors, iter, sortedEntries);
|
||||||
|
|
Loading…
Reference in New Issue