Skip to content

Count only connected peers in /net_info n_peers - #4500

Merged
masih merged 5 commits into
mainfrom
masih/1791381948-net-info-connected-peers
Oct 9, 2026
Merged

masih merged 5 commits into
mainfrom
masih/1791381948-net-info-connected-peers

Conversation

@masih

@masih masih commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

/net_info builds n_peers from Router.AllAddrs(), which merges the live connections with every address in the persistent and regular PEX tables. On pacific-1 that reports roughly 175-200 "peers" on nodes that are actually connected to around 45, which an operator running max-connections = 31 took for a broken peer cap. CometBFT tooling and dashboards read n_peers as the connected-peer count. The known-peer semantics come from the Tendermint v0.35 fork (PeerManager.Peers() over the peer store); #2539 moved the source to the pool address maps, and #3037 switched it to AllAddrs() while moving peer_connections to live connections, which is why the two now disagree.

Environment.NetInfo now sets n_peers to the number of connected peers, the same set as peer_connections. peers keeps listing every known address, because the rpcnode init script and the sei-infra state-sync and init scripts seed persistent-peers from .peers[].url. Limiting it to connected peers left those lists empty whenever the source node only had inbound peers without an external-address, which is what made the Chain Operation Test time out in the merge queue. Exposing the known-address count as a Prometheus metric is left to a follow-up.

This is an RPC-only change with no consensus or state impact. TestNetInfo_NPeersCountsConnectedPeers and TestNetInfo_PeersIncludesPexAddresses both fail on main and pass here.

@devin-ai-integration

devin-ai-integration Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 9, 2026, 10:22 AM

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.22%. Comparing base (8d4ac58) to head (691d45b).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4500      +/-   ##
==========================================
+ Coverage   57.11%   57.22%   +0.11%     
==========================================
  Files        2127     2135       +8     
  Lines      166521   167077     +556     
==========================================
+ Hits        95101    95609     +508     
- Misses      71415    71463      +48     
  Partials        5        5              
Flag Coverage Δ
sei-chain 55.41% <100.00%> (+0.13%) ⬆️
sei-db 75.17% <ø> (ø)
sei-db-state-db 78.95% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-tendermint/internal/rpc/core/net.go 51.42% <100.00%> (+51.42%) ⬆️

... and 56 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masih
masih marked this pull request as ready for review October 7, 2026 14:15
@cursor

cursor Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
RPC-only response semantics fix with no consensus or state impact; operators and dashboards will see lower, accurate n_peers values.

Overview
Fixes /net_info so n_peers reports connected peers (aligned with peer_connections) instead of every address from Router.AllAddrs() (live connections plus PEX/persistent tables), which had been inflating counts on mainnet.

The peers field is unchanged: it still lists all known peer URLs (including PEX-learned addresses) for tooling that seeds persistent-peers. Comments on NetInfo document the split semantics.

Adds TestNetInfo_NPeersCountsConnectedPeers and TestNetInfo_PeersIncludesPexAddresses to lock in the behavior.

Reviewed by Cursor Bugbot for commit 691d45b. Bugbot is set up for automated code reviews on this repo. Configure here.

@seidroid seidroid Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change makes /net_info build peers and n_peers from Router.ConnInfos(), so they report live connections, which already come deduplicated by node ID, instead of every address learned via PEX; it also removes Router.AllAddrs and adds a test-only KnownAddrs helper. The new logic is correct and nothing blocks it; the tree was checked out at the PR merge but Go is not installed here, so the new test was not run, and the one scout reading (codex) found nothing, so it added no findings and none were dropped.

1 nit, not posted on the code
  • sei-tendermint/internal/rpc/core/net.go:21 — An inbound connection whose handshake carried no SelfAddr now shows up in peers with url: ""; before this change such a peer was left out. SplitAndTrimEmpty drops empty entries, so persistent-peers built by scripts that read .peers[].url is unaffected, but leaving the peer out of peers would keep the output clean for other readers.

seidroid review · decision approve · session 1ba11012dd11415ba145e8fdf7c42349 · turn resp_claude_b624230ebcbfb83a1cc4ca3d9961254c · item fefbd1cd4c7152f79c4eb829be3a6db3

Findings: 0 blocking | 0 non-blocking | 0 posted inline

@masih masih added the backport release/v6.7 Backport to release v6.7 label Oct 7, 2026
Comment thread sei-tendermint/internal/rpc/core/net.go Outdated
PeerConnections: slices.Collect(maps.Values(peerConnections)),
NPeers: len(peerConnections),
Peers: peers,
PeerConnections: peerConnections,

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.

Based on what you described, it is probably correct semantics for the tools.

But should we export count of AllAddrs somewhere so we have visibility on that? I think we already exported all peers (whether they are connected or not) before PR#2539?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think we should; as a prometheus metric 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you for reviewing; I will action this as a separate follow up PR for metrics.

@alexander-sei
alexander-sei added this pull request to the merge queue Oct 7, 2026
@alexander-sei
alexander-sei removed this pull request from the merge queue due to a manual request Oct 7, 2026
@alexander-sei
alexander-sei added this pull request to the merge queue Oct 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 7, 2026
@alexander-sei
alexander-sei added this pull request to the merge queue Oct 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 7, 2026
@alexander-sei
alexander-sei added this pull request to the merge queue Oct 7, 2026
@alexander-sei
alexander-sei removed this pull request from the merge queue due to a manual request Oct 7, 2026
@alexander-sei
alexander-sei added this pull request to the merge queue Oct 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 7, 2026
@alexander-sei
alexander-sei added this pull request to the merge queue Oct 7, 2026
@masih
masih removed this pull request from the merge queue due to a manual request Oct 7, 2026
@wen-coding

Copy link
Copy Markdown
Contributor

@masih @alexander-sei My AI claimed not being able to merge into main could be because of this:

Yes. This job died because the RPC node never got a peer to dial, and that comes from the new /net_info peers list.

The merge-queue run for this PR cancelled Integration Test (Chain Operation Test) at the 30-minute limit. The chain-operation tests never started. The step was stuck on seid status inside sei-rpc-node, which got connection refused on port 26657 from 20:59 until 21:27.

rpc-node.log shows why the port was closed. State sync runs inside reactor startup, before the RPC server is bound, and it sat at peers=0 for 28 minutes (target=2). The router log is out=0/20 the whole time, with no dial attempts.

The RPC node fills persistent-peers from node 0:

step1_configure_init.sh
Ln 157–158
curl "$STATE_SYNC_RPC"/net_info |jq -r '.peers[] | .url' |sed -e 's#mconn://##' >> build/generated/PEERS
STATE_SYNC_PEER=$(paste -s -d ',' build/generated/PEERS)
192.168.10.10 is node 0. In this run its connections were unconditional in=3 out=0, and the docker config leaves external-address empty. After this PR an inbound peer with no self-declared address is counted in n_peers and left out of peers. Node 0's peers array was empty, the script replaced the fallback peer list with that empty result, and the RPC node had nothing to dial.

Before this PR, AllAddrs still included addresses learned over PEX. Nodes 1–3 each had two outbound connections, so those dialed addresses were in node 0's response and the RPC node could connect. The other integration jobs in this run passed; this one is the case where node 0 accepted every connection inbound.

@masih

masih commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

@wen-coding ty! Yes I am aware and disscussed with @alexander-sei in DMs. This is why I explicitly removed it from the merge queue.

We can ship this one in the second patch of v6.7 after migration settles 🙌

ty for your review and letting me take your time on this 🙇

@devin-ai-integration devin-ai-integration Bot changed the title Report only connected peers in /net_info n_peers and peers Count only connected peers in /net_info n_peers Oct 9, 2026
@masih

masih commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Taking the path of least resistence: only count connected peers as n_peers. That has the least ecosystem breakage since they read these values as it is understood by cometbft.

I will add extra prometheus metrics in a separate PR.

@masih
masih added this pull request to the merge queue Oct 9, 2026
Merged via the queue into main with commit 8ab697f Oct 9, 2026
58 checks passed
@masih
masih deleted the masih/1791381948-net-info-connected-peers branch October 9, 2026 12:01
@seidroid

seidroid Bot commented Oct 9, 2026

Copy link
Copy Markdown

Successfully created backport PR for release/v6.7:

devin-ai-integration Bot pushed a commit that referenced this pull request Oct 9, 2026
Follow-up to #4500, which changes `/net_info` `n_peers` to count
connected peers so it stops reporting the ~180-200 known addresses that
operators took for a broken peer cap. The known-address count is still
worth watching, for example to see how much the PEX tables grow, so this
exports it as a Prometheus gauge rather than an RPC field, as wen
suggested on #4500.

`tendermint_p2p_known_addresses` is the length of
`peerManager.AllAddrs()`: distinct node IDs across the live connections
and the persistent and regular PEX tables, the same set `/net_info`
`peers` lists. `NewRouter` seeds it and `metricsRoutine` refreshes it
every 10s, next to `tendermint_p2p_peers`, which keeps counting live
connections and is unchanged. The seed-node Prometheus test now also
checks that the new series is served. This only adds a metric, with no
consensus or state impact.

(cherry picked from commit 2009d55)
revofusion pushed a commit to revofusion/sei-chain that referenced this pull request Oct 10, 2026
)

Follow-up to sei-protocol#4500, which changes `/net_info` `n_peers` to count
connected peers so it stops reporting the ~180-200 known addresses that
operators took for a broken peer cap. The known-address count is still
worth watching, for example to see how much the PEX tables grow, so this
exports it as a Prometheus gauge rather than an RPC field, as wen
suggested on sei-protocol#4500.

`tendermint_p2p_known_addresses` is the length of
`peerManager.AllAddrs()`: distinct node IDs across the live connections
and the persistent and regular PEX tables, the same set `/net_info`
`peers` lists. `NewRouter` seeds it and `metricsRoutine` refreshes it
every 10s, next to `tendermint_p2p_peers`, which keeps counting live
connections and is unchanged. The seed-node Prometheus test now also
checks that the new series is served. This only adds a metric, with no
consensus or state impact.
alexander-sei added a commit that referenced this pull request Oct 12, 2026
…ers (#4515)

Backport of #4500 to `release/v6.7`.

Co-authored-by: Masih H. Derkani <m@derkani.org>
Co-authored-by: alexander-sei <alexanderh@seinetwork.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants