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"
|
2021-02-21 08:38:00 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
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()
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2020-08-20 03:52:27 +00:00
|
|
|
db, backend, err := cli.OpenDB(*cfg)
|
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 {
|
|
|
|
ff = filters.New(backend)
|
|
|
|
} else {
|
|
|
|
log.Info("filters are not supported in chaindata mode")
|
|
|
|
}
|
|
|
|
|
2021-02-21 08:38:00 +00:00
|
|
|
return cli.StartRpcServer(cmd.Context(), *cfg, commands.APIList(ethdb.NewObjectDatabase(db), backend, ff, *cfg, nil))
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 11:46:20 +00:00
|
|
|
if err := cmd.ExecuteContext(utils.RootContext()); err != nil {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|