2019-12-02 13:47:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-12 07:11:46 +00:00
|
|
|
"context"
|
|
|
|
"errors"
|
2023-05-07 06:28:15 +00:00
|
|
|
"fmt"
|
2019-12-02 13:47:00 +00:00
|
|
|
"os"
|
|
|
|
|
2022-01-19 03:49:07 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli"
|
2023-09-21 07:38:47 +00:00
|
|
|
"github.com/ledgerwatch/erigon/rpc"
|
2023-05-07 06:28:15 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/debug"
|
2023-07-08 17:01:26 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/jsonrpc"
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-12-02 13:47:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd, cfg := cli.RootCommand()
|
2022-01-19 03:49:07 +00:00
|
|
|
rootCtx, rootCancel := common.RootContext()
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2022-02-12 12:47:19 +00:00
|
|
|
ctx := cmd.Context()
|
2023-07-09 07:04:20 +00:00
|
|
|
logger := debug.SetupCobra(cmd, "sentry")
|
2023-10-06 10:58:08 +00:00
|
|
|
db, backend, txPool, mining, stateCache, blockReader, engine, ff, agg, err := cli.RemoteServices(ctx, *cfg, logger, rootCancel)
|
2020-08-19 11:46:20 +00:00
|
|
|
if err != nil {
|
2023-10-12 07:11:46 +00:00
|
|
|
if !errors.Is(err, context.Canceled) {
|
|
|
|
logger.Error("Could not connect to DB", "err", err)
|
|
|
|
}
|
2020-08-19 11:46:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-10-10 06:06:54 +00:00
|
|
|
defer db.Close()
|
2023-10-06 10:58:08 +00:00
|
|
|
defer engine.Close()
|
2019-12-02 13:47:00 +00:00
|
|
|
|
2023-10-02 17:55:31 +00:00
|
|
|
apiList := jsonrpc.APIList(db, backend, txPool, mining, ff, stateCache, blockReader, agg, *cfg, engine, logger)
|
2023-09-21 07:38:47 +00:00
|
|
|
rpc.PreAllocateRPCMetricLabels(apiList)
|
2023-07-12 16:11:41 +00:00
|
|
|
if err := cli.StartRpcServer(ctx, *cfg, apiList, logger); err != nil {
|
2023-05-07 06:28:15 +00:00
|
|
|
logger.Error(err.Error())
|
2021-03-25 06:42:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
2022-01-25 16:44:35 +00:00
|
|
|
|
2021-03-25 06:42:45 +00:00
|
|
|
return nil
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 12:39:34 +00:00
|
|
|
if err := cmd.ExecuteContext(rootCtx); err != nil {
|
2023-05-07 06:28:15 +00:00
|
|
|
fmt.Printf("ExecuteContext: %v\n", err)
|
2020-08-19 11:46:20 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|