erigon-pulse/cmd/rpcdaemon/main.go

48 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
"context"
"errors"
"fmt"
"os"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/jsonrpc"
"github.com/spf13/cobra"
)
func main() {
cmd, cfg := cli.RootCommand()
rootCtx, rootCancel := common.RootContext()
cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
2023-07-09 07:04:20 +00:00
logger := debug.SetupCobra(cmd, "sentry")
db, backend, txPool, mining, stateCache, blockReader, engine, ff, agg, err := cli.RemoteServices(ctx, *cfg, logger, rootCancel)
if err != nil {
if !errors.Is(err, context.Canceled) {
logger.Error("Could not connect to DB", "err", err)
}
return nil
}
defer db.Close()
defer engine.Close()
apiList := jsonrpc.APIList(db, backend, txPool, mining, ff, stateCache, blockReader, agg, *cfg, engine, logger)
rpc.PreAllocateRPCMetricLabels(apiList)
if err := cli.StartRpcServer(ctx, *cfg, apiList, logger); err != nil {
logger.Error(err.Error())
return nil
}
2022-01-25 16:44:35 +00:00
return nil
}
if err := cmd.ExecuteContext(rootCtx); err != nil {
fmt.Printf("ExecuteContext: %v\n", err)
os.Exit(1)
}
}