Skip to content

cli: rework -addrinfo cli to use addresses which aren’t filtered for quality/recency #26988

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stratospher
Copy link
Contributor

@stratospher stratospher commented Jan 29, 2023

Rework of -addrinfo CLI is done using getaddrmaninfo RPC proposed in #27511. This would be useful for users who want to know the total number of addresses the node knows about and can make connections to.

Currently, -addrinfo returns total number of addresses the node knows about after filtering them for quality + recency using isTerrible. However isTerribleaddresses don't matter when selecting outbound peers to connect to. Total number of addresses the node knows about could be higher than what -addrinfo currently displays. See #24370.

open questions:

  1. should we continue displaying filtered address stats?

currently the PR displays both total + filtered addresses stats. the total address stats is more relevant since that is what is used by node to find peers to connect to. the filtered addresses stats is kept as it is for not breaking backward compatibilty when a newer bitcoin-cli is used on an older bitcoind binary (v22 - v25). my personal preference is for displaying only the relevant total addresses stats - see this branch. but i'm fine with either approach based on what reviewers think.

$ build/bin/bitcoin-cli -addrinfo
{
  "all addresses known (used for selecting peers)": {
    "ipv4": 5927,
    "ipv6": 958,
    "onion": 382,
    "i2p": 0,
    "cjdns": 0,
    "total": 7267
  },
  "addresses known after quality/recency filtering (for original -addrinfo compatibility)": {
    "ipv4": 5888,
    "ipv6": 928,
    "onion": 382,
    "i2p": 0,
    "cjdns": 0,
    "total": 7198
  }
}

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 29, 2023

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

Code Coverage & Benchmarks

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

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK mzumsande, brunoerg
Stale ACK amitiuttarwar, pablomartin4btc

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

Conflicts

No conflicts as of last run.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • filtered address -> filtered addresses [plural form for consistency in “stats of filtered address(s) in the addrman”]

drahtbot_id_4_m

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.

Concept ACK, will review soon.

@amitiuttarwar
Copy link
Contributor

obvious concept ack considering I proposed #26907

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.

Looks good to me, only minor nits.

ping @jonatack, could you have a look, especially at the changes to bitcoin-cli?

@fanquake fanquake changed the title [rpc]: Add test-only RPC addrmaninfo for new/tried table address count rpc: Add test-only RPC addrmaninfo for new/tried table address count Feb 7, 2023
@stratospher stratospher changed the title rpc: Add test-only RPC addrmaninfo for new/tried table address count rpc: Add test-only RPC getaddrmaninfo for new/tried table address count Feb 22, 2023
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

@brunoerg
Copy link
Contributor

brunoerg commented Feb 22, 2023

"network" : "str",    (string) The network (ipv4, ipv6, onion, i2p, cjdns)

Instead of being a string, wouldn't make sense it to be an array? E.g. I want to get new/tried table address count for ipv4 and ipv6 together.

@stratospher
Copy link
Contributor Author

Instead of being a string, wouldn't make sense it to be an array? E.g. I want to get new/tried table address count for ipv5 and ipv6 together.

i'm confused about this since making it into RPCArg::Type::ARR would make the RPC harder to type and use?
$ bitcoin-cli getaddrmaninfo "[\"ipv4\", \"ipv6\"]"

and there are only few network types. would be interested in what others think.

@amitiuttarwar
Copy link
Contributor

to minimize the complexity that we need to maintain over time, we try to reduce the amount of client-side niftiness that we offer. it seems to me that the string would offer all the information needed for a client to write a simple query if they wanted the sum of multiple. agreed that the syntax is another challenge of the array type

so I am +1 to leaving as is

@brunoerg
Copy link
Contributor

brunoerg commented Mar 9, 2023

that was just a question, thinking about complexity I agree on leaving it as is.

going to review in depth soon.

@amitiuttarwar
Copy link
Contributor

light code review ACK 7c34c35. tested that the RPC and cli endpoints make sense & handle errors reasonably. these changes will require release notes, which can be done here or in a separate PR.

@stratospher stratospher marked this pull request as ready for review September 23, 2024 12:35
@stratospher
Copy link
Contributor Author

Rebased. thanks @jonatack! reaching out.

@DrahtBot
Copy link
Contributor

Needs rebase, if still relevant

@stratospher stratospher marked this pull request as draft June 20, 2025 07:20
stratospher added a commit to stratospher/bitcoin that referenced this pull request Jun 20, 2025
stratospher added a commit to stratospher/bitcoin that referenced this pull request Jun 20, 2025
stratospher added a commit to stratospher/bitcoin that referenced this pull request Jun 20, 2025
stratospher added a commit to stratospher/bitcoin that referenced this pull request Jun 20, 2025
stratospher added a commit to stratospher/bitcoin that referenced this pull request Jun 20, 2025
@stratospher
Copy link
Contributor Author

thanks Drahtbot! i've rebased and changed the approach in the PR to display both total + filtered addresses stats as suggested in #26988 (comment).

  • the total address stats is more relevant since that is what is used by node to find peers to connect to.
  • the filtered addresses stats is kept as it is for backward compatibilty/not breaking user space when a newer bitcoin-cli is used on an older bitcoind binary (v22 - v25).

my personal preference is for displaying only the relevant total addresses stats - see this branch.
but i'm fine with either approach based on what reviewers think!

@stratospher stratospher marked this pull request as ready for review June 20, 2025 12:54
Copy link
Member

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

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

tACK c2f3225

my personal preference is for displaying only the relevant total addresses stats

I also lean toward showing only the total known addresses, as I think it better reflects what the node has in its addrman and avoids suggesting that only the filtered set "counts."
I'd consider whether passing an argument might offer one or both views (filtered/unfiltered) depending on the use case, but I’ve read the previous discussions here and in #27511, and I understand the concerns around compatibility.
The filtered view (based on IsTerrible()) may be misleading for users who assume those are the only addresses known — unless they're explicitly inspecting address table quality.
That said, happy to follow the current direction — just sharing those thoughts for context.

Comparing this latest output against my previous testing I noticed that the all_networks element has been removed (?).
./build_26988/bin/bitcoin-cli -signet -datadir=/tmp/btc -addrinfo
{
  "all addresses known (used for selecting peers)": {
    "ipv4": 1368,
    "ipv6": 893,
    "onion": 0,
    "i2p": 0,
    "cjdns": 0,
    "total": 2261
  },
  "addresses known after quality/recency filtering (for original -addrinfo compatibility)": {
    "ipv4": 1352,
    "ipv6": 883,
    "onion": 0,
    "i2p": 0,
    "cjdns": 0,
    "total": 2235
  }
}

currently -addrinfo returns addresses known to the node after
filtering for quality and recency. However, the node considers
all known addresses (even the filtered out addresses) when
selecting peers to connect to.

So update -addrinfo to also display the full set of known
addresses for more useful node information. The address stats
after filtering is kept as it is and displayed for not breaking
userspace and could someday be removed.
@stratospher
Copy link
Contributor Author

Comparing this latest output against my previous testing I noticed that the all_networks element has been removed (?)

good observation! the old version was incorrect because all_networks and total were the same thing (total number of addresses from all networks in addrman). pushed an update which doesn't require us to sum up total number of addresses again since that information is already computed in getaddrmaninfo.

DashCoreAutoGuix pushed a commit to DashCoreAutoGuix/dash that referenced this pull request Jul 28, 2025
…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
DashCoreAutoGuix pushed a commit to DashCoreAutoGuix/dash that referenced this pull request Aug 3, 2025
…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
DashCoreAutoGuix pushed a commit to DashCoreAutoGuix/dash that referenced this pull request Aug 5, 2025
e6e444c refactor: add and use EnsureAnyAddrman in rpc (stratospher)
bf589a5 doc: add release notes for bitcoin#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. [bitcoin#26988 (comment)](bitcoin#26988 (comment))
  - add missing `all_networks` key to RPC help. [bitcoin#27511 (comment)](bitcoin#27511 (comment))
  - fix clang format spacing
  - add and use `EnsureAddrman` in RPC code. [bitcoin#27511 (comment)](bitcoin#27511 (comment))

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

Tree-SHA512: c14090d5c64ff15e92d252578de2437bb2ce2e1e431d6698580241a29190f0a3528ae5b013c0ddb76a9ae538507191295c37cab7fd93469941cadbde44587072
DashCoreAutoGuix pushed a commit to DashCoreAutoGuix/dash that referenced this pull request Aug 9, 2025
…onal tests

2cc8ca1 [test] Use deterministic addrman in addrman info tests (stratospher)
a897866 [test] Restart a node with empty addrman (stratospher)
71c1991 [test] Use deterministic addrman in addpeeraddress test (stratospher)
7b868e6 Revert "test: avoid non-determinism in asmap-addrman test" (stratospher)
69e091f [init] Create deterministic addrman in tests using -test=addrman (stratospher)
be25ac3 [init] Remove -addrmantest command line arg (stratospher)
802e6e1 [init] Add new command line arg for use only in functional tests (stratospher)

Pull request description:

  An address is placed in a `[bucket,position]` in the addrman table (new table or tried table) using the `addpeeraddress` RPC. This `[bucket,position]` is calculated using `nKey`(and other metrics) for the addrman which is chosen randomly during every run.

  Supposing there are 2 addresses to be placed in an addrman table. During every test run, a different `[bucket,position]` would be calculated for each address.These calculated `[bucket,position]` could even be the same for the 2 addresses in some test runs and result in collisions in the addrman. We wouldn't be able to predict when the collisions are going to happen because we can't predict the `nKey` value which is chosen at random. This can cause flaky tests.

  Because of these non deterministic collisions, we are limited in what we can do to test addrman functionality. Currently in our tests don't add a second address to prevent these collisions from happening - we only keep 1 address in the new table and 1 address in the tried table. See bitcoin#26988 (comment), bitcoin#23084, [bitcoin#22831(comment)](https://github.com/bitcoin/bitcoin/pull/22831/files#r708302639).

  This PR lets us create a deterministic addrman with fixed `nKey` so that we can know the `[bucket,position]` collisions beforehand, safely add more addresses in an addrman table and write more extensive tests.

ACKs for top commit:
  amitiuttarwar:
    ACK 2cc8ca1
  achow101:
    ACK 2cc8ca1
  0xB10C:
    ACK 2cc8ca1
  mzumsande:
    Code Review ACK 2cc8ca1

Tree-SHA512: 8acd9bdfe7de1eb44d22373bf13533d8ecf602df966fdd5b8b78afcd8cc35a286c95d2712f67a89473a0d68dded7d38f5599f6e4bf95a6589475444545bfb189

# Conflicts:
#	src/addrdb.cpp
#	src/common/args.cpp
#	src/init.cpp
#	src/net.cpp
#	test/functional/feature_asmap.py
#	test/functional/rpc_net.py
#	test/functional/test_framework/test_framework.py
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.