fix_: code review

This commit is contained in:
Richard Ramos 2024-09-25 18:14:20 -04:00
parent 6b0668371d
commit 4d0163dead
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
1 changed files with 42 additions and 30 deletions

View File

@ -399,7 +399,11 @@ func (w *Waku) getDiscV5BootstrapNodes(ctx context.Context, addresses []string,
go func(addr string) {
defer wg.Done()
if err := w.dnsDiscover(ctx, addr, retrieveENR, useOnlyDnsDiscCache); err != nil {
go w.retryDnsDiscoveryWithBackoff(ctx, addr, w.dnsDiscAsyncRetrievedSignal)
wg.Add(1)
go func() {
defer wg.Done()
w.retryDnsDiscoveryWithBackoff(ctx, addr, w.dnsDiscAsyncRetrievedSignal)
}()
}
}(addrString)
} else {
@ -482,6 +486,10 @@ func (w *Waku) retryDnsDiscoveryWithBackoff(ctx context.Context, addr string, su
retries++
backoff := time.Second * time.Duration(math.Exp2(float64(retries)))
if backoff > time.Minute {
backoff = time.Minute
}
t := time.NewTimer(backoff)
select {
case <-w.ctx.Done():
@ -1761,21 +1769,27 @@ func (w *Waku) seedBootnodesForDiscV5() {
for {
select {
case <-w.dnsDiscAsyncRetrievedSignal:
if canQuery() {
if !canQuery() {
continue
}
err := w.restartDiscV5(true)
if err != nil {
w.logger.Warn("failed to restart discv5", zap.Error(err))
}
retries = 0
lastTry = now()
}
case <-ticker.C:
if w.seededBootnodesForDiscV5 && len(w.node.Host().Network().Peers()) > 3 {
w.logger.Debug("not querying bootnodes", zap.Bool("seeded", w.seededBootnodesForDiscV5), zap.Int("peer-count", len(w.node.Host().Network().Peers())))
continue
}
if canQuery() {
if !canQuery() {
w.logger.Info("can't query bootnodes", zap.Int("peer-count", len(w.node.Host().Network().Peers())), zap.Int64("lastTry", lastTry), zap.Int64("now", now()), zap.Int64("backoff", bootnodesQueryBackoffMs*int64(math.Exp2(float64(retries)))), zap.Int("retries", retries))
continue
}
w.logger.Info("querying bootnodes to restore connectivity", zap.Int("peer-count", len(w.node.Host().Network().Peers())))
err := w.restartDiscV5(false)
if err != nil {
@ -1789,20 +1803,18 @@ func (w *Waku) seedBootnodesForDiscV5() {
retries = 0
}
} else {
w.logger.Info("can't query bootnodes", zap.Int("peer-count", len(w.node.Host().Network().Peers())), zap.Int64("lastTry", lastTry), zap.Int64("now", now()), zap.Int64("backoff", bootnodesQueryBackoffMs*int64(math.Exp2(float64(retries)))), zap.Int("retries", retries))
}
// If we go online, trigger immediately
case <-w.goingOnline:
if canQuery() {
if !canQuery() {
continue
}
err := w.restartDiscV5(false)
if err != nil {
w.logger.Warn("failed to restart discv5", zap.Error(err))
}
retries = 0
lastTry = now()
}
case <-w.ctx.Done():
w.logger.Debug("bootnode seeding stopped")