@@ -1608,6 +1608,26 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
1608
1608
}
1609
1609
}
1610
1610
1611
+ // ! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
1612
+ CTransactionRef static FindTxForGetData (const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds longlived_mempool_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1613
+ {
1614
+ // Look up transaction in relay pool
1615
+ auto mi = mapRelay.find (txid);
1616
+ if (mi != mapRelay.end ()) return mi->second ;
1617
+
1618
+ auto txinfo = mempool.info (txid);
1619
+ if (txinfo.tx ) {
1620
+ // To protect privacy, do not answer getdata using the mempool when
1621
+ // that TX couldn't have been INVed in reply to a MEMPOOL request,
1622
+ // or when it's too recent to have expired from mapRelay.
1623
+ if ((mempool_req.count () && txinfo.m_time <= mempool_req) || txinfo.m_time <= longlived_mempool_time) {
1624
+ return txinfo.tx ;
1625
+ }
1626
+ }
1627
+
1628
+ return {};
1629
+ }
1630
+
1611
1631
void static ProcessGetData (CNode* pfrom, const CChainParams& chainparams, CConnman* connman, CTxMemPool& mempool, const std::atomic<bool >& interruptMsgProc) LOCKS_EXCLUDED(cs_main)
1612
1632
{
1613
1633
AssertLockNotHeld (cs_main);
@@ -1643,31 +1663,10 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
1643
1663
continue ;
1644
1664
}
1645
1665
1646
- // Send stream from relay memory
1647
- bool push = false ;
1648
- auto mi = mapRelay.find (inv.hash );
1649
- int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0 );
1650
- if (mi != mapRelay.end ()) {
1651
- connman->PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::TX, *mi->second ));
1652
- push = true ;
1653
- } else {
1654
- auto txinfo = mempool.info (inv.hash );
1655
- // To protect privacy, do not answer getdata using the mempool when
1656
- // that TX couldn't have been INVed in reply to a MEMPOOL request,
1657
- // or when it's too recent to have expired from mapRelay.
1658
- if (txinfo.tx && (
1659
- (mempool_req.count () && txinfo.m_time <= mempool_req)
1660
- || (txinfo.m_time <= longlived_mempool_time)))
1661
- {
1662
- connman->PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::TX, *txinfo.tx ));
1663
- push = true ;
1664
- }
1665
- }
1666
-
1667
- if (push) {
1668
- // We interpret fulfilling a GETDATA for a transaction as a
1669
- // successful initial broadcast and remove it from our
1670
- // unbroadcast set.
1666
+ CTransactionRef tx = FindTxForGetData (inv.hash , mempool_req, longlived_mempool_time);
1667
+ if (tx) {
1668
+ int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0 );
1669
+ connman->PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::TX, *tx));
1671
1670
mempool.RemoveUnbroadcastTx (inv.hash );
1672
1671
} else {
1673
1672
vNotFound.push_back (inv);
0 commit comments