mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-05-17 23:56:39 +00:00
CValidationInterface: modify the parameter of TransactionAddedToMempool
Create a new struct `NewMempoolTransactionInfo` that will be used as the new parameter of `TransactionAddedToMempool` callback.
This commit is contained in:
parent
91532bd382
commit
dff5ad3b99
@ -208,4 +208,33 @@ struct RemovedMempoolTransactionInfo {
|
|||||||
: info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {}
|
: info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NewMempoolTransactionInfo {
|
||||||
|
TransactionInfo info;
|
||||||
|
/*
|
||||||
|
* This boolean indicates whether the transaction was added
|
||||||
|
* without enforcing mempool fee limits.
|
||||||
|
*/
|
||||||
|
const bool m_from_disconnected_block;
|
||||||
|
/* This boolean indicates whether the transaction is part of a package. */
|
||||||
|
const bool m_submitted_in_package;
|
||||||
|
/*
|
||||||
|
* This boolean indicates whether the blockchain is up to date when the
|
||||||
|
* transaction is added to the mempool.
|
||||||
|
*/
|
||||||
|
const bool m_chainstate_is_current;
|
||||||
|
/* Indicates whether the transaction has unconfirmed parents. */
|
||||||
|
const bool m_has_no_mempool_parents;
|
||||||
|
|
||||||
|
explicit NewMempoolTransactionInfo(const CTransactionRef& tx, const CAmount& fee,
|
||||||
|
const int64_t vsize, const unsigned int height,
|
||||||
|
const bool from_disconnected_block, const bool submitted_in_package,
|
||||||
|
const bool chainstate_is_current,
|
||||||
|
const bool has_no_mempool_parents)
|
||||||
|
: info{tx, fee, vsize, height},
|
||||||
|
m_from_disconnected_block{from_disconnected_block},
|
||||||
|
m_submitted_in_package{submitted_in_package},
|
||||||
|
m_chainstate_is_current{chainstate_is_current},
|
||||||
|
m_has_no_mempool_parents{has_no_mempool_parents} {}
|
||||||
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_KERNEL_MEMPOOL_ENTRY_H
|
#endif // BITCOIN_KERNEL_MEMPOOL_ENTRY_H
|
||||||
|
@ -428,9 +428,9 @@ public:
|
|||||||
explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
|
explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
|
||||||
: m_notifications(std::move(notifications)) {}
|
: m_notifications(std::move(notifications)) {}
|
||||||
virtual ~NotificationsProxy() = default;
|
virtual ~NotificationsProxy() = default;
|
||||||
void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override
|
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override
|
||||||
{
|
{
|
||||||
m_notifications->transactionAddedToMempool(tx);
|
m_notifications->transactionAddedToMempool(tx.info.m_tx);
|
||||||
}
|
}
|
||||||
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
|
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
|
||||||
{
|
{
|
||||||
|
@ -55,13 +55,13 @@ struct OutpointsUpdater final : public CValidationInterface {
|
|||||||
explicit OutpointsUpdater(std::set<COutPoint>& r)
|
explicit OutpointsUpdater(std::set<COutPoint>& r)
|
||||||
: m_mempool_outpoints{r} {}
|
: m_mempool_outpoints{r} {}
|
||||||
|
|
||||||
void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t /* mempool_sequence */) override
|
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
|
||||||
{
|
{
|
||||||
// for coins spent we always want to be able to rbf so they're not removed
|
// for coins spent we always want to be able to rbf so they're not removed
|
||||||
|
|
||||||
// outputs from this tx can now be spent
|
// outputs from this tx can now be spent
|
||||||
for (uint32_t index{0}; index < tx->vout.size(); ++index) {
|
for (uint32_t index{0}; index < tx.info.m_tx->vout.size(); ++index) {
|
||||||
m_mempool_outpoints.insert(COutPoint{tx->GetHash(), index});
|
m_mempool_outpoints.insert(COutPoint{tx.info.m_tx->GetHash(), index});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +85,10 @@ struct TransactionsDelta final : public CValidationInterface {
|
|||||||
explicit TransactionsDelta(std::set<CTransactionRef>& a)
|
explicit TransactionsDelta(std::set<CTransactionRef>& a)
|
||||||
: m_added{a} {}
|
: m_added{a} {}
|
||||||
|
|
||||||
void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t /* mempool_sequence */) override
|
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
|
||||||
{
|
{
|
||||||
// Transactions may be entered and booted any number of times
|
// Transactions may be entered and booted any number of times
|
||||||
m_added.insert(tx);
|
m_added.insert(tx.info.m_tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
|
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
|
||||||
|
@ -59,9 +59,9 @@ struct TransactionsDelta final : public CValidationInterface {
|
|||||||
explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
|
explicit TransactionsDelta(std::set<CTransactionRef>& r, std::set<CTransactionRef>& a)
|
||||||
: m_removed{r}, m_added{a} {}
|
: m_removed{r}, m_added{a} {}
|
||||||
|
|
||||||
void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t /* mempool_sequence */) override
|
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /* mempool_sequence */) override
|
||||||
{
|
{
|
||||||
Assert(m_added.insert(tx).second);
|
Assert(m_added.insert(tx.info.m_tx).second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
|
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t /* mempool_sequence */) override
|
||||||
|
@ -1222,7 +1222,13 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>&
|
|||||||
results.emplace(ws.m_ptx->GetWitnessHash(),
|
results.emplace(ws.m_ptx->GetWitnessHash(),
|
||||||
MempoolAcceptResult::Success(std::move(ws.m_replaced_transactions), ws.m_vsize,
|
MempoolAcceptResult::Success(std::move(ws.m_replaced_transactions), ws.m_vsize,
|
||||||
ws.m_base_fees, effective_feerate, effective_feerate_wtxids));
|
ws.m_base_fees, effective_feerate, effective_feerate_wtxids));
|
||||||
GetMainSignals().TransactionAddedToMempool(ws.m_ptx, m_pool.GetAndIncrementSequence());
|
const CTransaction& tx = *ws.m_ptx;
|
||||||
|
const auto tx_info = NewMempoolTransactionInfo(ws.m_ptx, ws.m_base_fees,
|
||||||
|
ws.m_vsize, ws.m_entry->GetHeight(),
|
||||||
|
args.m_bypass_limits, args.m_package_submission,
|
||||||
|
IsCurrentForFeeEstimation(m_active_chainstate),
|
||||||
|
m_pool.HasNoInputsOf(tx));
|
||||||
|
GetMainSignals().TransactionAddedToMempool(tx_info, m_pool.GetAndIncrementSequence());
|
||||||
}
|
}
|
||||||
return all_submitted;
|
return all_submitted;
|
||||||
}
|
}
|
||||||
@ -1265,7 +1271,13 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
|
|||||||
return MempoolAcceptResult::FeeFailure(ws.m_state, CFeeRate(ws.m_modified_fees, ws.m_vsize), {ws.m_ptx->GetWitnessHash()});
|
return MempoolAcceptResult::FeeFailure(ws.m_state, CFeeRate(ws.m_modified_fees, ws.m_vsize), {ws.m_ptx->GetWitnessHash()});
|
||||||
}
|
}
|
||||||
|
|
||||||
GetMainSignals().TransactionAddedToMempool(ptx, m_pool.GetAndIncrementSequence());
|
const CTransaction& tx = *ws.m_ptx;
|
||||||
|
const auto tx_info = NewMempoolTransactionInfo(ws.m_ptx, ws.m_base_fees,
|
||||||
|
ws.m_vsize, ws.m_entry->GetHeight(),
|
||||||
|
args.m_bypass_limits, args.m_package_submission,
|
||||||
|
IsCurrentForFeeEstimation(m_active_chainstate),
|
||||||
|
m_pool.HasNoInputsOf(tx));
|
||||||
|
GetMainSignals().TransactionAddedToMempool(tx_info, m_pool.GetAndIncrementSequence());
|
||||||
|
|
||||||
return MempoolAcceptResult::Success(std::move(ws.m_replaced_transactions), ws.m_vsize, ws.m_base_fees,
|
return MempoolAcceptResult::Success(std::move(ws.m_replaced_transactions), ws.m_vsize, ws.m_base_fees,
|
||||||
effective_feerate, single_wtxid);
|
effective_feerate, single_wtxid);
|
||||||
|
@ -206,13 +206,14 @@ void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInd
|
|||||||
fInitialDownload);
|
fInitialDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainSignals::TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) {
|
void CMainSignals::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence)
|
||||||
|
{
|
||||||
auto event = [tx, mempool_sequence, this] {
|
auto event = [tx, mempool_sequence, this] {
|
||||||
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); });
|
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.TransactionAddedToMempool(tx, mempool_sequence); });
|
||||||
};
|
};
|
||||||
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
|
ENQUEUE_AND_LOG_EVENT(event, "%s: txid=%s wtxid=%s", __func__,
|
||||||
tx->GetHash().ToString(),
|
tx.info.m_tx->GetHash().ToString(),
|
||||||
tx->GetWitnessHash().ToString());
|
tx.info.m_tx->GetWitnessHash().ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) {
|
void CMainSignals::TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) {
|
||||||
|
@ -22,6 +22,7 @@ class CValidationInterface;
|
|||||||
class CScheduler;
|
class CScheduler;
|
||||||
enum class MemPoolRemovalReason;
|
enum class MemPoolRemovalReason;
|
||||||
struct RemovedMempoolTransactionInfo;
|
struct RemovedMempoolTransactionInfo;
|
||||||
|
struct NewMempoolTransactionInfo;
|
||||||
|
|
||||||
/** Register subscriber */
|
/** Register subscriber */
|
||||||
void RegisterValidationInterface(CValidationInterface* callbacks);
|
void RegisterValidationInterface(CValidationInterface* callbacks);
|
||||||
@ -97,7 +98,7 @@ protected:
|
|||||||
*
|
*
|
||||||
* Called on a background thread.
|
* Called on a background thread.
|
||||||
*/
|
*/
|
||||||
virtual void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) {}
|
virtual void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies listeners of a transaction leaving mempool.
|
* Notifies listeners of a transaction leaving mempool.
|
||||||
@ -210,7 +211,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
|
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
|
||||||
void TransactionAddedToMempool(const CTransactionRef&, uint64_t mempool_sequence);
|
void TransactionAddedToMempool(const NewMempoolTransactionInfo&, uint64_t mempool_sequence);
|
||||||
void TransactionRemovedFromMempool(const CTransactionRef&, MemPoolRemovalReason, uint64_t mempool_sequence);
|
void TransactionRemovedFromMempool(const CTransactionRef&, MemPoolRemovalReason, uint64_t mempool_sequence);
|
||||||
void MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>&, unsigned int nBlockHeight);
|
void MempoolTransactionsRemovedForBlock(const std::vector<RemovedMempoolTransactionInfo>&, unsigned int nBlockHeight);
|
||||||
void BlockConnected(ChainstateRole, const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex);
|
void BlockConnected(ChainstateRole, const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
#include <kernel/chain.h>
|
#include <kernel/chain.h>
|
||||||
|
#include <kernel/mempool_entry.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
@ -152,9 +153,9 @@ void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, co
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CZMQNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, uint64_t mempool_sequence)
|
void CZMQNotificationInterface::TransactionAddedToMempool(const NewMempoolTransactionInfo& ptx, uint64_t mempool_sequence)
|
||||||
{
|
{
|
||||||
const CTransaction& tx = *ptx;
|
const CTransaction& tx = *(ptx.info.m_tx);
|
||||||
|
|
||||||
TryForEachAndRemoveFailed(notifiers, [&tx, mempool_sequence](CZMQAbstractNotifier* notifier) {
|
TryForEachAndRemoveFailed(notifiers, [&tx, mempool_sequence](CZMQAbstractNotifier* notifier) {
|
||||||
return notifier->NotifyTransaction(tx) && notifier->NotifyTransactionAcceptance(tx, mempool_sequence);
|
return notifier->NotifyTransaction(tx) && notifier->NotifyTransactionAcceptance(tx, mempool_sequence);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
class CBlock;
|
class CBlock;
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class CZMQAbstractNotifier;
|
class CZMQAbstractNotifier;
|
||||||
|
struct NewMempoolTransactionInfo;
|
||||||
|
|
||||||
class CZMQNotificationInterface final : public CValidationInterface
|
class CZMQNotificationInterface final : public CValidationInterface
|
||||||
{
|
{
|
||||||
@ -31,7 +32,7 @@ protected:
|
|||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
// CValidationInterface
|
// CValidationInterface
|
||||||
void TransactionAddedToMempool(const CTransactionRef& tx, uint64_t mempool_sequence) override;
|
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override;
|
||||||
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
|
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override;
|
||||||
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
|
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override;
|
||||||
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
|
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user