cmd

package
v0.0.156 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package cmd provides the command line interface for the notary.

Index

Constants

This section is empty.

Variables

View Source
var NotaryInfoCommand = &cli.Command{
	Name:        "notary-info",
	Description: "learn how to use notary cli",
	Action: func(c *cli.Context) error {
		fmt.Println(string(markdown.Render(help, termsize.Width(), 6)))
		return nil
	},
}

NotaryInfoCommand gets info about using the notary agent.

View Source
var NotaryRunCommand = &cli.Command{
	Name:        "notary-run",
	Description: "runs the notary service",
	Flags:       []cli.Flag{configFlag, metricsPortFlag, ignoreInitErrorsFlag},
	Action: func(c *cli.Context) error {
		metricsProvider := metrics.Get()

		notaryConfig, err := config.DecodeAgentConfig(core.ExpandOrReturnPath(c.String(configFlag.Name)))
		if err != nil {
			return fmt.Errorf("failed to decode config: %w", err)
		}

		var shouldRetryAtomic atomic.Bool
		shouldRetryAtomic.Store(true)

		for shouldRetryAtomic.Load() {
			shouldRetryAtomic.Store(false)

			var scribeClient client.ScribeClient

			g, _ := errgroup.WithContext(c.Context)

			eventDB, err := scribeAPI.InitDB(c.Context, "mysql", "root:MysqlPassword@tcp(agents-mysql:3306)/notaryscribe?parseTime=true", metrics.Get())
			if err != nil {
				return fmt.Errorf("failed to initialize database: %w", err)
			}

			scribeClients := make(map[uint32][]backfill.ScribeBackend)

			for _, domain := range notaryConfig.Domains {
				for confNum := 1; confNum <= scribeCmd.MaxConfirmations; confNum++ {
					chainID := domain.DomainID
					backendClient, err := backfill.DialBackend(c.Context, fmt.Sprintf("%s/%d/rpc/%d", "https://rpc.interoperability.institute/confirmations", confNum, chainID), metricsProvider)
					if err != nil {
						return fmt.Errorf("could not start client for %s", fmt.Sprintf("%s/1/rpc/%d", "https://rpc.interoperability.institute/confirmations", chainID))
					}

					scribeClients[chainID] = append(scribeClients[chainID], backendClient)
				}
			}

			scribe, err := node.NewScribe(eventDB, scribeClients, notaryConfig.EmbeddedScribeConfig, metricsProvider)
			if err != nil {
				return fmt.Errorf("failed to initialize scribe: %w", err)
			}

			g.Go(func() error {
				err := scribe.Start(c.Context)
				if err != nil {
					return fmt.Errorf("failed to start scribe: %w", err)
				}

				return nil
			})

			embedded := client.NewEmbeddedScribe("mysql", "root:MysqlPassword@tcp(agents-mysql:3306)/notaryscribe?parseTime=true", metricsProvider)

			g.Go(func() error {
				err := embedded.Start(c.Context)
				if err != nil {
					return fmt.Errorf("failed to start embedded scribe: %w", err)
				}

				return nil
			})

			scribeClient = embedded.ScribeClient

			notaryConfig.ScribeURL = scribeClient.URL
			notaryConfig.ScribePort = uint32(scribeClient.Port)
			notary, err := notary.NewNotary(c.Context, notaryConfig, metricsProvider)
			if err != nil && !c.Bool(ignoreInitErrorsFlag.Name) {
				return fmt.Errorf("failed to create notary: %w", err)
			}

			g.Go(func() error {
				err = notary.Start(c.Context)
				if err != nil {
					shouldRetryAtomic.Store(true)

					log.Errorf("Error running guard, will sleep for a minute and retry: %v", err)
					time.Sleep(60 * time.Second)
					return fmt.Errorf("failed to create notary: %w", err)
				}

				return nil
			})

			g.Go(func() error {
				err := api.Start(c.Context, uint16(c.Uint(metricsPortFlag.Name)))
				if err != nil {
					return fmt.Errorf("failed to start api: %w", err)
				}

				return nil
			})

			if err := g.Wait(); err != nil {
				return fmt.Errorf("failed to run notary: %w", err)
			}
		}

		return nil
	},
}

NotaryRunCommand runs the notary.

Functions

func Start

func Start(args []string, buildInfo config.BuildInfo)

Start starts the command line.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL