net: Avoid SetTxRelay for feeler connections #26396

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2210-feeler-less-memory-🥑 changing 3 files +17 −8
  1. maflcko commented at 3:49 pm on October 26, 2022: member

    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.

  2. DrahtBot added the label P2P on Oct 26, 2022
  3. in src/net.h:494 in faea347bcb outdated
    488@@ -489,9 +489,8 @@ class CNode
    489     /** Whether this peer provides all services that we want. Used for eviction decisions */
    490     std::atomic_bool m_has_all_wanted_services{false};
    491 
    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+    /** Whether we should relay transactions to this peer.
    496+     *  This only changes from false to true. It will never change
    497      *  back to false. Used only in inbound eviction logic. */
    


    mzumsande commented at 7:17 pm on October 26, 2022:
    Since this line is touched anyway “Used only in inbound eviction logic” is no longer the case, Erlay also uses it.

    maflcko commented at 2:07 pm on October 27, 2022:
    Thanks, done
  4. mzumsande commented at 7:18 pm on October 26, 2022: contributor
    Concept ACK. This has been suggested before (https://github.com/bitcoin/bitcoin/pull/22778#discussion_r858578282)
  5. DrahtBot commented at 11:04 pm on October 26, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25572 (refactor: Introduce EvictionManager and use it for the inbound eviction logic by dergoegge)
    • #25268 (refactor: Introduce EvictionManager by dergoegge)
    • #24170 (p2p, rpc: Manual block-relay-only connections with addnode by mzumsande)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  6. net: Avoid SetTxRelay for feeler connections fa24239a1c
  7. maflcko force-pushed on Oct 27, 2022
  8. fanquake requested review from naumenkogs on Oct 28, 2022
  9. fanquake requested review from dergoegge on Oct 28, 2022
  10. fanquake requested review from sdaftuar on Oct 28, 2022
  11. in test/functional/p2p_sendtxrcncl.py:173 in fa24239a1c
    168@@ -163,6 +169,11 @@ def run_test(self):
    169         assert not peer.sendtxrcncl_msg_received
    170         peer.peer_disconnect()
    171 
    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")
    


    vasild commented at 1:12 pm on October 28, 2022:
    Shouldn’t that be p2p_idx=3 and the below bumped to p2p_idx=4?

    maflcko commented at 1:19 pm on October 28, 2022:

    This is only used to pick a port (if none was given). The previous connection was closed, so the index can be reused.

    Though, happy to change this test or remove it, since it isn’t too important.


    vasild commented at 1:40 pm on October 28, 2022:
    Ok, then this is functionally fine. Could be somewhat confusing because surrounding tests do disconnect and bump p2p_idx after that.

    mzumsande commented at 11:40 pm on November 1, 2022:
    If changed, I think that this should be cleaned up to use an incremented variable like in p2p_add_connections.py to make future changes easier, but not necessary to do this here and invalidate ACKs. Maybe include in #26359 @naumenkogs?

    naumenkogs commented at 11:20 am on November 2, 2022:
    @mzumsande I think it makes sense to just set them all to 1, because it doesn’t matter, rather than handle increments.

    mzumsande commented at 5:18 am on November 3, 2022:
    @MarcoFalke @naumenkogs After looking at current CI failures such as https://cirrus-ci.com/task/5511952184115200?logs=ci#L4024, I think it does matter: peer_disconnect doesn’t wait until the node has completed the disconnection. So there is a race between setting up the next connection (next addconnection RPC), and if the old one hasn’t been removed and is identical to the new one (because we didn’t increment the ID), CConnman::OpenNetworkConnection just returns without establishing a connection.

    naumenkogs commented at 8:24 am on November 3, 2022:
    Good point! I think you’re right, I’ve been looking at it for a bit and haven’t found a better explanation. Please have this requirement documented in the PR you gonna open :)

    mzumsande commented at 5:06 pm on November 3, 2022:
    Done in #26448
  12. vasild approved
  13. vasild commented at 1:13 pm on October 28, 2022: contributor
    ACK fa24239a1c2281f61ab70a62228e88f4c7e72701
  14. jonatack commented at 5:39 pm on October 28, 2022: contributor
    ACK fa24239a1c2281f61ab70a62228e88f4c7e72701
  15. naumenkogs commented at 8:47 am on October 31, 2022: member
    Should we add AddrFetch to this?
  16. maflcko commented at 9:20 am on October 31, 2022: member
    Not sure. addrfetch may live up to 5 minutes and they are sent version.relay=True. So if this is changed, it should be done at the same time that changes relay=False. Maybe leave for a separate pull request, as this one is mostly about memory allocation?
  17. naumenkogs commented at 4:00 pm on October 31, 2022: member
    ACK fa24239a1c2281f61ab70a62228e88f4c7e72701
  18. mzumsande commented at 1:32 am on November 2, 2022: contributor

    ACK fa24239a1c2281f61ab70a62228e88f4c7e72701

    Should we add AddrFetch to this?

    I agree that this shouldn’t be done here, but fwiw I’m hesitant about this in general. In the rare occasions where we do AddrFetch connections, we usually have an empty addrman, few (if any) other peers and are most vulnerable to eclipse attacks. It might be better not to implement behavior from which the peer can conclude already at version negotation that this is likely an AddrFetch connection instead of a normal outbound connection, if the benefit is just to save a little memory on a connection that is short-lived anyway.

  19. maflcko merged this on Nov 2, 2022
  20. maflcko closed this on Nov 2, 2022

  21. naumenkogs commented at 7:48 am on November 2, 2022: member
    @mzumsande my initial motivation was not even memory, but just for the code to be more logical :) I don’t care much, but what would be wrong if the peer new that this is AddrFetch?
  22. maflcko deleted the branch on Nov 2, 2022
  23. sidhujag referenced this in commit 881ef9e962 on Nov 3, 2022
  24. mzumsande commented at 5:10 pm on November 3, 2022: contributor

    I don’t care much, but what would be wrong if the peer new that this is AddrFetch?

    I was thinking of an attacker that would specifically target new and vulnerable nodes in an eclipse attack, giving legitimate GETADDR answer to other peers, so it would be hard to detect what this attacker is doing. But maybe that is a bit too hypothetical.

  25. bitcoin locked this on Nov 3, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-04 19:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me