Skip to content

Commit

Permalink
go/p2p/peermgmt/backup: Prevent overwriting TTL when restoring peers
Browse files Browse the repository at this point in the history
If the peer address of a seed node was added to the libp2p address book
before peer manager restored backup peer addresses, its permanent TTL
was replaced with the TTL for recently connected peers.
  • Loading branch information
peternose committed Nov 24, 2023
1 parent 2870101 commit 5031e5b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changelog/5469.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/p2p/peermgmt/backup: Prevent overwriting TTL when restoring peers

If the peer address of a seed node was added to the libp2p address book
before peer manager restored backup peer addresses, its permanent TTL
was replaced with the TTL for recently connected peers.
3 changes: 2 additions & 1 deletion go/p2p/peermgmt/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func (b *peerstoreBackup) restore(ctx context.Context) error {
}

for _, info := range peers[peerstoreNamespace] {
b.store.SetAddrs(info.ID, info.Addrs, peerstore.RecentlyConnectedAddrTTL)
// Make sure to add, not set, the address to avoid overwriting the TTL.
b.store.AddAddrs(info.ID, info.Addrs, peerstore.RecentlyConnectedAddrTTL)
}

return nil
Expand Down

0 comments on commit 5031e5b

Please sign in to comment.