Merge pull request #9113 from filecoin-project/9083-shed-command-for-getting-raw-bytes-stored-in-active-deals
feat: market: Add lotus-shed cmd to get total active deal storage
This commit is contained in:
commit
f023f04b40
@ -185,6 +185,10 @@ func GetDealFees(deal market{{.latestVersion}}.DealProposal, height abi.ChainEpo
|
|||||||
return ef, big.Sub(tf, ef)
|
return ef, big.Sub(tf, ef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsDealActive(state market{{.latestVersion}}.DealState) bool {
|
||||||
|
return state.SectorStartEpoch > -1 && state.SlashEpoch == -1
|
||||||
|
}
|
||||||
|
|
||||||
func labelFromGoString(s string) (market{{.latestVersion}}.DealLabel, error) {
|
func labelFromGoString(s string) (market{{.latestVersion}}.DealLabel, error) {
|
||||||
if utf8.ValidString(s) {
|
if utf8.ValidString(s) {
|
||||||
return market{{.latestVersion}}.NewLabelFromString(s)
|
return market{{.latestVersion}}.NewLabelFromString(s)
|
||||||
|
@ -240,6 +240,10 @@ func GetDealFees(deal market8.DealProposal, height abi.ChainEpoch) (abi.TokenAmo
|
|||||||
return ef, big.Sub(tf, ef)
|
return ef, big.Sub(tf, ef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsDealActive(state market8.DealState) bool {
|
||||||
|
return state.SectorStartEpoch > -1 && state.SlashEpoch == -1
|
||||||
|
}
|
||||||
|
|
||||||
func labelFromGoString(s string) (market8.DealLabel, error) {
|
func labelFromGoString(s string) (market8.DealLabel, error) {
|
||||||
if utf8.ValidString(s) {
|
if utf8.ValidString(s) {
|
||||||
return market8.NewLabelFromString(s)
|
return market8.NewLabelFromString(s)
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/lib/backupds"
|
"github.com/filecoin-project/lotus/lib/backupds"
|
||||||
"github.com/filecoin-project/lotus/node/repo"
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
@ -32,6 +33,7 @@ var marketCmd = &cli.Command{
|
|||||||
marketDealFeesCmd,
|
marketDealFeesCmd,
|
||||||
marketExportDatastoreCmd,
|
marketExportDatastoreCmd,
|
||||||
marketImportDatastoreCmd,
|
marketImportDatastoreCmd,
|
||||||
|
marketDealsTotalStorageCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,6 +285,42 @@ var marketImportDatastoreCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var marketDealsTotalStorageCmd = &cli.Command{
|
||||||
|
Name: "get-deals-total-storage",
|
||||||
|
Usage: "View the total storage available in all active market deals",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, closer, err := lcli.GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
deals, err := api.StateMarketDeals(ctx, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
total := big.Zero()
|
||||||
|
count := 0
|
||||||
|
|
||||||
|
for _, deal := range deals {
|
||||||
|
if market.IsDealActive(deal.State) {
|
||||||
|
dealStorage := big.NewIntUnsigned(uint64(deal.Proposal.PieceSize))
|
||||||
|
total = big.Add(total, dealStorage)
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Total deals: ", count)
|
||||||
|
fmt.Println("Total storage: ", total)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func openLockedRepo(path string) (repo.LockedRepo, error) {
|
func openLockedRepo(path string) (repo.LockedRepo, error) {
|
||||||
// Open the repo at the repo path
|
// Open the repo at the repo path
|
||||||
rpo, err := repo.NewFS(path)
|
rpo, err := repo.NewFS(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user