2023-08-23 23:57:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-11-15 01:00:23 +00:00
|
|
|
"context"
|
2023-08-23 23:57:34 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2023-12-30 15:37:04 +00:00
|
|
|
"strings"
|
2023-08-26 03:07:17 +00:00
|
|
|
"time"
|
2023-08-23 23:57:34 +00:00
|
|
|
|
2023-10-16 15:28:58 +00:00
|
|
|
"github.com/pkg/errors"
|
2023-08-23 23:57:34 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"go.opencensus.io/stats"
|
|
|
|
"go.opencensus.io/tag"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2024-03-15 21:38:13 +00:00
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/deps"
|
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/rpc"
|
|
|
|
"github.com/filecoin-project/lotus/cmd/curio/tasks"
|
2023-08-23 23:57:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/ulimit"
|
|
|
|
"github.com/filecoin-project/lotus/metrics"
|
|
|
|
"github.com/filecoin-project/lotus/node"
|
|
|
|
)
|
|
|
|
|
2023-10-16 15:28:58 +00:00
|
|
|
type stackTracer interface {
|
|
|
|
StackTrace() errors.StackTrace
|
|
|
|
}
|
|
|
|
|
2023-08-23 23:57:34 +00:00
|
|
|
var runCmd = &cli.Command{
|
|
|
|
Name: "run",
|
2024-03-15 21:38:13 +00:00
|
|
|
Usage: "Start a Curio process",
|
2023-08-23 23:57:34 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
2023-08-30 04:16:05 +00:00
|
|
|
Name: "listen",
|
|
|
|
Usage: "host address and port the worker api will listen on",
|
|
|
|
Value: "0.0.0.0:12300",
|
|
|
|
EnvVars: []string{"LOTUS_WORKER_LISTEN"},
|
2023-08-23 23:57:34 +00:00
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "nosync",
|
|
|
|
Usage: "don't check full-node sync status",
|
|
|
|
},
|
2023-08-25 23:17:31 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "halt-after-init",
|
|
|
|
Usage: "only run init, then return",
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2023-08-23 23:57:34 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "manage-fdlimit",
|
|
|
|
Usage: "manage open file limit",
|
|
|
|
Value: true,
|
|
|
|
},
|
2023-10-25 00:26:13 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "storage-json",
|
|
|
|
Usage: "path to json file containing storage config",
|
2024-03-15 21:38:13 +00:00
|
|
|
Value: "~/.curio/storage.json",
|
2023-10-25 00:26:13 +00:00
|
|
|
},
|
2023-10-26 22:19:39 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "journal",
|
|
|
|
Usage: "path to journal files",
|
2024-03-15 21:38:13 +00:00
|
|
|
Value: "~/.curio/",
|
2023-10-26 22:19:39 +00:00
|
|
|
},
|
2024-03-06 09:41:37 +00:00
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "layers",
|
|
|
|
Usage: "list of layers to be interpreted (atop defaults). Default: base",
|
|
|
|
},
|
2023-08-23 23:57:34 +00:00
|
|
|
},
|
2023-10-16 15:28:58 +00:00
|
|
|
Action: func(cctx *cli.Context) (err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
if err, ok := err.(stackTracer); ok {
|
|
|
|
for _, f := range err.StackTrace() {
|
|
|
|
fmt.Printf("%+s:%d\n", f, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2023-08-23 23:57:34 +00:00
|
|
|
if !cctx.Bool("enable-gpu-proving") {
|
|
|
|
err := os.Setenv("BELLMAN_NO_GPU", "true")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-16 13:31:13 +00:00
|
|
|
if err := os.MkdirAll(os.TempDir(), 0755); err != nil {
|
|
|
|
log.Errorf("ensuring tempdir exists: %s", err)
|
|
|
|
}
|
|
|
|
|
2023-08-23 23:57:34 +00:00
|
|
|
ctx, _ := tag.New(lcli.DaemonContext(cctx),
|
|
|
|
tag.Insert(metrics.Version, build.BuildVersion),
|
|
|
|
tag.Insert(metrics.Commit, build.CurrentCommit),
|
2024-03-15 21:38:13 +00:00
|
|
|
tag.Insert(metrics.NodeType, "curio"),
|
2023-08-23 23:57:34 +00:00
|
|
|
)
|
2023-11-15 16:04:04 +00:00
|
|
|
shutdownChan := make(chan struct{})
|
2023-12-03 06:40:01 +00:00
|
|
|
{
|
|
|
|
var ctxclose func()
|
|
|
|
ctx, ctxclose = context.WithCancel(ctx)
|
|
|
|
go func() {
|
|
|
|
<-shutdownChan
|
|
|
|
ctxclose()
|
|
|
|
}()
|
|
|
|
}
|
2023-08-23 23:57:34 +00:00
|
|
|
// Register all metric views
|
|
|
|
/*
|
|
|
|
if err := view.Register(
|
|
|
|
metrics.MinerNodeViews...,
|
|
|
|
); err != nil {
|
|
|
|
log.Fatalf("Cannot register the view: %v", err)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Set the metric to one so it is published to the exporter
|
|
|
|
stats.Record(ctx, metrics.LotusInfo.M(1))
|
|
|
|
|
|
|
|
if cctx.Bool("manage-fdlimit") {
|
|
|
|
if _, _, err := ulimit.ManageFdLimit(); err != nil {
|
|
|
|
log.Errorf("setting file descriptor limit: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-12 05:15:41 +00:00
|
|
|
dependencies := &deps.Deps{}
|
|
|
|
err = dependencies.PopulateRemainingDeps(ctx, cctx, true)
|
2023-10-16 15:28:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-10-26 22:19:39 +00:00
|
|
|
|
2023-12-05 04:30:40 +00:00
|
|
|
taskEngine, err := tasks.StartTasks(ctx, dependencies)
|
2023-11-15 01:00:23 +00:00
|
|
|
|
2023-10-11 22:51:46 +00:00
|
|
|
if err != nil {
|
2023-12-05 04:30:40 +00:00
|
|
|
return nil
|
2023-10-11 22:51:46 +00:00
|
|
|
}
|
2023-08-26 03:07:17 +00:00
|
|
|
defer taskEngine.GracefullyTerminate(time.Hour)
|
|
|
|
|
2023-12-05 04:30:40 +00:00
|
|
|
err = rpc.ListenAndServe(ctx, dependencies, shutdownChan) // Monitor for shutdown.
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-12-03 06:40:01 +00:00
|
|
|
}
|
2023-08-30 20:57:20 +00:00
|
|
|
finishCh := node.MonitorShutdown(shutdownChan) //node.ShutdownHandler{Component: "rpc server", StopFunc: rpcStopper},
|
2024-03-15 21:38:13 +00:00
|
|
|
//node.ShutdownHandler{Component: "curio", StopFunc: stop},
|
2023-08-23 23:57:34 +00:00
|
|
|
|
|
|
|
<-finishCh
|
|
|
|
return nil
|
|
|
|
},
|
2023-12-12 03:10:15 +00:00
|
|
|
}
|
2023-12-18 22:02:54 +00:00
|
|
|
|
|
|
|
var webCmd = &cli.Command{
|
|
|
|
Name: "web",
|
2024-03-15 21:38:13 +00:00
|
|
|
Usage: "Start Curio web interface",
|
|
|
|
Description: `Start an instance of Curio web interface.
|
2023-12-18 22:02:54 +00:00
|
|
|
This creates the 'web' layer if it does not exist, then calls run with that layer.`,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "listen",
|
|
|
|
Usage: "Address to listen on",
|
|
|
|
Value: "127.0.0.1:4701",
|
|
|
|
},
|
2023-12-30 15:37:04 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "nosync",
|
|
|
|
Usage: "don't check full-node sync status",
|
|
|
|
},
|
2024-03-06 09:41:37 +00:00
|
|
|
&cli.StringSliceFlag{
|
|
|
|
Name: "layers",
|
|
|
|
Usage: "list of layers to be interpreted (atop defaults). Default: base",
|
|
|
|
},
|
2023-12-18 22:02:54 +00:00
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
db, err := deps.MakeDB(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
webtxt, err := getConfig(db, "web")
|
|
|
|
if err != nil || webtxt == "" {
|
2024-01-13 12:47:22 +00:00
|
|
|
|
|
|
|
s := `[Susbystems]
|
|
|
|
EnableWebGui = true
|
|
|
|
`
|
|
|
|
if err = setConfig(db, "web", s); err != nil {
|
2023-12-18 22:02:54 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-12-30 15:37:04 +00:00
|
|
|
layers := append([]string{"web"}, cctx.StringSlice("layers")...)
|
|
|
|
err = cctx.Set("layers", strings.Join(layers, ","))
|
|
|
|
if err != nil {
|
2023-12-20 00:58:55 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-12-18 22:02:54 +00:00
|
|
|
return runCmd.Action(cctx)
|
|
|
|
},
|
|
|
|
}
|