Add termination-estimate
to get an estimation for how much a termination penalty will be:
- Usage example: `./lotus-shed sectors termation-estimate 5 8 10`.
This commit is contained in:
parent
3d02dba5dc
commit
2f4582147a
@ -25,6 +25,7 @@ var sectorsCmd = &cli.Command{
|
|||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
terminateSectorCmd,
|
terminateSectorCmd,
|
||||||
|
terminateSectorPenaltyEstimationCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,3 +132,101 @@ var terminateSectorCmd = &cli.Command{
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findPenaltyInInternalExecutions(prefix string, trace []types.ExecutionTrace) {
|
||||||
|
for _, im := range trace {
|
||||||
|
if im.Msg.To.String() == "f099" /*Burn actor*/ {
|
||||||
|
fmt.Printf("Estimated termination penalty: %s attoFIL\n", im.Msg.Value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
findPenaltyInInternalExecutions(prefix+"\t", im.Subcalls)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var terminateSectorPenaltyEstimationCmd = &cli.Command{
|
||||||
|
Name: "termination-estimate",
|
||||||
|
Usage: "Estimate the termination penalty",
|
||||||
|
ArgsUsage: "[sectorNum1 sectorNum2 ...]",
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
mi, err := nodeApi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
terminationDeclarationParams := []miner2.TerminationDeclaration{}
|
||||||
|
|
||||||
|
for _, sn := range cctx.Args().Slice() {
|
||||||
|
sectorNum, err := strconv.ParseUint(sn, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not parse sector number: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sectorbit := bitfield.New()
|
||||||
|
sectorbit.Set(sectorNum)
|
||||||
|
|
||||||
|
loca, err := nodeApi.StateSectorPartition(ctx, maddr, abi.SectorNumber(sectorNum), types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get state sector partition %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
para := miner2.TerminationDeclaration{
|
||||||
|
Deadline: loca.Deadline,
|
||||||
|
Partition: loca.Partition,
|
||||||
|
Sectors: sectorbit,
|
||||||
|
}
|
||||||
|
|
||||||
|
terminationDeclarationParams = append(terminationDeclarationParams, para)
|
||||||
|
}
|
||||||
|
|
||||||
|
terminateSectorParams := &miner2.TerminateSectorsParams{
|
||||||
|
Terminations: terminationDeclarationParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
sp, err := actors.SerializeParams(terminateSectorParams)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("serializing params: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &types.Message{
|
||||||
|
From: mi.Owner,
|
||||||
|
To: maddr,
|
||||||
|
Method: miner.Methods.TerminateSectors,
|
||||||
|
|
||||||
|
Value: big.Zero(),
|
||||||
|
Params: sp,
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: 4667 add an option to give a more precise estimation with pending termination penalty excluded
|
||||||
|
|
||||||
|
invocResult, err := nodeApi.StateCall(ctx, msg, types.TipSetKey{})
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("fail to state call: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
findPenaltyInInternalExecutions("\t", invocResult.ExecutionTrace.Subcalls)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user