diff --git a/cmd/droplet-client/direct-deal.go b/cmd/droplet-client/direct-deal.go index beffcae3..63ef23b1 100644 --- a/cmd/droplet-client/direct-deal.go +++ b/cmd/droplet-client/direct-deal.go @@ -108,6 +108,9 @@ var directDealAllocate = &cli.Command{ Name: "start-epoch", Usage: "start epoch by when the deal should be proved by provider on-chain (default: 8 days from now)", }, + &cli.BoolFlag{ + Name: "piece-size-padded", + }, }, Action: func(cctx *cli.Context) error { if cctx.IsSet("piece-info") && cctx.IsSet("manifest") { @@ -136,6 +139,7 @@ var directDealAllocate = &cli.Command{ // Get all minerIDs from input maddrs := make(map[abi.ActorID]types.MinerInfo) + mIDs := make(map[abi.ActorID]struct{}) minerIds := cctx.StringSlice("miner") for _, id := range minerIds { maddr, err := address.NewFromString(id) @@ -155,6 +159,7 @@ var directDealAllocate = &cli.Command{ } maddrs[abi.ActorID(mid)] = m + mIDs[abi.ActorID(mid)] = struct{}{} } // Get all pieceCIDs from input @@ -267,7 +272,7 @@ var directDealAllocate = &cli.Command{ return fmt.Errorf("failed to execute the message with error: %s", res.Receipt.ExitCode.Error()) } - newAllocations, err := findNewAllocations(ctx, fapi, walletAddr, oldAllocations) + newAllocations, err := findNewAllocations(ctx, fapi, walletAddr, oldAllocations, mIDs) if err != nil { return fmt.Errorf("failed to find new allocations: %w", err) } @@ -302,6 +307,7 @@ func pieceInfosFromCtx(cctx *cli.Context) ([]*pieceInfo, uint64, error) { var pieceInfos []*pieceInfo var rDataCap uint64 pieces := cctx.StringSlice("piece-info") + pieceSizePadded := cctx.Bool("piece-size-padded") for _, p := range pieces { pieceDetail := strings.Split(p, "=") @@ -322,6 +328,10 @@ func pieceInfosFromCtx(cctx *cli.Context) ([]*pieceInfo, uint64, error) { } pieceSize := abi.UnpaddedPieceSize(n).Padded() + if pieceSizePadded { + pieceSize = abi.PaddedPieceSize(n) + } + pieceInfos = append(pieceInfos, &pieceInfo{ pieceSize: pieceSize, pieceCID: pcid, @@ -336,6 +346,7 @@ func pieceInfosFromFile(cctx *cli.Context) ([]*pieceInfo, uint64, error) { var pieceInfos []*pieceInfo var rDataCap uint64 manifest := cctx.String("manifest") + pieceSizePadded := cctx.Bool("piece-size-padded") pieces, err := loadManifest(manifest) if err != nil { @@ -347,6 +358,9 @@ func pieceInfosFromFile(cctx *cli.Context) ([]*pieceInfo, uint64, error) { return nil, 0, fmt.Errorf("invalid piece size: %d", p.pieceSize) } n := p.pieceSize.Padded() + if pieceSizePadded { + n = abi.PaddedPieceSize(p.pieceSize) + } pieceInfos = append(pieceInfos, &pieceInfo{ pieceSize: n, pieceCID: p.pieceCID, @@ -384,7 +398,7 @@ func getAllocationParams(cctx *cli.Context, currentHeight abi.ChainEpoch) (*allo return ¶ms, nil } -func findNewAllocations(ctx context.Context, fapi v1.FullNode, walletAddr address.Address, oldAllocations map[types.AllocationId]types.Allocation) (map[types.AllocationId]types.Allocation, error) { +func findNewAllocations(ctx context.Context, fapi v1.FullNode, walletAddr address.Address, oldAllocations map[types.AllocationId]types.Allocation, mIDs map[abi.ActorID]struct{}) (map[types.AllocationId]types.Allocation, error) { allAllocations, err := fapi.StateGetAllocations(ctx, walletAddr, types.EmptyTSK) if err != nil { return nil, fmt.Errorf("failed to get allocations: %w", err) @@ -393,6 +407,9 @@ func findNewAllocations(ctx context.Context, fapi v1.FullNode, walletAddr addres newAllocations := make(map[types.AllocationId]types.Allocation, len(allAllocations)-len(oldAllocations)) for k, v := range allAllocations { if _, ok := oldAllocations[k]; !ok { + if _, ok := mIDs[v.Provider]; !ok { + continue + } newAllocations[k] = v } } diff --git a/cmd/droplet-client/util.go b/cmd/droplet-client/util.go index a51aa853..901deb52 100644 --- a/cmd/droplet-client/util.go +++ b/cmd/droplet-client/util.go @@ -84,7 +84,7 @@ func loadManifest(path string) ([]*manifest, error) { manifests = append(manifests, &manifest{payloadCID: payloadCID, payloadSize: payloadSize, pieceCID: pieceCID, pieceSize: abi.UnpaddedPieceSize(pieceSize)}) } - } else if len(record) == 6 { + } else if len(record) >= 5 { // payload_cid,filename,piece_cid,payload_size,piece_size,detail payloadCID, err := cid.Parse(record[0]) if err != nil {