Skip to content

Add -netinfo peer connections dashboard - #19643

Merged
fanquake merged 13 commits into
bitcoin:masterfrom
jonatack:netinfo
Sep 15, 2020
Merged

Add -netinfo peer connections dashboard#19643
fanquake merged 13 commits into
bitcoin:masterfrom
jonatack:netinfo

Conversation

@jonatack

@jonatack jonatack commented Aug 2, 2020

Copy link
Copy Markdown
Member

This PR is inspired by laanwj's python script mentioned in #19405, which it turns out I ended up using every day and extending because I got hooked on using it to monitor Bitcoin peer connections.

For the full experience, run ./src/bitcoin-cli -netinfo 4

On Linux, try it with watch watch ./src/bitcoin-cli -netinfo 4

Help doc

$ ./src/bitcoin-cli -help | grep -A3 netinfo
  -netinfo
       Get network peer connection information from the remote server. An
       optional integer argument from 0 to 4 can be passed for different
       peers listings (default: 0).

@jonatack

jonatack commented Aug 2, 2020

Copy link
Copy Markdown
Member Author

@sumBTC you might find this useful--I've been using it to observe your issue #19500.

@ghost

ghost commented Aug 2, 2020

Copy link
Copy Markdown

@jonatack Ah was wondering what you were using. Nice to know this kind of information will soon be part of bitcoin-cli.

@DrahtBot

DrahtBot commented Aug 2, 2020

Copy link
Copy Markdown
Contributor

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

Conflicts

No conflicts as of last run.

@0xB10C

0xB10C commented Aug 3, 2020

Copy link
Copy Markdown
Contributor

Concept ACK. Especially on the detailed peers listing as getpeerinfo formatted for humans.

@practicalswift

Copy link
Copy Markdown
Contributor

Wow, this is really neat!

As a pure terminal user I love the bitcoin-cli -netinfo t output -- that is terminal usability at its finest!

Concept ACK

@0xB10C 0xB10C 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.

Ran unit tests and the extend functional tests.

Mainly played around with the verbose mode on testnet without inbound peers. Works great with watch!

Did not see anything in the asmap column. Guess that's due to me not using the asmap feature.

Tested the bitcoin-cli build from this PR with -netinfo 1 on a v0.20.0 Bitcoin Core node and they seem to be compatible. That's super awesome!

Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/netaddress.h Outdated
Comment thread src/httpserver.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated

@jnewbery jnewbery 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. This is very cool. I'd normally be against adding this kind of functionality to bitcoin-cli for reasons of scope creep and bloat, but this seems really useful, and it's very neatly encapsulated in the NetinfoRequestHandler class. I'm looking forward to playing around with it.

Comment thread src/httpserver.cpp Outdated
Comment thread src/torcontrol.cpp Outdated

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

Concept ACK, but not sure about min ping data usefulness though.

Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/bitcoin-cli.cpp Outdated
Comment thread src/netaddress.h Outdated
@jonatack

jonatack commented Aug 6, 2020

Copy link
Copy Markdown
Member Author

Concept ACK, but not sure about min ping data usefulness though.

Thanks for having a look. min ping is an inbound eviction criterium and I look at it more than ping; also mulling adding a human-readable conntime column and maybe a couple others (last send/recv, addnode).

@hebasto

hebasto commented Aug 6, 2020

Copy link
Copy Markdown
Member

Concept ACK, but not sure about min ping data usefulness though.

Thanks for having a look. min ping is an inbound eviction criterium and I look at it more than ping; also mulling adding a human-readable conntime column and maybe a couple others (last send/recv, addnode).

Great!

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

laanwj commented Aug 6, 2020

Copy link
Copy Markdown
Member

Concept and functionality ACK

@ariard ariard 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/bitcoin-cli.cpp Outdated
@theStack

theStack commented Aug 7, 2020

Copy link
Copy Markdown
Contributor

Concept ACK 👍

@jonatack

jonatack commented Aug 9, 2020

Copy link
Copy Markdown
Member Author

Took most all of the feedback and also added lastsend and lastrecv in addition to the requested version column.

@jonatack

jonatack commented Aug 9, 2020

Copy link
Copy Markdown
Member Author

Did not see anything in the asmap column. Guess that's due to me not using the asmap feature.

Updated to not display the asmap column unless it is being used.

@jonatack
jonatack force-pushed the netinfo branch 2 times, most recently from e64170b to f0ff7cb Compare August 9, 2020 18:39
@jonatack

Copy link
Copy Markdown
Member Author

Further updates, per git diff 1492754 8587e78

  • No longer display peer version when value from getpeerinfo is 0
  • No longer display peer minping or ping when value from getpeerinfo is null
  • If user enters an integer greater than 4, parse it as the default of 0 rather than 4
  • Show the chain name when testnet or regtest

@practicalswift

Copy link
Copy Markdown
Contributor

Tested ACK 8587e78221492ee26aafbbc332453f7639912a41 -- patch looks correct and is limited to src/bitcoin-cli.cpp

@RandyMcMillan

RandyMcMillan commented Sep 1, 2020

Copy link
Copy Markdown
Contributor

Awesome stuff @jonatack - I was wondering if it would be possible to add some flags to make it automatically report after each new block (or some other arbitrary time interval) - the idea would be to generate a report that could be easily read into another service such as statsd.
-netinfo -p (for polling) -I (interval in seconds) -bn=true (triggered by a blocknotify event)

Thanks!

@0xB10C

0xB10C commented Sep 2, 2020

Copy link
Copy Markdown
Contributor

I was wondering if it would be possible to add some flags to make it automatically report after each new block (or some other arbitrary time interval)

I've been using watch bitcoin-cli -netinfo for a dashboard-like view of the report updated every few seconds. I don't see the need for adding a refreshing, dashboard-like view (and the complexity that comes with it) here.

the idea would be to generate a report that could be easily read into another service such as statsd.

I wouldn't use the bitcoin-cli -netinfo interface for this. The interface is designed to be developer-readable and not machine-readable. Under the hood -netinfo just calls getnetworkinfo and getpeerinfo. Calling these RPCs directly is probably more suited for your use-case. They are designed to be machine-readable and changes to these RPCs are documented in the release notes. Changes to -netinfo (which could break your statsd importing) will most likely not be documented.

@jonatack

jonatack commented Sep 2, 2020

Copy link
Copy Markdown
Member Author

@0xB10C thanks, I couldn't have said it better. Edit: added your watch suggestion to the PR description.

If we want this in the next release (and feature freeze isn't far away now), it's probably best to stabilize this PR on what we have now. It has gone through several rounds of review with lots of good feedback and updates. I'd propose to try to have this merged in its current state and consider further changes (e.g. possible future getpeerinfo fields like conn_type or bip152_hb_{to/from}) after that.

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

Copy link
Copy Markdown
Contributor

ACK bf1f913 -- patch looks correct and is limited to src/bitcoin-cli.cpp

@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 bf1f913

It is easier to change the doc to conform to the code :-D

Comment thread src/bitcoin-cli.cpp
const UniValue& getpeerinfo{batch[ID_PEERINFO]["result"]};

for (const UniValue& peer : getpeerinfo.getValues()) {
const std::string addr{peer["addr"].get_str()};

@n-thumann n-thumann Sep 4, 2020

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.

peer["addr"] can also contain hostnames (bitcoin-cli addnode "foo.bar" onetry) or IPv6 addresses without square brackets (bitcoin-cli addnode "2001:db8::1337" onetry). In theses cases the IsAddrIPv6 will not recognize them properly and they will be always marked as IPv4 🤔.

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.

Maybe, if there are no square brackets, ask inet_pton if it´s a valid IPv6 address? But what if there´s a hostname?

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.

Dug a little bit deeper: Adding a new field to getpeerinfo seems to be a better solution IMO. The actual remote address (that is IPv6 with square brackets or resolved hostname) is already stored here, but only addrName is passed back as addr instead.
I would suggest to return both addrName & addr so that the former contains the hostname (or ordinary IP address) and the latter the actual resolved remote address. This would at least solve the hostname/IPv6 problems, not sure how that effects onion addresses. Let me know what you think and if I should prepare a PR :)

@jonatack jonatack Sep 4, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@n-thumann Thanks for having a look. I don't plan to make further changes for edge cases unless they can be addressed within the scope of this PR (but am willing to update if they can be!)

The net address code is currently being deeply changed for BIP155 addrv2. This PR has seen a lot of review and updates, and if we begin gating it on changes in code outside this PR, we'll risk missing the next feature freeze (October 15 deadline for merge). I think this is very useable in its current state--if you start using it, good luck doing without it afterward 😃--and if merged, I'll be happy to make further improvements based on the state of the codebase at that time.

@n-thumann n-thumann 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.

tACK, works as expected! Minor bug in edge cases is tolerable ✌️

@0xB10C

0xB10C commented Sep 5, 2020

Copy link
Copy Markdown
Contributor

ACK bf1f913

I tested with a testnet node having connections both via clearnet and tor.

nit: I think age is a bit less ambiguous than uptime. uptime could be confused with the actual uptime of the remote node and not the time since the connection was established.

@jonatack

jonatack commented Sep 5, 2020

Copy link
Copy Markdown
Member Author

@0xB10C thanks! s/uptime/age/ sgtm for next update/follow-up.

@practicalswift

Copy link
Copy Markdown
Contributor

I think this src/bitcoin-cli.cpp-only PR is ready to merge with four ACK:s (@vasild @0xB10C @practicalswift @n-thumann) and six Concept ACK:s (@jnewbery @hebasto @laanwj @ariard @theStack @RandyMcMillan).

Thanks @jonatack for coming up with this nifty utility. I'm using it daily!

Looking forward to being able to use it directly from master! :)

@maflcko

maflcko commented Sep 7, 2020

Copy link
Copy Markdown
Member

Concept ACK, haven't reviewed/tested at all, but this might come in handy when testing pull requests on the live network.

bitcoin-cli isn't a stable interface, so we can change or remove this at will if issues come up in the future.

@0xB10C

0xB10C commented Sep 7, 2020

Copy link
Copy Markdown
Contributor

fwiw: ce57bf6 (leaving out the last three commits) can be used with bitcoind versions before v0.20.99.

edit:
archiving this here: https://github.com/0xB10C/bitcoin/tree/jonatacks-netinfo-pre-v0.20.99

@fanquake
fanquake merged commit a336518 into bitcoin:master Sep 15, 2020
@jonatack
jonatack deleted the netinfo branch September 15, 2020 07:11
@jonatack

jonatack commented Sep 15, 2020

Copy link
Copy Markdown
Member Author

Next steps checklist

Easy, do in next commit (done in #20115):

  • release note
  • s/uptime/age/ per @0xB10C suggestion
  • add one additional space between the net and mping columns
  • accomodate variable size of addrv2 addresses
  • handle occasional large mping/ping times like 1.17348e+06 per @practicalswift feedback
  • add new signet chain
  • display reachable networks

Medium term:

@jonatack

jonatack commented Sep 16, 2020

Copy link
Copy Markdown
Member Author

@practicalswift A couple of times I saw ephemeral very long minping times

@practicalswift I'm still seeing these (both mping and ping), so added it to the checklist above.

@jnewbery

Copy link
Copy Markdown
Contributor

I've been using this to test another PR and it's very helpful. Thanks @jonatack !

One thing I've noticed is that connections are inaccurately classified as blocks-only on first connection, I think because all connections start out as fRelayTxes set to false. It'd be better to explicitly use the connection type.

@jonatack

Copy link
Copy Markdown
Member Author

Here's a branch with some of the updates, including using the connection type:

https://github.com/jonatack/bitcoin/commits/netinfo-2

@ghost ghost mentioned this pull request Sep 26, 2020
laanwj added a commit that referenced this pull request Oct 29, 2020
398045b cli -netinfo: print oversized/extreme ping times as "-" (Jon Atack)
773f4c9 cli -netinfo: handle longer tor v3 local addresses (Jon Atack)
33e9874 cli -netinfo: make age column variable-width (Jon Atack)
f8a1c4d cli -netinfo: various quick updates and fixes (Jon Atack)

Pull request description:

  Quick fixups and updates for v0.21.0:

  - [x] handle larger BIP155 `addrv2` addresses
  - [x] add Signet chain
  - [x] add an additional space between the `net` and `mping` columns; add missing `tinyformat` and `algorithm` headers
  - [x] s/uptime/age/ per 0xB10C suggestion, and make the column auto-adjusting variable width
  - [x] display `-` for oversized mping/ping times like `1.17348e+06`, as reported by practicalswift

  Edit: removed the release note commit, as this PR was not merged before the notes were moved to the wiki. It's here:
  ```
  - A new `bitcoin-cli -netinfo` command returns a network peer connections
    dashboard that displays data from the `getpeerinfo` and `getnetworkinfo` RPCs
    in a human-readable format. An optional integer argument from `0` to `4` may
    be passed to see various levels of detail. (#19643)
  ```

ACKs for top commit:
  michaelfolkson:
    ACK 398045b
  Emzy:
    Tested ACK 398045b

Tree-SHA512: 0625ee840141bafbfcaf8f1fce53f8f850ae91721b2bdad4279372da87c18a1fe3a214d90bfdbbabdf6da38d58290d7dd0f1109b4e2ca5d20cacf417d6ced0f9
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 22, 2021
Summary:
```
This PR is inspired by laanwj's python script mentioned in #19405, which
it turns out I ended up using every day and extending because I got
hooked on using it to monitor Bitcoin peer connections.

For the full experience, run ./src/bitcoin-cli -netinfo 4

On Linux, try it with watch watch ./src/bitcoin-cli -netinfo 4

Help doc

$ ./src/bitcoin-cli -help | grep -A3 netinfo
  -netinfo
       Get network peer connection information from the remote server.
An
       optional integer argument from 0 to 4 can be passed for different
       peers listings (default: 0).
```

Backport of [[bitcoin/bitcoin#19643 | core#19643]].

Depends on D9331 and D9333.

Test Plan:
  watch ./src/bitcoin-cli -netinfo 4

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9334
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.