mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
Merge #19848: Remove mempool global from interfaces
fa9ee52556
doc: Add doxygen comment to IsRBFOptIn (MarcoFalke)faef4fc9b4
Remove mempool global from interfaces (MarcoFalke)fa831684e5
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: utACKfa9ee52556
darosior: ACKfa9ee52
hebasto: re-ACKfa9ee52556
, since my [previous](https://github.com/bitcoin/bitcoin/pull/19848#pullrequestreview-482403942) review: Tree-SHA512: 11b4c1446f0860a743fdaa67f95c52bf0262d0a4f888be0eaf07ee497448965d32be414111bf016bd568f2989cde923430e3a3889e224057b73c499f06de7199
This commit is contained in:
commit
3ba25e3bdd
3 changed files with 41 additions and 15 deletions
|
@ -276,13 +276,15 @@ public:
|
||||||
}
|
}
|
||||||
RBFTransactionState isRBFOptIn(const CTransaction& tx) override
|
RBFTransactionState isRBFOptIn(const CTransaction& tx) override
|
||||||
{
|
{
|
||||||
LOCK(::mempool.cs);
|
if (!m_node.mempool) return IsRBFOptInEmptyMempool(tx);
|
||||||
return IsRBFOptIn(tx, ::mempool);
|
LOCK(m_node.mempool->cs);
|
||||||
|
return IsRBFOptIn(tx, *m_node.mempool);
|
||||||
}
|
}
|
||||||
bool hasDescendantsInMempool(const uint256& txid) override
|
bool hasDescendantsInMempool(const uint256& txid) override
|
||||||
{
|
{
|
||||||
LOCK(::mempool.cs);
|
if (!m_node.mempool) return false;
|
||||||
auto it = ::mempool.GetIter(txid);
|
LOCK(m_node.mempool->cs);
|
||||||
|
auto it = m_node.mempool->GetIter(txid);
|
||||||
return it && (*it)->GetCountWithDescendants() > 1;
|
return it && (*it)->GetCountWithDescendants() > 1;
|
||||||
}
|
}
|
||||||
bool broadcastTransaction(const CTransactionRef& tx,
|
bool broadcastTransaction(const CTransactionRef& tx,
|
||||||
|
@ -298,7 +300,9 @@ public:
|
||||||
}
|
}
|
||||||
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) override
|
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) override
|
||||||
{
|
{
|
||||||
::mempool.GetTransactionAncestry(txid, ancestors, descendants);
|
ancestors = descendants = 0;
|
||||||
|
if (!m_node.mempool) return;
|
||||||
|
m_node.mempool->GetTransactionAncestry(txid, ancestors, descendants);
|
||||||
}
|
}
|
||||||
void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
|
void getPackageLimits(unsigned int& limit_ancestor_count, unsigned int& limit_descendant_count) override
|
||||||
{
|
{
|
||||||
|
@ -307,6 +311,7 @@ public:
|
||||||
}
|
}
|
||||||
bool checkChainLimits(const CTransactionRef& tx) override
|
bool checkChainLimits(const CTransactionRef& tx) override
|
||||||
{
|
{
|
||||||
|
if (!m_node.mempool) return true;
|
||||||
LockPoints lp;
|
LockPoints lp;
|
||||||
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
|
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
|
||||||
CTxMemPool::setEntries ancestors;
|
CTxMemPool::setEntries ancestors;
|
||||||
|
@ -315,8 +320,9 @@ public:
|
||||||
auto limit_descendant_count = gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
|
auto limit_descendant_count = gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT);
|
||||||
auto limit_descendant_size = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000;
|
auto limit_descendant_size = gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000;
|
||||||
std::string unused_error_string;
|
std::string unused_error_string;
|
||||||
LOCK(::mempool.cs);
|
LOCK(m_node.mempool->cs);
|
||||||
return ::mempool.CalculateMemPoolAncestors(entry, ancestors, limit_ancestor_count, limit_ancestor_size,
|
return m_node.mempool->CalculateMemPoolAncestors(
|
||||||
|
entry, ancestors, limit_ancestor_count, limit_ancestor_size,
|
||||||
limit_descendant_count, limit_descendant_size, unused_error_string);
|
limit_descendant_count, limit_descendant_size, unused_error_string);
|
||||||
}
|
}
|
||||||
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
|
CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc) override
|
||||||
|
@ -329,7 +335,8 @@ public:
|
||||||
}
|
}
|
||||||
CFeeRate mempoolMinFee() override
|
CFeeRate mempoolMinFee() override
|
||||||
{
|
{
|
||||||
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
|
if (!m_node.mempool) return {};
|
||||||
|
return m_node.mempool->GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
|
||||||
}
|
}
|
||||||
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
|
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
|
||||||
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }
|
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }
|
||||||
|
@ -395,8 +402,9 @@ public:
|
||||||
}
|
}
|
||||||
void requestMempoolTransactions(Notifications& notifications) override
|
void requestMempoolTransactions(Notifications& notifications) override
|
||||||
{
|
{
|
||||||
LOCK2(::cs_main, ::mempool.cs);
|
if (!m_node.mempool) return;
|
||||||
for (const CTxMemPoolEntry& entry : ::mempool.mapTx) {
|
LOCK2(::cs_main, m_node.mempool->cs);
|
||||||
|
for (const CTxMemPoolEntry& entry : m_node.mempool->mapTx) {
|
||||||
notifications.transactionAddedToMempool(entry.GetSharedTx());
|
notifications.transactionAddedToMempool(entry.GetSharedTx());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,3 +36,9 @@ RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool)
|
||||||
}
|
}
|
||||||
return RBFTransactionState::FINAL;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -7,16 +7,28 @@
|
||||||
|
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
|
|
||||||
|
/** The rbf state of unconfirmed transactions */
|
||||||
enum class RBFTransactionState {
|
enum class RBFTransactionState {
|
||||||
|
/** Unconfirmed tx that does not signal rbf and is not in the mempool */
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
|
/** Either this tx or a mempool ancestor signals rbf */
|
||||||
REPLACEABLE_BIP125,
|
REPLACEABLE_BIP125,
|
||||||
FINAL
|
/** Neither this tx nor a mempool ancestor signals rbf */
|
||||||
|
FINAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Determine whether an in-mempool transaction is signaling opt-in to RBF
|
/**
|
||||||
// according to BIP 125
|
* Determine whether an unconfirmed transaction is signaling opt-in to RBF
|
||||||
// This involves checking sequence numbers of the transaction, as well
|
* according to BIP 125
|
||||||
// as the sequence numbers of all in-mempool ancestors.
|
* This involves checking sequence numbers of the transaction, as well
|
||||||
|
* as the sequence numbers of all in-mempool ancestors.
|
||||||
|
*
|
||||||
|
* @param tx The unconfirmed transaction
|
||||||
|
* @param pool The mempool, which may contain the tx
|
||||||
|
*
|
||||||
|
* @return The rbf state
|
||||||
|
*/
|
||||||
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
|
RBFTransactionState IsRBFOptIn(const CTransaction& tx, const CTxMemPool& pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
|
||||||
|
RBFTransactionState IsRBFOptInEmptyMempool(const CTransaction& tx);
|
||||||
|
|
||||||
#endif // BITCOIN_POLICY_RBF_H
|
#endif // BITCOIN_POLICY_RBF_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue