rpc,net: Add getpeerbyid and listpeersbyids RPCs #32972

pull waketraindev wants to merge 3 commits into bitcoin:master from waketraindev:2025-07-14-getpeerbyid-rpc changing 6 files +410 −148
  1. waketraindev commented at 4:40 PM on July 14, 2025: none

    Add fast peer lookup by NodeId using m_node_id_map in CConnman.

    Adds GetNodeStatsById and GetNodeStatsByIds in net.{cpp,h} for efficient internal access.

    Introduces two new RPCs:

    • getpeerbyid(id): returns info for a single connected peer
    • listpeersbyids([ids], strict=false): batch query with optional strict mode

    Includes functional tests covering expected behavior and edge cases.

    Useful for tools that track peers by ID without scanning the full list, or for quickly looking up peer IDs seen in debug logs.

  2. DrahtBot commented at 4:40 PM on July 14, 2025: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32972.

    <!--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:

    • #32741 (rpc: add optional nodeid param to filter getpeerinfo by waketraindev)
    • #32394 (net: make m_nodes_mutex non-recursive by vasild)
    • #32278 (doc: better document NetEventsInterface and the deletion of "CNode"s by vasild)
    • #32015 (net: replace manual reference counting of CNode with shared_ptr by vasild)
    • #31672 (rpc: add cpu_load to getpeerinfo by vasild)
    • #30988 (Split CConnman by vasild)
    • #27052 (test: rpc: add last block announcement time to getpeerinfo result by LarryRuane)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. glozow commented at 6:31 PM on July 14, 2025: member

    Is anything here not already provided by getpeerinfo?

  4. waketraindev commented at 6:37 PM on July 14, 2025: none

    Is anything here not already provided by getpeerinfo?

    yes, the option to retrieve result by peer id.

  5. DrahtBot added the label CI failed on Jul 14, 2025
  6. net: add m_node_id_map for fast lookup of nodes by id f54db2dbfa
  7. refactor: extract peer info object construction from getpeerinfo cd9003b0ed
  8. rpc: add getpeerbyid and listpeersbyids RPCs with functional tests 8e6874cc4f
  9. mzumsande commented at 9:19 PM on July 14, 2025: contributor

    yes, the option to retrieve result by peer id.

    Isn't this what your other PR #32741 suggests? Is this meant to be an alternative to that?

  10. waketraindev commented at 9:30 PM on July 14, 2025: none

    yes, the option to retrieve result by peer id.

    Isn't this what your other PR #32741 suggests? Is this meant to be an alternative to that?

    Yes, this is essentially a more complete version of that, incorporating feedback and suggestions from other contributors. It serves as an alternative approach to PR #32741.

  11. DrahtBot removed the label CI failed on Jul 15, 2025
  12. in src/rpc/net.cpp:262 in 8e6874cc4f
     257 | +            {RPCResult::Type::STR, "session_id", "The session ID for this connection, or \"\" if there is none (\"v2\" transport protocol only).\n"},
     258 | +        }
     259 | +    };
     260 | +}
     261 | +
     262 | +static RPCHelpMan listpeersbyids()
    


    maflcko commented at 6:52 AM on July 15, 2025:

    how's that different from a batch call or just filtering getpeerinfo? Not sure we need three RPCs where the input is None, int, array, but everything else is the same. I can understand the use case of server-side filtering here, but it should be fine to just add the filtering to getpeerinfo whether that is int- or array-based. One filtering should be sufficient?

  13. maflcko commented at 7:03 AM on July 15, 2025: member

    seems better to just push to the other pull?

  14. fanquake commented at 8:57 AM on July 15, 2025: member

    Yea, please combine these changes into #32741.

  15. fanquake closed this on Jul 15, 2025

  16. mzumsande commented at 2:50 PM on July 15, 2025: contributor

    I also prefer the current approach from #32741 to this - while users can always just filter getpeerinfo output with jq or other tools I can see how that is inconvenient for some - but introducing multiple new RPCs for this seems overkill to me.


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-02 12:12 UTC

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