Skip to content

Commit 4246246

Browse files
committed
Only generate CommD for what was given, not full sector
I misread the original code ( again - we have no tests :/ )
1 parent 684be82 commit 4246246

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

nonffi/commd.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nonffi
22

33
import (
4+
"errors"
45
"fmt"
56
"math/bits"
67

@@ -16,18 +17,18 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
1617
if !found {
1718
return cid.Undef, fmt.Errorf("unknown seal proof type %d", proofType)
1819
}
19-
20-
target := abi.PaddedPieceSize(spi.SectorSize)
2120
if len(pieces) == 0 {
22-
return zerocomm.ZeroPieceCommitment(target.Unpadded()), nil
21+
return cid.Undef, errors.New("no pieces provided")
2322
}
2423

24+
maxSize := abi.PaddedPieceSize(spi.SectorSize)
25+
2526
// sancheck everything
2627
for i, p := range pieces {
2728
if p.Size < 128 {
2829
return cid.Undef, fmt.Errorf("invalid Size of PieceInfo %d: value %d is too small", i, p.Size)
2930
}
30-
if pieces[i].Size > target {
31+
if pieces[i].Size > maxSize {
3132
return cid.Undef, fmt.Errorf("invalid Size of PieceInfo %d: value %d is larger than sector size of SealProofType %d", i, p.Size, proofType)
3233
}
3334
if bits.OnesCount64(uint64(p.Size)) != 1 {
@@ -68,7 +69,7 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
6869
)
6970
}
7071

71-
for len(stack) > 1 || stack[0].Size < target {
72+
for len(stack) > 1 {
7273
lastSize := stack[len(stack)-1].Size
7374
stack = reduceStack(
7475
append(
@@ -81,7 +82,7 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
8182
)
8283
}
8384

84-
if stack[0].Size > target {
85+
if stack[0].Size > maxSize {
8586
return cid.Undef, fmt.Errorf("provided pieces sum up to %d bytes, which is larger than sector size of SealProofType %d", stack[0].Size, proofType)
8687
}
8788

nonffi/commd_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package nonffi
33
import (
44
"testing"
55

6+
"github.com/filecoin-project/go-commp-utils/zerocomm"
67
"github.com/filecoin-project/go-state-types/abi"
78
"github.com/ipfs/go-cid"
89
)
@@ -37,6 +38,10 @@ func TestGenerateUnsealedCID(t *testing.T) {
3738
{PieceCID: cidMustParse("baga6ea4seaqa3qbabsbmvk5er6rhsjzt74beplzgulthamm22jue4zgqcuszofi"), Size: 1024 << 20}, // https://filfox.info/en/deal/3755803
3839
{PieceCID: cidMustParse("baga6ea4seaqiekvf623muj6jpxg6vsqaikyw3r4ob5u7363z7zcaixqvfqsc2ji"), Size: 256 << 20}, // https://filfox.info/en/deal/3755883
3940
{PieceCID: cidMustParse("baga6ea4seaqhsewv65z2d4m5o4vo65vl5o6z4bcegdvgnusvlt7rao44gro36pi"), Size: 512 << 20}, // https://filfox.info/en/deal/3755882
41+
42+
// GenerateUnsealedCID does not "fill a sector", do it here to match the SP provided sector commD
43+
{PieceCID: zerocomm.ZeroPieceCommitment(abi.PaddedPieceSize(8 << 30).Unpadded()), Size: 8 << 30},
44+
{PieceCID: zerocomm.ZeroPieceCommitment(abi.PaddedPieceSize(16 << 30).Unpadded()), Size: 16 << 30},
4045
},
4146
)
4247

0 commit comments

Comments
 (0)