Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: Add test-only RPC getaddrmaninfo for new/tried table address count #27511

Merged
merged 2 commits into from Sep 20, 2023

Conversation

stratospher
Copy link
Contributor

implements #26907. split off from #26988 to keep RPC, CLI discussions separate.

This PR introduces a new RPC getaddrmaninfowhich returns the count of addresses in the new/tried table of a node's addrman broken down by network type. This would be useful for users who want to see the distribution of addresses from different networks across new/tried table in the addrman.

$ getaddrmaninfo

Result:
{                   (json object) json object with network type as keys
  "network" : {     (json object) The network (ipv4, ipv6, onion, i2p, cjdns)
    "new" : n,      (numeric) number of addresses in new table
    "tried" : n,    (numeric) number of addresses in tried table
    "total" : n     (numeric) total number of addresses in both new/tried tables from a network
  },
  ...
}

additional context from original PR

  1. network coverage tests were skipped because there’s a small chance that addresses from different networks could hash to the same bucket and cause count of different network addresses in the tests to fail. see cli: rework -addrinfo cli to use addresses which aren’t filtered for quality/recency #26988 (comment).
  2. cli: rework -addrinfo cli to use addresses which aren’t filtered for quality/recency #26988 uses this RPC in -addrinfo CLI. Slight preference for keeping the RPC hidden since this info will mostly be useful to only super users. see cli: rework -addrinfo cli to use addresses which aren’t filtered for quality/recency #26988 (comment).

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 21, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK 0xB10C, brunoerg, theStack, willcl-ark, achow101
Concept ACK jonatack
Stale ACK ryanofsky, mzumsande, amitiuttarwar

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26988 (cli: rework -addrinfo cli to use addresses which aren’t filtered for quality/recency by stratospher)

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.

@jonatack
Copy link
Contributor

jonatack commented Apr 21, 2023

This PR is based on master from two months age. You may need to rebase it to current master for the (tidy) CI to be green.

@jonatack
Copy link
Contributor

jonatack commented Apr 21, 2023

Tested Concept ACK. It might be good to have the breakdown of pre/post IsTerrible filtering (RPC getnodeaddresses and CLI -addrinfo return post) -- see the large differences between them.

Screenshot 2023-04-21 at 10 21 42

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK c505611

just tested it with my "clearnet only" node, results:

➜  bitcoin-core-dev git:(27511-stratospher) ✗ ./src/bitcoin-cli getaddrmaninfo
{
  "ipv4": {
    "new": 28765,
    "tried": 277,
    "total": 29042
  },
  "ipv6": {
    "new": 7245,
    "tried": 67,
    "total": 7312
  },
  "onion": {
    "new": 0,
    "tried": 0,
    "total": 0
  },
  "i2p": {
    "new": 0,
    "tried": 0,
    "total": 0
  },
  "cjdns": {
    "new": 0,
    "tried": 0,
    "total": 0
  }
}

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review ACK c505611, I would use this rpc a lot in my work.

I also think that a totals field would be useful.

I don't think that a split-up with respect to "terrible" would be necessary, because in my opinion "terrible" is an internal property used only in address relay / addrman collisions that is not so critical to expose because it isn't used for the main purpose of addrman: selecting peers for outbound connections

@jonatack
Copy link
Contributor

jonatack commented May 12, 2023

"terrible" is an internal property

It's used in RPC getnodeaddresses and CLI -addrinfo to return only non-IsTerrible peers to users. (I meant pre and post that filtering in the suggestion above).

@mzumsande
Copy link
Contributor

It's used in RPC getnodeaddresses and CLI -addrinfo to return only non-IsTerrible peers to users. (I meant pre and post that filtering in the suggestion above).

in my opinion unfortunately. I think this was mostly coincidental, because #13152 chose to reuse an addrman function used only for GETADDR answers before. Then #21595 used that output without any mentioning of that restriction, and the doc was only adjusted a year later in #24370. I think that ideally we never should have exposed the terrible filter in the first place.

@fanquake
Copy link
Member

I think that ideally we never should have exposed the terrible filter in the first place.

@mzumsande do you want to propose some changes to remove its exposure?

@jonatack
Copy link
Contributor

The author and the numerous reviewers of #13152 were aware of the relationship to getaddr (see the PR description and review discussion), as well as mention of IsTerrible in #13152 (review).

I don't see it as unfortunate; as a frequent user of getnodeaddresses and -addrinfo it seems useful that the data doesn't include terrible/non-recent (and banned/discouraged) peers.

But guessing whether it was coincidental is beside the point. What is relevant is that changing those calls to return different data would break user space, including any tracking over time using that data.

Adding data is fine, but let's not needlessly break user space.

@jonatack
Copy link
Contributor

@stratospher do you plan to repush after rebase to current master for the CI and perhaps with the totals?

@mzumsande
Copy link
Contributor

@mzumsande do you want to propose some changes to remove its exposure?

no, I don't want to spend time on discussions on whether some change breaks user space or not. I'd be happy to have an alternative way to query the actual, unfiltered numbers per network, which are much more relevant to my use cases as a developer.

I don't see it as unfortunate; as a frequent user of getnodeaddresses and -addrinfo it seems useful that the data doesn't include terrible/non-recent (and banned/discouraged) peers.

For me, it makes no sense that these commands might withhold our very next outbound peer - which would be picked with no disadvantage over non-terrible peers if it, for example, just has an older timestamp.
Or, when dealing with a peers.dat that is >30 days old, that these commands won't give any results at all anymore, even though the peers.dat is still perfectly useful and able to find peers (many nodes are reachable under the same address for way longer than a month).

@jonatack
Copy link
Contributor

jonatack commented May 15, 2023

I'd be happy to have an alternative way to query the actual, unfiltered numbers per network

I think that would be useful, too, perhaps by passing an argument to getnodeaddresses and -addrinfo, and/or returning both pre and post filter in -addrinfo.

@stratospher
Copy link
Contributor Author

so sorry for the delay and thank you for the suggestions! the CI is all green now. i've updated the PR to include:

  • addrman new/tried/total count for "all networks"
  • test coverage for "all networks" and for total (total refers to both new/tried table count)

I'd want this RPC to be the alternative way to access the actual count of all addresses in the addrman.

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK 7d7ee5e

@DrahtBot DrahtBot requested a review from brunoerg May 16, 2023 14:36
@fanquake
Copy link
Member

no, I don't want to spend time on discussions on whether some change breaks user space or not.

@mzumsande fair enough. I don't quite understand what "user space" means, when it has been used in comments here (and in other PRs), as we are not the Linux Kernel, but I assume it's a somewhat less direct way of saying backwards compatibility/continuity?

In any case, as far as I'm aware, we offer no special "backwards compatiblity", or other, guarantees for our CLI tools, and I don't really think we should. Doing so would put us in an awkward position, of having our RPCs backwards compatibility requirements, extended to those tools (consumers, which just happen to exist in this codebase).

We don't want to be in position where we can't change an RPC, to stop it doing something possibly incorrect/illogical, just because a CLI tool happens to call that RPC. These tools shouldn't get any special treatment, and, as far as I'm concerned, should just adapt to any RPC changes we might make, like every other consumer (internal or external) of that RPC.

@ryanofsky
Copy link
Contributor

The code change here seems very simple, but since this PR does add a new RPC it would be useful to have more concept ACKs to know whether this is appropriate to merge. I noticed a number of contributors added github reactions to some comments here, so perhaps more of the people following the discussion could add concept acks or mention any reservations

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 7d7ee5e

src/rpc/net.cpp Outdated Show resolved Hide resolved
@stratospher
Copy link
Contributor Author

updated the PR to include better docs inspired from #27511 (comment). left "RPC is for testing only" as it is since all hidden RPCs have that line in the help. getaddrmaninfo's help looks like this now:

Provides high-level information about the node's address manager by returning the number of addresses in the `new` and `tried` tables and their sum for all networks.
This RPC is for testing only.

Result:
{                   (json object) json object with network type as keys
  "network" : {     (json object) the network (ipv4, ipv6, onion, i2p, cjdns)
    "new" : n,      (numeric) number of addresses in new table. The new table contains addresses of potential new peers that are periodically tested for connectivity to increase the node's network reach.
    "tried" : n,    (numeric) number of addresses in tried table. The tried table contains addresses of peers with whom the node has successfully connected to in the past.
    "total" : n     (numeric) total number of addresses in both new/tried tables from a network
  },
  ...
}

Examples:
> bitcoin-cli getaddrmaninfo 
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getaddrmaninfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/

@0xB10C
Copy link
Contributor

0xB10C commented Sep 19, 2023

ACK 28bac81

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 28bac81

CI failure seems unrelated.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-review ACK 28bac81

src/rpc/net.cpp Show resolved Hide resolved
@willcl-ark
Copy link
Member

reACK 28bac81

@DrahtBot DrahtBot removed the request for review from willcl-ark September 20, 2023 12:10
@achow101
Copy link
Member

ACK 28bac81

@achow101 achow101 merged commit ff564c7 into bitcoin:master Sep 20, 2023
15 of 16 checks passed
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Sep 25, 2023
…ied table address count

28bac81 test: add functional test for getaddrmaninfo (stratospher)
c8eb8da rpc: Introduce getaddrmaninfo for count of addresses stored in new/tried table (stratospher)

Pull request description:

  implements bitcoin#26907. split off from bitcoin#26988 to keep RPC, CLI discussions separate.

  This PR introduces a new RPC `getaddrmaninfo`which returns the count of addresses in the new/tried table of a node's addrman broken down by network type. This would be useful for users who want to see the distribution of addresses from different networks across new/tried table in the addrman.

  ```jsx
  $ getaddrmaninfo

  Result:
  {                   (json object) json object with network type as keys
    "network" : {     (json object) The network (ipv4, ipv6, onion, i2p, cjdns)
      "new" : n,      (numeric) number of addresses in new table
      "tried" : n,    (numeric) number of addresses in tried table
      "total" : n     (numeric) total number of addresses in both new/tried tables from a network
    },
    ...
  }
  ```

  ### additional context from [original PR](bitcoin#26988)

  1. network coverage tests were skipped because there’s a small chance that addresses from different networks could hash to the same bucket and cause count of different network addresses in the tests to fail. see bitcoin#26988 (comment).
  2. bitcoin#26988 uses this RPC in -addrinfo CLI. Slight preference for keeping the RPC hidden since this info will mostly be useful to only super users. see bitcoin#26988 (comment).

ACKs for top commit:
  0xB10C:
    ACK 28bac81
  willcl-ark:
    reACK 28bac81
  achow101:
    ACK 28bac81
  brunoerg:
    reACK 28bac81
  theStack:
    Code-review ACK 28bac81

Tree-SHA512: 346390167e1ebed7ca5c79328ea452633736aff8b7feefea77460e04d4489059334ae78a3f757f32f5fb7827b309d7186bebab3c3760b3dfb016d564a647371a
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 26, 2023
…ied table address count

28bac81 test: add functional test for getaddrmaninfo (stratospher)
c8eb8da rpc: Introduce getaddrmaninfo for count of addresses stored in new/tried table (stratospher)

Pull request description:

  implements bitcoin#26907. split off from bitcoin#26988 to keep RPC, CLI discussions separate.

  This PR introduces a new RPC `getaddrmaninfo`which returns the count of addresses in the new/tried table of a node's addrman broken down by network type. This would be useful for users who want to see the distribution of addresses from different networks across new/tried table in the addrman.

  ```jsx
  $ getaddrmaninfo

  Result:
  {                   (json object) json object with network type as keys
    "network" : {     (json object) The network (ipv4, ipv6, onion, i2p, cjdns)
      "new" : n,      (numeric) number of addresses in new table
      "tried" : n,    (numeric) number of addresses in tried table
      "total" : n     (numeric) total number of addresses in both new/tried tables from a network
    },
    ...
  }
  ```

  ### additional context from [original PR](bitcoin#26988)

  1. network coverage tests were skipped because there’s a small chance that addresses from different networks could hash to the same bucket and cause count of different network addresses in the tests to fail. see bitcoin#26988 (comment).
  2. bitcoin#26988 uses this RPC in -addrinfo CLI. Slight preference for keeping the RPC hidden since this info will mostly be useful to only super users. see bitcoin#26988 (comment).

ACKs for top commit:
  0xB10C:
    ACK 28bac81
  willcl-ark:
    reACK 28bac81
  achow101:
    ACK 28bac81
  brunoerg:
    reACK 28bac81
  theStack:
    Code-review ACK 28bac81

Tree-SHA512: 346390167e1ebed7ca5c79328ea452633736aff8b7feefea77460e04d4489059334ae78a3f757f32f5fb7827b309d7186bebab3c3760b3dfb016d564a647371a
0xB10C added a commit to 0xB10C/bitcoin that referenced this pull request Sep 27, 2023
Exposing address manager table entries in a hidden RPC allows to introspect
addrman tables in tests and during development.

Also ran clang-format-diff.py on my diff to reduce the extra indentation
from the getaddrmaninfo RPC implementation.

Can be reviewed with --ignore-all-space

Includes a small follow-up from bitcoin#27511 too which adds `all_networks` to
the list of possible "network" key's in the JSON response.
See bitcoin#27511 (comment)
0xB10C added a commit to 0xB10C/bitcoin that referenced this pull request Sep 27, 2023
Exposing address manager table entries in a hidden RPC allows to introspect
addrman tables in tests and during development.

Also ran clang-format-diff.py on my diff to reduce the extra indentation
from the getaddrmaninfo RPC implementation.

Can be reviewed with --ignore-all-space

Includes a small follow-up from bitcoin#27511 too which adds `all_networks` to
the list of possible "network" key's in the JSON response.
See bitcoin#27511 (comment)
stratospher added a commit to stratospher/bitcoin that referenced this pull request Oct 3, 2023
stratospher added a commit to stratospher/bitcoin that referenced this pull request Oct 3, 2023
achow101 added a commit that referenced this pull request Oct 3, 2023
… entries

352d5eb test: getrawaddrman RPC (0xb10c)
da384a2 rpc: getrawaddrman for addrman entries (0xb10c)

Pull request description:

  Inspired by `getaddrmaninfo` (#27511), this adds a hidden/test-only `getrawaddrman` RPC. The RPC returns information on all addresses in the address manager new and tried tables. Addrman table contents can be used in tests and during development.

  The RPC result encodes the `bucket` and `position`, the internal location of addresses in the tables, in the address object's string key. This allows users to choose to consume or to ignore the location information. If the internals of the address manager implementation change, the location encoding might change too.

  ```
  getrawaddrman

  EXPERIMENTAL warning: this call may be changed in future releases.

  Returns information on all address manager entries for the new and tried tables.

  Result:
  {                                  (json object)
    "table" : {                      (json object) buckets with addresses in the address manager table ( new, tried )
      "bucket/position" : {          (json object) the location in the address manager table (<bucket>/<position>)
        "address" : "str",           (string) The address of the node
        "port" : n,                  (numeric) The port number of the node
        "network" : "str",           (string) The network (ipv4, ipv6, onion, i2p, cjdns) of the address
        "services" : n,              (numeric) The services offered by the node
        "time" : xxx,                (numeric) The UNIX epoch time when the node was last seen
        "source" : "str",            (string) The address that relayed the address to us
        "source_network" : "str"     (string) The network (ipv4, ipv6, onion, i2p, cjdns) of the source address
      },
      ...
    },
    ...
  }

  Examples:
  > bitcoin-cli getrawaddrman
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawaddrman", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
  ```

ACKs for top commit:
  willcl-ark:
    reACK 352d5eb
  amitiuttarwar:
    reACK 352d5eb
  stratospher:
    reACK 352d5eb.
  achow101:
    ACK 352d5eb

Tree-SHA512: cc462666b5c709617c66b0e3e9a17c4c81e9e295f91bdd9572492d1cb6466fc9b6d48ee805ebe82f9f16010798370effe5c8f4db15065b8c7c0d8637675d615e
stratospher added a commit to stratospher/bitcoin that referenced this pull request Oct 4, 2023
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
…n table entries

352d5eb test: getrawaddrman RPC (0xb10c)
da384a2 rpc: getrawaddrman for addrman entries (0xb10c)

Pull request description:

  Inspired by `getaddrmaninfo` (bitcoin#27511), this adds a hidden/test-only `getrawaddrman` RPC. The RPC returns information on all addresses in the address manager new and tried tables. Addrman table contents can be used in tests and during development.

  The RPC result encodes the `bucket` and `position`, the internal location of addresses in the tables, in the address object's string key. This allows users to choose to consume or to ignore the location information. If the internals of the address manager implementation change, the location encoding might change too.

  ```
  getrawaddrman

  EXPERIMENTAL warning: this call may be changed in future releases.

  Returns information on all address manager entries for the new and tried tables.

  Result:
  {                                  (json object)
    "table" : {                      (json object) buckets with addresses in the address manager table ( new, tried )
      "bucket/position" : {          (json object) the location in the address manager table (<bucket>/<position>)
        "address" : "str",           (string) The address of the node
        "port" : n,                  (numeric) The port number of the node
        "network" : "str",           (string) The network (ipv4, ipv6, onion, i2p, cjdns) of the address
        "services" : n,              (numeric) The services offered by the node
        "time" : xxx,                (numeric) The UNIX epoch time when the node was last seen
        "source" : "str",            (string) The address that relayed the address to us
        "source_network" : "str"     (string) The network (ipv4, ipv6, onion, i2p, cjdns) of the source address
      },
      ...
    },
    ...
  }

  Examples:
  > bitcoin-cli getrawaddrman
  > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawaddrman", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
  ```

ACKs for top commit:
  willcl-ark:
    reACK 352d5eb
  amitiuttarwar:
    reACK 352d5eb
  stratospher:
    reACK 352d5eb.
  achow101:
    ACK 352d5eb

Tree-SHA512: cc462666b5c709617c66b0e3e9a17c4c81e9e295f91bdd9572492d1cb6466fc9b6d48ee805ebe82f9f16010798370effe5c8f4db15065b8c7c0d8637675d615e
fanquake added a commit that referenced this pull request Oct 16, 2023
e6e444c refactor: add and use EnsureAnyAddrman in rpc (stratospher)
bf589a5 doc: add release notes for #27511 (stratospher)
3931e6a rpc: `getaddrmaninfo` followups (stratospher)

Pull request description:

  - make `getaddrmaninfo` RPC public since it's not for development purposes only and regular users might find it useful. [#26988 (comment)](#26988 (comment))
  - add missing `all_networks` key to RPC help. [#27511 (comment)](#27511 (comment))
  - fix clang format spacing
  - add and use `EnsureAddrman` in RPC code. [#27511 (comment)](#27511 (comment))

ACKs for top commit:
  0xB10C:
    Code Review re-ACK e6e444c
  theStack:
    Code-review ACK e6e444c
  pablomartin4btc:
    tested ACK e6e444c

Tree-SHA512: c14090d5c64ff15e92d252578de2437bb2ce2e1e431d6698580241a29190f0a3528ae5b013c0ddb76a9ae538507191295c37cab7fd93469941cadbde44587072
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Oct 20, 2023
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet