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 cli to update direct deal state #516

Merged
merged 2 commits into from
Apr 1, 2024
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
10 changes: 10 additions & 0 deletions api/impl/venus_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,3 +1369,13 @@ func (m *MarketNodeImpl) GetDirectDealByAllocationID(ctx context.Context, id vTy
func (m *MarketNodeImpl) ListDirectDeals(ctx context.Context, queryParams types.DirectDealQueryParams) ([]*types.DirectDeal, error) {
return m.Repo.DirectDealRepo().ListDeal(ctx, queryParams)
}

func (m *MarketNodeImpl) UpdateDirectDealState(ctx context.Context, id uuid.UUID, state types.DirectDealState) error {
deal, err := m.Repo.DirectDealRepo().GetDeal(ctx, id)
if err != nil {
return err
}
deal.State = state

return m.Repo.DirectDealRepo().SaveDeal(ctx, deal)
}
40 changes: 38 additions & 2 deletions cli/direct-deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ var directDealCmds = &cli.Command{
Name: "direct-deal",
Usage: "the tool for direct deal",
Subcommands: []*cli.Command{
getDirectDeal,
getDirectDealCmd,
listDirectDealCmd,
updateDirectDealStateCmd,
importDirectDealCmd,
importDirectDealsCmd,
},
}

var getDirectDeal = &cli.Command{
var getDirectDealCmd = &cli.Command{
Name: "get",
Usage: "Print a direct deal by id",
Flags: []cli.Flag{
Expand Down Expand Up @@ -557,3 +558,38 @@ func loadAllocations(path string) ([]*allocationWithPiece, error) {

return allocations, nil
}

var updateDirectDealStateCmd = &cli.Command{
Name: "update-state",
Usage: "update direct deal state",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "state",
Usage: "deal state, 1: DealAllocated, 2: DealSealing, 3: DealActive, 4: DealExpired, 5: DealSlashed, 6: DealError",
},
},
ArgsUsage: "<deal uuid>",
Action: func(cliCtx *cli.Context) error {
api, closer, err := NewMarketNode(cliCtx)
if err != nil {
return err
}
defer closer()

if cliCtx.Args().Len() != 1 {
return fmt.Errorf("must specify deal uuid")
}

dealUUID, err := uuid.Parse(cliCtx.Args().Get(0))
if err != nil {
return err
}

state := types.DirectDealState(cliCtx.Int("state"))
if state < types.DealAllocated || state > types.DealError {
return fmt.Errorf("invalid state")
}

return api.UpdateDirectDealState(cliCtx.Context, dealUUID, state)
},
}
3 changes: 3 additions & 0 deletions cmd/droplet-client/direct-deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ var directDealAllocate = &cli.Command{
if err != nil {
return err
}
if aDataCap == nil {
return fmt.Errorf("datacap not found")
}

// Check that we have enough data cap to make the allocation
if rDataCap.GreaterThan(types.NewInt(uint64(aDataCap.Int64()))) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/droplet-client/retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func toRetrievalOutput(d client.RetrievalInfo, verbose bool) map[string]interfac
return retrievalOutput
}

func outputRetrievalDeals(ctx context.Context, out io.Writer, localDeals []client.RetrievalInfo, verbose bool, showFailed bool, completed bool) error {
func outputRetrievalDeals(_ context.Context, out io.Writer, localDeals []client.RetrievalInfo, verbose bool, showFailed bool, completed bool) error {
var deals []client.RetrievalInfo
for _, deal := range localDeals {
if !showFailed && isTerminalError(deal.Status) {
Expand Down
4 changes: 1 addition & 3 deletions cmd/droplet-client/storage_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
types2 "github.com/ipfs-force-community/droplet/v2/types"
"github.com/ipfs/go-cid"
inet "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -361,7 +360,7 @@ var storageDealStatus = &cli.Command{
}
defer s.Close() // nolint

resp, err := sendDealStatusRequest(ctx, s, addrInfo.ID, dealUUID, from, signer)
resp, err := sendDealStatusRequest(ctx, s, dealUUID, from, signer)
if err != nil {
return fmt.Errorf("send deal status request failed: %w", err)
}
Expand Down Expand Up @@ -407,7 +406,6 @@ var storageDealStatus = &cli.Command{

func sendDealStatusRequest(ctx context.Context,
s inet.Stream,
id peer.ID,
dealUUID uuid.UUID,
from address.Address,
signer signer.ISigner,
Expand Down
2 changes: 1 addition & 1 deletion 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.15.0-rc1.0.20240325083156-be02046db71b
github.com/filecoin-project/venus v1.15.0-rc1.0.20240330062001-1bb8f318c662
github.com/golang/mock v1.6.0
github.com/google/uuid v1.5.0
github.com/gorilla/mux v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ github.com/filecoin-project/specs-actors/v7 v7.0.1 h1:w72xCxijK7xs1qzmJiw+WYJaVt
github.com/filecoin-project/specs-actors/v7 v7.0.1/go.mod h1:tPLEYXoXhcpyLh69Ccq91SOuLXsPWjHiY27CzawjUEk=
github.com/filecoin-project/specs-actors/v8 v8.0.1 h1:4u0tIRJeT5G7F05lwLRIsDnsrN+bJ5Ixj6h49Q7uE2Y=
github.com/filecoin-project/specs-storage v0.4.1 h1:yvLEaLZj8f+uByhNC4mFOtCUyL2wQku+NGBp6hjTe9M=
github.com/filecoin-project/venus v1.15.0-rc1.0.20240325083156-be02046db71b h1:ShdSf/z9xg0QDtiQSLZF0wybp0My9PlPeEcR28M42Kw=
github.com/filecoin-project/venus v1.15.0-rc1.0.20240325083156-be02046db71b/go.mod h1:ODirmUeiMiyvbE8bHxelmqN0KbFWWJlQEDE36EEfmvw=
github.com/filecoin-project/venus v1.15.0-rc1.0.20240330062001-1bb8f318c662 h1:XNOJdSngXXdd01tomFaeZO7LcM5aQKtIZVIov94ppoM=
github.com/filecoin-project/venus v1.15.0-rc1.0.20240330062001-1bb8f318c662/go.mod h1:ODirmUeiMiyvbE8bHxelmqN0KbFWWJlQEDE36EEfmvw=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
Expand Down
Loading