mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
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:
parent
f911bdfff9
commit
5481f65849
2 changed files with 35 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -566,6 +567,26 @@ public:
|
|||
const Limits& limits,
|
||||
bool fSearchForParents = true) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
/**
|
||||
* Same as CalculateMemPoolAncestors, but always returns a (non-optional) setEntries.
|
||||
* Should only be used when it is assumed CalculateMemPoolAncestors would not fail. If
|
||||
* CalculateMemPoolAncestors does unexpectedly fail, an empty setEntries is returned and the
|
||||
* error is logged to BCLog::MEMPOOL with level BCLog::Level::Error. In debug builds, failure
|
||||
* of CalculateMemPoolAncestors will lead to shutdown due to assertion failure.
|
||||
*
|
||||
* @param[in] calling_fn_name Name of calling function so we can properly log the call site
|
||||
*
|
||||
* @return a setEntries corresponding to the result of CalculateMemPoolAncestors or an empty
|
||||
* setEntries if it failed
|
||||
*
|
||||
* @see CTXMemPool::CalculateMemPoolAncestors()
|
||||
*/
|
||||
setEntries AssumeCalculateMemPoolAncestors(
|
||||
std::string_view calling_fn_name,
|
||||
const CTxMemPoolEntry &entry,
|
||||
const Limits& limits,
|
||||
bool fSearchForParents = true) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
/** Calculate all in-mempool ancestors of a set of transactions not already in the mempool and
|
||||
* check ancestor and descendant limits. Heuristics are used to estimate the ancestor and
|
||||
* descendant count of all entries if the package were to be added to the mempool. The limits
|
||||
|
|
Loading…
Add table
Reference in a new issue