main.go 2.11 KB
Newer Older
1 2 3 4 5
package main

import (
	"os"

6
	"github.com/ethereum-optimism/optimism/op-program/host"
7 8 9
	"github.com/ethereum-optimism/optimism/op-program/host/config"
	"github.com/ethereum-optimism/optimism/op-program/host/flags"
	"github.com/ethereum-optimism/optimism/op-program/host/version"
10
	opservice "github.com/ethereum-optimism/optimism/op-service"
11 12
	oplog "github.com/ethereum-optimism/optimism/op-service/log"
	"github.com/ethereum/go-ethereum/log"
13
	"github.com/urfave/cli/v2"
14 15 16 17 18 19 20 21
)

var (
	GitCommit = ""
	GitDate   = ""
)

// VersionWithMeta holds the textual version string including the metadata.
22
var VersionWithMeta = opservice.FormatVersion(version.Version, GitCommit, GitDate, version.Meta)
23 24 25

func main() {
	args := os.Args
26
	if err := run(args, host.Main); err != nil {
27
		log.Crit("Application failed", "err", err)
28 29 30
	}
}

31
type ConfigAction func(log log.Logger, config *config.Config) error
32

33 34 35
// run parses the supplied args to create a config.Config instance, sets up logging
// then calls the supplied ConfigAction.
// This allows testing the translation from CLI arguments to Config
36 37 38 39 40 41 42 43 44 45 46 47
func run(args []string, action ConfigAction) error {
	// Set up logger with a default INFO level in case we fail to parse flags,
	// otherwise the final critical log won't show what the parsing error was.
	oplog.SetupDefaults()

	app := cli.NewApp()
	app.Version = VersionWithMeta
	app.Flags = flags.Flags
	app.Name = "op-program"
	app.Usage = "Optimism Fault Proof Program"
	app.Description = "The Optimism Fault Proof Program fault proof program that runs through the rollup state-transition to verify an L2 output from L1 inputs."
	app.Action = func(ctx *cli.Context) error {
48 49
		logger, err := setupLogging(ctx)
		if err != nil {
50 51 52 53
			return err
		}
		logger.Info("Starting fault proof program", "version", VersionWithMeta)

54
		cfg, err := config.NewConfigFromCLI(logger, ctx)
55 56 57 58 59 60 61 62 63
		if err != nil {
			return err
		}
		return action(logger, cfg)
	}

	return app.Run(args)
}

64 65
func setupLogging(ctx *cli.Context) (log.Logger, error) {
	logCfg := oplog.ReadCLIConfig(ctx)
66
	logger := oplog.NewLogger(oplog.AppOut(ctx), logCfg)
67
	oplog.SetGlobalLogHandler(logger.Handler())
68 69
	return logger, nil
}