Skip to content

Commit faa2976

Browse files
author
MarcoFalke
committed
Remove mapRelay
1 parent fccecd7 commit faa2976

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@
5151
#include <optional>
5252
#include <typeinfo>
5353

54-
/** How long to cache transactions in mapRelay for normal relay */
55-
static constexpr auto RELAY_TX_CACHE_TIME = 15min;
56-
/** How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay). */
54+
/** How long a transaction has to be in the mempool before it can unconditionally be relayed. */
5755
static constexpr auto UNCONDITIONAL_RELAY_DELAY = 2min;
5856
/** Headers download timeout.
5957
* Timeout = base + per_header * (expected number of headers) */
@@ -920,12 +918,6 @@ class PeerManagerImpl final : public PeerManager
920918
/** Process a new block. Perform any post-processing housekeeping */
921919
void ProcessBlock(CNode& node, const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked);
922920

923-
/** Relay map (txid or wtxid -> CTransactionRef) */
924-
typedef std::map<uint256, CTransactionRef> MapRelay;
925-
MapRelay mapRelay GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
926-
/** Expiration-time ordered list of (expire time, relay map entry) pairs. */
927-
std::deque<std::pair<std::chrono::microseconds, MapRelay::iterator>> g_relay_expiration GUARDED_BY(NetEventsInterface::g_msgproc_mutex);
928-
929921
/**
930922
* When a peer sends us a valid block, instruct it to announce blocks to us
931923
* using CMPCTBLOCK if possible by adding its nodeid to the end of
@@ -2322,12 +2314,6 @@ CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay,
23222314
}
23232315
}
23242316

2325-
// Or it might be recent and in the relay pool.
2326-
if (recent) {
2327-
auto mi = mapRelay.find(gtxid.GetHash());
2328-
if (mi != mapRelay.end()) return mi->second;
2329-
}
2330-
23312317
return {};
23322318
}
23332319

@@ -5796,7 +5782,6 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
57965782
continue;
57975783
}
57985784
auto txid = txinfo.tx->GetHash();
5799-
auto wtxid = txinfo.tx->GetWitnessHash();
58005785
// Peer told you to not send transactions at that feerate? Don't bother sending it.
58015786
if (txinfo.fee < filterrate.GetFee(txinfo.vsize)) {
58025787
continue;
@@ -5806,24 +5791,6 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
58065791
tx_relay->m_recently_announced_invs.insert(hash);
58075792
vInv.push_back(inv);
58085793
nRelayedTransactions++;
5809-
{
5810-
// Expire old relay messages
5811-
while (!g_relay_expiration.empty() && g_relay_expiration.front().first < current_time)
5812-
{
5813-
mapRelay.erase(g_relay_expiration.front().second);
5814-
g_relay_expiration.pop_front();
5815-
}
5816-
5817-
auto ret = mapRelay.emplace(txid, std::move(txinfo.tx));
5818-
if (ret.second) {
5819-
g_relay_expiration.emplace_back(current_time + RELAY_TX_CACHE_TIME, ret.first);
5820-
}
5821-
// Add wtxid-based lookup into mapRelay as well, so that peers can request by wtxid
5822-
auto ret2 = mapRelay.emplace(wtxid, ret.first->second);
5823-
if (ret2.second) {
5824-
g_relay_expiration.emplace_back(current_time + RELAY_TX_CACHE_TIME, ret2.first);
5825-
}
5826-
}
58275794
if (vInv.size() == MAX_INV_SZ) {
58285795
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv));
58295796
vInv.clear();

test/functional/p2p_leak_tx.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test transaction upload"""
66

7-
from test_framework.messages import msg_getdata, CInv, MSG_TX
8-
from test_framework.p2p import p2p_lock, P2PDataStore
7+
from test_framework.messages import msg_getdata, CInv, MSG_TX, MSG_WTX
8+
from test_framework.p2p import p2p_lock, P2PDataStore, P2PTxInvStore
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import (
1111
assert_equal,
@@ -27,6 +27,7 @@ def run_test(self):
2727
self.miniwallet = MiniWallet(self.gen_node)
2828

2929
self.test_tx_in_block()
30+
self.test_notfound_on_replaced_tx()
3031
self.test_notfound_on_unannounced_tx()
3132

3233
def test_tx_in_block(self):
@@ -45,8 +46,36 @@ def test_tx_in_block(self):
4546
inbound_peer.send_and_ping(want_tx)
4647
assert_equal(inbound_peer.last_message.get("tx").tx.getwtxid(), wtxid)
4748

49+
def test_notfound_on_replaced_tx(self):
50+
self.gen_node.disconnect_p2ps()
51+
inbound_peer = self.gen_node.add_p2p_connection(P2PTxInvStore())
52+
53+
self.log.info("Transaction tx_a is broadcast")
54+
tx_a = self.miniwallet.send_self_transfer(from_node=self.gen_node)
55+
inbound_peer.wait_for_broadcast(txns=[tx_a["wtxid"]])
56+
57+
tx_b = tx_a["tx"]
58+
tx_b.vout[0].nValue -= 9000
59+
self.gen_node.sendrawtransaction(tx_b.serialize().hex())
60+
61+
self.log.info("Re-request of tx_a after replacement is answered with notfound")
62+
req_vec = [
63+
CInv(t=MSG_TX, h=int(tx_a["txid"], 16)),
64+
CInv(t=MSG_WTX, h=int(tx_a["wtxid"], 16)),
65+
]
66+
want_tx = msg_getdata()
67+
want_tx.inv = req_vec
68+
with p2p_lock:
69+
inbound_peer.last_message.pop("notfound", None)
70+
inbound_peer.last_message.pop("tx", None)
71+
inbound_peer.send_and_ping(want_tx)
72+
73+
assert_equal(inbound_peer.last_message.get("notfound").vec, req_vec)
74+
assert "tx" not in inbound_peer.last_message
75+
4876
def test_notfound_on_unannounced_tx(self):
4977
self.log.info("Check that we don't leak txs to inbound peers that we haven't yet announced to")
78+
self.gen_node.disconnect_p2ps()
5079
inbound_peer = self.gen_node.add_p2p_connection(P2PNode()) # An "attacking" inbound peer
5180

5281
MAX_REPEATS = 100

0 commit comments

Comments
 (0)