light: correctly handle contexts (backport -> v0.34.x) (#6685)

This commit is contained in:
Callum Waters
2021-07-09 14:30:33 +02:00
committed by GitHub
parent 8b84c7c168
commit 2c2f511f24
7 changed files with 87 additions and 62 deletions

View File

@@ -154,6 +154,7 @@ func (r *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
Hash: msg.Hash,
Metadata: msg.Metadata,
})
// TODO: We may want to consider punishing the peer for certain errors
if err != nil {
r.Logger.Error("Failed to add snapshot", "height", msg.Height, "format", msg.Format,
"peer", src.ID(), "err", err)

View File

@@ -213,6 +213,10 @@ func (s *syncer) SyncAny(discoveryTime time.Duration, retryHook func()) (sm.Stat
s.logger.Info("Snapshot sender rejected", "peer", peer.ID())
}
case errors.Is(err, context.DeadlineExceeded):
s.logger.Info("Timed out validating snapshot, rejecting", "height", snapshot.Height, "err", err)
s.snapshots.Reject(snapshot)
default:
return sm.State{}, nil, fmt.Errorf("snapshot restoration failed: %w", err)
}
@@ -256,7 +260,7 @@ func (s *syncer) Sync(snapshot *snapshot, chunks *chunkQueue) (sm.State, *types.
go s.fetchChunks(ctx, snapshot, chunks)
}
pctx, pcancel := context.WithTimeout(context.Background(), 10*time.Second)
pctx, pcancel := context.WithTimeout(context.Background(), 15*time.Second)
defer pcancel()
// Optimistically build new state, so we don't discover any light client failures at the end.