diff --git a/cmd/zetaclientd/start.go b/cmd/zetaclientd/start.go index 176e1b5847..6a4d0b6f4d 100644 --- a/cmd/zetaclientd/start.go +++ b/cmd/zetaclientd/start.go @@ -30,6 +30,7 @@ import ( zctx "github.com/zeta-chain/zetacore/zetaclient/context" "github.com/zeta-chain/zetacore/zetaclient/metrics" "github.com/zeta-chain/zetacore/zetaclient/orchestrator" + "github.com/zeta-chain/zetacore/zetaclient/zetacore" ) type Multiaddr = core.Multiaddr @@ -253,17 +254,15 @@ func start(_ *cobra.Command, _ []string) error { startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String()) } - observerList, err := zetacoreClient.GetObserverList(ctx) - if err != nil { - startLogger.Error().Err(err).Msg("GetObserverList error") + isObserver, err := isObserverNode(ctx, zetacoreClient) + switch { + case err != nil: + startLogger.Error().Msgf("Unable to determine if node is an observer") return err - } - isNodeActive := false - for _, observer := range observerList { - if observer == zetacoreClient.GetKeys().GetOperatorAddress().String() { - isNodeActive = true - break - } + case !isObserver: + addr := zetacoreClient.GetKeys().GetOperatorAddress().String() + startLogger.Info().Str("operator_address", addr).Msg("This node is not an observer. Exit 0") + return nil } // CreateSignerMap: This creates a map of all signers for each chain. @@ -281,23 +280,14 @@ func start(_ *cobra.Command, _ []string) error { } dbpath := filepath.Join(userDir, ".zetaclient/chainobserver") - // Creates a map of all chain observers for each chain. Each chain observer is responsible for observing events on the chain and processing them. + // Creates a map of all chain observers for each chain. + // Each chain observer is responsible for observing events on the chain and processing them. observerMap, err := orchestrator.CreateChainObserverMap(ctx, zetacoreClient, tss, dbpath, logger, telemetryServer) if err != nil { startLogger.Err(err).Msg("CreateChainObserverMap") return err } - if !isNodeActive { - startLogger.Error(). - Msgf("Node %s is not an active observer external chain observers will not be started", zetacoreClient.GetKeys().GetOperatorAddress().String()) - } else { - startLogger.Debug().Msgf("Node %s is an active observer starting external chain observers", zetacoreClient.GetKeys().GetOperatorAddress().String()) - for _, observer := range observerMap { - observer.Start(ctx) - } - } - // Orchestrator wraps the zetacore client and adds the observers and signer maps to it. // This is the high level object used for CCTX interactions maestro, err := orchestrator.New( @@ -313,6 +303,7 @@ func start(_ *cobra.Command, _ []string) error { return err } + // Start orchestrator with all observers and signers if err := maestro.Start(ctx); err != nil { startLogger.Error().Err(err).Msg("Unable to start orchestrator") return err @@ -338,10 +329,6 @@ func start(_ *cobra.Command, _ []string) error { sig := <-ch startLogger.Info().Msgf("stop signal received: %s", sig) - // stop chain observers - for _, observer := range observerMap { - observer.Stop() - } zetacoreClient.Stop() return nil @@ -405,3 +392,21 @@ func promptPasswords() (string, string, error) { return hotKeyPass, TSSKeyPass, err } + +// isObserverNode checks whether THIS node is an observer node. +func isObserverNode(ctx context.Context, client *zetacore.Client) (bool, error) { + observers, err := client.GetObserverList(ctx) + if err != nil { + return false, errors.Wrap(err, "unable to get observers list") + } + + operatorAddress := client.GetKeys().GetOperatorAddress().String() + + for _, observer := range observers { + if observer == operatorAddress { + return true, nil + } + } + + return false, nil +} diff --git a/zetaclient/orchestrator/orchestrator.go b/zetaclient/orchestrator/orchestrator.go index d355c41249..b0965a9d1b 100644 --- a/zetaclient/orchestrator/orchestrator.go +++ b/zetaclient/orchestrator/orchestrator.go @@ -113,6 +113,10 @@ func (oc *Orchestrator) Start(ctx context.Context) error { oc.logger.Info().Str("signer", signerAddress.String()).Msg("Starting orchestrator") + for _, observer := range oc.observerMap { + observer.Start(ctx) + } + // start cctx scheduler bg.Work(ctx, oc.StartCctxScheduler, bg.WithName("StartCctxScheduler"), bg.WithLogger(oc.logger.Logger))