Skip to content

Commit

Permalink
fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed May 15, 2024
1 parent 50bec52 commit b1b785f
Showing 1 changed file with 46 additions and 41 deletions.
87 changes: 46 additions & 41 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism

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)
}
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
return nil

}
Expand Down

0 comments on commit b1b785f

Please sign in to comment.