2020-09-06 11:35:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-07-04 07:50:32 +00:00
|
|
|
"context"
|
2020-09-06 11:35:32 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2021-07-29 11:53:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils"
|
2021-07-04 07:50:32 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
2021-06-13 16:41:39 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/debug"
|
2021-07-04 07:50:32 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
2021-06-11 08:34:37 +00:00
|
|
|
"github.com/ledgerwatch/erigon/params"
|
2021-05-26 10:35:39 +00:00
|
|
|
erigoncli "github.com/ledgerwatch/erigon/turbo/cli"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/node"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2020-09-06 11:35:32 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2021-05-26 10:35:39 +00:00
|
|
|
app := erigoncli.MakeApp(runErigon, erigoncli.DefaultFlags)
|
2020-09-06 11:35:32 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
2020-10-06 19:25:01 +00:00
|
|
|
|
2021-05-26 10:35:39 +00:00
|
|
|
func runErigon(cliCtx *cli.Context) {
|
2021-07-28 02:47:38 +00:00
|
|
|
logger := log.New()
|
2020-09-21 14:10:25 +00:00
|
|
|
// initializing the node and providing the current git commit there
|
2021-07-28 02:47:38 +00:00
|
|
|
logger.Info("Build info", "git_branch", params.GitBranch, "git_tag", params.GitTag, "git_commit", params.GitCommit)
|
2021-07-04 07:50:32 +00:00
|
|
|
nodeCfg := node.NewNodConfigUrfave(cliCtx)
|
|
|
|
ethCfg := node.NewEthConfigUrfave(cliCtx, nodeCfg)
|
|
|
|
if cliCtx.GlobalIsSet(utils.DataDirFlag.Name) {
|
|
|
|
// Check if we have an already initialized chain and fall back to
|
|
|
|
// that if so. Otherwise we need to generate a new genesis spec.
|
2021-07-28 02:47:38 +00:00
|
|
|
chaindb := utils.MakeChainDatabase(logger, nodeCfg)
|
|
|
|
if err := chaindb.View(context.Background(), func(tx kv.Tx) error {
|
2021-07-04 07:50:32 +00:00
|
|
|
h, err := rawdb.ReadCanonicalHash(tx, 0)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if h != (common.Hash{}) {
|
|
|
|
ethCfg.Genesis = nil // fallback to db content
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
chaindb.Close()
|
|
|
|
}
|
2020-09-06 11:35:32 +00:00
|
|
|
|
2021-07-28 02:47:38 +00:00
|
|
|
err := node.New(nodeCfg, ethCfg, logger).Serve()
|
2020-09-06 11:35:32 +00:00
|
|
|
if err != nil {
|
2021-05-26 10:35:39 +00:00
|
|
|
log.Error("error while serving a Erigon node", "err", err)
|
2020-09-06 11:35:32 +00:00
|
|
|
}
|
|
|
|
}
|