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-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"
|
|
|
|
"github.com/ledgerwatch/erigon/ethdb"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/log"
|
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"
|
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
|
|
|
// creating a erigon-api app with all defaults
|
|
|
|
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) {
|
2020-09-21 14:10:25 +00:00
|
|
|
// initializing the node and providing the current git commit there
|
2021-06-11 08:34:37 +00:00
|
|
|
log.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.
|
|
|
|
chaindb := utils.MakeChainDatabase(nodeCfg)
|
|
|
|
if err := chaindb.View(context.Background(), func(tx ethdb.Tx) error {
|
|
|
|
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-04 07:50:32 +00:00
|
|
|
err := node.New(nodeCfg, ethCfg).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
|
|
|
}
|
|
|
|
}
|