From 18829194ca68152ac0b38d34e94b9265ee74c410 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Mon, 14 Oct 2024 10:19:44 -0400 Subject: [PATCH] Enforce that there is only one changeset at a time --- src/txmempool.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/txmempool.h b/src/txmempool.h index 4832ebef9fa..ee4f269fac4 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -811,7 +811,7 @@ public: class ChangeSet { public: explicit ChangeSet(CTxMemPool* pool) : m_pool(pool) {} - ~ChangeSet() = default; + ~ChangeSet() EXCLUSIVE_LOCKS_REQUIRED(m_pool->cs) { m_pool->m_have_changeset = false; } ChangeSet(const ChangeSet&) = delete; ChangeSet& operator=(const ChangeSet&) = delete; @@ -860,7 +860,13 @@ public: friend class CTxMemPool; }; - std::unique_ptr GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs) { return std::make_unique(this); } + std::unique_ptr GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs) { + Assume(!m_have_changeset); + m_have_changeset = true; + return std::make_unique(this); + } + + bool m_have_changeset GUARDED_BY(cs){false}; friend class CTxMemPool::ChangeSet;