From 5031e5be281a283e1ecb752c61e2ed8866527a8b Mon Sep 17 00:00:00 2001 From: Peter Nose Date: Fri, 24 Nov 2023 12:18:32 +0100 Subject: [PATCH] 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. --- .changelog/5469.bugfix.md | 5 +++++ go/p2p/peermgmt/backup.go | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changelog/5469.bugfix.md diff --git a/.changelog/5469.bugfix.md b/.changelog/5469.bugfix.md new file mode 100644 index 00000000000..28fcdce1bbf --- /dev/null +++ b/.changelog/5469.bugfix.md @@ -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. diff --git a/go/p2p/peermgmt/backup.go b/go/p2p/peermgmt/backup.go index 378b3d67a94..9062f127b4e 100644 --- a/go/p2p/peermgmt/backup.go +++ b/go/p2p/peermgmt/backup.go @@ -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