Skip to content

Commit

Permalink
Merge pull request #402 from filecoin-project/new-lotus-apis
Browse files Browse the repository at this point in the history
feat: add various new APIs for Lotus
  • Loading branch information
magik6k authored Jul 31, 2023
2 parents a458f63 + 8bc9a5a commit ba86847
Show file tree
Hide file tree
Showing 7 changed files with 1,053 additions and 536 deletions.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set -e
make clean
cd rust
rm -f Cargo.lock
rustup target add x86_64-apple-darwin --toolchain $(cat rust-toolchain)
rustup target add aarch64-apple-darwin --toolchain $(cat rust-toolchain)
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
cargo update -p "filecoin-proofs-api"
cargo install cargo-lipo
cd ..
Expand Down
36 changes: 36 additions & 0 deletions cgo/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,39 @@ func MergeWindowPoStPartitionProofs(registeredProof RegisteredPoStProof, partiti

return resp.value.copy(), nil
}

// PoRep primitives

func GenerateSDR(registeredProof RegisteredPoStProof, outDir SliceRefUint8, replicaID *ByteArray32) error {
resp := C.generate_sdr(registeredProof, outDir, replicaID)
defer resp.destroy()

return CheckErr(resp)
}

func GenerateTreeRLast(registeredProof RegisteredPoStProof, replicaPath, outDir SliceRefUint8) ([]byte, error) {
resp := C.generate_tree_r_last(registeredProof, replicaPath, outDir)
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
}

return resp.value.copy(), nil
}

func GenerateTreeC(registeredProof RegisteredPoStProof, inputDir, outDir SliceRefUint8) ([]byte, error) {
resp := C.generate_tree_c(registeredProof, inputDir, outDir)
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
}

return resp.value.copy(), nil
}

func EmptySectorUpdateDecodeFromRange(registeredProof RegisteredUpdateProof, commD, commR *ByteArray32, inputFd, sectorKeyFd, outputFd int32, nodesOffset, numNodes uint64) error {
resp := C.empty_sector_update_decode_from_range(registeredProof, commD, commR, C.int(inputFd), C.int(sectorKeyFd), C.int(outputFd), C.uint64_t(nodesOffset), C.uint64_t(numNodes))
defer resp.destroy()

return CheckErr(resp)
}
19 changes: 19 additions & 0 deletions proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,25 @@ func UnsealRange(
)
}

func GenerateSDR(
proofType abi.RegisteredSealProof,
cacheDirPath string,
replicaId [32]byte,
) (err error) {
sp, err := toFilRegisteredSealProof(proofType)
if err != nil {
return err
}

replicaIdtBytes := cgo.AsByteArray32(replicaId[:])

return cgo.GenerateSDR(
sp,
cgo.AsSliceRefUint8([]byte(cacheDirPath)),
&replicaIdtBytes,
)
}

// GenerateWinningPoStSectorChallenge
func GenerateWinningPoStSectorChallenge(
proofType abi.RegisteredPoStProof,
Expand Down
Loading

0 comments on commit ba86847

Please sign in to comment.