2020-09-06 11:35:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-06 19:25:01 +00:00
|
|
|
"net"
|
2020-09-06 11:35:32 +00:00
|
|
|
"os"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils"
|
|
|
|
"github.com/ledgerwatch/erigon/log"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-06-06 08:05:30 +00:00
|
|
|
// Following vars are injected through the build flags (see Makefile)
|
2020-09-11 16:42:33 +00:00
|
|
|
gitCommit string
|
2021-03-01 04:02:06 +00:00
|
|
|
gitBranch string
|
2021-06-06 08:05:30 +00:00
|
|
|
gitTag string
|
2020-09-06 11:35:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
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) {
|
2021-05-20 12:17:47 +00:00
|
|
|
// creating staged sync with all default parameters
|
2020-09-06 11:35:32 +00:00
|
|
|
|
2021-04-26 12:39:34 +00:00
|
|
|
ctx, _ := utils.RootContext()
|
2020-10-06 19:25:01 +00:00
|
|
|
|
2020-09-21 14:10:25 +00:00
|
|
|
// initializing the node and providing the current git commit there
|
2021-06-06 08:05:30 +00:00
|
|
|
log.Info("Build info", "git_branch", gitBranch, "git_tag", gitTag, "git_commit", gitCommit)
|
2021-06-07 11:00:16 +00:00
|
|
|
eri := node.New(cliCtx, node.Params{GitCommit: gitCommit, GitBranch: gitBranch})
|
2021-05-26 10:35:39 +00:00
|
|
|
eri.SetP2PListenFunc(func(network, addr string) (net.Listener, error) {
|
2020-10-06 19:25:01 +00:00
|
|
|
var lc net.ListenConfig
|
|
|
|
return lc.Listen(ctx, network, addr)
|
|
|
|
})
|
2020-09-21 14:10:25 +00:00
|
|
|
// running the node
|
2021-05-26 10:35:39 +00:00
|
|
|
err := eri.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
|
|
|
}
|
|
|
|
}
|