From fa831684e54783f6b40533ca218eb7636bdae667 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 19 Jul 2020 11:09:59 +0200 Subject: refactor: Add IsRBFOptInEmptyMempool Co-authored-by: John Newbery --- src/interfaces/chain.cpp | 5 +++-- src/policy/rbf.cpp | 6 ++++++ src/policy/rbf.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index 313c1265de..19de8ab202 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -276,8 +276,9 @@ public: } RBFTransactionState isRBFOptIn(const CTransaction& tx) override { - LOCK(::mempool.cs); - return IsRBFOptIn(tx, ::mempool); + if (!m_node.mempool) return IsRBFOptInEmptyMempool(tx); + LOCK(m_node.mempool->cs); + return IsRBFOptIn(tx, *m_node.mempool); } bool hasDescendantsInMempool(const uint256& txid) override { diff --git a/src/policy/rbf.cpp b/src/policy/rbf.cpp index f8b17d18d5..4b55934891 100644 --- a/src/policy/rbf.cpp +++ b/src/policy/rbf.cpp @@ -36,3 +36,9 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) } return RBFTransactionState::FINAL; } + +RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx) +{ + // If we don't have a local mempool we can only check the transaction itself. + return SignalsOptInRBF(tx) ? RBFTransactionState::REPLACEABLE_BIP125 : RBFTransactionState::UNKNOWN; +} diff --git a/src/policy/rbf.h b/src/policy/rbf.h index d335fbbb36..463c5b61e6 100644 --- a/src/policy/rbf.h +++ b/src/policy/rbf.h @@ -18,5 +18,6 @@ enum class RBFTransactionState { // This involves checking sequence numbers of the transaction, as well // as the sequence numbers of all in-mempool ancestors. RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs); +RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx); #endif // BITCOIN_POLICY_RBF_H -- cgit v1.2.3