diff --git a/client/collector/collector.go b/client/collector/collector.go index 0441f10..8dadbcf 100644 --- a/client/collector/collector.go +++ b/client/collector/collector.go @@ -123,8 +123,6 @@ func New(user *config.UserRaw, system *config.System, sharedDataPipes *shared.Da // Run starts SigningPolicyInitializedListener, BitVoteListener, and AttestationRequestListener in go routines. func (c *Collector) Run(ctx context.Context) { - WaitForDBToSync(ctx, c.DB) - go SigningPolicyInitializedListener(ctx, c.DB, c.RelayContractAddress, c.VoterRegistryContractAddress, c.SigningPolicies) go AttestationRequestListener(ctx, c.DB, c.FdcContractAddress, requestListenerInterval, c.Requests) @@ -134,13 +132,13 @@ func (c *Collector) Run(ctx context.Context) { } // WaitForDBToSync waits for db to sync. After many unsuccessful attempts it panics. -func WaitForDBToSync(ctx context.Context, db *gorm.DB) { +func (c *Collector) WaitForDBToSync(ctx context.Context) { k := 0 for k < syncRetry { if k > 0 { logger.Debugf("Checking database for %v/%v time", k, syncRetry) } - state, err := database.FetchState(ctx, db, nil) + state, err := database.FetchState(ctx, c.DB, nil) if err != nil { logger.Panic("database error:", err) } @@ -162,7 +160,7 @@ func WaitForDBToSync(ctx context.Context, db *gorm.DB) { } logger.Warnf("Checking database for the final time") - state, err := database.FetchState(ctx, db, nil) + state, err := database.FetchState(ctx, c.DB, nil) if err != nil { logger.Panic("database error:", err) } diff --git a/main/main.go b/main/main.go index 3336f40..11b26b5 100644 --- a/main/main.go +++ b/main/main.go @@ -47,15 +47,16 @@ func main() { sharedDataPipes := shared.NewDataPipes() // Start attestation client collector - collector := collector.New(userConfigRaw, systemConfig, sharedDataPipes) - collector.Run(ctx) + col := collector.New(userConfigRaw, systemConfig, sharedDataPipes) + col.WaitForDBToSync(ctx) + go col.Run(ctx) // Start attestation client manager - manager, err := manager.New(userConfigRaw, attestationTypeConfig, sharedDataPipes) + mngr, err := manager.New(userConfigRaw, attestationTypeConfig, sharedDataPipes) if err != nil { logger.Panicf("failed to create the manager: %s", err) } - go manager.Run(ctx) + go mngr.Run(ctx) // Run attestation client server srv := server.New(&sharedDataPipes.Rounds, userConfigRaw.ProtocolID, userConfigRaw.RestServer)