Skip to content

Commit

Permalink
Add --actor flag in lotus-shed sectors terminate
Browse files Browse the repository at this point in the history
Can specify miner actor address when terminate sectors,
so that you can terminate sectors without miner api.
  • Loading branch information
chadwick2143 committed Mar 16, 2021
1 parent a54c6bf commit 7417a13
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions cmd/lotus-shed/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
Expand Down Expand Up @@ -34,6 +35,10 @@ var terminateSectorCmd = &cli.Command{
Usage: "Forcefully terminate a sector (WARNING: This means losing power and pay a one-time termination penalty(including collateral) for the terminated sector)",
ArgsUsage: "[sectorNum1 sectorNum2 ...]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "actor",
Usage: "specify the address of miner actor",
},
&cli.BoolFlag{
Name: "really-do-it",
Usage: "pass this flag if you know what you are doing",
Expand All @@ -44,6 +49,15 @@ var terminateSectorCmd = &cli.Command{
return fmt.Errorf("at least one sector must be specified")
}

var maddr address.Address
if act := cctx.String("actor"); act != "" {
var err error
maddr, err = address.NewFromString(act)
if err != nil {
return fmt.Errorf("parsing address %s: %w", act, err)
}
}

if !cctx.Bool("really-do-it") {
return fmt.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing")
}
Expand All @@ -54,17 +68,19 @@ var terminateSectorCmd = &cli.Command{
}
defer closer()

api, acloser, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer acloser()

ctx := lcli.ReqContext(cctx)

maddr, err := api.ActorAddress(ctx)
if err != nil {
return err
if maddr.Empty() {
api, acloser, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer acloser()

maddr, err = api.ActorAddress(ctx)
if err != nil {
return err
}
}

mi, err := nodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
Expand Down Expand Up @@ -147,28 +163,45 @@ var terminateSectorPenaltyEstimationCmd = &cli.Command{
Name: "termination-estimate",
Usage: "Estimate the termination penalty",
ArgsUsage: "[sectorNum1 sectorNum2 ...]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "actor",
Usage: "specify the address of miner actor",
},
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() < 1 {
return fmt.Errorf("at least one sector must be specified")
}

nodeApi, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
var maddr address.Address
if act := cctx.String("actor"); act != "" {
var err error
maddr, err = address.NewFromString(act)
if err != nil {
return fmt.Errorf("parsing address %s: %w", act, err)
}
}
defer closer()

api, acloser, err := lcli.GetStorageMinerAPI(cctx)
nodeApi, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer acloser()
defer closer()

ctx := lcli.ReqContext(cctx)

maddr, err := api.ActorAddress(ctx)
if err != nil {
return err
if maddr.Empty() {
api, acloser, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer acloser()

maddr, err = api.ActorAddress(ctx)
if err != nil {
return err
}
}

mi, err := nodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
Expand Down

0 comments on commit 7417a13

Please sign in to comment.