Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Status Requests Asynchronous #4577

Merged
merged 6 commits into from Jan 19, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions beacon-chain/sync/rpc_status.go
Expand Up @@ -24,17 +24,19 @@ func (r *Service) maintainPeerStatuses() {
interval := time.Duration(params.BeaconConfig().SecondsPerSlot*params.BeaconConfig().SlotsPerEpoch/2) * time.Second
runutil.RunEvery(r.ctx, interval, func() {
for _, pid := range r.p2p.Peers().Connected() {
// If the status hasn't been updated in the recent interval time.
lastUpdated, err := r.p2p.Peers().ChainStateLastUpdated(pid)
if err != nil {
// Peer has vanished; nothing to do
continue
}
if roughtime.Now().After(lastUpdated.Add(interval)) {
if err := r.sendRPCStatusRequest(r.ctx, pid); err != nil {
log.WithField("peer", pid).WithError(err).Error("Failed to request peer status")
go func(id peer.ID) {
// If the status hasn't been updated in the recent interval time.
lastUpdated, err := r.p2p.Peers().ChainStateLastUpdated(id)
if err != nil {
// Peer has vanished; nothing to do.
return
}
}
if roughtime.Now().After(lastUpdated.Add(interval)) {
if err := r.sendRPCStatusRequest(r.ctx, id); err != nil {
log.WithField("peer", id).WithError(err).Error("Failed to request peer status")
}
}
}(pid)
}
})
}
Expand Down