lotus/cmd/lotus-miner/main.go

191 lines
5.0 KiB
Go
Raw Normal View History

2019-07-18 23:16:23 +00:00
package main
import (
"context"
2020-07-10 12:18:09 +00:00
"fmt"
2019-07-18 23:16:23 +00:00
"github.com/fatih/color"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
"go.opencensus.io/trace"
"golang.org/x/xerrors"
2019-07-18 23:16:23 +00:00
integrate DAG store and CARv2 in deal-making (#6671) This commit removes badger from the deal-making processes, and moves to a new architecture with the dagstore as the cental component on the miner-side, and CARv2s on the client-side. Every deal that has been handed off to the sealing subsystem becomes a shard in the dagstore. Shards are mounted via the LotusMount, which teaches the dagstore how to load the related piece when serving retrievals. When the miner starts the Lotus for the first time with this patch, we will perform a one-time migration of all active deals into the dagstore. This is a lightweight process, and it consists simply of registering the shards in the dagstore. Shards are backed by the unsealed copy of the piece. This is currently a CARv1. However, the dagstore keeps CARv2 indices for all pieces, so when it's time to acquire a shard to serve a retrieval, the unsealed CARv1 is joined with its index (safeguarded by the dagstore), to form a read-only blockstore, thus taking the place of the monolithic badger. Data transfers have been adjusted to interface directly with CARv2 files. On inbound transfers (client retrievals, miner storage deals), we stream the received data into a CARv2 ReadWrite blockstore. On outbound transfers (client storage deals, miner retrievals), we serve the data off a CARv2 ReadOnly blockstore. Client-side imports are managed by the refactored *imports.Manager component (when not using IPFS integration). Just like it before, we use the go-filestore library to avoid duplicating the data from the original file in the resulting UnixFS DAG (concretely the leaves). However, the target of those imports are what we call "ref-CARv2s": CARv2 files placed under the `$LOTUS_PATH/imports` directory, containing the intermediate nodes in full, and the leaves as positional references to the original file on disk. Client-side retrievals are placed into CARv2 files in the location: `$LOTUS_PATH/retrievals`. A new set of `Dagstore*` JSON-RPC operations and `lotus-miner dagstore` subcommands have been introduced on the miner-side to inspect and manage the dagstore. Despite moving to a CARv2-backed system, the IPFS integration has been respected, and it continues to be possible to make storage deals with data held in an IPFS node, and to perform retrievals directly into an IPFS node. NOTE: because the "staging" and "client" Badger blockstores are no longer used, existing imports on the client will be rendered useless. On startup, Lotus will enumerate all imports and print WARN statements on the log for each import that needs to be reimported. These log lines contain these messages: - import lacks carv2 path; import will not work; please reimport - import has missing/broken carv2; please reimport At the end, we will print a "sanity check completed" message indicating the count of imports found, and how many were deemed broken. Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com> Co-authored-by: Dirk McCormick <dirkmdev@gmail.com> Co-authored-by: Raúl Kripalani <raul@protocol.ai> Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
2021-08-16 22:34:32 +00:00
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/api"
"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"
"github.com/filecoin-project/lotus/node/repo"
2019-07-18 23:16:23 +00:00
)
var log = logging.Logger("main")
const (
FlagMinerRepo = "miner-repo"
FlagMarketsRepo = "markets-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() {
api.RunningNodeType = api.NodeMiner
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{
initCmd,
runCmd,
stopCmd,
configCmd,
2020-10-01 11:58:26 +00:00
backupCmd,
2020-07-21 17:19:47 +00:00
lcli.WithCategory("chain", actorCmd),
lcli.WithCategory("chain", infoCmd),
lcli.WithCategory("market", storageDealsCmd),
lcli.WithCategory("market", retrievalDealsCmd),
lcli.WithCategory("market", dataTransfersCmd),
integrate DAG store and CARv2 in deal-making (#6671) This commit removes badger from the deal-making processes, and moves to a new architecture with the dagstore as the cental component on the miner-side, and CARv2s on the client-side. Every deal that has been handed off to the sealing subsystem becomes a shard in the dagstore. Shards are mounted via the LotusMount, which teaches the dagstore how to load the related piece when serving retrievals. When the miner starts the Lotus for the first time with this patch, we will perform a one-time migration of all active deals into the dagstore. This is a lightweight process, and it consists simply of registering the shards in the dagstore. Shards are backed by the unsealed copy of the piece. This is currently a CARv1. However, the dagstore keeps CARv2 indices for all pieces, so when it's time to acquire a shard to serve a retrieval, the unsealed CARv1 is joined with its index (safeguarded by the dagstore), to form a read-only blockstore, thus taking the place of the monolithic badger. Data transfers have been adjusted to interface directly with CARv2 files. On inbound transfers (client retrievals, miner storage deals), we stream the received data into a CARv2 ReadWrite blockstore. On outbound transfers (client storage deals, miner retrievals), we serve the data off a CARv2 ReadOnly blockstore. Client-side imports are managed by the refactored *imports.Manager component (when not using IPFS integration). Just like it before, we use the go-filestore library to avoid duplicating the data from the original file in the resulting UnixFS DAG (concretely the leaves). However, the target of those imports are what we call "ref-CARv2s": CARv2 files placed under the `$LOTUS_PATH/imports` directory, containing the intermediate nodes in full, and the leaves as positional references to the original file on disk. Client-side retrievals are placed into CARv2 files in the location: `$LOTUS_PATH/retrievals`. A new set of `Dagstore*` JSON-RPC operations and `lotus-miner dagstore` subcommands have been introduced on the miner-side to inspect and manage the dagstore. Despite moving to a CARv2-backed system, the IPFS integration has been respected, and it continues to be possible to make storage deals with data held in an IPFS node, and to perform retrievals directly into an IPFS node. NOTE: because the "staging" and "client" Badger blockstores are no longer used, existing imports on the client will be rendered useless. On startup, Lotus will enumerate all imports and print WARN statements on the log for each import that needs to be reimported. These log lines contain these messages: - import lacks carv2 path; import will not work; please reimport - import has missing/broken carv2; please reimport At the end, we will print a "sanity check completed" message indicating the count of imports found, and how many were deemed broken. Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com> Co-authored-by: Dirk McCormick <dirkmdev@gmail.com> Co-authored-by: Raúl Kripalani <raul@protocol.ai> Co-authored-by: Dirk McCormick <dirkmdev@gmail.com>
2021-08-16 22:34:32 +00:00
lcli.WithCategory("market", dagstoreCmd),
2020-07-21 17:19:47 +00:00
lcli.WithCategory("storage", sectorsCmd),
lcli.WithCategory("storage", provingCmd),
lcli.WithCategory("storage", storageCmd),
2020-07-21 18:07:49 +00:00
lcli.WithCategory("storage", sealingCmd),
lcli.WithCategory("retrieval", piecesCmd),
2019-07-18 23:16:23 +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 cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}
if originBefore != nil {
return originBefore(cctx)
}
return nil
}
}
2019-07-18 23:16:23 +00:00
// adapt the Net* commands to always hit the node running the markets
// subsystem, as that is the only one that runs a libp2p node.
netCmd := *lcli.NetCmd // make a copy.
prev := netCmd.Before
netCmd.Before = func(c *cli.Context) error {
if prev != nil {
if err := prev(c); err != nil {
return err
}
}
c.App.Metadata["repoType"] = repo.Markets
return nil
}
2019-07-18 23:16:23 +00:00
app := &cli.App{
2021-07-29 11:54:23 +00:00
Name: "lotus-miner",
Usage: "Filecoin decentralized storage network miner",
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 query / manipulate",
2020-07-03 17:45:21 +00:00
Aliases: []string{"a"},
2020-07-02 16:48:39 +00:00
},
&cli.BoolFlag{
// examined in the Before above
Name: "color",
Usage: "use color in display output",
DefaultText: "depends on output being a TTY",
},
2021-09-17 22:01:54 +00:00
&cli.StringFlag{
Name: "panic-reports",
EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"},
Hidden: true,
Value: "~/.lotusminer", // should follow --repo default
2021-09-17 22:01:54 +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
},
2021-07-29 12:38:08 +00:00
&cli.StringFlag{
Name: FlagMarketsRepo,
EnvVars: []string{"LOTUS_MARKETS_PATH"},
Usage: fmt.Sprintf("Markets repo path"),
},
&cli.BoolFlag{
Name: "call-on-markets",
Usage: "(experimental; may be removed) call this command against a markets node; use only with common commands like net, auth, pprof, etc. whose target may be ambiguous",
},
2021-07-27 19:46:02 +00:00
cliutil.FlagVeryVerbose,
2019-07-18 23:16:23 +00:00
},
Commands: append(local, append(lcli.CommonCommands, &netCmd)...),
Before: func(c *cli.Context) error {
// this command is explicitly called on markets, inform
// common commands by overriding the repoType.
if c.Bool("call-on-markets") {
c.App.Metadata["repoType"] = repo.Markets
}
return nil
},
2021-09-17 22:01:54 +00:00
After: func(c *cli.Context) error {
if r := recover(); r != nil {
// Generate report in LOTUS_PATH and re-raise panic
build.GeneratePanicReport(c.String("panic-reports"), c.String(FlagMinerRepo), c.App.Name)
2021-09-17 22:01:54 +00:00
panic(r)
}
return nil
},
2019-07-18 23:16:23 +00:00
}
app.Setup()
app.Metadata["repoType"] = repo.StorageMiner
lcli.RunApp(app)
2019-07-18 23:16:23 +00:00
}
func getActorAddress(ctx context.Context, cctx *cli.Context) (maddr address.Address, err error) {
if cctx.IsSet("actor") {
maddr, err = address.NewFromString(cctx.String("actor"))
if err != nil {
return maddr, err
}
return
}
nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return address.Undef, err
}
defer closer()
2020-07-03 17:49:21 +00:00
maddr, err = nodeAPI.ActorAddress(ctx)
if err != nil {
return maddr, xerrors.Errorf("getting actor address: %w", err)
}
return maddr, nil
}