Skip to content

Commit

Permalink
support v1.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-t committed Nov 9, 2024
2 parents 62131ac + ffe45b1 commit 473e05e
Show file tree
Hide file tree
Showing 19 changed files with 2,206 additions and 582 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ filcrypto.pc
filecoin.h
filecoin.pc
*.a
Cargo.lock
simulator
Cargo.lock
rust/Cargo.lock
56 changes: 50 additions & 6 deletions cgo/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var (
emptyBool C.bool = false
emptyUint8 C.uint8_t = 0
emptyUint64 C.uint64_t = 0
emptyUint C.size_t = 0
Expand All @@ -25,6 +26,13 @@ var (
emptySliceBoxedUint8 C.slice_boxed_uint8_t = C.slice_boxed_uint8_t{}
)

func AsBool(bl bool) C.bool {
if bl {
return !emptyBool
}
return emptyBool
}

func AsSliceRefUint8(goBytes []byte) SliceRefUint8 {
len := len(goBytes)

Expand Down Expand Up @@ -235,13 +243,49 @@ func NewAggregationInputs(commR ByteArray32, commD ByteArray32, sectorId uint64,
}
}

func NewPrivateReplicaInfo(pp RegisteredPoStProof, cacheDirPath string, commR ByteArray32, replicaPath string, sectorId uint64) PrivateReplicaInfo {
func NewPrivateSectorPathInfo(
endpoints string,
accessKey string,
secretKey string,
bucketName string,
landedDir string,
sectorName string,
region string,
multiRanges bool,
) PrivateSectorPathInfo {
return PrivateSectorPathInfo{
endpoints: AllocSliceBoxedUint8([]byte(endpoints)),
access_key: AllocSliceBoxedUint8([]byte(accessKey)),
secret_key: AllocSliceBoxedUint8([]byte(secretKey)),
bucket_name: AllocSliceBoxedUint8([]byte(bucketName)),
landed_dir: AllocSliceBoxedUint8([]byte(landedDir)),
sector_name: AllocSliceBoxedUint8([]byte(sectorName)),
region: AllocSliceBoxedUint8([]byte(region)),
multi_ranges: AsBool(multiRanges),
}
}

func NewPrivateReplicaInfo(
pp RegisteredPoStProof,
cacheDirPath string,
cacheInOss bool,
cacheSectorPathInfo PrivateSectorPathInfo,
commR ByteArray32,
replicaPath string,
replicaInOss bool,
replicaSectorPathInfo PrivateSectorPathInfo,
sectorId uint64,
) PrivateReplicaInfo {
return PrivateReplicaInfo{
registered_proof: pp,
cache_dir_path: AllocSliceBoxedUint8([]byte(cacheDirPath)),
replica_path: AllocSliceBoxedUint8([]byte(replicaPath)),
sector_id: C.uint64_t(sectorId),
comm_r: commR,
registered_proof: pp,
cache_dir_path: AllocSliceBoxedUint8([]byte(cacheDirPath)),
cache_in_oss: AsBool(cacheInOss),
cache_sector_path_info: cacheSectorPathInfo,
replica_path: AllocSliceBoxedUint8([]byte(replicaPath)),
replica_in_oss: AsBool(replicaInOss),
replica_sector_path_info: replicaSectorPathInfo,
sector_id: C.uint64_t(sectorId),
comm_r: commR,
}
}

Expand Down
14 changes: 12 additions & 2 deletions cgo/proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,18 @@ func WriteWithoutAlignment(registeredProof RegisteredSealProof, srcFd int32, src
return uint64(resp.value.total_write_unpadded), resp.value.comm_p.copy(), nil
}

func SealPreCommitPhase1(registeredProof RegisteredSealProof, cacheDirPath SliceRefUint8, stagedSectorPath SliceRefUint8, sealedSectorPath SliceRefUint8, sectorId uint64, proverId *ByteArray32, ticket *ByteArray32, pieces SliceRefPublicPieceInfo) ([]byte, error) {
resp := C.seal_pre_commit_phase1(registeredProof, cacheDirPath, stagedSectorPath, sealedSectorPath, C.uint64_t(sectorId), proverId, ticket, pieces)
func SealPreCommitPhase1(
registeredProof RegisteredSealProof,
cacheDirPath SliceRefUint8,
stagedSectorPath SliceRefUint8,
sealedSectorPath SliceRefUint8,
sectorId uint64,
proverId *ByteArray32,
ticket *ByteArray32,
pieces SliceRefPublicPieceInfo,
hasDeal C.bool,
) ([]byte, error) {
resp := C.seal_pre_commit_phase1(registeredProof, cacheDirPath, stagedSectorPath, sealedSectorPath, C.uint64_t(sectorId), proverId, ticket, pieces, hasDeal)
defer resp.destroy()
if err := CheckErr(resp); err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions cgo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type PrivateReplicaInfo = C.PrivateReplicaInfo_t
type PartitionSnarkProof = C.PartitionSnarkProof_t
type PoStProof = C.PoStProof_t
type PublicPieceInfo = C.PublicPieceInfo_t
type PrivateSectorPathInfo = C.PrivateSectorPathInfo_t

type SliceRefPublicReplicaInfo = C.slice_ref_PublicReplicaInfo_t
type SliceRefPrivateReplicaInfo = C.slice_ref_PrivateReplicaInfo_t
Expand Down
2 changes: 1 addition & 1 deletion install-filcrypto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -Exeo pipefail
auth_header=()
if [ -n "${GITHUB_TOKEN}" ]; then
auth_header=("-H" "Authorization: token ${GITHUB_TOKEN}")
auth_header=("-H" "Authorization: token ${GITHUB_TOKEN}")
fi

# set CWD to the root of filecoin-ffi
Expand Down
80 changes: 80 additions & 0 deletions proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ package ffi
// #include "./filcrypto.h"
import "C"
import (
"fmt"
"os"
"path"
"runtime"

"github.com/filecoin-project/go-state-types/proof"
Expand All @@ -25,6 +27,8 @@ import (
"github.com/filecoin-project/filecoin-ffi/cgo"
)

// var log = logging.Logger("ffi-proof")

// VerifySeal returns true if the sealing operation from which its inputs were
// derived was valid, and false if not.
func VerifySeal(info proof.SealVerifyInfo) (bool, error) {
Expand Down Expand Up @@ -291,6 +295,7 @@ func SealPreCommitPhase1(
minerID abi.ActorID,
ticket abi.SealRandomness,
pieces []abi.PieceInfo,
hasDeals bool,
) (phase1Output []byte, err error) {
sp, err := toFilRegisteredSealProof(proofType)
if err != nil {
Expand All @@ -317,6 +322,7 @@ func SealPreCommitPhase1(
&proverID,
&ticketBytes,
cgo.AsSliceRefPublicPieceInfo(filPublicPieceInfos),
cgo.AsBool(hasDeals),
)
}

Expand Down Expand Up @@ -820,11 +826,36 @@ func toFilPrivateReplicaInfo(src PrivateSectorInfo) (cgo.PrivateReplicaInfo, err
return cgo.PrivateReplicaInfo{}, err
}

cacheOss := cgo.NewPrivateSectorPathInfo(
src.CacheSectorPathInfo.Endpoints,
src.CacheSectorPathInfo.AccessKey,
src.CacheSectorPathInfo.SecretKey,
src.CacheSectorPathInfo.BucketName,
src.CacheSectorPathInfo.LandedDir,
src.CacheSectorPathInfo.SectorName,
src.CacheSectorPathInfo.Region,
src.CacheSectorPathInfo.MultiRanges,
)
sealedOss := cgo.NewPrivateSectorPathInfo(
src.SealedSectorPathInfo.Endpoints,
src.SealedSectorPathInfo.AccessKey,
src.SealedSectorPathInfo.SecretKey,
src.SealedSectorPathInfo.BucketName,
src.SealedSectorPathInfo.LandedDir,
src.SealedSectorPathInfo.SectorName,
src.SealedSectorPathInfo.Region,
src.SealedSectorPathInfo.MultiRanges,
)

return cgo.NewPrivateReplicaInfo(
pp,
src.CacheDirPath,
src.CacheInOss,
cacheOss,
commR,
src.SealedSectorPath,
src.SealedInOss,
sealedOss,
uint64(src.SectorNumber),
), nil
}
Expand Down Expand Up @@ -853,11 +884,36 @@ func toFilPrivateReplicaInfos(src []PrivateSectorInfo, typ string) ([]cgo.Privat
return nil, nil, err
}

cacheOss := cgo.NewPrivateSectorPathInfo(
src[idx].CacheSectorPathInfo.Endpoints,
src[idx].CacheSectorPathInfo.AccessKey,
src[idx].CacheSectorPathInfo.SecretKey,
src[idx].CacheSectorPathInfo.BucketName,
src[idx].CacheSectorPathInfo.LandedDir,
src[idx].CacheSectorPathInfo.SectorName,
src[idx].CacheSectorPathInfo.Region,
src[idx].CacheSectorPathInfo.MultiRanges,
)
sealedOss := cgo.NewPrivateSectorPathInfo(
src[idx].SealedSectorPathInfo.Endpoints,
src[idx].SealedSectorPathInfo.AccessKey,
src[idx].SealedSectorPathInfo.SecretKey,
src[idx].SealedSectorPathInfo.BucketName,
src[idx].SealedSectorPathInfo.LandedDir,
src[idx].SealedSectorPathInfo.SectorName,
src[idx].SealedSectorPathInfo.Region,
src[idx].SealedSectorPathInfo.MultiRanges,
)

out[idx] = cgo.NewPrivateReplicaInfo(
pp,
src[idx].CacheDirPath,
src[idx].CacheInOss,
cacheOss,
commR,
src[idx].SealedSectorPath,
src[idx].SealedInOss,
sealedOss,
uint64(src[idx].SectorNumber),
)
}
Expand Down Expand Up @@ -1108,3 +1164,27 @@ func toVanillaProofs(src [][]byte) ([]cgo.SliceBoxedUint8, func()) {

return out, makeCleanerSBU(out, len(src))
}

func InitLog() {
gofile := os.Getenv("GOLOG_FILE")
file := os.Getenv("RUSTLOG_FILE")
if len(file) == 0 {
if 0 < len(gofile) {
file = fmt.Sprintf("%v/rust-%v", path.Dir(gofile), path.Base(gofile))
} else {
file = "/var/log/lotus/rust-log.log"
}
}
if len(file) == 0 {
fmt.Printf("FFI log filename is not given\n")
return
}
filLogFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
fmt.Printf("CANNOT open FFI log file %v: %v\n", file, err)
return
}
cgo.InitLogFd(int32(filLogFile.Fd()))
// syscall.Dup2(int(filLogFile.Fd()), 1)
// syscall.Dup2(int(filLogFile.Fd()), 2)
}
Loading

0 comments on commit 473e05e

Please sign in to comment.