diff options
author | stickies-v <stickies-v@protonmail.com> | 2022-10-25 12:33:37 +0100 |
---|---|---|
committer | stickies-v <stickies-v@protonmail.com> | 2022-12-13 15:43:17 +0000 |
commit | 5481f65849313ff947f38433b1ac28285a7f7694 (patch) | |
tree | fd50bdac791948290cb633c526b156b5278c404d /src/txmempool.cpp | |
parent | f911bdfff95eba3793fffaf71a31cc8bfc6f80c9 (diff) |
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
Diffstat (limited to 'src/txmempool.cpp')
-rw-r--r-- | src/txmempool.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 32f285276b..4232c6d305 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -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(); |