mempool: add AssumeCalculateMemPoolAncestors helper function

There are quite a few places that assume CalculateMemPoolAncestors
will return a value without raising an error. This helper function
adds logging (and Assume for debug builds) that ensures robustness
but increases visibility in case of unexpected failures
This commit is contained in:
stickies-v
2022-10-25 12:33:37 +01:00
parent f911bdfff9
commit 5481f65849
2 changed files with 35 additions and 0 deletions

View File

@@ -254,6 +254,20 @@ util::Result<CTxMemPool::setEntries> CTxMemPool::CalculateMemPoolAncestors(
limits);
}
CTxMemPool::setEntries CTxMemPool::AssumeCalculateMemPoolAncestors(
std::string_view calling_fn_name,
const CTxMemPoolEntry &entry,
const Limits& limits,
bool fSearchForParents /* = true */) const
{
auto result{Assume(CalculateMemPoolAncestors(entry, limits, fSearchForParents))};
if (!result) {
LogPrintLevel(BCLog::MEMPOOL, BCLog::Level::Error, "%s: CalculateMemPoolAncestors failed unexpectedly, continuing with empty ancestor set (%s)\n",
calling_fn_name, util::ErrorString(result).original);
}
return std::move(result).value_or(CTxMemPool::setEntries{});
}
void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors)
{
const CTxMemPoolEntry::Parents& parents = it->GetMemPoolParentsConst();