Statesync:attempt to retry if only two peers and fail

This commit is contained in:
Jasmina Malicevic
2022-07-22 17:26:14 +02:00
parent a7b31ed80f
commit 38d1488829
2 changed files with 13 additions and 3 deletions

View File

@@ -47,6 +47,7 @@ func (d *Dispatcher) LightBlock(ctx context.Context, height int64, peer types.No
// dispatch the request to the peer
callCh, err := d.dispatch(ctx, peer, height)
if err != nil {
return nil, err
}
@@ -188,12 +189,13 @@ func (p *BlockProvider) LightBlock(ctx context.Context, height int64) (*types.Li
switch err {
case nil:
if lb == nil {
return nil, provider.ErrLightBlockNotFound
}
case context.DeadlineExceeded, context.Canceled:
return nil, err
case errPeerAlreadyBusy:
return nil, provider.ErrLightBlockNotFound
return nil, err
default:
return nil, provider.ErrUnreliableProvider{Reason: err}
}

View File

@@ -279,7 +279,9 @@ func (r *Reactor) OnStart(ctx context.Context) error {
"trustHeight", to.Height, "useP2P", r.cfg.UseP2P)
if r.cfg.UseP2P {
if err := r.waitForEnoughPeers(ctx, 2); err != nil {
WAIT:
failed := 0
if err := r.waitForEnoughPeers(ctx, 2+failed); err != nil {
return err
}
@@ -291,8 +293,14 @@ func (r *Reactor) OnStart(ctx context.Context) error {
stateProvider, err := NewP2PStateProvider(ctx, chainID, initialHeight, providers, to, paramsCh, r.logger.With("module", "stateprovider"))
if err != nil {
return fmt.Errorf("failed to initialize P2P state provider: %w", err)
failed++
if len(peers) == 2 && failed == 1 {
r.logger.Info("***** attempting to find more peers due to init error")
goto WAIT
}
return fmt.Errorf("failed to initialize P2P state provider: %w %d %s %s", err, r.peers.Len(), providers[0].ID(), providers[1].ID())
}
r.stateProvider = stateProvider
return nil
}