From 754f294992fd292a706d4e55305ee51162b59264 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 14 Dec 2022 16:37:42 -0500 Subject: [PATCH 1/2] Add cli command for removing expired claims --- cli/filplus.go | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/cli/filplus.go b/cli/filplus.go index 0e81ccd3e36..7f469b4d9d2 100644 --- a/cli/filplus.go +++ b/cli/filplus.go @@ -44,6 +44,7 @@ var filplusCmd = &cli.Command{ filplusSignRemoveDataCapProposal, filplusListAllocationsCmd, filplusRemoveExpiredAllocationsCmd, + filplusRemoveExpiredClaimsCmd, }, } @@ -403,6 +404,99 @@ var filplusRemoveExpiredAllocationsCmd = &cli.Command{ }, } +var filplusRemoveExpiredClaimsCmd = &cli.Command{ + Name: "remove-expired-claims", + Usage: "remove expired claims (if no claims are specified all eligible claims are removed)", + ArgsUsage: "providerAddress Optional[...claimId]", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "from", + Usage: "optionally specify the account to send the message from", + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.NArg() < 1 { + return IncorrectNumArgs(cctx) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + args := cctx.Args().Slice() + + providerAddr, err := address.NewFromString(args[0]) + if err != nil { + return err + } + + providerIdAddr, err := api.StateLookupID(ctx, providerAddr, types.EmptyTSK) + if err != nil { + return err + } + + providerId, err := address.IDFromAddress(providerIdAddr) + if err != nil { + return err + } + + fromAddr := providerIdAddr + if from := cctx.String("from"); from != "" { + addr, err := address.NewFromString(from) + if err != nil { + return err + } + + fromAddr = addr + } + + claimIDs := make([]verifregtypes9.ClaimId, len(args)-1) + for i, claimStr := range args[1:] { + id, err := strconv.ParseUint(claimStr, 10, 64) + if err != nil { + return err + } + claimIDs[i] = verifregtypes9.ClaimId(id) + } + + params, err := actors.SerializeParams(&verifregtypes9.RemoveExpiredClaimsParams{ + Provider: abi.ActorID(providerId), + ClaimIds: claimIDs, + }) + if err != nil { + return err + } + + msg := &types.Message{ + To: verifreg.Address, + From: fromAddr, + Method: verifreg.Methods.RemoveExpiredClaims, + Params: params, + } + + smsg, err := api.MpoolPushMessage(ctx, msg, nil) + if err != nil { + return err + } + + fmt.Printf("message sent, now waiting on cid: %s\n", smsg.Cid()) + + mwait, err := api.StateWaitMsg(ctx, smsg.Cid(), build.MessageConfidence) + if err != nil { + return err + } + + if mwait.Receipt.ExitCode.IsError() { + return fmt.Errorf("failed to remove expired allocations: %d", mwait.Receipt.ExitCode) + } + + return nil + }, +} + var filplusCheckClientCmd = &cli.Command{ Name: "check-client-datacap", Usage: "check verified client remaining bytes", From 6ca975e83a3471970aa0d406b858fc0e3c7b00dc Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 14 Dec 2022 16:55:50 -0500 Subject: [PATCH 2/2] Add cli command to get a list of claims --- cli/filplus.go | 86 +++++++++++++++++++++++++++++++++++ documentation/en/cli-lotus.md | 28 ++++++++++++ 2 files changed, 114 insertions(+) diff --git a/cli/filplus.go b/cli/filplus.go index 7f469b4d9d2..9fbd2a489ad 100644 --- a/cli/filplus.go +++ b/cli/filplus.go @@ -43,6 +43,7 @@ var filplusCmd = &cli.Command{ filplusCheckNotaryCmd, filplusSignRemoveDataCapProposal, filplusListAllocationsCmd, + filplusListClaimsCmd, filplusRemoveExpiredAllocationsCmd, filplusRemoveExpiredClaimsCmd, }, @@ -311,6 +312,91 @@ var filplusListAllocationsCmd = &cli.Command{ }, } +var filplusListClaimsCmd = &cli.Command{ + Name: "list-claims", + Usage: "List claims made by provider", + ArgsUsage: "providerAddress", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "expired", + Usage: "list only expired claims", + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + providerAddr, err := address.NewFromString(cctx.Args().Get(0)) + if err != nil { + return err + } + + providerIdAddr, err := api.StateLookupID(ctx, providerAddr, types.EmptyTSK) + if err != nil { + return err + } + + store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api))) + + verifregActor, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK) + if err != nil { + return err + } + + verifregState, err := verifreg.Load(store, verifregActor) + if err != nil { + return err + } + + ts, err := api.ChainHead(ctx) + if err != nil { + return err + } + + claimsMap, err := verifregState.GetClaims(providerIdAddr) + if err != nil { + return err + } + + tw := tablewriter.New( + tablewriter.Col("ID"), + tablewriter.Col("Provider"), + tablewriter.Col("Client"), + tablewriter.Col("Data"), + tablewriter.Col("Size"), + tablewriter.Col("TermMin"), + tablewriter.Col("TermMax"), + tablewriter.Col("TermStart"), + tablewriter.Col("Sector"), + ) + + for claimId, claim := range claimsMap { + if ts.Height() > claim.TermMax || !cctx.IsSet("expired") { + tw.Write(map[string]interface{}{ + "ID": claimId, + "Provider": claim.Provider, + "Client": claim.Client, + "Data": claim.Data, + "Size": claim.Size, + "TermMin": claim.TermMin, + "TermMax": claim.TermMax, + "TermStart": claim.TermStart, + "Sector": claim.Sector, + }) + } + } + return tw.Flush(os.Stdout) + }, +} + var filplusRemoveExpiredAllocationsCmd = &cli.Command{ Name: "remove-expired-allocations", Usage: "remove expired allocations (if no allocations are specified all eligible allocations are removed)", diff --git a/documentation/en/cli-lotus.md b/documentation/en/cli-lotus.md index 2f662f017cd..86ce59ba442 100644 --- a/documentation/en/cli-lotus.md +++ b/documentation/en/cli-lotus.md @@ -1210,7 +1210,9 @@ COMMANDS: check-notary-datacap check a notary's remaining bytes sign-remove-data-cap-proposal allows a notary to sign a Remove Data Cap Proposal list-allocations List allocations made by client + list-claims List claims made by provider remove-expired-allocations remove expired allocations (if no allocations are specified all eligible allocations are removed) + remove-expired-claims remove expired claims (if no claims are specified all eligible claims are removed) help, h Shows a list of commands or help for one command OPTIONS: @@ -1309,6 +1311,19 @@ OPTIONS: ``` +### lotus filplus list-claims +``` +NAME: + lotus filplus list-claims - List claims made by provider + +USAGE: + lotus filplus list-claims [command options] providerAddress + +OPTIONS: + --expired list only expired claims (default: false) + +``` + ### lotus filplus remove-expired-allocations ``` NAME: @@ -1322,6 +1337,19 @@ OPTIONS: ``` +### lotus filplus remove-expired-claims +``` +NAME: + lotus filplus remove-expired-claims - remove expired claims (if no claims are specified all eligible claims are removed) + +USAGE: + lotus filplus remove-expired-claims [command options] providerAddress Optional[...claimId] + +OPTIONS: + --from value optionally specify the account to send the message from + +``` + ## lotus paych ``` NAME: