Skip to content

Commit 47c4b1f

Browse files
committed
mempool: log/halt when CalculateMemPoolAncestors fails unexpectedly
When CalculateMemPoolAncestors fails unexpectedly (e.g. it exceeds ancestor/descendant limits even though we expect no limits to be applied), add an error log entry for increased visibility. For debug builds, the application will even halt completely since this is not supposed to happen.
1 parent 5481f65 commit 47c4b1f

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

src/node/miner.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ void BlockAssembler::addPackageTxs(const CTxMemPool& mempool, int& nPackagesSele
394394
continue;
395395
}
396396

397-
auto ancestors_result{mempool.CalculateMemPoolAncestors(*iter, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
398-
auto ancestors{std::move(ancestors_result).value_or(CTxMemPool::setEntries{})};
397+
auto ancestors{mempool.AssumeCalculateMemPoolAncestors(__func__, *iter, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
399398

400399
onlyUnconfirmed(ancestors);
401400
ancestors.insert(iter);

src/policy/rbf.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <util/rbf.h>
1717

1818
#include <limits>
19-
#include <utility>
2019
#include <vector>
2120

2221
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
@@ -36,9 +35,9 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
3635

3736
// If all the inputs have nSequence >= maxint-1, it still might be
3837
// signaled for RBF if any unconfirmed parents have signaled.
39-
CTxMemPoolEntry entry = *pool.mapTx.find(tx.GetHash());
40-
auto ancestors_result{pool.CalculateMemPoolAncestors(entry, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
41-
auto ancestors{std::move(ancestors_result).value_or(CTxMemPool::setEntries{})};
38+
const CTxMemPoolEntry entry{*pool.mapTx.find(tx.GetHash())};
39+
auto ancestors{pool.AssumeCalculateMemPoolAncestors(__func__, entry, CTxMemPool::Limits::NoLimits(),
40+
/*fSearchForParents=*/false)};
4241

4342
for (CTxMemPool::txiter it : ancestors) {
4443
if (SignalsOptInRBF(it->GetTx())) {

src/rpc/mempool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ static RPCHelpMan getmempoolancestors()
451451
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
452452
}
453453

454-
auto ancestors_result{mempool.CalculateMemPoolAncestors(*it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
455-
auto ancestors{std::move(ancestors_result).value_or(CTxMemPool::setEntries{})};
454+
auto ancestors{mempool.AssumeCalculateMemPoolAncestors(__func__, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
456455

457456
if (!fVerbose) {
458457
UniValue o(UniValue::VARR);

src/txmempool.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, b
349349
// mempool parents we'd calculate by searching, and it's important that
350350
// we use the cached notion of ancestor transactions as the set of
351351
// things to update for removal.
352-
auto ancestors_result{CalculateMemPoolAncestors(entry, Limits::NoLimits(), /*fSearchForParents=*/false)};
353-
auto ancestors{std::move(ancestors_result).value_or(setEntries{})};
352+
auto ancestors{AssumeCalculateMemPoolAncestors(__func__, entry, Limits::NoLimits(), /*fSearchForParents=*/false)};
354353
// Note that UpdateAncestorsOf severs the child links that point to
355354
// removeIt in the entries for the parents of removeIt.
356355
UpdateAncestorsOf(false, removeIt, ancestors);
@@ -703,8 +702,7 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
703702
assert(setParentCheck.size() == it->GetMemPoolParentsConst().size());
704703
assert(std::equal(setParentCheck.begin(), setParentCheck.end(), it->GetMemPoolParentsConst().begin(), comp));
705704
// Verify ancestor state is correct.
706-
auto ancestors_result{CalculateMemPoolAncestors(*it, Limits::NoLimits())};
707-
auto ancestors{std::move(ancestors_result).value_or(setEntries{})};
705+
auto ancestors{AssumeCalculateMemPoolAncestors(__func__, *it, Limits::NoLimits())};
708706
uint64_t nCountCheck = ancestors.size() + 1;
709707
uint64_t nSizeCheck = it->GetTxSize();
710708
CAmount nFeesCheck = it->GetModifiedFee();
@@ -865,8 +863,7 @@ void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeD
865863
if (it != mapTx.end()) {
866864
mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntry& e) { e.UpdateModifiedFee(nFeeDelta); });
867865
// Now update all ancestors' modified fees with descendants
868-
auto ancestors_result{CalculateMemPoolAncestors(*it, Limits::NoLimits(), /*fSearchForParents=*/false)};
869-
auto ancestors{std::move(ancestors_result).value_or(setEntries{})};
866+
auto ancestors{AssumeCalculateMemPoolAncestors(__func__, *it, Limits::NoLimits(), /*fSearchForParents=*/false)};
870867
for (txiter ancestorIt : ancestors) {
871868
mapTx.modify(ancestorIt, [=](CTxMemPoolEntry& e){ e.UpdateDescendantState(0, nFeeDelta, 0);});
872869
}
@@ -1004,8 +1001,7 @@ int CTxMemPool::Expire(std::chrono::seconds time)
10041001

10051002
void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate)
10061003
{
1007-
auto ancestors_result{CalculateMemPoolAncestors(entry, Limits::NoLimits())};
1008-
auto ancestors{std::move(ancestors_result).value_or(CTxMemPool::setEntries{})};
1004+
auto ancestors{AssumeCalculateMemPoolAncestors(__func__, entry, Limits::NoLimits())};
10091005
return addUnchecked(entry, ancestors, validFeeEstimate);
10101006
}
10111007

0 commit comments

Comments
 (0)