<div dir="ltr">Hi Suhas,<br><br>Thank you for this proposal. I agree with your aims, but I think a new<br>P2P message isn't necessary to achieve them.<br><br># Motivation<br><br>There are two distinct (but interacting) motivations:<br><br>1. Allow a node to accept more incoming connections which will only be<br>   used for block propagation (no transaction relay or addr gossip),<br>   while minimizing resource requirements.<br><br>2. Prevent `addr` gossip messages from being sent to peers which will<br>   'black hole' those addrs (i.e. not relay them further).<br><br>These motivations interact because if we simply increase the number of<br>block-relay-only connections that nodes make without making any<br>allowance for the fact those connections won't gossip addr records, then<br>we'll increase the number of addr black holes and worsen addr gossip.<br><br># Using fRelay=false to signal no transaction relay.<br><br>`fRelay` is an optional field in the `version` message. There are three<br>BIPs concerned with `fRelay`:<br><br>- BIP 37[1] introduced the `fRelay` field to indicate to the recipient<br>  that they must not relay transactions over the connection until a<br>  `filteradd` message has been received.<br><br>- BIP 60[2] aimed to make the `fRelay` field mandatory. It is not clear<br>  how widely this BIP has been adopted by implementations.<br><br>- BIP 111[3] introduced a `NODE_BLOOM` service bit to indicate that<br>  bloom filters are served by this node. According to this BIP, "If a<br>  node does not support bloom filters but receives a "filterload",<br>  "filteradd", or "filterclear" message from a peer the node should<br>  disconnect that peer immediately."<br><br>Within Bitcoin Core:<br><br>- PR 1795[4] (merged in January 2013) added support for BIP 37 Bloom<br>  filters.<br><br>- Since PR 2763[5] (merged in June 2013), Bitcoin Core will _always_<br>  include the `fRelay` flag in `version` messages that it sends. Bitcoin<br>  Core will tolerate the `fRelay` field being present or absent in any<br>  `version` message that it receives[6].<br><br>- PR 6579[7] (merged in August 2015) implemented BIP 111. From that<br>  point on, a Bitcoin Core node would disconnect peers that sent it<br>  `filter*` messages if it hadn't enabled `NODE_BLOOM`, provided the<br>  peer's version was >= 70011. In PR 7708[8] (merged in March 2016) this<br>  was extended to disconnect any peer that sends a `filter*` message,<br>  regardless of its version (in general, a 'polite disconnect' for any<br>  peer that requests an unsupported service is probably the best<br>  behaviour). In PR 16152[9] (merged in July 2019), serving Bloom<br>  filters was disabled by default, due to potential denial-of-service<br>  attacks being possible against nodes which serve bloom filters on<br>  public connections.<br><br>- PR 6993[10] (merged in November 2015) started reusing the `fRelay`<br>  field for the new `-blocksonly` mode. If Bitcoin Core is started with<br>  `-blocksonly` configured, then it includes `fRelay=false` in all of<br>  the `version` messages it sends. In PR 15759[11] (merged  in September<br>  2019), this usage of `fRelay` to permanently disable tx relay was<br>  extended for use by the new block-relay only connection type.<br><br>The net effect is that `fRelay` is already being used to indicate that<br>transactions should not be relayed over a connection. In the motivation<br>for your BIP, you write:<br><br>> The low-bandwidth / minimal-resource nature of these connections is<br>> currently known only by the initiator of the connection; this is<br>> because the transaction relay field in the version message is not a<br>> permanent setting for the lifetime of the connection.  Consequently, a<br>> node receiving an inbound connection with transaction relay disabled<br>> cannot distinguish between a peer that will never enable transaction<br>> relay (as described in BIP 37) and one that will...<br><br>However, as AJ points out in his response [12], the Bitcoin Core node<br>_does_ know whether transaction relay can be supported as soon as the<br>`version` message is received:<br><br>> [...] you either set m_tx_relay->fRelayTxes to true via the VERSION<br>> message (either explicitly or by not setting fRelay), or you enable it<br>> later with FILTERLOAD or FILTERCLEAR, both of which will cause a<br>> disconnect if bloom filters aren't supported. Bloom filter support is<br>> (optionally?) indicated via a service bit (BIP 111), so you could<br>> assume you know whether they're supported as soon as you receive the<br>> VERSION line.<br><br>i.e. if Bitcoin Core node is running under normal configuration with<br>bloom filters disabled for public connections (which is both the default<br>setting and highly recommended due to DoS concerns), then as soon as it<br>receives a `version` message with `fRelay=false`, it can be sure that<br>there will never be any transaction relay with that peer. If the peer<br>later tries to enable transaction relay by sending a `filterload`<br>message, then the node will disconnect that peer immediately.<br><br>In summary, we can continue using the `fRelay` field to indicate that<br>no transaction relay can happen for the entire lifetime of the<br>connection.  Bitcoin Core can postpone allocating resources for<br>transaction relay data structures until after the version message has<br>been received to minimize resource usage for incoming block-relay-only<br>connections. A rough implementation is here[13]. Obviously, a node that<br>has been configured to serve bloom filters on public connections would<br>not be able to take advantage of this and accept additional incoming<br>block-relay-only peers, but I think that's fine - we already discourage<br>that configuration.<br><br>I think a good counter-argument against simply using `fRelay` for this<br>purpose is that we shouldn't reuse a protocol feature designed for one<br>function to achieve a totally different aim. However, we know that nodes<br>on the network have been using `fRelay` to disable transaction relay<br>since Bitcoin Core version 0.12 (when `-blocksonly` was added), and that<br>usage was expanded to _all_ nodes running Bitcoin Core version 0.19 or<br>later (when block-relay-only connections were introduced), so using<br>`fRelay` to disable transaction relay is now de facto part of the p2p<br>protocol.<br><br># Preventing addr black holes<br><br>Addresses of potential peers are gossiped around the p2p network using<br>`addr` messages. When a Bitcoin Core node learns of a new `addr` record,<br>it will relay that record to one or two of its peers, chosen at<br>random[14]. The idea is that eventually the `addr` record will reach<br>most of the nodes on the network.<br><br>If there are too many nodes on the network that receive `addr` records<br>and do not relay those records on to their peers (termed _addr black<br>hole_ nodes), then propagation of those `addr` records suffers -- any<br>individual `addr` record is unlikely to reach a large proportion of<br>nodes on the network.<br><br>Since a motivation for block-relay-only connections is to protect<br>against eclipse attacks and thwart network topology analysis, Bitcoin<br>Core will not relay `addr` records on those connections, and will ignore<br>any `addr` record received over those connections. Therefore, increasing<br>the number of block-relay-only connections without changing the `addr`<br>gossip logic is likely to increase the prevalence of addr black holes,<br>and negatively impact addr propagation. This is why BIP 338 includes:<br><br>> It is RECOMMENDED that a node that has sent or received a disabletx<br>> message to/from a peer not send any of these messages to the peer:<br>> <br>> - addr/getaddr<br>> - addrv2 (BIP 155)<br><br>I think a better approach would be for Bitcoin Core to only relay addr<br>records to an inbound peer if it has previously received an `addr` or<br>`addrv2` message from that peer, since that indicates definitively that<br>the peer actively gossips `addr` records. This approach was first<br>suggested by AJ in the original block-relay-only PR[15].<br><br>An advantage of this approach is that it will improve addr propagation<br>immediately and without any change to the P2P protocol, and will prevent<br>sending `addr` records to all addr black holes (such as light clients),<br>not just incoming block-relay-only connections.<br><br># Conclusion<br><br>We can increase the permitted number of inbound block-relay-only peers<br>while minimizing resource requirement _and_ improving addr record<br>propagation, without any changes to the p2p protocol required.<br><br>I propose that for Bitcoin Core version 22.0:<br><br>- only initialize the transaction relay data structures after the<br>  `version` message is received, and only if fRelay=true and<br>  `NODE_BLOOM` is not offered on this connection.<br>- only initialize the addr data structures for inbound connections when<br>  an `addr`, `addrv2` or `getaddr` message is received on the<br>  connection, and only consider a connection for addr relay if its addr<br>  data structures are initialized.<br>- update the inbound eviction logic to protect more inbound peers which<br>  do not have transaction relay data structures.<br><br>Then, in version 23.0:<br><br>- modestly increase the number of outbound block-relay-only connections.<br><br>John<br><br>[1] <a href="https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki">https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki</a><br>[2] <a href="https://github.com/bitcoin/bips/blob/master/bip-0060.mediawiki">https://github.com/bitcoin/bips/blob/master/bip-0060.mediawiki</a><br>[3] <a href="https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki">https://github.com/bitcoin/bips/blob/master/bip-0111.mediawiki</a><br>[4] <a href="https://github.com/bitcoin/bitcoin/pull/1795">https://github.com/bitcoin/bitcoin/pull/1795</a><br>[5] <a href="https://github.com/bitcoin/bitcoin/pull/2763">https://github.com/bitcoin/bitcoin/pull/2763</a><br>[6] <a href="https://github.com/bitcoin/bitcoin/blob/e49117470b77fb7d53be122c6490ba163c6e304d/src/net_processing.cpp#L2582-L2583">https://github.com/bitcoin/bitcoin/blob/e49117470b77fb7d53be122c6490ba163c6e304d/src/net_processing.cpp#L2582-L2583</a><br>[7] <a href="https://github.com/bitcoin/bitcoin/pull/6579">https://github.com/bitcoin/bitcoin/pull/6579</a><br>[8] <a href="https://github.com/bitcoin/bitcoin/pull/7708">https://github.com/bitcoin/bitcoin/pull/7708</a><br>[9] <a href="https://github.com/bitcoin/bitcoin/pull/16152">https://github.com/bitcoin/bitcoin/pull/16152</a><br>[10] <a href="https://github.com/bitcoin/bitcoin/pull/6993">https://github.com/bitcoin/bitcoin/pull/6993</a><br>[11] <a href="https://github.com/bitcoin/bitcoin/pull/15759">https://github.com/bitcoin/bitcoin/pull/15759</a><br>[12] <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-January/018347.html">https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-January/018347.html</a><br>[13] <a href="https://github.com/jnewbery/bitcoin/tree/2021-02-lazy-init-peer">https://github.com/jnewbery/bitcoin/tree/2021-02-lazy-init-peer</a><br>[14] <a href="https://github.com/bitcoin/bitcoin/blob/e52ce9f2b312b3cf3b0837918e07d7603e241d63/src/net_processing.cpp#L1696-L1700">https://github.com/bitcoin/bitcoin/blob/e52ce9f2b312b3cf3b0837918e07d7603e241d63/src/net_processing.cpp#L1696-L1700</a><br>[15] <a href="https://github.com/bitcoin/bitcoin/pull/15759#issuecomment-527012757">https://github.com/bitcoin/bitcoin/pull/15759#issuecomment-527012757</a><br><br>> Hi,<br>> <br>> I'm proposing the addition of a new, optional p2p message to allow peers to communicate that they do not want to send or receive (loose) transactions for the lifetime of a connection. <br>> <br>> The goal of this message is to help facilitate connections on the network over which only block-related data (blocks/headers/compact blocks/etc) are relayed, to create low-resource connections that help protect against partition attacks on the network.  In particular, by adding a network message that communicates that transactions will not be relayed for the life of the connection, we ease the implementation of software that could have increased inbound connection limits for such peers, which in turn will make it easier to add additional persistent block-relay-only connections on the network -- strengthening network security for little additional bandwidth.<br>> <br>> Software has been deployed for over a year now which makes such connections, using the BIP37/BIP60 "fRelay" field in the version message to signal that transactions should not be sent initially.  However, BIP37 allows for transaction relay to be enabled later in the connection's lifetime, complicating software that would try to distinguish inbound peers that will never relay transactions from those that might.<br>> <br>> This proposal would add a single new p2p message, "disabletx", which (if used at all) must be sent between version and verack.  I propose that this message is valid for peers advertising protocol version 70017 or higher.  Software is free to implement this BIP or ignore this message and remain compatible with software that does implement it.<br>> <br>> Full text of the proposed BIP is below.<br>> <br>> Thanks,<br>> Suhas<br>> <br>> ---------------------------------------------------<br>> <br>> <pre><br>>   BIP: XXX<br>>   Layer: Peer Services<br>>   Title: Disable transaction relay message<br>>   Author: Suhas Daftuar <<a href="mailto:sdaftuar@chaincode.com">sdaftuar@chaincode.com</a>><br>>   Comments-Summary: No comments yet.<br>>   Comments-URI:<br>>   Status: Draft<br>>   Type: Standards Track<br>>   Created: 2020-09-03<br>>   License: BSD-2-Clause<br>> </pre><br>> <br>> ==Abstract==<br>> <br>> This BIP describes a change to the p2p protocol to allow a node to tell a peer<br>> that a connection will not be used for transaction relay, to support<br>> block-relay-only connections that are currently in use on the network.<br>> <br>> ==Motivation==<br>> <br>> For nearly the past year, software has been deployed[1] which initiates<br>> connections on the Bitcoin network and sets the transaction relay field<br>> (introduced by BIP 37 and also defined in BIP 60) to false, to prevent<br>> transaction relay from occurring on the connection. Additionally, addr messages<br>> received from the peer are ignored by this software.<br>> <br>> The purpose of these connections is two-fold: by making additional<br>> low-bandwidth connections on which blocks can propagate, the robustness of a<br>> node to network partitioning attacks is strengthened.  Additionally, by not<br>> relaying transactions and ignoring received addresses, the ability of an<br>> adversary to learn the complete network graph (or a subgraph) is reduced[2],<br>> which in turn increases the cost or difficulty to an attacker seeking to carry<br>> out a network partitioning attack (when compared with having such knowledge).<br>> <br>> The low-bandwidth / minimal-resource nature of these connections is currently<br>> known only by the initiator of the connection; this is because the transaction<br>> relay field in the version message is not a permanent setting for the lifetime<br>> of the connection.  Consequently, a node receiving an inbound connection with<br>> transaction relay disabled cannot distinguish between a peer that will never<br>> enable transaction relay (as described in BIP 37) and one that will.  Moreover,<br>> the node also cannot determine that the incoming connection will ignore relayed<br>> addresses; with that knowledge a node would likely choose other peers to<br>> receive announced addresses instead.<br>> <br>> This proposal adds a new, optional message that a node can send a peer when<br>> initiating a connection to that peer, to indicate that connection should not be<br>> used for transaction-relay for the connection's lifetime. In addition, without<br>> a current mechanism to negotiate whether addresses should be relayed on a<br>> connection, this BIP suggests that address messages not be sent on links where<br>> tx-relay has been disabled.<br>> <br>> ==Specification==<br>> <br>> # A new disabletx message is added, which is defined as an empty message where pchCommand == "disabletx".<br>> # The protocol version of nodes implementing this BIP must be set to 70017 or higher.<br>> # If a node sets the transaction relay field in the version message to a peer to false, then the disabletx message MAY also be sent in response to a version message from that peer if the peer's protocol version is >= 70017. If sent, the disabletx message MUST be sent prior to sending a verack.<br>> # A node that has sent or received a disabletx message to/from a peer MUST NOT send any of these messages to the peer:<br>> ## inv messages for transactions<br>> ## getdata messages for transactions<br>> ## getdata messages for merkleblock (BIP 37)<br>> ## filteradd/filterload/filterclear (BIP 37)<br>> ## mempool (BIP 35)<br>> # It is RECOMMENDED that a node that has sent or received a disabletx message to/from a peer not send any of these messages to the peer:<br>> ## addr/getaddr<br>> ## addrv2 (BIP 155)<br>> # The behavior regarding sending or processing other message types is not specified by this BIP.<br>> # Nodes MAY decide to not remain connected to peers that send this message (for example, if trying to find a peer that will relay transactions).<br>> <br>> ==Compatibility==<br>> <br>> Nodes with protocol version >= 70017 that do not implement this BIP, and nodes<br>> with protocol version < 70017, will continue to remain compatible with<br>> implementing software: transactions would not be relayed to peers sending the<br>> disabletx message (provided that BIP 37 or BIP 60 has been implemented), and while<br>> periodic address relay may still take place, software implementing this BIP<br>> should not be disconnecting such peers solely for that reason.<br>> <br>> Disabling address relay is suggested but not required by this BIP, to allow for<br>> future protocol extensions that might specify more carefully how address relay<br>> is to be negotiated. This BIP's recommendations for software to not relay<br>> addresses is intended to be interpreted as guidance in the absence of any such<br>> future protocol extension, to accommodate existing software behavior.<br>> <br>> Note that all messages specified in BIP 152, including blocktxn and<br>> getblocktxn, are permitted between peers that have sent/received a disabletx<br>> message, subject to the feature negotiation of BIP 152.<br>> <br>> ==Implementation==<br>> <br>> TBD<br>> <br>> ==References==<br>> <br>> # Bitcoin Core has [<a href="https://github.com/bitcoin/bitcoin/pull/15759">https://github.com/bitcoin/bitcoin/pull/15759</a> implemented this functionality] since version 0.19.0.1, released in November 2019.<br>> # For example, see <a href="https://www.cs.umd.edu/projects/coinscope/coinscope.pdf">https://www.cs.umd.edu/projects/coinscope/coinscope.pdf</a> and <a href="https://arxiv.org/pdf/1812.00942.pdf">https://arxiv.org/pdf/1812.00942.pdf</a>.<br>> <br>> ==Copyright==<br>> <br>> This BIP is licensed under the 2-clause BSD license.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 6, 2021 at 4:35 PM Suhas Daftuar via bitcoin-dev <<a href="mailto:bitcoin-dev@lists.linuxfoundation.org">bitcoin-dev@lists.linuxfoundation.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I'm proposing the addition of a new, optional p2p message to allow peers to communicate that they do not want to send or receive (loose) transactions for the lifetime of a connection. </div><div><br></div><div>The goal of this message is to help facilitate connections on the network over which only block-related data (blocks/headers/compact blocks/etc) are relayed, to create low-resource connections that help protect against partition attacks on the network.  In particular, by adding a network message that communicates that transactions will not be relayed for the life of the connection, we ease the implementation of software that could have increased inbound connection limits for such peers, which in turn will make it easier to add additional persistent block-relay-only connections on the network -- strengthening network security for little additional bandwidth.</div><div><br></div><div>Software has been deployed for over a year now which makes such connections, using the BIP37/BIP60 "fRelay" field in the version message to signal that transactions should not be sent initially.  However, BIP37 allows for transaction relay to be enabled later in the connection's lifetime, complicating software that would try to distinguish inbound peers that will never relay transactions from those that might.</div><div><br></div><div>This proposal would add a single new p2p message, "disabletx", which (if used at all) must be sent between version and verack.  I propose that this message is valid for peers advertising protocol version 70017 or higher.  Software is free to implement this BIP or ignore this message and remain compatible with software that does implement it.</div><div><br></div><div>Full text of the proposed BIP is below.</div><div><br></div><div>Thanks,<br></div><div>Suhas<br></div><div><br></div><div>---------------------------------------------------</div><div><br></div><div><pre style="color:rgb(0,0,0);white-space:pre-wrap"><pre>
  BIP: XXX
  Layer: Peer Services
  Title: Disable transaction relay message
  Author: Suhas Daftuar <<a href="mailto:sdaftuar@chaincode.com" target="_blank">sdaftuar@chaincode.com</a>>
  Comments-Summary: No comments yet.
  Comments-URI:
  Status: Draft
  Type: Standards Track
  Created: 2020-09-03
  License: BSD-2-Clause
</pre>

==Abstract==

This BIP describes a change to the p2p protocol to allow a node to tell a peer
that a connection will not be used for transaction relay, to support
block-relay-only connections that are currently in use on the network.

==Motivation==

For nearly the past year, software has been deployed[1] which initiates
connections on the Bitcoin network and sets the transaction relay field
(introduced by BIP 37 and also defined in BIP 60) to false, to prevent
transaction relay from occurring on the connection. Additionally, addr messages
received from the peer are ignored by this software.

The purpose of these connections is two-fold: by making additional
low-bandwidth connections on which blocks can propagate, the robustness of a
node to network partitioning attacks is strengthened.  Additionally, by not
relaying transactions and ignoring received addresses, the ability of an
adversary to learn the complete network graph (or a subgraph) is reduced[2],
which in turn increases the cost or difficulty to an attacker seeking to carry
out a network partitioning attack (when compared with having such knowledge).

The low-bandwidth / minimal-resource nature of these connections is currently
known only by the initiator of the connection; this is because the transaction
relay field in the version message is not a permanent setting for the lifetime
of the connection.  Consequently, a node receiving an inbound connection with
transaction relay disabled cannot distinguish between a peer that will never
enable transaction relay (as described in BIP 37) and one that will.  Moreover,
the node also cannot determine that the incoming connection will ignore relayed
addresses; with that knowledge a node would likely choose other peers to
receive announced addresses instead.

This proposal adds a new, optional message that a node can send a peer when
initiating a connection to that peer, to indicate that connection should not be
used for transaction-relay for the connection's lifetime. In addition, without
a current mechanism to negotiate whether addresses should be relayed on a
connection, this BIP suggests that address messages not be sent on links where
tx-relay has been disabled.

==Specification==

# A new disabletx message is added, which is defined as an empty message where pchCommand == "disabletx".
# The protocol version of nodes implementing this BIP must be set to 70017 or higher.
# If a node sets the transaction relay field in the version message to a peer to false, then the disabletx message MAY also be sent in response to a version message from that peer if the peer's protocol version is >= 70017. If sent, the disabletx message MUST be sent prior to sending a verack.
# A node that has sent or received a disabletx message to/from a peer MUST NOT send any of these messages to the peer:
## inv messages for transactions
## getdata messages for transactions
## getdata messages for merkleblock (BIP 37)
## filteradd/filterload/filterclear (BIP 37)
## mempool (BIP 35)
# It is RECOMMENDED that a node that has sent or received a disabletx message to/from a peer not send any of these messages to the peer:
## addr/getaddr
## addrv2 (BIP 155)
# The behavior regarding sending or processing other message types is not specified by this BIP.
# Nodes MAY decide to not remain connected to peers that send this message (for example, if trying to find a peer that will relay transactions).

==Compatibility==

Nodes with protocol version >= 70017 that do not implement this BIP, and nodes
with protocol version < 70017, will continue to remain compatible with
implementing software: transactions would not be relayed to peers sending the
disabletx message (provided that BIP 37 or BIP 60 has been implemented), and while
periodic address relay may still take place, software implementing this BIP
should not be disconnecting such peers solely for that reason.

Disabling address relay is suggested but not required by this BIP, to allow for
future protocol extensions that might specify more carefully how address relay
is to be negotiated. This BIP's recommendations for software to not relay
addresses is intended to be interpreted as guidance in the absence of any such
future protocol extension, to accommodate existing software behavior.

Note that all messages specified in BIP 152, including blocktxn and
getblocktxn, are permitted between peers that have sent/received a disabletx
message, subject to the feature negotiation of BIP 152.

==Implementation==

TBD

==References==

# Bitcoin Core has [<a href="https://github.com/bitcoin/bitcoin/pull/15759" target="_blank">https://github.com/bitcoin/bitcoin/pull/15759</a> implemented this functionality] since version 0.19.0.1, released in November 2019.
# For example, see <a href="https://www.cs.umd.edu/projects/coinscope/coinscope.pdf" target="_blank">https://www.cs.umd.edu/projects/coinscope/coinscope.pdf</a> and <a href="https://arxiv.org/pdf/1812.00942.pdf" target="_blank">https://arxiv.org/pdf/1812.00942.pdf</a>.

==Copyright==

This BIP is licensed under the 2-clause BSD license.</pre></div></div>
_______________________________________________<br>
bitcoin-dev mailing list<br>
<a href="mailto:bitcoin-dev@lists.linuxfoundation.org" target="_blank">bitcoin-dev@lists.linuxfoundation.org</a><br>
<a href="https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev" rel="noreferrer" target="_blank">https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev</a><br>
</blockquote></div>