2019-11-21 14:10:51 +00:00
|
|
|
package main
|
2019-11-21 00:52:59 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2019-12-06 00:27:32 +00:00
|
|
|
"github.com/mitchellh/go-homedir"
|
|
|
|
|
2019-11-21 00:52:59 +00:00
|
|
|
logging "github.com/ipfs/go-log"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
2019-11-21 14:10:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2019-11-21 00:52:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2019-12-09 12:36:56 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
|
|
|
manet "github.com/multiformats/go-multiaddr-net"
|
2019-11-21 00:52:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var log = logging.Logger("main")
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
logging.SetLogLevel("*", "INFO")
|
|
|
|
|
|
|
|
log.Info("Starting lotus worker")
|
|
|
|
|
|
|
|
local := []*cli.Command{
|
|
|
|
runCmd,
|
|
|
|
}
|
|
|
|
|
|
|
|
app := &cli.App{
|
2019-11-22 16:25:56 +00:00
|
|
|
Name: "lotus-seal-worker",
|
2019-11-21 00:52:59 +00:00
|
|
|
Usage: "Remote storage miner worker",
|
|
|
|
Version: build.Version,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo",
|
|
|
|
EnvVars: []string{"WORKER_PATH"},
|
|
|
|
Value: "~/.lotusworker", // TODO: Consider XDG_DATA_HOME
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2019-11-21 16:10:04 +00:00
|
|
|
Name: "storagerepo",
|
|
|
|
EnvVars: []string{"LOTUS_STORAGE_PATH"},
|
2019-11-21 00:52:59 +00:00
|
|
|
Value: "~/.lotusstorage", // TODO: Consider XDG_DATA_HOME
|
|
|
|
},
|
2019-12-07 14:19:46 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "enable-gpu-proving",
|
|
|
|
Usage: "enable use of GPU for mining operations",
|
|
|
|
Value: true,
|
|
|
|
},
|
2019-12-06 00:27:32 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-precommit",
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "no-commit",
|
|
|
|
},
|
2019-11-21 00:52:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Commands: local,
|
|
|
|
}
|
2019-12-09 12:36:56 +00:00
|
|
|
app.Setup()
|
|
|
|
app.Metadata["repoType"] = repo.StorageMiner
|
2019-11-21 00:52:59 +00:00
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2019-11-21 18:38:43 +00:00
|
|
|
log.Warnf("%+v", err)
|
2019-11-21 00:52:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var runCmd = &cli.Command{
|
|
|
|
Name: "run",
|
2019-11-21 14:10:51 +00:00
|
|
|
Usage: "Start lotus worker",
|
2019-11-21 00:52:59 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-12-07 14:19:46 +00:00
|
|
|
if !cctx.Bool("enable-gpu-proving") {
|
|
|
|
os.Setenv("BELLMAN_NO_GPU", "true")
|
|
|
|
}
|
|
|
|
|
2019-11-21 00:52:59 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
2019-11-21 18:38:43 +00:00
|
|
|
return xerrors.Errorf("getting miner api: %w", err)
|
2019-11-21 00:52:59 +00:00
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2019-12-09 12:36:56 +00:00
|
|
|
ainfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner)
|
2019-11-21 16:10:04 +00:00
|
|
|
if err != nil {
|
2019-12-09 12:36:56 +00:00
|
|
|
return xerrors.Errorf("could not get api info: %w", err)
|
2019-11-21 16:10:04 +00:00
|
|
|
}
|
2019-12-09 12:36:56 +00:00
|
|
|
_, storageAddr, err := manet.DialArgs(ainfo.Addr)
|
2019-11-21 16:10:04 +00:00
|
|
|
|
2019-11-21 18:38:43 +00:00
|
|
|
r, err := homedir.Expand(cctx.String("repo"))
|
2019-11-21 16:10:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-21 00:52:59 +00:00
|
|
|
v, err := nodeApi.Version(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if v.APIVersion != build.APIVersion {
|
2019-11-21 14:10:51 +00:00
|
|
|
return xerrors.Errorf("lotus-storage-miner API version doesn't match: local: ", api.Version{APIVersion: build.APIVersion})
|
2019-11-21 00:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
<-ctx.Done()
|
2019-12-04 16:53:32 +00:00
|
|
|
log.Warn("Shutting down..")
|
2019-11-21 00:52:59 +00:00
|
|
|
}()
|
|
|
|
|
2019-12-09 12:36:56 +00:00
|
|
|
return acceptJobs(ctx, nodeApi, "http://"+storageAddr, ainfo.AuthHeader(), r, cctx.Bool("no-precommit"), cctx.Bool("no-commit"))
|
2019-11-21 00:52:59 +00:00
|
|
|
},
|
|
|
|
}
|