Skip to content

Commit 3ba25e3

Browse files
author
MarcoFalke
committed
Merge #19848: Remove mempool global from interfaces
fa9ee52 doc: Add doxygen comment to IsRBFOptIn (MarcoFalke) faef4fc Remove mempool global from interfaces (MarcoFalke) fa83168 refactor: Add IsRBFOptInEmptyMempool (MarcoFalke) Pull request description: The chain interface has an `m_node` member, which has a pointer to the mempool global. Use the pointer instead of the global to prepare the removal of the mempool global. See #19556 ACKs for top commit: jnewbery: utACK fa9ee52 darosior: ACK fa9ee52 hebasto: re-ACK fa9ee52, since my [previous](bitcoin/bitcoin#19848 (review)) review: Tree-SHA512: 11b4c1446f0860a743fdaa67f95c52bf0262d0a4f888be0eaf07ee497448965d32be414111bf016bd568f2989cde923430e3a3889e224057b73c499f06de7199
2 parents 416efcb + fa9ee52 commit 3ba25e3

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

src/interfaces/chain.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,15 @@ class ChainImpl : public Chain
276276
}
277277
RBFTransactionState isRBFOptIn(const CTransaction& tx) override
278278
{
279-
LOCK(::mempool.cs);
280-
return IsRBFOptIn(tx, ::mempool);
279+
if (!m_node.mempool) return IsRBFOptInEmptyMempool(tx);
280+
LOCK(m_node.mempool->cs);
281+
return IsRBFOptIn(tx, *m_node.mempool);
281282
}
282283
bool hasDescendantsInMempool(const uint256& txid) override
283284
{
284-
LOCK(::mempool.cs);
285-
auto it = ::mempool.GetIter(txid);
285+
if (!m_node.mempool) return false;
286+
LOCK(m_node.mempool->cs);
287+
auto it = m_node.mempool->GetIter(txid);
286288
return it && (*it)->GetCountWithDescendants() > 1;
287289
}
288290
bool broadcastTransaction(const CTransactionRef& tx,
@@ -298,7 +300,9 @@ class ChainImpl : public Chain
298300
}
299301
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) override
300302
{
301-
::mempool.GetTransactionAncestry(txid, ancestors, descendants);
303+
ancestors = descendants = 0;
304+
if (!m_node.mempool) return;
305+
m_node.mempool->GetTransactionAncestry(txid, ancestors, descendants);
302306
}
303307
void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
304308
{
@@ -307,6 +311,7 @@ class ChainImpl : public Chain
307311
}
308312
bool checkChainLimits(const CTransactionRef& tx) override
309313
{
314+
if (!m_node.mempool) return true;
310315
LockPoints lp;
311316
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
312317
CTxMemPool::setEntries ancestors;
@@ -315,8 +320,9 @@ class ChainImpl : public Chain
315320
auto limit_descendant_count = gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
316321
auto limit_descendant_size = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000;
317322
std::string unused_error_string;
318-
LOCK(::mempool.cs);
319-
return ::mempool.CalculateMemPoolAncestors(entry, ancestors, limit_ancestor_count, limit_ancestor_size,
323+
LOCK(m_node.mempool->cs);
324+
return m_node.mempool->CalculateMemPoolAncestors(
325+
entry, ancestors, limit_ancestor_count, limit_ancestor_size,
320326
limit_descendant_count, limit_descendant_size, unused_error_string);
321327
}
322328
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
@@ -329,7 +335,8 @@ class ChainImpl : public Chain
329335
}
330336
CFeeRate mempoolMinFee() override
331337
{
332-
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
338+
if (!m_node.mempool) return {};
339+
return m_node.mempool->GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
333340
}
334341
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
335342
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }
@@ -395,8 +402,9 @@ class ChainImpl : public Chain
395402
}
396403
void requestMempoolTransactions(Notifications& notifications) override
397404
{
398-
LOCK2(::cs_main, ::mempool.cs);
399-
for (const CTxMemPoolEntry& entry : ::mempool.mapTx) {
405+
if (!m_node.mempool) return;
406+
LOCK2(::cs_main, m_node.mempool->cs);
407+
for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
400408
notifications.transactionAddedToMempool(entry.GetSharedTx());
401409
}
402410
}

src/policy/rbf.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
3636
}
3737
return RBFTransactionState::FINAL;
3838
}
39+
40+
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx)
41+
{
42+
// If we don't have a local mempool we can only check the transaction itself.
43+
return SignalsOptInRBF(tx) ? RBFTransactionState::REPLACEABLE_BIP125 : RBFTransactionState::UNKNOWN;
44+
}

src/policy/rbf.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@
77

88
#include <txmempool.h>
99

10+
/** The rbf state of unconfirmed transactions */
1011
enum class RBFTransactionState {
12+
/** Unconfirmed tx that does not signal rbf and is not in the mempool */
1113
UNKNOWN,
14+
/** Either this tx or a mempool ancestor signals rbf */
1215
REPLACEABLE_BIP125,
13-
FINAL
16+
/** Neither this tx nor a mempool ancestor signals rbf */
17+
FINAL,
1418
};
1519

16-
// Determine whether an in-mempool transaction is signaling opt-in to RBF
17-
// according to BIP 125
18-
// This involves checking sequence numbers of the transaction, as well
19-
// as the sequence numbers of all in-mempool ancestors.
20+
/**
21+
* Determine whether an unconfirmed transaction is signaling opt-in to RBF
22+
* according to BIP 125
23+
* This involves checking sequence numbers of the transaction, as well
24+
* as the sequence numbers of all in-mempool ancestors.
25+
*
26+
* @param tx The unconfirmed transaction
27+
* @param pool The mempool, which may contain the tx
28+
*
29+
* @return The rbf state
30+
*/
2031
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
32+
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx);
2133

2234
#endif // BITCOIN_POLICY_RBF_H

0 commit comments

Comments
 (0)