erigon-pulse/cmd/devnettest/erigon/node.go
Leonard Chinonso 592fe32217
Refactoring To Increase Code Quality (#4842)
* General cleanup and fixes

* Cleaning part 2

* cleanup part 3

* Refactored staterunner to have a handler function

* Fixed linting

* Cleanup part 4

* Changed the initialization of the require package and updated .golangci.yml

* Fixed lint errors from golangci-lint

* deleted state_recon_1.go

* fixed build error

* Added ReadHeaderTimeouts for httpServer

* made changes to golangci

* Reset golangci.yml
2022-08-04 20:23:00 +07:00

65 lines
1.7 KiB
Go

package erigon
import (
"fmt"
"os"
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon/cmd/devnettest/rpcdaemon"
"github.com/ledgerwatch/erigon/params"
erigonapp "github.com/ledgerwatch/erigon/turbo/app"
erigoncli "github.com/ledgerwatch/erigon/turbo/cli"
"github.com/ledgerwatch/erigon/turbo/node"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli"
)
const DevPeriod = 5
func RunNode() {
defer func() {
panicResult := recover()
if panicResult == nil {
return
}
log.Error("catch panic", "err", panicResult, "stack", dbg.Stack())
os.Exit(1)
}()
app := erigonapp.MakeApp(runDevnet, erigoncli.DefaultFlags) // change to erigoncli.DefaultFlags later on
customArgs := []string{"./build/bin/devnettest", "--datadir=./dev", "--chain=dev", "--mine", fmt.Sprintf("--dev.period=%d", DevPeriod), "--verbosity=0"}
if err := app.Run(customArgs); err != nil {
_, printErr := fmt.Fprintln(os.Stderr, err)
if printErr != nil {
log.Warn("Fprintln error", "err", printErr)
}
os.Exit(1)
}
}
func runDevnet(cliCtx *cli.Context) {
logger := log.New()
// 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)
nodeCfg := node.NewNodConfigUrfave(cliCtx)
ethCfg := node.NewEthConfigUrfave(cliCtx, nodeCfg)
ethNode, err := node.New(nodeCfg, ethCfg, logger)
if err != nil {
log.Error("Devnet startup", "err", err)
return
}
err = ethNode.Serve()
if err != nil {
log.Error("error while serving a Devnet node", "err", err)
}
}
func StartProcess() {
fmt.Println("Starting erigon node and rpc daemon...")
go RunNode()
go rpcdaemon.RunDaemon()
}