Commit 648392e0 authored by Mark Tyneway's avatar Mark Tyneway Committed by Liam Horne

l2geth: sync service retries connection to remote server

parent 7c6fa5b3
...@@ -128,22 +128,29 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co ...@@ -128,22 +128,29 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
// requirement of the remote server being up. // requirement of the remote server being up.
if service.enable { if service.enable {
// Ensure that the rollup client can connect to a remote server // Ensure that the rollup client can connect to a remote server
// before starting. // before starting. Retry until it can connect.
err := service.ensureClient() t1 := time.NewTicker(10 * time.Second)
if err != nil { for ; true; <-t1.C {
return nil, fmt.Errorf("Rollup client unable to connect: %w", err) err := service.ensureClient()
if err != nil {
log.Info("Cannot connect to upstream service", "msg", err)
} else {
log.Info("Connected to upstream service")
t1.Stop()
break
}
} }
// Wait until the remote service is done syncing // Wait until the remote service is done syncing
t := time.NewTicker(10 * time.Second) t2 := time.NewTicker(10 * time.Second)
for ; true; <-t.C { for ; true; <-t2.C {
status, err := service.client.SyncStatus(service.backend) status, err := service.client.SyncStatus(service.backend)
if err != nil { if err != nil {
log.Error("Cannot get sync status") log.Error("Cannot get sync status")
continue continue
} }
if !status.Syncing { if !status.Syncing {
t.Stop() t2.Stop()
break break
} }
log.Info("Still syncing", "index", status.CurrentTransactionIndex, "tip", status.HighestKnownTransactionIndex) log.Info("Still syncing", "index", status.CurrentTransactionIndex, "tip", status.HighestKnownTransactionIndex)
...@@ -153,7 +160,7 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co ...@@ -153,7 +160,7 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co
// it happens before the RPC endpoints open up // it happens before the RPC endpoints open up
// Only do it if the sync service is enabled so that this // Only do it if the sync service is enabled so that this
// can be ran without needing to have a configured RollupClient. // can be ran without needing to have a configured RollupClient.
err = service.initializeLatestL1(cfg.CanonicalTransactionChainDeployHeight) err := service.initializeLatestL1(cfg.CanonicalTransactionChainDeployHeight)
if err != nil { if err != nil {
return nil, fmt.Errorf("Cannot initialize latest L1 data: %w", err) return nil, fmt.Errorf("Cannot initialize latest L1 data: %w", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment