Skip to content

Commit 39f026b

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#26396: net: Avoid SetTxRelay for feeler connections
fa24239 net: Avoid SetTxRelay for feeler connections (MacroFake) Pull request description: Seems odd to reserve memory for the struct (the heaviest member being `m_tx_inventory_known_filter`) when it is never used. This also avoids sending out `msg_sendtxrcncl` before disconnecting. This shouldn't matter, as other messages, such as `msg_wtxidrelay`, `msg_sendaddrv2`, `msg_verack` or `msg_getaddr` are still sent. Though, it allows to test the changes here as a side-effect. ACKs for top commit: naumenkogs: ACK fa24239 vasild: ACK fa24239 jonatack: ACK fa24239 mzumsande: ACK fa24239 Tree-SHA512: d7604c7eb4df8f2de811e600bdd312440ee03e508d3a0f09ae79f7f2d3eeec663bfd47a2d079fa50b756d61e35dfa998de068a7b9afaf35378fa0e62a538263d
2 parents bf0cb43 + fa24239 commit 39f026b

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/net.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,8 @@ class CNode
489489
/** Whether this peer provides all services that we want. Used for eviction decisions */
490490
std::atomic_bool m_has_all_wanted_services{false};
491491

492-
/** Whether we should relay transactions to this peer (their version
493-
* message did not include fRelay=false and this is not a block-relay-only
494-
* connection). This only changes from false to true. It will never change
495-
* back to false. Used only in inbound eviction logic. */
492+
/** Whether we should relay transactions to this peer. This only changes
493+
* from false to true. It will never change back to false. */
496494
std::atomic_bool m_relays_txs{false};
497495

498496
/** Whether this peer has loaded a bloom filter. Used only in inbound

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ struct Peer {
395395
private:
396396
Mutex m_tx_relay_mutex;
397397

398-
/** Transaction relay data. Will be a nullptr if we're not relaying
399-
* transactions with this peer (e.g. if it's a block-relay-only peer or
400-
* the peer has sent us fRelay=false with bloom filters disabled). */
398+
/** Transaction relay data. May be a nullptr. */
401399
std::unique_ptr<TxRelay> m_tx_relay GUARDED_BY(m_tx_relay_mutex);
402400
};
403401

@@ -3256,12 +3254,14 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32563254
}
32573255
peer->m_starting_height = starting_height;
32583256

3259-
// We only initialize the Peer::TxRelay m_relay_txs data structure if:
3257+
// Only initialize the Peer::TxRelay m_relay_txs data structure if:
32603258
// - this isn't an outbound block-relay-only connection, and
3259+
// - this isn't an outbound feeler connection, and
32613260
// - fRelay=true (the peer wishes to receive transaction announcements)
32623261
// or we're offering NODE_BLOOM to this peer. NODE_BLOOM means that
32633262
// the peer may turn on transaction relay later.
32643263
if (!pfrom.IsBlockOnlyConn() &&
3264+
!pfrom.IsFeelerConn() &&
32653265
(fRelay || (peer->m_our_services & NODE_BLOOM))) {
32663266
auto* const tx_relay = peer->SetTxRelay();
32673267
{

test/functional/p2p_sendtxrcncl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def __init__(self):
3939
def on_sendtxrcncl(self, message):
4040
self.sendtxrcncl_msg_received = message
4141

42+
43+
class P2PFeelerReceiver(SendTxrcnclReceiver):
44+
def on_version(self, message):
45+
pass # feeler connections can not send any message other than their own version
46+
47+
4248
class PeerTrackMsgOrder(P2PInterface):
4349
def __init__(self):
4450
super().__init__()
@@ -163,6 +169,11 @@ def run_test(self):
163169
assert not peer.sendtxrcncl_msg_received
164170
peer.peer_disconnect()
165171

172+
self.log.info("SENDTXRCNCL should not be sent if feeler")
173+
peer = self.nodes[0].add_outbound_p2p_connection(P2PFeelerReceiver(), p2p_idx=2, connection_type="feeler")
174+
assert not peer.sendtxrcncl_msg_received
175+
peer.peer_disconnect()
176+
166177
self.log.info('SENDTXRCNCL if block-relay-only triggers a disconnect')
167178
peer = self.nodes[0].add_outbound_p2p_connection(
168179
PeerNoVerack(), wait_for_verack=False, p2p_idx=3, connection_type="block-relay-only")

0 commit comments

Comments
 (0)