Skip to content

Commit

Permalink
Merge pull request #529 from ipfs-force-community/fix/piece-size-alre…
Browse files Browse the repository at this point in the history
…ady-padded

fix: piece size already padded
  • Loading branch information
simlecode authored Jun 25, 2024
2 parents b3ca5a8 + 68b1e04 commit 86ed0b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions cmd/droplet-client/direct-deal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
Expand All @@ -155,6 +159,7 @@ var directDealAllocate = &cli.Command{
}

maddrs[abi.ActorID(mid)] = m
mIDs[abi.ActorID(mid)] = struct{}{}
}

// Get all pieceCIDs from input
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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, "=")
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -384,7 +398,7 @@ func getAllocationParams(cctx *cli.Context, currentHeight abi.ChainEpoch) (*allo
return &params, 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)
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/droplet-client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 86ed0b2

Please sign in to comment.