From 44e81424f22fbfc95ae0da75049520376bee57d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 8 Jul 2021 19:39:58 +0200 Subject: [PATCH] Print completed deal stats in miner info --- cmd/lotus-storage-miner/info.go | 44 ++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 7a4e316ed..b909d9ff7 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -17,6 +17,7 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" + "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -227,26 +228,26 @@ func infoCmdAct(cctx *cli.Context) error { type dealStat struct { count, verifCount int - bytes, verifBytes abi.PaddedPieceSize + bytes, verifBytes uint64 } dsAdd := func(ds *dealStat, deal storagemarket.MinerDeal) { ds.count++ - ds.bytes += deal.Proposal.PieceSize + ds.bytes += uint64(deal.Proposal.PieceSize) if deal.Proposal.VerifiedDeal { ds.verifCount++ - ds.verifBytes += deal.Proposal.PieceSize + ds.verifBytes += uint64(deal.Proposal.PieceSize) } } showDealStates := map[storagemarket.StorageDealStatus]struct{}{ - storagemarket.StorageDealActive: {}, - storagemarket.StorageDealTransferring: {}, - storagemarket.StorageDealStaged: {}, - storagemarket.StorageDealAwaitingPreCommit: {}, - storagemarket.StorageDealSealing: {}, - storagemarket.StorageDealPublish: {}, + storagemarket.StorageDealActive: {}, + storagemarket.StorageDealTransferring: {}, + storagemarket.StorageDealStaged: {}, + storagemarket.StorageDealAwaitingPreCommit: {}, + storagemarket.StorageDealSealing: {}, + storagemarket.StorageDealPublish: {}, storagemarket.StorageDealCheckForAcceptance: {}, - storagemarket.StorageDealPublishing: {}, + storagemarket.StorageDealPublishing: {}, } var total dealStat @@ -271,7 +272,7 @@ func infoCmdAct(cctx *cli.Context) error { for status, stat := range perState { st := strings.TrimPrefix(storagemarket.DealStates[status], "StorageDeal") sorted = append(sorted, wstr{ - str: fmt.Sprintf(" %s:\t%d\t\t%s\t(Verified: %d\t%s)\n", st, stat.count, types.SizeStr(types.NewInt(uint64(stat.bytes))), stat.verifCount, types.SizeStr(types.NewInt(uint64(stat.verifBytes)))), + str: fmt.Sprintf(" %s:\t%d\t\t%s\t(Verified: %d\t%s)\n", st, stat.count, types.SizeStr(types.NewInt(stat.bytes)), stat.verifCount, types.SizeStr(types.NewInt(stat.verifBytes))), status: status, }, ) @@ -283,14 +284,33 @@ func infoCmdAct(cctx *cli.Context) error { return sorted[i].status > sorted[j].status }) - fmt.Printf("Storage Deals: %d, %s\n", total.count, types.SizeStr(types.NewInt(uint64(total.bytes)))) + fmt.Printf("Storage Deals: %d, %s\n", total.count, types.SizeStr(types.NewInt(total.bytes))) + tw := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0) for _, e := range sorted { _, _ = tw.Write([]byte(e.str)) } + _ = tw.Flush() fmt.Println() + retrievals, err := nodeApi.MarketListRetrievalDeals(ctx) + if err != nil { + return xerrors.Errorf("getting retrieval deal list: %w", err) + } + + var retrComplete dealStat + for _, retrieval := range retrievals { + if retrieval.Status == retrievalmarket.DealStatusCompleted { + retrComplete.count++ + retrComplete.bytes += retrieval.TotalSent + } + } + + fmt.Printf("Retrieval Deals (complete): %d, %s\n", retrComplete.count, types.SizeStr(types.NewInt(retrComplete.bytes))) + + fmt.Println() + spendable := big.Zero() // NOTE: there's no need to unlock anything here. Funds only