refactor: Make m_mempool optional in PeerManager #26247

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2210-opt-mem-🔱 changing 5 files +44 −32
  1. maflcko commented at 1:43 PM on October 4, 2022: member

    Make m_mempool an optional pointer in PeerManager, instead of a reference.

    • This is a prerequisite for the introduction of a -nomempool option. (To run a node with just libbitcoinkernel and a minimal P2P stack to receive blocks)
    • The mempool is already treated optional in pretty much every other part of the codebase (validation, RPC, ...), so doing it consistently is preferable.
    • Removing the requirement of PeerManager to hold a reference to a mempool makes (unit/fuzz) testing easier if there is a test that doesn't need the mempool. Also, it makes the coupling of CTxMemPool and PeerManager a bit more loose.

    Picked up from #22850

  2. DrahtBot added the label Refactoring on Oct 4, 2022
  3. DrahtBot cross-referenced this on Oct 4, 2022 from issue net: Set relay in version msg to peers with relay permission in -blocksonly mode by maflcko
  4. DrahtBot commented at 8:26 PM on October 4, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #26969 (net: net_processing, add ProcessCompactBlockTxns by brunoerg)
    • #26900 (refactor: Add BlockManager getters by MarcoFalke)
    • #26621 (refactor: Continue moving application data from CNode to Peer by dergoegge)
    • #25781 (Remove almost all blockstorage globals by MarcoFalke)
    • #25572 (refactor: Introduce EvictionManager and use it for the inbound eviction logic by dergoegge)
    • #25268 (refactor: Introduce EvictionManager by dergoegge)

    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.

  5. DrahtBot cross-referenced this on Oct 4, 2022 from issue refactor: Guard TxRequestTracker by its own lock instead of cs_main by dergoegge
  6. DrahtBot cross-referenced this on Oct 4, 2022 from issue rpc, doc: getpeerinfo updates by jonatack
  7. ajtowns commented at 3:49 AM on October 5, 2022: contributor

    What's the benefit of a -nomempool option? There doesn't seem to be an open issue justifying it. This approach just seems to introduce a lot of places where you need to Assert(m_mempool) or if (!m_mempool) return; -- ie, introduces potential bugs.

    If the goal is to limit memory usage by avoiding having 300MB dedicated to the mempool (which might be filled up during a large reorg, even if you don't accept txs normally), wouldn't it be better to still have the mempool data structure, and at most add an option that guarantees the mempool will remain empty by ignoring attempts to add txs to it; ie a const bool always_empty; in CTxMemPool or similar?

  8. DrahtBot cross-referenced this on Oct 5, 2022 from issue refactor: Introduce EvictionManager and use it for the inbound eviction logic by dergoegge
  9. DrahtBot cross-referenced this on Oct 6, 2022 from issue p2p, rpc: Manual block-relay-only connections with addnode by mzumsande
  10. DrahtBot cross-referenced this on Oct 6, 2022 from issue p2p: Replace RecursiveMutex `m_tx_inventory_mutex` with Mutex and rename it by w0xlt
  11. ariard commented at 12:32 AM on October 7, 2022: member

    What's the benefit of a -nomempool option? There doesn't seem to be an open issue justifying it. This approach just seems to introduce a lot of places where you need to Assert(m_mempool) or if (!m_mempool) return; -- ie, introduces potential bugs.

    Embedded systems where the binary size matters and you would like to run a bitcoin-node daemon only connected to a stateful signer? Assuming you can also cut out the p2p stack. However, if this is a relevant use-case, the nomempool option could be introduced at the build-level, like --disable-mempool.

  12. maflcko marked this as a draft on Oct 7, 2022
  13. maflcko added the label Brainstorming on Oct 7, 2022
  14. maflcko commented at 1:32 PM on October 7, 2022: member

    Code wise there seems to be a preference to have a pointer than an empty struct, see also #22415 and #25223 . (Updated OP with motivation)

    Though, I agree that the code doesn't look particularly nice. I was thinking about turning RejectIncomingTxs into a helper that returns a pointer to the mempool (if the peer is allowed to "see" the mempool), and similar methods for the other places where a mempool is used.

  15. DrahtBot cross-referenced this on Oct 11, 2022 from issue Replace global g_cs_orphans lock with local by ajtowns
  16. DrahtBot added the label Needs rebase on Oct 13, 2022
  17. maflcko force-pushed on Oct 18, 2022
  18. DrahtBot removed the label Needs rebase on Oct 18, 2022
  19. DrahtBot added the label Needs rebase on Oct 21, 2022
  20. glozow commented at 4:10 PM on January 19, 2023: member

    Wondering if people here would have an opinion on #26471?

  21. maflcko force-pushed on Jan 19, 2023
  22. maflcko force-pushed on Jan 19, 2023
  23. DrahtBot cross-referenced this on Jan 19, 2023 from issue refactor: Add BlockManager getters by maflcko
  24. DrahtBot removed the label Needs rebase on Jan 19, 2023
  25. DrahtBot cross-referenced this on Jan 19, 2023 from issue refactor: Continue moving application data from CNode to Peer by dergoegge
  26. DrahtBot cross-referenced this on Jan 19, 2023 from issue p2p: Track orphans by who provided them by ajtowns
  27. DrahtBot cross-referenced this on Jan 19, 2023 from issue Remove almost all blockstorage globals by maflcko
  28. DrahtBot cross-referenced this on Jan 24, 2023 from issue refactor: Introduce EvictionManager by dergoegge
  29. DrahtBot cross-referenced this on Jan 26, 2023 from issue net, refactor: net_processing, add `ProcessCompactBlockTxns` by brunoerg
  30. DrahtBot added the label Needs rebase on Jan 26, 2023
  31. Make m_mempool optional in PeerManager
    - Make m_mempool a pointer in the initialization of PeerManager
    - Check that m_mempool exists before dereferencing the pointer in PeerManager functions
    - If m_mempool is a nullptr, turn off transaction relay with all peers by setting m_tx_relay to nullptr
    f413f4061d
  32. maflcko force-pushed on Jan 26, 2023
  33. DrahtBot removed the label Needs rebase on Jan 26, 2023
  34. DrahtBot commented at 5:22 PM on January 27, 2023: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

    🐙 This pull request conflicts with the target branch and needs rebase.

  35. DrahtBot added the label Needs rebase on Jan 27, 2023
  36. maflcko closed this on Feb 20, 2023

  37. maflcko deleted the branch on Feb 20, 2023
  38. bitcoin locked this on Feb 20, 2024

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: 2026-05-19 06:52 UTC

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