Skip to content

Commit

Permalink
chore: convert everything relevant to go-commp-utils/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi authored and rvagg committed Aug 13, 2024
1 parent 2ecc690 commit 0b94fee
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 221 deletions.
48 changes: 12 additions & 36 deletions chain/proofs/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-commp-utils/nonffi"
"github.com/filecoin-project/go-commp-utils/zerocomm"
"github.com/filecoin-project/go-commp-utils/v2"
"github.com/filecoin-project/go-commp-utils/v2/zerocomm"
"github.com/filecoin-project/go-state-types/abi"
)

Expand All @@ -19,48 +19,24 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn
if err != nil {
return cid.Undef, err
}
upssize := abi.PaddedPieceSize(ssize).Unpadded()

pssize := abi.PaddedPieceSize(ssize)
allPieces := make([]abi.PieceInfo, 0, len(pieces))
if len(pieces) == 0 {
allPieces = append(allPieces, abi.PieceInfo{
Size: pssize,
PieceCID: zerocomm.ZeroPieceCommitment(pssize.Unpadded()),
})
} else {
var sum abi.PaddedPieceSize

padTo := func(pads []abi.PaddedPieceSize) {
for _, p := range pads {
allPieces = append(allPieces, abi.PieceInfo{
Size: p,
PieceCID: zerocomm.ZeroPieceCommitment(p.Unpadded()),
})

sum += p
}
}

for _, p := range pieces {
ps, _ := getRequiredPadding(sum, p.Size)
padTo(ps)

allPieces = append(allPieces, p)
sum += p.Size
}
return zerocomm.ZeroPieceCommitment(upssize), nil
}

ps, _ := getRequiredPadding(sum, pssize)
padTo(ps)
pcid, psz, err := commp.PieceAggregateCommP(proofType, pieces)
if err != nil {
return cid.Undef, err
}

// Next we need to generate the unsealed CID by merkleizing the pieces; even though this function
// has the same name, it does a different job and won't give us the desired results if we hadn't
// done the piece-padding first.
return nonffi.GenerateUnsealedCID(proofType, allPieces)
return commp.ZeroPadPieceCommitment(pcid, psz.Unpadded(), upssize)
}

func getRequiredPadding(oldLength abi.PaddedPieceSize, newPieceLength abi.PaddedPieceSize) ([]abi.PaddedPieceSize, abi.PaddedPieceSize) {
func GetRequiredPadding(oldLength abi.PaddedPieceSize, newPieceLength abi.PaddedPieceSize) ([]abi.PaddedPieceSize, abi.PaddedPieceSize) {

padPieces := make([]abi.PaddedPieceSize, 0)

toFill := uint64(-oldLength % newPieceLength)

n := bits.OnesCount64(toFill)
Expand Down
11 changes: 2 additions & 9 deletions chain/proofs/proofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/stretchr/testify/require"

ffi "github.com/filecoin-project/filecoin-ffi"
commpffi "github.com/filecoin-project/go-commp-utils/ffiwrapper"
"github.com/filecoin-project/go-commp-utils/v2"
"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/chain/proofs"
Expand All @@ -19,14 +18,8 @@ func TestGenerateUnsealedCID(t *testing.T) {
ups := int(abi.PaddedPieceSize(2048).Unpadded())

commP := func(b []byte) cid.Cid {
pf, werr, err := commpffi.ToReadableFile(bytes.NewReader(b), int64(len(b)))
c, err := commp.GeneratePieceCIDFromFile(pt, bytes.NewReader(b), abi.UnpaddedPieceSize(len(b)))
require.NoError(t, err)

c, err := ffi.GeneratePieceCIDFromFile(pt, pf, abi.UnpaddedPieceSize(len(b)))
require.NoError(t, err)

require.NoError(t, werr())

return c
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-seed/seed/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-commp-utils/zerocomm"
"github.com/filecoin-project/go-commp-utils/v2/zerocomm"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-shed/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-amt-ipld/v4"
"github.com/filecoin-project/go-commp-utils/v2"
"github.com/filecoin-project/go-hamt-ipld/v3"
"github.com/filecoin-project/go-state-types/abi"
actorstypes "github.com/filecoin-project/go-state-types/actors"
Expand Down Expand Up @@ -1225,7 +1225,7 @@ func checkMinerUnsealedCID(act *types.Actor, stateTreeV9 *state.StateTree, store
return xerrors.Errorf("nil unsealed CID for sector with deals")
}

pieceCID, err := ffi.GenerateUnsealedCID(abi.RegisteredSealProof_StackedDrg64GiBV1_1, pieceCids)
pieceCID, _, err := commp.PieceAggregateCommP(abi.RegisteredSealProof_StackedDrg64GiBV1_1, pieceCids)
if err != nil {
return err
}
Expand Down
18 changes: 10 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ require (
github.com/filecoin-project/go-amt-ipld/v4 v4.3.0
github.com/filecoin-project/go-bitfield v0.2.4
github.com/filecoin-project/go-cbor-util v0.0.1
github.com/filecoin-project/go-commp-utils v0.1.3
github.com/filecoin-project/go-commp-utils/nonffi v0.0.0-20220905160352-62059082a837
github.com/filecoin-project/go-commp-utils/v2 v2.1.0
github.com/filecoin-project/go-crypto v0.0.1
github.com/filecoin-project/go-f3 v0.0.7
github.com/filecoin-project/go-fil-commcid v0.1.0
Expand Down Expand Up @@ -136,7 +135,7 @@ require (
github.com/triplewz/poseidon v0.0.0-20230828015038-79d8165c88ed
github.com/urfave/cli/v2 v2.25.5
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
github.com/whyrusleeping/cbor-gen v0.1.1
github.com/whyrusleeping/cbor-gen v0.1.2
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/xeipuuv/gojsonschema v1.2.0
github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542
Expand All @@ -154,15 +153,15 @@ require (
go.uber.org/fx v1.22.1
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.24.0
golang.org/x/crypto v0.25.0
golang.org/x/mod v0.17.0
golang.org/x/net v0.26.0
golang.org/x/sync v0.7.0
golang.org/x/sys v0.21.0
golang.org/x/term v0.21.0
golang.org/x/sys v0.23.0
golang.org/x/term v0.22.0
golang.org/x/time v0.5.0
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9
gopkg.in/cheggaaa/pb.v1 v1.0.28
gotest.tools v2.2.0+incompatible
)
Expand Down Expand Up @@ -196,6 +195,9 @@ require (
github.com/filecoin-project/go-amt-ipld/v2 v2.1.0 // indirect
github.com/filecoin-project/go-amt-ipld/v3 v3.1.0 // indirect
github.com/filecoin-project/go-clock v0.1.0 // indirect
github.com/filecoin-project/go-commp-utils v0.1.4 // indirect
github.com/filecoin-project/go-commp-utils/nonffi v0.0.0-20240802040721-2a04ffc8ffe8 // indirect
github.com/filecoin-project/go-fil-commp-hashhash v0.2.0 // indirect
github.com/filecoin-project/go-hamt-ipld v0.1.5 // indirect
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 // indirect
github.com/flynn/noise v1.1.0 // indirect
Expand Down Expand Up @@ -248,7 +250,7 @@ require (
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
Expand Down
Loading

0 comments on commit 0b94fee

Please sign in to comment.