From 993d58efe8c9271ad0fd2ff96197f0687189844e Mon Sep 17 00:00:00 2001 From: ptrus Date: Thu, 19 Oct 2023 15:28:22 +0200 Subject: [PATCH] fix consensus light client status shows empty peer IDs --- .changelog/5408.bugfix.md | 1 + go/consensus/cometbft/light/p2p/p2p.go | 2 ++ go/consensus/cometbft/light/service.go | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changelog/5408.bugfix.md diff --git a/.changelog/5408.bugfix.md b/.changelog/5408.bugfix.md new file mode 100644 index 00000000000..27161f2144f --- /dev/null +++ b/.changelog/5408.bugfix.md @@ -0,0 +1 @@ +Fix showing empty peer IDs in the Consensus light client status output diff --git a/go/consensus/cometbft/light/p2p/p2p.go b/go/consensus/cometbft/light/p2p/p2p.go index d4c25b64803..de3ad54d1e4 100644 --- a/go/consensus/cometbft/light/p2p/p2p.go +++ b/go/consensus/cometbft/light/p2p/p2p.go @@ -189,6 +189,8 @@ func (lp *lightClientProvider) Initialized() <-chan struct{} { func (lp *lightClientProvider) PeerID() string { peer := lp.getPeer() if peer == nil { + // This happens if a provider is not yet initialized, or + // (less likely) if a peer was just dropped and no new peer is available. return "" } return peer.String() diff --git a/go/consensus/cometbft/light/service.go b/go/consensus/cometbft/light/service.go index f1d076600ca..9b1455407c5 100644 --- a/go/consensus/cometbft/light/service.go +++ b/go/consensus/cometbft/light/service.go @@ -106,7 +106,9 @@ func (c *client) GetStatus() (*consensus.LightClientStatus, error) { } for _, p := range c.providers { - status.PeerIDs = append(status.PeerIDs, p.PeerID()) + if id := p.PeerID(); id != "" { + status.PeerIDs = append(status.PeerIDs, id) + } } return status, nil