2019-12-02 13:47:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/cli"
|
2019-12-02 13:47:00 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/commands"
|
2020-11-17 19:13:41 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/filters"
|
2020-10-10 06:06:54 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/cmd/utils"
|
2020-12-09 18:24:08 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/common/fdlimit"
|
2019-12-02 13:47:00 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-12-02 13:47:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-12-09 18:24:08 +00:00
|
|
|
raiseFdLimit()
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd, cfg := cli.RootCommand()
|
2021-04-26 12:39:34 +00:00
|
|
|
rootCtx, rootCancel := utils.RootContext()
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2021-05-17 12:15:19 +00:00
|
|
|
db, backend, txPool, mining, err := cli.RemoteServices(*cfg, rootCancel)
|
2020-08-19 11:46:20 +00:00
|
|
|
if err != nil {
|
2020-10-25 08:39:09 +00:00
|
|
|
log.Error("Could not connect to DB", "error", err)
|
2020-08-19 11:46:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-10-10 06:06:54 +00:00
|
|
|
defer db.Close()
|
2019-12-02 13:47:00 +00:00
|
|
|
|
2020-11-17 19:13:41 +00:00
|
|
|
var ff *filters.Filters
|
|
|
|
if backend != nil {
|
2021-05-17 12:15:19 +00:00
|
|
|
ff = filters.New(rootCtx, backend, txPool, mining)
|
2020-11-17 19:13:41 +00:00
|
|
|
} else {
|
|
|
|
log.Info("filters are not supported in chaindata mode")
|
|
|
|
}
|
|
|
|
|
2021-05-17 12:15:19 +00:00
|
|
|
if err := cli.StartRpcServer(cmd.Context(), *cfg, commands.APIList(cmd.Context(), db, backend, txPool, mining, ff, *cfg, nil)); err != nil {
|
2021-03-25 06:42:45 +00:00
|
|
|
log.Error(err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
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 {
|
2020-08-19 11:46:20 +00:00
|
|
|
log.Error(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|
2020-12-09 18:24:08 +00:00
|
|
|
|
|
|
|
// raiseFdLimit raises out the number of allowed file handles per process
|
|
|
|
func raiseFdLimit() {
|
|
|
|
limit, err := fdlimit.Maximum()
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Failed to retrieve file descriptor allowance", "error", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, err = fdlimit.Raise(uint64(limit)); err != nil {
|
|
|
|
log.Error("Failed to raise file descriptor allowance", "error", err)
|
|
|
|
}
|
|
|
|
}
|