Skip to content

Commit

Permalink
light: handle too high errors correctly (backport #6346) (#6351)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Jan 6, 2022
1 parent eb6d5ba commit f5f905e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions light/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,17 @@ func (c *Client) verifySkipping(
pivotHeight := verifiedBlock.Height + (blockCache[depth].Height-verifiedBlock.
Height)*verifySkippingNumerator/verifySkippingDenominator
interimBlock, providerErr := source.LightBlock(ctx, pivotHeight)
if providerErr != nil {
switch providerErr {
case nil:
blockCache = append(blockCache, interimBlock)

// if the error is benign, the client does not need to replace the primary
case provider.ErrLightBlockNotFound, provider.ErrNoResponse, provider.ErrHeightTooHigh:
return nil, err

// all other errors such as ErrBadLightBlock or ErrUnreliableProvider are seen as malevolent and the
// provider is removed
default:
return nil, ErrVerificationFailed{From: verifiedBlock.Height, To: pivotHeight, Reason: providerErr}
}
blockCache = append(blockCache, interimBlock)
Expand Down Expand Up @@ -1008,7 +1018,7 @@ func (c *Client) lightBlockFromPrimary(ctx context.Context, height int64) (*type
// Everything went smoothly. We reset the lightBlockRequests and return the light block
return l, nil

case provider.ErrNoResponse, provider.ErrLightBlockNotFound:
case provider.ErrNoResponse, provider.ErrLightBlockNotFound, provider.ErrHeightTooHigh:
// we find a new witness to replace the primary
c.logger.Debug("error from light block request from primary, replacing...",
"error", err, "height", height, "primary", c.primary)
Expand Down Expand Up @@ -1111,7 +1121,7 @@ func (c *Client) findNewPrimary(ctx context.Context, height int64, remove bool)
return response.lb, nil

// process benign errors by logging them only
case provider.ErrNoResponse, provider.ErrLightBlockNotFound:
case provider.ErrNoResponse, provider.ErrLightBlockNotFound, provider.ErrHeightTooHigh:
lastError = response.err
c.logger.Debug("error on light block request from witness",
"error", response.err, "primary", c.witnesses[response.witnessIndex])
Expand Down

0 comments on commit f5f905e

Please sign in to comment.