Browse Source

light: fix early erroring (#6905)

release/v0.34.13
Callum Waters 3 years ago
committed by GitHub
parent
commit
0f8932f4ef
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      light/client.go

+ 11
- 6
light/client.go View File

@ -239,7 +239,7 @@ func NewClientFromTrustedStore(
}
// Validate the number of witnesses.
if len(c.witnesses) < 1 {
if len(c.witnesses) == 0 {
return nil, ErrNoWitnesses
}
@ -1001,14 +1001,14 @@ func (c *Client) lightBlockFromPrimary(ctx context.Context, height int64) (*type
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...",
c.logger.Info("error from light block request from primary, replacing...",
"error", err, "height", height, "primary", c.primary)
return c.findNewPrimary(ctx, height, false)
default:
// The light client has most likely received either provider.ErrUnreliableProvider or provider.ErrBadLightBlock
// These errors mean that the light client should drop the primary and try with another provider instead
c.logger.Error("error from light block request from primary, removing...",
c.logger.Info("error from light block request from primary, removing...",
"error", err, "height", height, "primary", c.primary)
return c.findNewPrimary(ctx, height, true)
}
@ -1046,7 +1046,7 @@ func (c *Client) findNewPrimary(ctx context.Context, height int64, remove bool)
c.providerMutex.Lock()
defer c.providerMutex.Unlock()
if len(c.witnesses) <= 1 {
if len(c.witnesses) == 0 {
return nil, ErrNoWitnesses
}
@ -1117,6 +1117,11 @@ func (c *Client) findNewPrimary(ctx context.Context, height int64, remove bool)
}
}
// remove witnesses marked as bad. Removal is done in descending order
if err := c.removeWitnesses(witnessesToRemove); err != nil {
c.logger.Error("failed to remove witnesses", "err", err, "witnessesToRemove", witnessesToRemove)
}
return nil, lastError
}
@ -1129,7 +1134,7 @@ func (c *Client) compareFirstHeaderWithWitnesses(ctx context.Context, h *types.S
c.providerMutex.Lock()
defer c.providerMutex.Unlock()
if len(c.witnesses) < 1 {
if len(c.witnesses) == 0 {
return ErrNoWitnesses
}
@ -1171,7 +1176,7 @@ and remove witness. Otherwise, use the different primary`, e.WitnessIndex), "wit
// remove witnesses that have misbehaved
if err := c.removeWitnesses(witnessesToRemove); err != nil {
return err
c.logger.Error("failed to remove witnesses", "err", err, "witnessesToRemove", witnessesToRemove)
}
return nil


Loading…
Cancel
Save