package main import ( "fmt" "net/http" "os" "github.com/ledgerwatch/log/v3" "github.com/urfave/cli/v2" "github.com/ledgerwatch/erigon-lib/common/datadir" "github.com/ledgerwatch/erigon-lib/common/dbg" "github.com/ledgerwatch/erigon-lib/metrics" "github.com/ledgerwatch/erigon/diagnostics" "github.com/ledgerwatch/erigon/params" erigonapp "github.com/ledgerwatch/erigon/turbo/app" erigoncli "github.com/ledgerwatch/erigon/turbo/cli" "github.com/ledgerwatch/erigon/turbo/debug" "github.com/ledgerwatch/erigon/turbo/node" ) func main() { defer func() { panicResult := recover() if panicResult == nil { return } log.Error("catch panic", "err", panicResult, "stack", dbg.Stack()) os.Exit(1) }() app := erigonapp.MakeApp("erigon", runErigon, erigoncli.DefaultFlags) if err := app.Run(os.Args); err != nil { _, printErr := fmt.Fprintln(os.Stderr, err) if printErr != nil { log.Warn("Fprintln error", "err", printErr) } os.Exit(1) } } func runErigon(cliCtx *cli.Context) error { var logger log.Logger var err error var metricsMux *http.ServeMux if logger, metricsMux, err = debug.Setup(cliCtx, true /* root logger */); err != nil { return err } // initializing the node and providing the current git commit there logger.Info("Build info", "git_branch", params.GitBranch, "git_tag", params.GitTag, "git_commit", params.GitCommit) erigonInfoGauge := metrics.GetOrCreateGauge(fmt.Sprintf(`erigon_info{version="%s",commit="%s"}`, params.Version, params.GitCommit)) erigonInfoGauge.Set(1) nodeCfg := node.NewNodConfigUrfave(cliCtx, logger) if err := datadir.ApplyMigrations(nodeCfg.Dirs); err != nil { return err } ethCfg := node.NewEthConfigUrfave(cliCtx, nodeCfg, logger) ethNode, err := node.New(cliCtx.Context, nodeCfg, ethCfg, logger) if err != nil { log.Error("Erigon startup", "err", err) return err } if metricsMux != nil { diagnostics.Setup(cliCtx, metricsMux, ethNode) } err = ethNode.Serve() if err != nil { log.Error("error while serving an Erigon node", "err", err) } return err }