From b1b785f41a4e4e6e12a8e1c6ca56c17926567f1d Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Wed, 15 May 2024 16:48:24 +0200 Subject: [PATCH] fix lint error --- da/celestia/celestia.go | 87 ++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/da/celestia/celestia.go b/da/celestia/celestia.go index b3a21138d..65ed60ff3 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -139,53 +139,58 @@ func (c *DataAvailabilityLayerClient) Start() (err error) { return err } - go retry.Do( - func() error { - state, err := rpc.Header.SyncState(c.ctx) - if err != nil { - c.logger.Error("Failed to start Celestia DA.", "Error", err) - return err - } - - if !state.Finished() { - c.logger.Info("waiting for celestia-node to finish syncing", "height", state.Height, "target", state.ToHeight) - - done := make(chan error, 1) - go func() { - done <- rpc.Header.SyncWait(c.ctx) - }() - - ticker := time.NewTicker(1 * time.Minute) - defer ticker.Stop() + go func() { + err := retry.Do( + func() error { + state, err := rpc.Header.SyncState(c.ctx) + if err != nil { + c.logger.Error("Failed to start Celestia DA.", "Error", err) + return err + } - for { - select { - case err := <-done: - if err != nil { - return err + if !state.Finished() { + c.logger.Info("waiting for celestia-node to finish syncing", "height", state.Height, "target", state.ToHeight) + + done := make(chan error, 1) + go func() { + done <- rpc.Header.SyncWait(c.ctx) + }() + + ticker := time.NewTicker(1 * time.Minute) + defer ticker.Stop() + + for { + select { + case err := <-done: + if err != nil { + return err + } + return nil + case <-ticker.C: + state, err := rpc.Header.SyncState(c.ctx) + if err != nil { + return err + } + c.logger.Info("celestia-node still syncing", "height", state.Height, "target", state.ToHeight) } - return nil - case <-ticker.C: - state, err := rpc.Header.SyncState(c.ctx) - if err != nil { - return err - } - c.logger.Info("celestia-node still syncing", "height", state.Height, "target", state.ToHeight) } } - } - c.rpc = NewOpenRPC(rpc) - c.started <- struct{}{} - c.logger.Info("celestia-node is synced", "height", state.ToHeight) + c.rpc = NewOpenRPC(rpc) + c.started <- struct{}{} + c.logger.Info("celestia-node is synced", "height", state.ToHeight) - return nil - }, - retry.Attempts(0), // try forever - retry.Delay(10*time.Second), - retry.LastErrorOnly(true), - retry.DelayType(retry.FixedDelay), - ) + return nil + }, + retry.Attempts(0), // try forever + retry.Delay(10*time.Second), + retry.LastErrorOnly(true), + retry.DelayType(retry.FixedDelay), + ) + if err != nil { + c.logger.Error("Error when waiting for Celestia data availability client to sync", "err", err) + } + }() return nil }