fix: no peers discovered

This commit is contained in:
frank 2024-03-04 16:06:16 +08:00
parent 881da9e654
commit 7eeeb07cab
2 changed files with 5 additions and 2 deletions

View File

@ -551,7 +551,6 @@ func (w *Waku) runPeerExchangeLoop() {
}
}
w.dnsAddressCacheLock.RUnlock()
time.Sleep(5 * time.Second)
err := w.node.PeerExchange().Request(w.ctx, peersToDiscover, peer_exchange.WithAutomaticPeerSelection())
if err != nil {
w.logger.Error("couldnt request peers via peer exchange", zap.Error(err))

View File

@ -268,7 +268,11 @@ func TestPeerExchange(t *testing.T) {
b.MaxElapsedTime = 30 * time.Second
}
err = tt.RetryWithBackOff(func() error {
if len(lightNode.Peers()) == 2 {
// we should not use lightNode.Peers() here as it only indicates peers that are connected right now,
// in light client mode,the peer will be closed via `w.node.Host().Network().ClosePeer(peerInfo.ID)`
// after invoking identifyAndConnect, instead, we should check the peerStore, peers from peerStore
// won't get deleted especially if they are statically added.
if len(lightNode.node.Host().Peerstore().Peers()) == 2 {
return nil
}
return errors.New("no peers discovered")