Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for early terminate secotrs manually #4433

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions cmd/lotus-storage-miner/proving.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ import (
"fmt"
"os"
"strconv"
"strings"
"text/tabwriter"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/api/apibstore"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/specs-actors/actors/builtin"
miner0 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
)

var provingCmd = &cli.Command{
Expand All @@ -25,6 +32,7 @@ var provingCmd = &cli.Command{
provingDeadlinesCmd,
provingDeadlineInfoCmd,
provingFaultsCmd,
provingTeminateCmd,
},
}

Expand Down Expand Up @@ -371,3 +379,111 @@ var provingDeadlineInfoCmd = &cli.Command{
return nil
},
}

var provingTeminateCmd = &cli.Command{
Name: "terminate",
Usage: "terminate specied sector early",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "really-do-it",
Usage: "pass this flag if you know what you are doing",
},
&cli.StringFlag{
Name: "sectors",
Usage: "specied sectors[xx,xx,xx]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo? :)

},
},
Action: func(cctx *cli.Context) error {
if !cctx.Bool("really-do-it") {
return xerrors.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing")
}

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

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

ctx := lcli.ReqContext(cctx)

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

mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

if cctx.String("sectors") == "" {
return xerrors.Errorf("sectors must be specied")
}

var sectorStr []string
if strings.Contains(cctx.String("sectors"), ",") {
sectorStr = strings.Split(cctx.String("sectors"), ",")
} else {
sectorStr = append(sectorStr, cctx.String("sectors"))
}

if len(sectorStr) == 0 {
return xerrors.Errorf("sectors length is empty")
}

param := []miner0.TerminationDeclaration{}
for _, s := range sectorStr {
sint, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return err
}

sectorbit := bitfield.New()
sectorbit.Set(sint)

loca, err := api.StateSectorPartition(ctx, maddr, abi.SectorNumber(sint), types.EmptyTSK)
if err != nil {
return xerrors.Errorf("get sector partition %s", err)
}

para := miner0.TerminationDeclaration{
Deadline: loca.Deadline,
Partition: loca.Partition,
Sectors: sectorbit,
}

param = append(param, para)
}

paras := &miner0.TerminateSectorsParams{
Terminations: param,
}

sp, err := actors.SerializeParams(paras)
if err != nil {
return xerrors.Errorf("serializing params: %w", err)
}

smsg, err := api.MpoolPushMessage(ctx, &types.Message{
From: mi.Owner,
To: maddr,
Method: builtin.MethodsMiner.TerminateSectors,

Value: big.Zero(),
Params: sp,
}, nil)
if err != nil {
return xerrors.Errorf("mpool push: %w", err)
}

fmt.Println("Message CID:", smsg.Cid())

return nil
},
}