aboutsummaryrefslogtreecommitdiff
path: root/src/txmempool.h
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2022-10-25 12:33:37 +0100
committerstickies-v <stickies-v@protonmail.com>2022-12-13 15:43:17 +0000
commit5481f65849313ff947f38433b1ac28285a7f7694 (patch)
treefd50bdac791948290cb633c526b156b5278c404d /src/txmempool.h
parentf911bdfff95eba3793fffaf71a31cc8bfc6f80c9 (diff)
downloadbitcoin-5481f65849313ff947f38433b1ac28285a7f7694.tar.xz
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.h')
-rw-r--r--src/txmempool.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/txmempool.h b/src/txmempool.h
index 14b0dc3871..c176b3602a 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -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