Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add command to print signer deal detail #298

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ func (m *MarketNodeImpl) MarketListDeals(ctx context.Context, addrs []address.Ad
return m.listDeals(ctx, addrs)
}

func (m *MarketNodeImpl) MarketGetDeal(ctx context.Context, dealPropCid cid.Cid) (*types.MinerDeal, error) {
deal, err := m.Repo.StorageDealRepo().GetDeal(ctx, dealPropCid)
if err != nil {
return nil, err
}
if err := jwtclient.CheckPermissionByMiner(ctx, m.AuthClient, deal.Proposal.Provider); err != nil {
return nil, err
}

return deal, nil
}

// MarketListRetrievalDeals todo add user isolate when is available to get miner from retrieve deal
// 检索订单没法按 `miner address` 过滤
func (m *MarketNodeImpl) MarketListRetrievalDeals(ctx context.Context) ([]types.ProviderDealState, error) {
Expand All @@ -262,6 +274,15 @@ func (m *MarketNodeImpl) MarketListRetrievalDeals(ctx context.Context) ([]types.
return out, nil
}

func (m *MarketNodeImpl) MarketGetRetrievalDeal(ctx context.Context, receiver peer.ID, dealID uint64) (*types.ProviderDealState, error) {
deal, err := m.Repo.RetrievalDealRepo().GetDeal(ctx, receiver, retrievalmarket.DealID(dealID))
if err != nil {
return nil, err
}

return deal, nil
}

func (m *MarketNodeImpl) MarketGetDealUpdates(ctx context.Context) (<-chan types.MinerDeal, error) {
results := make(chan types.MinerDeal)
unsub := m.StorageProvider.SubscribeToEvents(func(evt storagemarket.ProviderEvent, deal *types.MinerDeal) {
Expand Down
83 changes: 83 additions & 0 deletions cli/retrieval-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package cli
import (
"fmt"
"os"
"strconv"
"text/tabwriter"
"time"

"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/urfave/cli/v2"
)

Expand All @@ -24,6 +28,7 @@ var retrievalDealsCmds = &cli.Command{
Usage: "Manage retrieval deals and related configuration",
Subcommands: []*cli.Command{
retrievalDealsListCmd,
getRetrievalDealCmd,
},
}

Expand Down Expand Up @@ -65,3 +70,81 @@ var retrievalDealsListCmd = &cli.Command{
return w.Flush()
},
}

var getRetrievalDealCmd = &cli.Command{
Name: "get",
Usage: "Print a retrieval deal",
ArgsUsage: "<receiver> <dealID>",
Action: func(cliCtx *cli.Context) error {
api, closer, err := NewMarketNode(cliCtx)
if err != nil {
return err
}
defer closer()

if cliCtx.NArg() != 2 {
return fmt.Errorf("expected 2 arguments")
}

receiver, err := peer.Decode(cliCtx.Args().First())
if err != nil {
return err
}
dealID, err := strconv.ParseUint(cliCtx.Args().Get(1), 10, 64)
if err != nil {
return err
}

ctx := ReqContext(cliCtx)
deal, err := api.MarketGetRetrievalDeal(ctx, receiver, dealID)
if err != nil {
return err
}

return outputRetrievalDeal(deal)
},
}

func outputRetrievalDeal(deal *market.ProviderDealState) error {
var channelID, pieceCID string
var raw []byte
if deal.ChannelID != nil {
channelID = deal.ChannelID.String()
}
if deal.PieceCID != nil {
pieceCID = deal.PieceCID.String()
}
if deal.Selector != nil {
raw = deal.Selector.Raw
}
data := []kv{
{"Receiver", deal.Receiver},
{"DealID", deal.ID},
{"PayloadCID", deal.PayloadCID},
{"Status", retrievalmarket.DealStatuses[deal.Status]},
{"PricePerByte", deal.PricePerByte.String()},
{"BytesSent", deal.TotalSent},
{"Paid", deal.FundsReceived},
{"Interval", deal.CurrentInterval},
{"Message", deal.Message},
{"ChannelID", channelID},
{"StoreID", deal.StoreID},
{"SelStorageProposalCid", deal.SelStorageProposalCid},
{"PieceCID", pieceCID},
{"PaymentIntervalIncrease", deal.PaymentIntervalIncrease},
{"UnsealPrice", deal.UnsealPrice},
{"Selector", raw},
{"CreatedAt", time.Unix(int64(deal.CreatedAt), 0).Format(time.RFC3339)},
{"UpdatedAt", time.Unix(int64(deal.UpdatedAt), 0).Format(time.RFC3339)},
}

maxLen := len("PaymentIntervalIncrease")
for _, d := range data {
for i := len(d.k); i < maxLen; i++ {
d.k += " "
}
fmt.Println(d.k, d.v)
}

return nil
}
105 changes: 105 additions & 0 deletions cli/storage-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var storageDealsCmds = &cli.Command{
dealsListCmd,
updateStorageDealStateCmd,
dealsPendingPublish,
getDealCmd,
},
}

Expand Down Expand Up @@ -362,6 +363,37 @@ var dealsPendingPublish = &cli.Command{
},
}

var getDealCmd = &cli.Command{
Name: "get",
Usage: "Print a storage deal",
ArgsUsage: "<proposal cid>",
Action: func(cliCtx *cli.Context) error {
if cliCtx.NArg() != 1 {
return fmt.Errorf("expected 1 arguments")
}

api, closer, err := NewMarketNode(cliCtx)
if err != nil {
return err
}
defer closer()

proposalCid, err := cid.Decode(cliCtx.Args().First())
if err != nil {
return err
}

ctx := ReqContext(cliCtx)

deal, err := api.MarketGetDeal(ctx, proposalCid)
if err != nil {
return err
}

return outputStorageDeal(deal)
},
}

func outputStorageDeals(out io.Writer, deals []market.MinerDeal, verbose bool) error {
sort.Slice(deals, func(i, j int) bool {
return deals[i].CreationTime.Time().Before(deals[j].CreationTime.Time())
Expand Down Expand Up @@ -416,3 +448,76 @@ func outputStorageDeals(out io.Writer, deals []market.MinerDeal, verbose bool) e

return w.Flush()
}

type kv struct {
k string
v interface{}
}

func outputStorageDeal(deal *market.MinerDeal) error {
var err error
var transferChannelID, label, addFundsCid, publishCid string

if deal.TransferChannelID != nil {
transferChannelID = deal.TransferChannelID.String()
}
label, err = deal.Proposal.Label.ToString()
if err != nil {
return err
}
if deal.AddFundsCid != nil {
addFundsCid = deal.AddFundsCid.String()
}
if deal.PublishCid != nil {
publishCid = deal.PublishCid.String()
}
fil := types.FIL(types.BigMul(deal.Proposal.StoragePricePerEpoch, types.NewInt(uint64(deal.Proposal.Duration()))))

data := []kv{
{"Creation", deal.CreationTime.Time().Format(time.RFC3339)},
{"State", storagemarket.DealStates[deal.State]},
{"VerifiedDeal", deal.Proposal.VerifiedDeal},
{"DealID", deal.DealID},
{"PieceCID", deal.Proposal.PieceCID},
{"PieceStatus", deal.PieceStatus},
{"Provider", deal.Proposal.Provider},
{"PieceSize", units.BytesSize(float64(deal.Proposal.PieceSize))},
{"Price", fil},
{"Duration", deal.Proposal.Duration()},
{"Offset", deal.Offset},
{"Client", deal.Proposal.Client},
{"TransferID", transferChannelID},
{"AddFundsCid", addFundsCid},
{"PublishCid", publishCid},
{"Message", deal.Message},
{"TransferType", deal.Ref.TransferType},
{"PayloadCID", deal.Ref.Root},
{"PayloadSize", deal.PayloadSize},
{"StartEpoch", deal.Proposal.StartEpoch},
{"EndEpoch", deal.Proposal.EndEpoch},
{"SlashEpoch", deal.SlashEpoch},
{"StoragePricePerEpoch", deal.Proposal.StoragePricePerEpoch},
{"ProviderCollateral", deal.Proposal.ProviderCollateral},
{"ClientCollateral", deal.Proposal.ClientCollateral},
{"Label", label},
{"MinerPeerID", deal.Miner.Pretty()},
{"ClientPeerID", deal.Client.Pretty()},
{"FundsReserved", deal.FundsReserved},
{"AvailableForRetrieval", deal.AvailableForRetrieval},
{"SectorNumber", deal.SectorNumber},
{"PiecePath", deal.PiecePath},
{"MetadataPath", deal.MetadataPath},
{"FastRetrieval", deal.FastRetrieval},
{"InboundCAR", deal.InboundCAR},
{"UpdatedAt", time.Unix(int64(deal.UpdatedAt), 0).Format(time.RFC3339)},
}
maxLen := len("AvailableForRetrieval")
for _, d := range data {
for i := len(d.k); i < maxLen; i++ {
d.k += " "
}
fmt.Println(d.k, d.v)
}

return nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/specs-actors/v2 v2.3.6
github.com/filecoin-project/specs-actors/v7 v7.0.1
github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4
github.com/filecoin-project/venus v1.10.2-0.20230316084941-2180049a244b
github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e
github.com/filecoin-project/venus-messager v1.10.2-0.20230309071456-7cd8d49c6e9a
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -82,7 +82,7 @@ require (
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
go.mongodb.org/mongo-driver v1.8.4
go.opencensus.io v0.23.0
go.uber.org/fx v1.15.0
go.uber.org/fx v1.17.1
go.uber.org/multierr v1.8.0
golang.org/x/sync v0.0.0-20220907140024-f12130a52804
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2
Expand Down Expand Up @@ -289,7 +289,7 @@ require (
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/dig v1.12.0 // indirect
go.uber.org/dig v1.14.1 // indirect
go.uber.org/zap v1.23.0 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893
github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893/go.mod h1:S7590oDimBvXMUtzWsBXoshu9HtYKwtXl47zAK9rcP8=
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v1.2.4/go.mod h1:hJULXHGAnWuq5S5KRtPkwbT8DqgM9II7NwyNU7t59D0=
github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4 h1:yLcesIYnlrkLc9dVgIfMtNu11+sF5jeQP1ykTOhjCDg=
github.com/filecoin-project/venus v1.10.2-0.20230309014040-73746cec80e4/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8=
github.com/filecoin-project/venus v1.10.2-0.20230316084941-2180049a244b h1:T0TIlKIFsOvOKDIADN4P7xBC+coJ7YlbUqift11TCIE=
github.com/filecoin-project/venus v1.10.2-0.20230316084941-2180049a244b/go.mod h1:d6XlyUBZd+SHydYimTTkUr3O5rjYOHQTsydI4Nxy6U8=
github.com/filecoin-project/venus-auth v1.3.2/go.mod h1:m5Jog2GYxztwP7w3m/iJdv/V1/bTcAVU9rm/CbhxRQU=
github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e h1:Bxpt1AzPeNxmUnFT2Y8rpabr9x0wIC0Q87DeRmjL2co=
github.com/filecoin-project/venus-auth v1.10.2-0.20230308100319-913815325d5e/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs=
Expand Down Expand Up @@ -2275,10 +2275,12 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/dig v1.12.0 h1:l1GQeZpEbss0/M4l/ZotuBndCrkMdjnygzgcuOjAdaY=
go.uber.org/dig v1.12.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
go.uber.org/fx v1.15.0 h1:kcfBpAm98n0ksanyyZLFE/Q3T7yPi13Ge2liu3TxR+A=
go.uber.org/dig v1.14.1 h1:fyakRgZDdi2F8FgwJJoRGangMSPTIxPSLGzR3Oh0/54=
go.uber.org/dig v1.14.1/go.mod h1:52EKx/Vjdpz9EzeNcweC4YMsTrDdFn9mS/+Uw5ZnVTI=
go.uber.org/fx v1.15.0/go.mod h1:jI3RazQUhGv5KkpZIRv+kuP4CcgX3fnc0qX8bLnzbx8=
go.uber.org/fx v1.17.1 h1:S42dZ6Pok8hQ3jxKwo6ZMYcCgHQA/wAS/gnpRa1Pksg=
go.uber.org/fx v1.17.1/go.mod h1:yO7KN5rhlARljyo4LR047AjaV6J+KFzd/Z7rnTbEn0A=
go.uber.org/goleak v1.0.0/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
Expand Down Expand Up @@ -2403,7 +2405,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
Expand Down