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: supportting update deal pieces state #105

Merged
merged 1 commit into from
Mar 8, 2022
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
7 changes: 5 additions & 2 deletions api/impl/market_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ type MarketEventAPI struct {
Event marketevent.IMarketEventAPI `optional:"true"`
}

var errNotSupportGateWayMode = xerrors.Errorf("MarketEvent api supported only when it runs in 'solo' mode")


func (marketEvent *MarketEventAPI) ResponseMarketEvent(ctx context.Context, resp *gateway.ResponseEvent) error {
if marketEvent.Event == nil {
return xerrors.Errorf("unsupport in gateway model")
return errNotSupportGateWayMode
}
return marketEvent.Event.ResponseMarketEvent(ctx, resp)
}

func (marketEvent *MarketEventAPI) ListenMarketEvent(ctx context.Context, policy *gateway.MarketRegisterPolicy) (<-chan *gateway.RequestEvent, error) {
if marketEvent.Event == nil {
return nil, xerrors.Errorf("unsupport in gateway model")
return nil, errNotSupportGateWayMode
}
return marketEvent.Event.ListenMarketEvent(ctx, policy)
}
21 changes: 13 additions & 8 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,16 @@ func (m MarketNodeImpl) MarketListRetrievalDeals(ctx context.Context, mAddr addr
return out, nil
}

func (m MarketNodeImpl) MarketGetDealUpdates(ctx context.Context) (<-chan storagemarket.MinerDeal, error) {
results := make(chan storagemarket.MinerDeal)
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 storagemarket.MinerDeal) {
mDeal, err := m.Repo.StorageDealRepo().GetDeal(ctx, deal.ProposalCid)
if err != nil {
log.Errorf("find deal by proposalCid failed:%s", err.Error())
return
}
select {
case results <- deal:
case results <- *mDeal:
case <-ctx.Done():
}
})
Expand All @@ -159,7 +164,7 @@ func (m MarketNodeImpl) MarketGetDealUpdates(ctx context.Context) (<-chan storag
return results, nil
}

func (m MarketNodeImpl) MarketListIncompleteDeals(ctx context.Context, mAddr address.Address) ([]storagemarket.MinerDeal, error) {
func (m MarketNodeImpl) MarketListIncompleteDeals(ctx context.Context, mAddr address.Address) ([]types.MinerDeal, error) {
var deals []*types.MinerDeal
var err error
if mAddr == address.Undef {
Expand All @@ -174,16 +179,16 @@ func (m MarketNodeImpl) MarketListIncompleteDeals(ctx context.Context, mAddr add
}
}

resDeals := make([]storagemarket.MinerDeal, len(deals))
resDeals := make([]types.MinerDeal, len(deals))
for idx, deal := range deals {
resDeals[idx] = *deal.FilMarketMinerDeal()
resDeals[idx] = *deal
}

return resDeals, nil
}

func (m MarketNodeImpl) UpdateStorageDealStatus(ctx context.Context, dealProposal cid.Cid, state storagemarket.StorageDealStatus) error {
return m.Repo.StorageDealRepo().UpdateDealStatus(ctx, dealProposal, state)
func (m MarketNodeImpl) UpdateStorageDealStatus(ctx context.Context, dealProposal cid.Cid, state storagemarket.StorageDealStatus, pieceState string) error {
return m.Repo.StorageDealRepo().UpdateDealStatus(ctx, dealProposal, state, pieceState)
}

func (m MarketNodeImpl) MarketSetAsk(ctx context.Context, mAddr address.Address, price vTypes.BigInt, verifiedPrice vTypes.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var actorSetPeeridCmd = &cli.Command{

var actorInfoCmd = &cli.Command{
Name: "info",
Usage: "query info of your miner",
Usage: "query info of specified miner",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "miner",
Expand Down Expand Up @@ -286,4 +286,4 @@ var actorInfoCmd = &cli.Command{

return nil
},
}
}
79 changes: 69 additions & 10 deletions cli/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"fmt"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/venus-market/storageprovider"
"github.com/filecoin-project/venus/venus-shared/types/market"
"io"
"log"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"text/tabwriter"
"time"

Expand Down Expand Up @@ -443,6 +445,31 @@ var dealsListCmd = &cli.Command{
},
}

var dealStateUsage = func() string {
const c, spliter = 5, " | "
size := len(storageprovider.StringToStorageState)
states := make([]string, 0, size+size/c)
idx := 0
for s, _ := range storageprovider.StringToStorageState {
states = append(states, s)
idx++
states = append(states, spliter)
if idx%c == 0 {
states = append(states, "\n\t")
continue
}
}

usage := strings.Join(states, "")
{
size := len(usage)
if size > 3 && usage[size-3:] == spliter {
usage = usage[:size-3]
}
}
return usage + ", set to 'StorageDealUnknown' means no change"
}

var updateStorageDealStateCmd = &cli.Command{
Name: "update",
Usage: "update deal status",
Expand All @@ -451,9 +478,18 @@ var updateStorageDealStateCmd = &cli.Command{
Name: "proposalcid",
Required: true,
},
&cli.BoolFlag{
Name: "really-do-it",
Usage: "Actually send transaction performing the action",
Value: false,
},
&cli.StringFlag{
Name: "state",
Required: true,
Name: "piece-state",
Usage: "Undefine | Assigned | Packing | Proving, empty means no change",
},
&cli.StringFlag{
Name: "state",
Usage: dealStateUsage(),
},
},
Action: func(cctx *cli.Context) error {
Expand All @@ -468,22 +504,44 @@ var updateStorageDealStateCmd = &cli.Command{
if err != nil {
return err
}
state := storageprovider.StringToStorageState[cctx.String("state")]
return api.UpdateStorageDealStatus(ctx, proposalCid, state)
var isParamOk bool
var state storagemarket.StorageDealStatus
var pieceState string

if cctx.IsSet("state") {
isParamOk = true
state = storageprovider.StringToStorageState[cctx.String("state")]
}

if cctx.IsSet("piece-state") {
pieceState = cctx.String("piece-state")
isParamOk = true
}

if !isParamOk {
return xerrors.Errorf("must set 'state' or 'piece-state'")
}

if !cctx.Bool("really-do-it") {
fmt.Println("Pass --really-do-it to actually execute this action")
return nil
}

return api.UpdateStorageDealStatus(ctx, proposalCid, state, pieceState)
},
}

func outputStorageDeals(out io.Writer, deals []storagemarket.MinerDeal, verbose bool) error {
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())
})

w := tabwriter.NewWriter(out, 2, 4, 2, ' ', 0)

if verbose {
_, _ = fmt.Fprintf(w, "Creation\tVerified\tProposalCid\tDealId\tState\tClient\tProvider\tSize\tPrice\tDuration\tTransferChannelID\tAddFundCid\tPublishCid\tMessage\n")
_, _ = fmt.Fprintf(w, "Creation\tVerified\tProposalCid\tDealId\tState\tPieceState\tClient\tProvider\tSize\tPrice\tDuration\tTransferChannelID\tAddFundCid\tPublishCid\tMessage\n")
} else {
_, _ = fmt.Fprintf(w, "ProposalCid\tDealId\tState\tClient\tProvider\tSize\tPrice\tDuration\n")
_, _ = fmt.Fprintf(w, "ProposalCid\tDealId\tState\tPieceState\tClient\tProvider\tSize\tPrice\tDuration\n")
}

for _, deal := range deals {
Expand All @@ -498,11 +556,12 @@ func outputStorageDeals(out io.Writer, deals []storagemarket.MinerDeal, verbose
_, _ = fmt.Fprintf(w, "%s\t%t\t", deal.CreationTime.Time().Format(time.Stamp), deal.Proposal.VerifiedDeal)
}

_, _ = fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s", propcid, deal.DealID, storagemarket.DealStates[deal.State], deal.Proposal.Client, deal.Proposal.Provider, units.BytesSize(float64(deal.Proposal.PieceSize)), fil, deal.Proposal.Duration())
_, _ = fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s", propcid, deal.DealID, storagemarket.DealStates[deal.State], deal.PieceStatus,
deal.Proposal.Client, deal.Proposal.Provider, units.BytesSize(float64(deal.Proposal.PieceSize)), fil, deal.Proposal.Duration())
if verbose {
tchid := ""
if deal.TransferChannelId != nil {
tchid = deal.TransferChannelId.String()
if deal.TransferChannelID != nil {
tchid = deal.TransferChannelID.String()
}

addFundcid := ""
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1
github.com/filecoin-project/specs-storage v0.2.0
github.com/filecoin-project/venus v1.2.0-rc6
github.com/filecoin-project/venus v1.2.3-0.20220308015952-1748f646f03b
github.com/filecoin-project/venus-auth v1.3.2
github.com/filecoin-project/venus-messager v1.4.0-rc2.0.20220218091700-29caa578c124
github.com/gbrlsnchs/jwt/v3 v3.0.1
Expand Down
Loading