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

fix: remove claim id #513

Merged
merged 13 commits into from
Mar 27, 2024
96 changes: 93 additions & 3 deletions cli/direct-deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"bytes"
"context"
"encoding/csv"
"fmt"
"os"
Expand All @@ -13,7 +14,11 @@ import (
"time"

"github.com/filecoin-project/go-address"
types2 "github.com/filecoin-project/venus/venus-shared/types"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
shared "github.com/filecoin-project/venus/venus-shared/types"
types "github.com/filecoin-project/venus/venus-shared/types/market"
"github.com/google/uuid"
"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -68,7 +73,7 @@ var getDirectDeal = &cli.Command{
return err
}
} else {
deal, err = api.GetDirectDealByAllocationID(cliCtx.Context, types2.AllocationId(cliCtx.Int64("allocation-id")))
deal, err = api.GetDirectDealByAllocationID(cliCtx.Context, shared.AllocationId(cliCtx.Int64("allocation-id")))
if err != nil {
return err
}
Expand All @@ -81,7 +86,6 @@ var getDirectDeal = &cli.Command{
{"Client", deal.Client},
{"Provider", deal.Provider},
{"AllocationID", deal.AllocationID},
{"ClaimID", deal.ClaimID},
{"State", deal.State.String()},
{"Message", deal.Message},
{"SectorID", deal.SectorID},
Expand Down Expand Up @@ -210,6 +214,10 @@ var importDirectDealCmd = &cli.Command{
Name: "payload-size",
Usage: "The size of the car file",
},
&cli.IntFlag{
Name: "start-epoch",
Usage: "start epoch by when the deal should be proved by provider on-chain (default: 2 days from now)",
},
},
Action: func(cliCtx *cli.Context) error {
if cliCtx.Args().Len() < 2 {
Expand All @@ -222,6 +230,12 @@ var importDirectDealCmd = &cli.Command{
}
defer closer()

fapi, fcloser, err := NewFullNode(cliCtx, OldMarketRepoPath)
if err != nil {
return err
}
defer fcloser()

pieceCidStr := cliCtx.Args().Get(0)
path := cliCtx.Args().Get(1)

Expand Down Expand Up @@ -255,6 +269,15 @@ var importDirectDealCmd = &cli.Command{

allocationID := cliCtx.Uint64("allocation-id")

startEpoch, err := getStartEpoch(cliCtx, fapi)
if err != nil {
return err
}
endEpoch, err := checkAndGetEndEpoch(cliCtx.Context, fapi, client, allocationID, startEpoch)
if err != nil {
return err
}

params := types.DirectDealParams{
SkipCommP: cliCtx.Bool("skip-commp"),
SkipGenerateIndex: cliCtx.Bool("skip-generate-index"),
Expand All @@ -267,6 +290,8 @@ var importDirectDealCmd = &cli.Command{
Client: client,
PieceCID: pieceCid,
FilePath: filepath,
StartEpoch: startEpoch,
EndEpoch: endEpoch,
},
},
}
Expand All @@ -280,6 +305,19 @@ var importDirectDealCmd = &cli.Command{
},
}

func getStartEpoch(cliCtx *cli.Context, fapi v1api.FullNode) (abi.ChainEpoch, error) {
startEpoch := abi.ChainEpoch(cliCtx.Int("start-epoch"))
if startEpoch == 0 {
head, err := fapi.ChainHead(cliCtx.Context)
if err != nil {
return 0, err
}
startEpoch = head.Height() + builtin.EpochsInDay*2
}

return startEpoch, nil
}

var importDirectDealsCmd = &cli.Command{
Name: "import-deals",
Usage: "import direct deal",
Expand Down Expand Up @@ -308,6 +346,10 @@ var importDirectDealsCmd = &cli.Command{
Name: "no-copy-car-file",
Usage: "not copy car files to piece storage",
},
&cli.IntFlag{
Name: "start-epoch",
Usage: "start epoch by when the deal should be proved by provider on-chain (default: 2 days from now)",
},
},
Action: func(cliCtx *cli.Context) error {
if cliCtx.IsSet("allocation-id-piece") == cliCtx.IsSet("allocation-file") {
Expand All @@ -320,6 +362,13 @@ var importDirectDealsCmd = &cli.Command{
}
defer closer()

fapi, fcloser, err := NewFullNode(cliCtx, OldMarketRepoPath)
if err != nil {
return err
}
defer fcloser()

ctx := cliCtx.Context
carDir := cliCtx.String("car-dir")

findCar := func(pieceCID cid.Cid) (string, error) {
Expand All @@ -336,6 +385,11 @@ var importDirectDealsCmd = &cli.Command{
return "", fmt.Errorf("car %s file not found", pieceCID.String())
}

startEpoch, err := getStartEpoch(cliCtx, fapi)
if err != nil {
return err
}

var directDealParams []types.DirectDealParam
if cliCtx.IsSet("allocation-info") {
for _, ai := range cliCtx.StringSlice("allocation-info") {
Expand All @@ -355,11 +409,19 @@ var importDirectDealsCmd = &cli.Command{
if err != nil {
return fmt.Errorf("invalid client: %w", err)
}

endEpoch, err := checkAndGetEndEpoch(ctx, fapi, client, allocationID, startEpoch)
if err != nil {
return err
}

param := types.DirectDealParam{
DealUUID: uuid.New(),
AllocationID: allocationID,
PieceCID: pieceCid,
Client: client,
StartEpoch: startEpoch,
EndEpoch: endEpoch,
}

if len(carDir) == 0 {
Expand All @@ -378,12 +440,18 @@ var importDirectDealsCmd = &cli.Command{
return fmt.Errorf("failed to load allocations: %w", err)
}
for _, a := range allocations {
endEpoch, err := checkAndGetEndEpoch(ctx, fapi, a.Client, a.AllocationID, startEpoch)
if err != nil {
return err
}
param := types.DirectDealParam{
DealUUID: uuid.New(),
AllocationID: a.AllocationID,
Client: a.Client,
PieceCID: a.PieceCID,
PayloadSize: a.PayloadSize,
StartEpoch: startEpoch,
EndEpoch: endEpoch,
}
if param.PayloadSize == 0 && len(carDir) == 0 {
return fmt.Errorf("must specify car-dir")
Expand Down Expand Up @@ -414,6 +482,28 @@ var importDirectDealsCmd = &cli.Command{
},
}

func checkAndGetEndEpoch(ctx context.Context,
fapi v1api.FullNode,
client address.Address,
allocationID uint64,
startEpoch abi.ChainEpoch,
) (abi.ChainEpoch, error) {
allocation, err := fapi.StateGetAllocation(ctx, client, verifreg.AllocationId(allocationID), shared.EmptyTSK)
if err != nil {
return 0, fmt.Errorf("failed to get allocation(%d): %w", allocationID, err)
}

if allocation == nil {
return 0, fmt.Errorf("allocation %d not found for client %s", allocationID, client)
}

if allocation.Expiration < startEpoch {
return 0, fmt.Errorf("allocation %d will expire on %d before start epoch %d", allocationID, allocation.Expiration, startEpoch)
}

return startEpoch + allocation.TermMin, nil
}

type allocationWithPiece struct {
AllocationID uint64
Client address.Address
Expand Down
4 changes: 2 additions & 2 deletions cli/storage-deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,8 @@ func outputStorageDeal(deal *market.MinerDeal) error {
{"ProviderCollateral", deal.Proposal.ProviderCollateral},
{"ClientCollateral", deal.Proposal.ClientCollateral},
{"Label", dataCid},
{"MinerPeerID", deal.Miner.Pretty()},
{"ClientPeerID", deal.Client.Pretty()},
{"MinerPeerID", deal.Miner.String()},
{"ClientPeerID", deal.Client.String()},
{"FundsReserved", deal.FundsReserved},
{"AvailableForRetrieval", deal.AvailableForRetrieval},
{"SectorNumber", deal.SectorNumber},
Expand Down
50 changes: 25 additions & 25 deletions cmd/droplet-client/direct-deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
datacap2 "github.com/filecoin-project/go-state-types/builtin/v9/datacap"
verifregst "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/actors/builtin/datacap"
v1 "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
Expand All @@ -36,25 +37,23 @@ var walletFlag = &cli.StringFlag{
Usage: "the wallet address that will used create the allocation",
}
var termMinFlag = &cli.Int64Flag{
Name: "term-min",
Usage: "The minimum duration which the provider must commit to storing the piece to avoid early-termination penalties (days).\n" +
Usage: "The minimum duration which the provider must commit to storing the piece to avoid early-termination penalties (epochs).\n" +
"Default is 180 days.",
// Value: types.MinimumVerifiedAllocationTerm,
Value: 180,
Aliases: []string{"tmin"},
Value: verifregst.MinimumVerifiedAllocationTerm,
}
var termMaxFlag = &cli.Int64Flag{ // nolint
var termMaxFlag = &cli.Int64Flag{
Name: "term-max",
// Usage: "The maximum period for which a provider can earn quality-adjusted power for the piece (epochs).\n",
Usage: "The maximum period for which a provider can earn quality-adjusted power for the piece (epochs).\n" +
"Default is min(5 years, term-min + 90 days).",
// Value: types.MaximumVerifiedAllocationTerm,
"Default is 5 years.",
Aliases: []string{"tmax"},
Value: verifregst.MaximumVerifiedAllocationTerm,
}
var expirationFlag = &cli.Int64Flag{
Name: "expiration",
Usage: "The latest epoch by which a provider must commit data before the allocation expires (days).\n" +
"Default is 8 days, max is 60 days.",
// Value: types.DefaultAllocationExpiration,
Value: 8,
Usage: "The latest epoch by which a provider must commit data before the allocation expires (epochs).\n" +
"Default is 60 days.",
Value: verifregst.MaximumVerifiedAllocationExpiration,
}

var directDealCommands = &cli.Command{
Expand All @@ -72,7 +71,7 @@ var directDealAllocate = &cli.Command{
minerFlag,
walletFlag,
termMinFlag,
// termMaxFlag,
termMaxFlag,
expirationFlag,
&cli.StringSliceFlag{
Name: "piece-info",
Expand Down Expand Up @@ -281,11 +280,12 @@ func pieceInfosFromCtx(cctx *cli.Context) ([]*pieceInfo, uint64, error) {
return nil, 0, fmt.Errorf("failed to parse the pieceCid for %s: %w", pieceDetail[0], err)
}

pieceSize := abi.UnpaddedPieceSize(n).Padded()
pieceInfos = append(pieceInfos, &pieceInfo{
pieceSize: abi.PaddedPieceSize(n),
pieceSize: pieceSize,
pieceCID: pcid,
})
rDataCap += n
rDataCap += uint64(pieceSize)
}

return pieceInfos, rDataCap, nil
Expand Down Expand Up @@ -328,17 +328,17 @@ type allocationParams struct {

func getAllocationParams(cctx *cli.Context, currentHeight abi.ChainEpoch) (*allocationParams, error) {
var params allocationParams
termMin := cctx.Int64("term-min")
expiration := cctx.Int64("expiration")
if termMin < 180 || termMin > 5*365 {
return nil, fmt.Errorf("invalid term-min: %d", termMin)
}
params.termMin = abi.ChainEpoch(termMin) * builtin.EpochsInDay
params.termMax = Min[abi.ChainEpoch](params.termMin+90*builtin.EpochsInDay, types.MaximumVerifiedAllocationTerm)
if expiration <= 0 || expiration > 60 {
return nil, fmt.Errorf("invalid expiration: %d", expiration)
termMin := cctx.Int64(termMinFlag.Name)
termMax := cctx.Int64(termMaxFlag.Name)
expiration := cctx.Int64(expirationFlag.Name)

if termMax < termMin {
return nil, fmt.Errorf("maximum duration %d cannot be smaller than minimum duration %d", termMax, termMin)
}
params.expiration = abi.ChainEpoch(expiration)*builtin.EpochsInDay + currentHeight

params.termMin = abi.ChainEpoch(termMin)
params.termMax = abi.ChainEpoch(termMax)
params.expiration = abi.ChainEpoch(expiration) + currentHeight

return &params, nil
}
Expand Down
4 changes: 2 additions & 2 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.15.0-rc1
github.com/filecoin-project/venus v1.15.0-rc1.0.20240325083156-be02046db71b
github.com/golang/mock v1.6.0
github.com/google/uuid v1.5.0
github.com/gorilla/mux v1.8.0
Expand Down Expand Up @@ -306,7 +306,7 @@ require (
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
google.golang.org/api v0.155.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
7 changes: 4 additions & 3 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 h1:XgJjci6IzuW5BbMqjfYhhz6OAO7/rE99BvbtnL6owbA=
github.com/filecoin-project/venus v1.15.0-rc1/go.mod h1:eGfNmxdPAFIdmMS6v9HqfTLrneI51N5KX/EtoY4dzJ4=
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/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 Expand Up @@ -2933,8 +2933,9 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 1 addition & 1 deletion models/badger/direct_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func prepareDirectDealTest(t *testing.T) (context.Context, repo.DirectDealRepo,

dealCases := make([]types.DirectDeal, 10)
testutil.Provide(t, &dealCases)
dealCases[0].State = types.DealAllocation
dealCases[0].State = types.DealAllocated
return ctx, r, dealCases
}

Expand Down
2 changes: 1 addition & 1 deletion models/badger/retrieval_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r retrievalDealRepo) ListDeals(ctx context.Context, params *types.Retrieva
return true, nil
}

if len(params.Receiver) > 0 && deal.Receiver.Pretty() != params.Receiver {
if len(params.Receiver) > 0 && deal.Receiver.String() != params.Receiver {
return false, nil
}
if len(params.PayloadCID) > 0 && deal.PayloadCID.String() != params.PayloadCID {
Expand Down
2 changes: 1 addition & 1 deletion models/badger/retrieval_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestListDeals(t *testing.T) {

for i := 0; i < 2; i++ {
deals, err = r.ListDeals(ctx, &types.RetrievalDealQueryParams{
Receiver: peers[i].Pretty(),
Receiver: peers[i].String(),
Page: defPage,
})
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion models/badger/storage_deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (sdr *storageDealRepo) ListDeal(ctx context.Context, params *types.StorageD
if !params.Miner.Empty() && deal.ClientDealProposal.Proposal.Provider != params.Miner {
return false, nil
}
if len(params.Client) != 0 && deal.Client.Pretty() != params.Client {
if len(params.Client) != 0 && deal.Client.String() != params.Client {
return false, nil
}
if params.State != nil && deal.State != *params.State {
Expand Down
Loading
Loading