diff --git a/light/detector.go b/light/detector.go index c0a5bd2c1..1d7a066cb 100644 --- a/light/detector.go +++ b/light/detector.go @@ -26,6 +26,8 @@ import ( // If there are no conflictinge headers, the light client deems the verified target header // trusted and saves it to the trusted store. func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.LightBlock, now time.Time) error { + c.providerMutex.Lock() + defer c.providerMutex.Unlock() if len(c.witnesses) < 1 { return nil } @@ -40,9 +42,6 @@ func (c *Client) detectDivergence(ctx context.Context, primaryTrace []*types.Lig c.logger.Debug("running detector against trace", "endBlockHeight", lastVerifiedHeader.Height, "endBlockHash", lastVerifiedHeader.Hash, "length", len(primaryTrace)) - c.providerMutex.Lock() - defer c.providerMutex.Unlock() - // launch one goroutine per witness to retrieve the light block of the target height // and compare it with the header from the primary errc := make(chan error, len(c.witnesses))