From bc2eb931da30bd98670528c0b96f6ca05f14f8b9 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Tue, 25 Nov 2025 13:03:46 -0500 Subject: [PATCH] Require mempool lock to be held when invoking TRUC checks --- src/policy/truc_policy.cpp | 3 ++- src/policy/truc_policy.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/policy/truc_policy.cpp b/src/policy/truc_policy.cpp index c5ba866a5da..bc5142c76f6 100644 --- a/src/policy/truc_policy.cpp +++ b/src/policy/truc_policy.cpp @@ -59,6 +59,7 @@ std::optional PackageTRUCChecks(const CTxMemPool& pool, const CTran const Package& package, const std::vector& mempool_parents) { + AssertLockHeld(pool.cs); // This function is specialized for these limits, and must be reimplemented if they ever change. static_assert(TRUC_ANCESTOR_LIMIT == 2); static_assert(TRUC_DESCENDANT_LIMIT == 2); @@ -173,7 +174,7 @@ std::optional> SingleTRUCChecks(const CT const std::set& direct_conflicts, int64_t vsize) { - LOCK(pool.cs); + AssertLockHeld(pool.cs); // Check TRUC and non-TRUC inheritance. for (const auto& entry_ref : mempool_parents) { const auto& entry = &entry_ref.get(); diff --git a/src/policy/truc_policy.h b/src/policy/truc_policy.h index 8b2ec097126..9eec8d2f179 100644 --- a/src/policy/truc_policy.h +++ b/src/policy/truc_policy.h @@ -66,7 +66,7 @@ static_assert(TRUC_MAX_VSIZE + TRUC_CHILD_MAX_VSIZE <= DEFAULT_CLUSTER_SIZE_LIMI std::optional> SingleTRUCChecks(const CTxMemPool& pool, const CTransactionRef& ptx, const std::vector& mempool_parents, const std::set& direct_conflicts, - int64_t vsize); + int64_t vsize) EXCLUSIVE_LOCKS_REQUIRED(pool.cs); /** Must be called for every transaction that is submitted within a package, even if not TRUC. * @@ -91,6 +91,6 @@ std::optional> SingleTRUCChecks(const CT * */ std::optional PackageTRUCChecks(const CTxMemPool& pool, const CTransactionRef& ptx, int64_t vsize, const Package& package, - const std::vector& mempool_parents); + const std::vector& mempool_parents) EXCLUSIVE_LOCKS_REQUIRED(pool.cs); #endif // BITCOIN_POLICY_TRUC_POLICY_H