Skip to content

bugfix: make router load addresses from peerdb#2941

Merged
pompon0 merged 4 commits intomainfrom
gprusak-peer-db
Feb 20, 2026
Merged

bugfix: make router load addresses from peerdb#2941
pompon0 merged 4 commits intomainfrom
gprusak-peer-db

Conversation

@pompon0
Copy link
Contributor

@pompon0 pompon0 commented Feb 20, 2026

Even though router was correctly storing the addresses of connected peers to db, it was not loading them back on startup. Therefore router was behaving as if peerdb did not exist in the first place. I have added a test for the fix.

@github-actions
Copy link

github-actions bot commented Feb 20, 2026

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 20, 2026, 7:29 PM

@pompon0 pompon0 enabled auto-merge (squash) February 20, 2026 15:50
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.61%. Comparing base (16884af) to head (de700ed).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
sei-tendermint/internal/p2p/router.go 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2941       +/-   ##
===========================================
+ Coverage   57.76%   71.61%   +13.84%     
===========================================
  Files        2111       21     -2090     
  Lines      174239     1913   -172326     
===========================================
- Hits       100652     1370    -99282     
+ Misses      64631      445    -64186     
+ Partials     8956       98     -8858     
Flag Coverage Δ
sei-chain 72.61% <83.33%> (+14.87%) ⬆️
sei-db 68.42% <ø> (ø)

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

Files with missing lines Coverage Δ
sei-tendermint/internal/p2p/routeroptions.go 86.66% <100.00%> (+0.62%) ⬆️
sei-tendermint/internal/p2p/router.go 82.20% <80.00%> (-1.28%) ⬇️

... and 2091 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.

}
for addr := range peerDB.All() {
if err := peerManager.AddAddrs(utils.Slice(addr)); err != nil {
logger.Error("peerDB: bad address", "addr", addr.String(), "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

How often do the addresses change? Is it possible that these addresses are outdated after you restart?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they might be outdated. We don't know how long the downtime was. We also don't know if the peers are down. We make no assumptions here. The amount of stored addresses is small. It is not problem to just dial them all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, the peer can be outdated but usually wouldn't with just a restart. Even if there are outdated peers, those will get evicted from the DB and be replaced by valid peers right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we only insert entries to db if we successfully connect to a peer and evict entries of peers that we haven't seen the longest

for _, conn := range r.peerManager.Conns().All() {
conns := r.peerManager.Conns()
if conns.Len() > 0 {
ctrl.Updated()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we call this only if any address changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this Watch was added only for the test purposes. It is fine to call Updated even of nothing changed. The point is to call it rarely enough to not waste cpu cycles. Here we call update ~10s by default, which is fine.

key := makeKey(rng)
info := makeInfo(key)
options := makeRouterOptions()
options.PeerStoreInterval = utils.Some(time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could we set it to even a bit lower to make the test run faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could, currently 1s is nowhere close the latency of many other tests, so it shouldn't hurt.

}
for addr := range peerDB.All() {
if err := peerManager.AddAddrs(utils.Slice(addr)); err != nil {
logger.Error("peerDB: bad address", "addr", addr.String(), "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we detect bad address, shall we remove them from peer db?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nah, peer db is a cyclic buffer in a sense, it will clean itself

@pompon0 pompon0 merged commit e82324c into main Feb 20, 2026
38 checks passed
@pompon0 pompon0 deleted the gprusak-peer-db branch February 20, 2026 19:42
github-actions bot pushed a commit that referenced this pull request Feb 20, 2026
Even though router was correctly storing the addresses of connected
peers to db, it was not loading them back on startup. Therefore router
was behaving as if peerdb did not exist in the first place. I have added
a test for the fix.

(cherry picked from commit e82324c)
@seidroid
Copy link

seidroid bot commented Feb 20, 2026

Successfully created backport PR for release/v6.3:

pompon0 added a commit that referenced this pull request Feb 21, 2026
…db (#2944)

Backport of #2941 to `release/v6.3`.

Co-authored-by: Grzegorz Prusak <pompon.pompon@gmail.com>
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.

3 participants