Skip to content

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

Merged
sedited merged 2 commits into
bitcoin:masterfrom
stratospher:rpc_addrmaninfo
Mar 11, 2026
Merged

cli: rework -addrinfo cli to use addresses which aren’t filtered for quality/recency#26988
sedited merged 2 commits into
bitcoin:masterfrom
stratospher:rpc_addrmaninfo

Conversation

@stratospher

@stratospher stratospher commented Jan 29, 2023

Copy link
Copy Markdown
Contributor

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.

@DrahtBot

DrahtBot commented Jan 29, 2023

Copy link
Copy Markdown
Contributor

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
ACK pablomartin4btc, vasild, ajtowns, sr-gi
Concept ACK mzumsande, brunoerg
Approach ACK jonatack, sipa
Stale ACK amitiuttarwar

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

No conflicts as of last run.

LLM Linter (✨ experimental)

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • [JSONRPCRequestObj("getaddrmaninfo", NullUniValue, 1)] in src/bitcoin-cli.cpp

2025-12-13

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread test/functional/rpc_net.py Outdated
@amitiuttarwar

Copy link
Copy Markdown
Contributor

obvious concept ack considering I proposed #26907

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor

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?

Comment thread src/rpc/net.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
@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
Comment thread src/rpc/net.cpp Outdated
@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

@brunoerg brunoerg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concept ACK

Comment thread src/rpc/net.cpp Outdated
@brunoerg

brunoerg commented Feb 22, 2023

Copy link
Copy Markdown
Contributor
"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
Copy Markdown
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
Copy Markdown
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

brunoerg commented Mar 9, 2023

Copy link
Copy Markdown
Contributor

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

going to review in depth soon.

@amitiuttarwar

Copy link
Copy Markdown
Contributor

light code review ACK 7c34c35b47. 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

Copy link
Copy Markdown
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.

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approach ACK 016ab85a13408ad980c3dbce4e041e14a4fcf3b8, thanks for updating, tested with a server on master, not yet tested with a server running pre-v26 (before getaddrmaninfo)

$ ./build/bin/bitcoin-cli -addrinfo
{
  "all addresses known (used for selecting peers)": {
    "ipv4": 48133,
    "ipv6": 8017,
    "onion": 17257,
    "i2p": 3757,
    "cjdns": 11,
    "total": 77175
  },
  "addresses known after quality/recency filtering (for original -addrinfo compatibility)": {
    "ipv4": 45921,
    "ipv6": 7487,
    "onion": 16259,
    "i2p": 3035,
    "cjdns": 7,
    "total": 72709
  }
}

Comment thread doc/release-notes-26988.md Outdated
Comment thread src/bitcoin-cli.cpp Outdated
@fanquake

fanquake commented Nov 2, 2025

Copy link
Copy Markdown
Member

not yet tested with a server running pre-v26 (before getaddrmaninfo)

25.x, 26.x and 27.x are all end-of-life; so that seems out of scope for needing to test / accomodate code-wise?

@sipa

sipa commented Nov 2, 2025

Copy link
Copy Markdown
Member

Concept ACK, but I think it's weird to use a long English phrase as field name. Maybe just "addresses_total" and "addresses_filtered" or so? If we care about backward compatibility, we could add a -deprecatedrpc=addresses_known option to enable the "addresses_known" field (which would be a copy of "addresses_filtered").

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed as of 016ab85a13

Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
@stratospher

Copy link
Copy Markdown
Contributor Author

thank you for the reviews! I've pushed an update changing the long key names.
also retained the original key name in -addrinfo's result (addresses_known) in case some other scripts/tools rely on it.

$ build/bin/bitcoin-cli -addrinfo
{
  "addresses_known": {
    "ipv4": 52037,
    "ipv6": 8855,
    "onion": 3465,
    "i2p": 0,
    "cjdns": 0,
    "total": 64357
  },
  "addresses_filtered": {
    "ipv4": 41811,
    "ipv6": 5808,
    "onion": 2465,
    "i2p": 0,
    "cjdns": 0,
    "total": 50084
  }
}

regarding #26988 (comment):

25.x, 26.x and 27.x are all end-of-life; so that seems out of scope for needing to test / accomodate code-wise?

Good point. Thinking of changing it in the next push.

According to bitnodes.io - among bitcoin core nodes, 95% are already on v26+ and therefore support getaddrmaninfo (introduced 2 years ago).

Maybe the concern regarding older node <-> newer CLI compatibility isn't there anymore considering how much the network/software has changed! (cc @jonatack, curious to hear your thoughts and anyone else's of course)

  • 95% of bitcoin core nodes are on v26+ and have access to getaddrmaninfo (introduced 2 years ago)
  • the nodes we're concerned about breaking user space (v22 - v26 nodes) with have reached EOL

@jonatack

Copy link
Copy Markdown
Member

CLI calls can be made to a node running a different, older version. If a researcher, data gatherer, developer, or node operator is calling this on a pre-getaddrmaninfo node, then the call should still work. As commented above, colleagues here requested that -netinfo continue to work in such cases, and we patched it. There doesn't seem to be any reason not to do the same here, rather than choosing to break it.

Comment thread src/bitcoin-cli.cpp Outdated
uint64_t total{0}; // Total address count
for (size_t i = 1; i < NETWORKS.size() - 1; ++i) {
addresses.pushKV(NETWORKS[i], counts.at(i));
total += counts.at(i);
}
addresses.pushKV("total", total);
result.pushKV("addresses_known", std::move(addresses));
result.pushKV("addresses_filtered", std::move(addresses));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with preferably keeping the field names short, but the data corresponding to "addresses_known" should not change.

Perhaps use "addresses_unfiltered" or "addresses_not_filtered_for_quality_and_recency" for the new field.

As this is a CLI output, as opposed to an RPC one, its output presentation can be more optimized for human use (see -getinfo, for instance) while providing consistent historical data.

@fanquake

fanquake commented Nov 20, 2025

Copy link
Copy Markdown
Member

CLI calls can be made to a node running a different, older version. If a researcher, data gatherer, developer, or node operator is calling this on a pre-getaddrmaninfo node,

Could you elaborate on why these people, particularly the developers, or node operators, are running EOL versions of Core (with known CVEs); and why they can't upgrade their nodes, but at the same time, they are downloading and using the latest version of bitcoin-cli?

There doesn't seem to be any reason not to do the same here, rather than choosing to break it.

The reason to not do it, is that it then implies we are still supporting versions of our software, which we have marked as EOL.

@mzumsande mzumsande left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CLI calls can be made to a node running a different, older version. If a researcher, data gatherer, developer, or node operator is calling this on a pre-getaddrmaninfo node, then the call should still work. As commented above, colleagues here requested that -netinfo continue to work in such cases, and we patched it. There doesn't seem to be any reason not to do the same here, rather than choosing to break it.

I don't agree with that. I don't see bitcoin-cli and bitcoind as completely separate programs that should be supported in arbitrary combinations for eternity.

If that was the case, it would have been a bad mistake to ever have added non-trivial functionality like -addrinfo or -netinfo to bitcoin-cli instead of bitcoind in the first place because that would have created an infinite obligation to maintain compatibility of current bitcoind versions with ancient versions of bitcoin-cli long out of support.

While it makes some limited sense to try to keep up compatibility over version ranges supported at the same time (although even that is debatable in my opinion), I don't think that it is reasonable to make any efforts supporting compatibility beyond this.

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.
@stratospher

Copy link
Copy Markdown
Contributor Author

I pushed an update. I also don't think we should implement a fallback to support a rare usecase for few individuals. I've run into a few occasions where I used older bitcoind and newer cli but it's when I misconfigure something accidentally and wasn't the behaviour I intended. I guess this is what most normal users would run into.

This is why I think we shouldn't implement a fallback:

  1. since -addrinfo is meant to be a human facing CLI dashboard (as implied in the documentation everywhere) and not an RPC endpoint (which other software/tools use programatically), the human facing CLI dashboard does not require a deprecation path (unlike RPCs). Humans can read and respond to it. It's not meant to used in automated scripts (those should use RPCs directly) and only meant to be read by humans.
  2. if different versions of bitcoind and bitcoin-cli are used - it's the responsibility of the user to do proper package management. bitcoind and bitcoin-cli are versioned and released together.
  3. This feels like an edge case for very few individuals. The transition period is over and 95% of bitcoin core nodes are already on v26+. If someone is capable of downloading the latest bitcoin-cli, they can upgrade their node/use an older bitcoin-cli.
  4. getaddrmaninfo support is there for 95% of bitcoin core nodes that are already on v26+
  5. v22-v27 are all EOL with known security vulnerabilities (from this comment)
  6. it would be contradictory to state in the release notes that we are maintaining compatibility solely for EOL versions only for the human facing CLI dashboard, when we do not maintain EOL support anywhere else.

So my preferred solution is to give human node operators a clear + helpful message explaining the issue and asking them to use an older CLI or newer bitcoind to which they can choose. A clear message is more helpful than silently falling back.

@jonatack, thank you for your feedback and I'm sorry there's a difference in opinion + this is dragging out so long.
I hope the reasons stated here and the comments (1 and 2) above make sense to you. I appreciate your time spent discussing this, and I hope the reasoning above contributes to finding the best long-term solution!

Comment thread doc/release-notes-26988.md Outdated
@sipa

sipa commented Dec 8, 2025

Copy link
Copy Markdown
Member

Concept/Approach ACK. I think it's fine to break compatibility with unmaintained node versions, given that there is a good error message for this case.

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 5b05a9959f1633bfee78d9edb180c672b0640ab5

@pablomartin4btc pablomartin4btc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tACK 5b05a9959f1633bfee78d9edb180c672b0640ab5

with bitcoind < v26:

/build/bin/bitcoin-cli -signet -datadir=/tmp/btc -addrinfo
error: -addrinfo requires bitcoind v26.0 or later which supports getaddrmaninfo RPC. Please upgrade your node or use bitcoin-cli from the same version.

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK 325f98bca07c3a0c48a46dc18f67376d44c5341d

Comment thread doc/release-notes-26988.md Outdated

@pablomartin4btc pablomartin4btc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 325f98bca07c3a0c48a46dc18f67376d44c5341d

(Left a small suggestion since the older node may be operated by someone other than the CLI user, and upgrading it might not be possible or appropriate when this change is the only reason. I think this would also align with @jonatack’s earlier note.)

@pablomartin4btc pablomartin4btc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

re-ACK b3046cc

@sedited

sedited commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

There are six stale reviews with various levels of approval here, while there has been no activity on this PR for three months now. Is there anything that can be done to resurrect progress again?

@sr-gi

sr-gi commented Mar 5, 2026

Copy link
Copy Markdown
Member

IMO this was dragging because of the difference in opinions on whether to have a simpler approach, or a more complex one to accommodate older versions of bitcoind. It'd be useful to me to know when we have landed.

My two cents on this: being about to release v31, I personally don't think it makes sense to have extra complexity to cater for versions pre-26, which are all EOL. I also think the usecase of having an old version of bitcoind with an up-to-date version of bitcoin-cli should be rare, and up to the user to figure out.

@fanquake

fanquake commented Mar 5, 2026

Copy link
Copy Markdown
Member

It'd be useful to me to know when we have landed.

There was no response to #26988 (comment), so it's not really clear what the "EOL, CVE-vulnerable bitcoind + latest available bitcoin-cli" use-case is. Ideally that's not something we are actively trying to support, and instead would be solving whichever issue is preventing those users from upgrading their bitcoind (assuming there is one).

@stratospher

Copy link
Copy Markdown
Contributor Author

IMO this was dragging because of the difference in opinions on whether to have a simpler approach, or a more complex one to accommodate older versions of bitcoind. It'd be useful to me to know when we have landed.

yeah, PR in the current state has the simpler approach implemented + informative error message if they're using a very old bitcoin-cli on a recent node + mention in the release notes.

@sr-gi

sr-gi commented Mar 5, 2026

Copy link
Copy Markdown
Member

IMO this was dragging because of the difference in opinions on whether to have a simpler approach, or a more complex one to accommodate older versions of bitcoind. It'd be useful to me to know when we have landed.

yeah, PR in the current state has the simpler approach implemented + informative error message if they're using a very old bitcoin-cli on a recent node + mention in the release notes.

SGTM. Will review

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK b3046cc

@ajtowns

ajtowns commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

ACK b3046cc

I wonder if a useful analogy is something like: suppose an charity has 9010 volunteers who've signed up to help out, but in practice over the past months it's turned out that only 420 of them actually followup reliably when askt ed. Having that organisation report that there are 9010 volunteers available is correct in a literal sense, but the 420 number is probably useful to at least have available if you're trying to predict how effective the organisation will be at its charitable purposes.

In that case, eliminating the "IsTerrible" nodes arguably performs a similar "we know about X nodes, but really only Y are likely to be useful". But probably the "total" vs "tried" count is already good enough for that? On mainnet, I'm seeing: 60k total, 10k tried, 53k not-terrible; so the 10k tried figure sounds more sensible to me. This PR getaddrmaninfo already reports total and tried figures, so perhaps it would be good if a followup had -addrinfo also do that?

@sr-gi sr-gi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tACK b3046cc

I tested this on top of b3046cc and against a 25.2 and 26.0 instances. I can confirm the exception is thrown for version < v26.

Comment thread src/bitcoin-cli.cpp
++counts.at(network_id);
if (!reply["error"].isNull()) {
if (reply["error"]["code"].getInt<int>() == RPC_METHOD_NOT_FOUND) {
throw std::runtime_error("-addrinfo requires bitcoind v26.0 or later which supports getaddrmaninfo RPC. Please upgrade your node or use bitcoin-cli from the same version.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: To my understanding, we tend not to suggest updating the software as this is something the user should choose on their own. I think we could be changed to something like:

"Please make sure your bitcoin-cli and bitcoind versions match".

Feel free to disregard, or only address if you need to retouch.

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.