Skip to content

Commit

Permalink
add lotus-miner storage-deals lwt
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Sep 10, 2021
1 parent 0a04302 commit 027c1b5
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions cmd/lotus-miner/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (
"github.com/libp2p/go-libp2p-core/peer"
"github.com/multiformats/go-multibase"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/xerrors"

cborutil "github.com/filecoin-project/go-cbor-util"
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
Expand Down Expand Up @@ -342,6 +345,7 @@ var storageDealsCmd = &cli.Command{
Subcommands: []*cli.Command{
dealsImportDataCmd,
dealsListCmd,
dealsListWithTransfersCmd,
storageDealSelectionCmd,
setAskCmd,
getAskCmd,
Expand Down Expand Up @@ -891,3 +895,86 @@ var dealsPendingPublish = &cli.Command{
return nil
},
}

var dealsListWithTransfersCmd = &cli.Command{
Name: "list-with-transfers",
Aliases: []string{"lwt"},
Usage: "List all deals with corresponding data transfers for this miner",
Action: func(cctx *cli.Context) error {
node, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := lcli.DaemonContext(cctx)

deals, err := node.MarketListIncompleteDeals(ctx)
if err != nil {
return err
}

channels, err := node.MarketListDataTransfers(ctx)
if err != nil {
return err
}

sort.Slice(deals, func(i, j int) bool {
return deals[i].CreationTime.Time().Before(deals[j].CreationTime.Time())
})

channelsByTransferID := map[datatransfer.TransferID]api.DataTransferChannel{}
for _, c := range channels {
channelsByTransferID[c.TransferID] = c
}

cfg := zap.Config{
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
Encoding: "json",
EncoderConfig: zapcore.EncoderConfig{
TimeKey: zapcore.OmitKey,
LevelKey: zapcore.OmitKey,
NameKey: zapcore.OmitKey,
CallerKey: zapcore.OmitKey,
FunctionKey: zapcore.OmitKey,
MessageKey: zapcore.OmitKey,
StacktraceKey: zapcore.OmitKey,
LineEnding: zapcore.DefaultLineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: zapcore.EpochTimeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
},
OutputPaths: []string{"stdout"},
ErrorOutputPaths: []string{"stdout"},
}

logger, _ := cfg.Build()
defer logger.Sync()

for _, deal := range deals {
fil := types.FIL(types.BigMul(deal.Proposal.StoragePricePerEpoch, types.NewInt(uint64(deal.Proposal.Duration()))))

if deal.TransferChannelId != nil {
if c, ok := channelsByTransferID[deal.TransferChannelId.ID]; ok {
logger.Info("",
zap.String("datetime", deal.CreationTime.Time().Format(time.RFC3339)),
zap.Bool("verified-deal", deal.Proposal.VerifiedDeal),
zap.String("proposal-cid", deal.ProposalCid.String()),
zap.Uint64("deal-id", uint64(deal.DealID)),
zap.String("deal-status", storagemarket.DealStates[deal.State]),
zap.String("client", deal.Proposal.Client.String()),
zap.String("piece-size", units.BytesSize(float64(deal.Proposal.PieceSize))),
zap.String("price", fil.String()),
zap.Int64("duration-epochs", int64(deal.Proposal.Duration())),
zap.Uint64("transfer-id", uint64(c.TransferID)),
zap.String("transfer-status", datatransfer.Statuses[c.Status]),
zap.String("transferred-data", units.BytesSize(float64(c.Transferred))),
)
}
}
}

return nil
},
}

0 comments on commit 027c1b5

Please sign in to comment.