2019-07-18 23:16:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-07-03 17:35:20 +00:00
|
|
|
"context"
|
2020-07-10 12:18:09 +00:00
|
|
|
"fmt"
|
2019-07-18 23:16:23 +00:00
|
|
|
|
2020-01-08 19:10:57 +00:00
|
|
|
logging "github.com/ipfs/go-log/v2"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-07-26 19:01:02 +00:00
|
|
|
"go.opencensus.io/trace"
|
2020-07-03 17:35:20 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-07-18 23:16:23 +00:00
|
|
|
|
2020-07-03 17:35:20 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2020-01-08 13:49:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/lotuslog"
|
2020-02-22 11:36:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/tracing"
|
2019-12-09 12:36:56 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/repo"
|
2019-07-18 23:16:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var log = logging.Logger("main")
|
|
|
|
|
2020-07-08 10:38:59 +00:00
|
|
|
const FlagMinerRepo = "miner-repo"
|
2020-07-17 13:18:40 +00:00
|
|
|
|
2020-07-10 12:18:09 +00:00
|
|
|
// TODO remove after deprecation period
|
|
|
|
const FlagMinerRepoDeprecation = "storagerepo"
|
2019-07-23 21:50:52 +00:00
|
|
|
|
2019-07-18 23:16:23 +00:00
|
|
|
func main() {
|
2020-01-08 13:49:34 +00:00
|
|
|
lotuslog.SetupLogLevels()
|
2019-10-29 19:51:44 +00:00
|
|
|
|
2019-07-18 23:16:23 +00:00
|
|
|
local := []*cli.Command{
|
2020-02-08 00:18:14 +00:00
|
|
|
initCmd,
|
|
|
|
runCmd,
|
2020-06-02 19:31:21 +00:00
|
|
|
stopCmd,
|
2020-07-21 17:19:47 +00:00
|
|
|
lcli.WithCategory("chain", actorCmd),
|
|
|
|
lcli.WithCategory("chain", rewardsCmd),
|
|
|
|
lcli.WithCategory("chain", infoCmd),
|
|
|
|
lcli.WithCategory("market", storageDealsCmd),
|
|
|
|
lcli.WithCategory("market", retrievalDealsCmd),
|
|
|
|
lcli.WithCategory("storage", sectorsCmd),
|
|
|
|
lcli.WithCategory("storage", provingCmd),
|
|
|
|
lcli.WithCategory("storage", storageCmd),
|
2020-07-21 18:07:49 +00:00
|
|
|
lcli.WithCategory("storage", sealingCmd),
|
2019-07-18 23:16:23 +00:00
|
|
|
}
|
2019-07-26 19:01:02 +00:00
|
|
|
jaeger := tracing.SetupJaegerTracing("lotus")
|
|
|
|
defer func() {
|
|
|
|
if jaeger != nil {
|
|
|
|
jaeger.Flush()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
for _, cmd := range local {
|
|
|
|
cmd := cmd
|
|
|
|
originBefore := cmd.Before
|
|
|
|
cmd.Before = func(cctx *cli.Context) error {
|
|
|
|
trace.UnregisterExporter(jaeger)
|
|
|
|
jaeger = tracing.SetupJaegerTracing("lotus/" + cmd.Name)
|
|
|
|
|
|
|
|
if originBefore != nil {
|
|
|
|
return originBefore(cctx)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 23:16:23 +00:00
|
|
|
|
|
|
|
app := &cli.App{
|
2020-07-08 10:38:59 +00:00
|
|
|
Name: "lotus-miner",
|
2020-07-11 08:55:13 +00:00
|
|
|
Usage: "Filecoin decentralized storage network miner",
|
2020-06-02 18:12:53 +00:00
|
|
|
Version: build.UserVersion(),
|
|
|
|
EnableBashCompletion: true,
|
2019-07-18 23:16:23 +00:00
|
|
|
Flags: []cli.Flag{
|
2020-07-02 16:48:39 +00:00
|
|
|
&cli.StringFlag{
|
2020-07-03 17:45:21 +00:00
|
|
|
Name: "actor",
|
|
|
|
Value: "",
|
|
|
|
Usage: "specify other actor to check state for (read only)",
|
|
|
|
Aliases: []string{"a"},
|
2020-07-02 16:48:39 +00:00
|
|
|
},
|
2019-07-18 23:16:23 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo",
|
|
|
|
EnvVars: []string{"LOTUS_PATH"},
|
|
|
|
Hidden: true,
|
|
|
|
Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2020-07-08 10:38:59 +00:00
|
|
|
Name: FlagMinerRepo,
|
2020-07-10 12:18:09 +00:00
|
|
|
Aliases: []string{FlagMinerRepoDeprecation},
|
|
|
|
EnvVars: []string{"LOTUS_MINER_PATH", "LOTUS_STORAGE_PATH"},
|
2020-07-08 10:53:04 +00:00
|
|
|
Value: "~/.lotusminer", // TODO: Consider XDG_DATA_HOME
|
2020-07-10 12:18:09 +00:00
|
|
|
Usage: fmt.Sprintf("Specify miner repo path. flag(%s) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON", FlagMinerRepoDeprecation),
|
2019-07-18 23:16:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-03-23 12:29:24 +00:00
|
|
|
Commands: append(local, lcli.CommonCommands...),
|
2019-07-18 23:16:23 +00:00
|
|
|
}
|
2019-12-09 12:36:56 +00:00
|
|
|
app.Setup()
|
|
|
|
app.Metadata["repoType"] = repo.StorageMiner
|
2019-07-18 23:16:23 +00:00
|
|
|
|
2020-07-23 18:41:53 +00:00
|
|
|
lcli.RunApp(app)
|
2019-07-18 23:16:23 +00:00
|
|
|
}
|
2020-07-03 17:35:20 +00:00
|
|
|
|
2020-07-03 17:49:21 +00:00
|
|
|
func getActorAddress(ctx context.Context, nodeAPI api.StorageMiner, overrideMaddr string) (maddr address.Address, err error) {
|
2020-07-03 17:35:20 +00:00
|
|
|
if overrideMaddr != "" {
|
|
|
|
maddr, err = address.NewFromString(overrideMaddr)
|
|
|
|
if err != nil {
|
|
|
|
return maddr, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 17:49:21 +00:00
|
|
|
maddr, err = nodeAPI.ActorAddress(ctx)
|
2020-07-03 17:35:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return maddr, xerrors.Errorf("getting actor address: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return maddr, nil
|
|
|
|
}
|