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
2021-07-13 10:19:55 +00:00
"github.com/fatih/color"
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"
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"
2023-11-14 00:06:11 +00:00
2020-07-03 17:35:20 +00:00
"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"
2022-06-14 15:00:51 +00:00
cliutil "github.com/filecoin-project/lotus/cli/util"
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" )
2021-07-29 15:10:04 +00:00
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 ( ) {
2021-03-05 21:01:20 +00:00
api . RunningNodeType = api . NodeMiner
2020-09-08 18:54:37 +00:00
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-08-17 03:51:04 +00:00
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 ) ,
2023-05-08 11:13:18 +00:00
lcli . WithCategory ( "market" , setHidden ( storageDealsCmd ) ) ,
lcli . WithCategory ( "market" , setHidden ( retrievalDealsCmd ) ) ,
lcli . WithCategory ( "market" , setHidden ( dataTransfersCmd ) ) ,
lcli . WithCategory ( "market" , setHidden ( dagstoreCmd ) ) ,
lcli . WithCategory ( "market" , setHidden ( indexProvCmd ) ) ,
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 ) ,
2023-05-08 11:13:18 +00:00
lcli . WithCategory ( "retrieval" , setHidden ( piecesCmd ) ) ,
2019-07-18 23:16:23 +00:00
}
2021-12-02 00:07:56 +00:00
2019-07-26 19:01:02 +00:00
jaeger := tracing . SetupJaegerTracing ( "lotus" )
defer func ( ) {
if jaeger != nil {
2021-12-02 00:07:56 +00:00
_ = jaeger . ForceFlush ( context . Background ( ) )
2019-07-26 19:01:02 +00:00
}
} ( )
for _ , cmd := range local {
cmd := cmd
originBefore := cmd . Before
cmd . Before = func ( cctx * cli . Context ) error {
2021-12-02 02:53:00 +00:00
if jaeger != nil {
_ = jaeger . Shutdown ( cctx . Context )
}
2019-07-26 19:01:02 +00:00
jaeger = tracing . SetupJaegerTracing ( "lotus/" + cmd . Name )
2021-07-13 10:19:55 +00:00
if cctx . IsSet ( "color" ) {
color . NoColor = ! cctx . Bool ( "color" )
}
2019-07-26 19:01:02 +00:00
if originBefore != nil {
return originBefore ( cctx )
}
2021-07-13 10:19:55 +00:00
2019-07-26 19:01:02 +00:00
return nil
}
}
2019-07-18 23:16:23 +00:00
2021-08-12 10:15:00 +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.
2023-05-08 11:13:18 +00:00
netCmd . Hidden = true
2021-08-12 10:15:00 +00:00
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 : "" ,
2021-09-14 09:29:58 +00:00
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
} ,
2020-07-14 12:31:15 +00:00
& cli . BoolFlag {
2021-07-13 10:19:55 +00:00
// examined in the Before above
2021-07-08 08:44:13 +00:00
Name : "color" ,
2021-07-13 10:19:55 +00:00
Usage : "use color in display output" ,
2021-07-08 08:44:13 +00:00
DefaultText : "depends on output being a TTY" ,
2020-07-14 12:31:15 +00:00
} ,
2021-09-17 22:01:54 +00:00
& cli . StringFlag {
Name : "panic-reports" ,
EnvVars : [ ] string { "LOTUS_PANIC_REPORT_PATH" } ,
Hidden : true ,
2021-09-30 13:06:55 +00:00
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" } ,
2023-05-08 11:13:18 +00:00
Hidden : true ,
2021-07-29 12:38:08 +00:00
} ,
2021-07-29 11:37:29 +00:00
& cli . BoolFlag {
2023-05-08 11:13:18 +00:00
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" ,
Hidden : true ,
2021-07-29 11:37:29 +00:00
} ,
2021-07-27 19:46:02 +00:00
cliutil . FlagVeryVerbose ,
2019-07-18 23:16:23 +00:00
} ,
2021-08-12 10:15:00 +00:00
Commands : append ( local , append ( lcli . CommonCommands , & netCmd ) ... ) ,
2021-07-29 11:37:29 +00:00
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
2021-09-30 13:06:55 +00:00
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
}
2019-12-09 12:36:56 +00:00
app . Setup ( )
app . Metadata [ "repoType" ] = repo . StorageMiner
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
2021-03-28 05:21:09 +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" ) )
2020-07-03 17:35:20 +00:00
if err != nil {
return maddr , err
}
2020-07-14 12:31:15 +00:00
return
2020-07-03 17:35:20 +00:00
}
2022-09-14 18:51:18 +00:00
minerApi , closer , err := lcli . GetStorageMinerAPI ( cctx )
2021-03-28 05:21:09 +00:00
if err != nil {
return address . Undef , err
}
defer closer ( )
2022-09-14 18:51:18 +00:00
maddr , err = minerApi . 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
}
2023-05-08 11:13:18 +00:00
func setHidden ( cmd * cli . Command ) * cli . Command {
cmd . Hidden = true
return cmd
}