mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
refactor: make txmempool interface use GenTxid
This commit is contained in:
parent
5c124e1740
commit
10b7a6d532
3 changed files with 16 additions and 11 deletions
|
@ -1453,7 +1453,7 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
|
||||||
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
|
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return recentRejects->contains(inv.hash) || mempool.exists(inv.hash, inv.IsMsgWtx());
|
return recentRejects->contains(inv.hash) || mempool.exists(ToGenTxid(inv));
|
||||||
}
|
}
|
||||||
case MSG_BLOCK:
|
case MSG_BLOCK:
|
||||||
case MSG_WITNESS_BLOCK:
|
case MSG_WITNESS_BLOCK:
|
||||||
|
@ -1673,7 +1673,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
|
||||||
//! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
|
//! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
|
||||||
CTransactionRef static FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main)
|
CTransactionRef static FindTxForGetData(const CNode& peer, const GenTxid& gtxid, const std::chrono::seconds mempool_req, const std::chrono::seconds now) LOCKS_EXCLUDED(cs_main)
|
||||||
{
|
{
|
||||||
auto txinfo = mempool.info(gtxid.GetHash(), gtxid.IsWtxid());
|
auto txinfo = mempool.info(gtxid);
|
||||||
if (txinfo.tx) {
|
if (txinfo.tx) {
|
||||||
// If a TX could have been INVed in reply to a MEMPOOL request,
|
// If a TX could have been INVed in reply to a MEMPOOL request,
|
||||||
// or is older than UNCONDITIONAL_RELAY_DELAY, permit the request
|
// or is older than UNCONDITIONAL_RELAY_DELAY, permit the request
|
||||||
|
@ -4358,6 +4358,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
std::set<uint256>::iterator it = vInvTx.back();
|
std::set<uint256>::iterator it = vInvTx.back();
|
||||||
vInvTx.pop_back();
|
vInvTx.pop_back();
|
||||||
uint256 hash = *it;
|
uint256 hash = *it;
|
||||||
|
CInv inv(state.m_wtxid_relay ? MSG_WTX : MSG_TX, hash);
|
||||||
// Remove it from the to-be-sent set
|
// Remove it from the to-be-sent set
|
||||||
pto->m_tx_relay->setInventoryTxToSend.erase(it);
|
pto->m_tx_relay->setInventoryTxToSend.erase(it);
|
||||||
// Check if not in the filter already
|
// Check if not in the filter already
|
||||||
|
@ -4365,7 +4366,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Not in the mempool anymore? don't bother sending it.
|
// Not in the mempool anymore? don't bother sending it.
|
||||||
auto txinfo = m_mempool.info(hash, state.m_wtxid_relay);
|
auto txinfo = m_mempool.info(ToGenTxid(inv));
|
||||||
if (!txinfo.tx) {
|
if (!txinfo.tx) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -4378,7 +4379,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
||||||
if (pto->m_tx_relay->pfilter && !pto->m_tx_relay->pfilter->IsRelevantAndUpdate(*txinfo.tx)) continue;
|
if (pto->m_tx_relay->pfilter && !pto->m_tx_relay->pfilter->IsRelevantAndUpdate(*txinfo.tx)) continue;
|
||||||
// Send
|
// Send
|
||||||
State(pto->GetId())->m_recently_announced_invs.insert(hash);
|
State(pto->GetId())->m_recently_announced_invs.insert(hash);
|
||||||
vInv.push_back(CInv(state.m_wtxid_relay ? MSG_WTX : MSG_TX, hash));
|
vInv.push_back(inv);
|
||||||
nRelayedTransactions++;
|
nRelayedTransactions++;
|
||||||
{
|
{
|
||||||
// Expire old relay messages
|
// Expire old relay messages
|
||||||
|
|
|
@ -811,15 +811,17 @@ CTransactionRef CTxMemPool::get(const uint256& hash) const
|
||||||
return i->GetSharedTx();
|
return i->GetSharedTx();
|
||||||
}
|
}
|
||||||
|
|
||||||
TxMempoolInfo CTxMemPool::info(const uint256& hash, bool wtxid) const
|
TxMempoolInfo CTxMemPool::info(const GenTxid& gtxid) const
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
indexed_transaction_set::const_iterator i = (wtxid ? get_iter_from_wtxid(hash) : mapTx.find(hash));
|
indexed_transaction_set::const_iterator i = (gtxid.IsWtxid() ? get_iter_from_wtxid(gtxid.GetHash()) : mapTx.find(gtxid.GetHash()));
|
||||||
if (i == mapTx.end())
|
if (i == mapTx.end())
|
||||||
return TxMempoolInfo();
|
return TxMempoolInfo();
|
||||||
return GetInfo(i);
|
return GetInfo(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TxMempoolInfo CTxMemPool::info(const uint256& txid) const { return info(GenTxid{false, txid}); }
|
||||||
|
|
||||||
void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
|
void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
@ -716,14 +716,15 @@ public:
|
||||||
return totalTxSize;
|
return totalTxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exists(const uint256& hash, bool wtxid=false) const
|
bool exists(const GenTxid& gtxid) const
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
if (wtxid) {
|
if (gtxid.IsWtxid()) {
|
||||||
return (mapTx.get<index_by_wtxid>().count(hash) != 0);
|
return (mapTx.get<index_by_wtxid>().count(gtxid.GetHash()) != 0);
|
||||||
}
|
}
|
||||||
return (mapTx.count(hash) != 0);
|
return (mapTx.count(gtxid.GetHash()) != 0);
|
||||||
}
|
}
|
||||||
|
bool exists(const uint256& txid) const { return exists(GenTxid{false, txid}); }
|
||||||
|
|
||||||
CTransactionRef get(const uint256& hash) const;
|
CTransactionRef get(const uint256& hash) const;
|
||||||
txiter get_iter_from_wtxid(const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
txiter get_iter_from_wtxid(const uint256& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
|
||||||
|
@ -731,7 +732,8 @@ public:
|
||||||
AssertLockHeld(cs);
|
AssertLockHeld(cs);
|
||||||
return mapTx.project<0>(mapTx.get<index_by_wtxid>().find(wtxid));
|
return mapTx.project<0>(mapTx.get<index_by_wtxid>().find(wtxid));
|
||||||
}
|
}
|
||||||
TxMempoolInfo info(const uint256& hash, bool wtxid=false) const;
|
TxMempoolInfo info(const uint256& hash) const;
|
||||||
|
TxMempoolInfo info(const GenTxid& gtxid) const;
|
||||||
std::vector<TxMempoolInfo> infoAll() const;
|
std::vector<TxMempoolInfo> infoAll() const;
|
||||||
|
|
||||||
size_t DynamicMemoryUsage() const;
|
size_t DynamicMemoryUsage() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue