Skip to content

Commit

Permalink
Make Status Requests Asynchronous (#4577)
Browse files Browse the repository at this point in the history
* make rpc status requests async
* make whole block async
* fix nogo
* Update beacon-chain/sync/rpc_status.go
* Merge branch 'master' into makeAsync
* Merge refs/heads/master into makeAsync
  • Loading branch information
nisdas authored and prylabs-bulldozer[bot] committed Jan 19, 2020
1 parent 1b62e92 commit 3e7e447
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit 3e7e447

Please sign in to comment.