Merge pull request #6708 from filecoin-project/feat/miner-info-deals
Add more deal details to lotus-miner info
This commit is contained in:
commit
4433c3cd7c
@ -5,7 +5,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
corebig "math/big"
|
corebig "math/big"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
@ -14,6 +17,7 @@ import (
|
|||||||
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
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-fil-markets/storagemarket"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
@ -222,29 +226,89 @@ func infoCmdAct(cctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var nactiveDeals, nVerifDeals, ndeals uint64
|
type dealStat struct {
|
||||||
var activeDealBytes, activeVerifDealBytes, dealBytes abi.PaddedPieceSize
|
count, verifCount int
|
||||||
for _, deal := range deals {
|
bytes, verifBytes uint64
|
||||||
if deal.State == storagemarket.StorageDealError {
|
}
|
||||||
continue
|
dsAdd := func(ds *dealStat, deal storagemarket.MinerDeal) {
|
||||||
}
|
ds.count++
|
||||||
|
ds.bytes += uint64(deal.Proposal.PieceSize)
|
||||||
ndeals++
|
if deal.Proposal.VerifiedDeal {
|
||||||
dealBytes += deal.Proposal.PieceSize
|
ds.verifCount++
|
||||||
|
ds.verifBytes += uint64(deal.Proposal.PieceSize)
|
||||||
if deal.State == storagemarket.StorageDealActive {
|
|
||||||
nactiveDeals++
|
|
||||||
activeDealBytes += deal.Proposal.PieceSize
|
|
||||||
|
|
||||||
if deal.Proposal.VerifiedDeal {
|
|
||||||
nVerifDeals++
|
|
||||||
activeVerifDealBytes += deal.Proposal.PieceSize
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Deals: %d, %s\n", ndeals, types.SizeStr(types.NewInt(uint64(dealBytes))))
|
showDealStates := map[storagemarket.StorageDealStatus]struct{}{
|
||||||
fmt.Printf("\tActive: %d, %s (Verified: %d, %s)\n", nactiveDeals, types.SizeStr(types.NewInt(uint64(activeDealBytes))), nVerifDeals, types.SizeStr(types.NewInt(uint64(activeVerifDealBytes))))
|
storagemarket.StorageDealActive: {},
|
||||||
|
storagemarket.StorageDealTransferring: {},
|
||||||
|
storagemarket.StorageDealStaged: {},
|
||||||
|
storagemarket.StorageDealAwaitingPreCommit: {},
|
||||||
|
storagemarket.StorageDealSealing: {},
|
||||||
|
storagemarket.StorageDealPublish: {},
|
||||||
|
storagemarket.StorageDealCheckForAcceptance: {},
|
||||||
|
storagemarket.StorageDealPublishing: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
var total dealStat
|
||||||
|
perState := map[storagemarket.StorageDealStatus]*dealStat{}
|
||||||
|
for _, deal := range deals {
|
||||||
|
if _, ok := showDealStates[deal.State]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if perState[deal.State] == nil {
|
||||||
|
perState[deal.State] = new(dealStat)
|
||||||
|
}
|
||||||
|
|
||||||
|
dsAdd(&total, deal)
|
||||||
|
dsAdd(perState[deal.State], deal)
|
||||||
|
}
|
||||||
|
|
||||||
|
type wstr struct {
|
||||||
|
str string
|
||||||
|
status storagemarket.StorageDealStatus
|
||||||
|
}
|
||||||
|
sorted := make([]wstr, 0, len(perState))
|
||||||
|
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(stat.bytes)), stat.verifCount, types.SizeStr(types.NewInt(stat.verifBytes))),
|
||||||
|
status: status,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
sort.Slice(sorted, func(i, j int) bool {
|
||||||
|
if sorted[i].status == storagemarket.StorageDealActive || sorted[j].status == storagemarket.StorageDealActive {
|
||||||
|
return sorted[i].status == storagemarket.StorageDealActive
|
||||||
|
}
|
||||||
|
return sorted[i].status > sorted[j].status
|
||||||
|
})
|
||||||
|
|
||||||
|
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()
|
fmt.Println()
|
||||||
|
|
||||||
spendable := big.Zero()
|
spendable := big.Zero()
|
||||||
|
@ -454,6 +454,11 @@ func (sm *StorageMinerAPI) MarketListRetrievalDeals(ctx context.Context) ([]retr
|
|||||||
deals := sm.RetrievalProvider.ListDeals()
|
deals := sm.RetrievalProvider.ListDeals()
|
||||||
|
|
||||||
for _, deal := range deals {
|
for _, deal := range deals {
|
||||||
|
if deal.ChannelID != nil {
|
||||||
|
if deal.ChannelID.Initiator == "" || deal.ChannelID.Responder == "" {
|
||||||
|
deal.ChannelID = nil // don't try to push unparsable peer IDs over jsonrpc
|
||||||
|
}
|
||||||
|
}
|
||||||
out = append(out, deal)
|
out = append(out, deal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user