Commit f015e2ea authored by 董子豪's avatar 董子豪

modify rust-ffi

parent c6ce771b
package pieces package pieces
import ( import (
"math/bits"
"github.com/minio/sha256-simd" "github.com/minio/sha256-simd"
"math/bits"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi"
"fil_integrate/build/fr32" "fil_integrate/build/fr32"
"github.com/filecoin-project/go-state-types/abi"
) )
const NODE_SIZE = 32 const NODE_SIZE = 32
...@@ -91,12 +91,12 @@ func MerkleTreeLoop(D []byte) ([]byte, error) { ...@@ -91,12 +91,12 @@ func MerkleTreeLoop(D []byte) ([]byte, error) {
h := sha256.New() h := sha256.New()
// write left child // write left child
trim_to_fr32(D[index:index+32]) trim_to_fr32(D[index : index+32])
h.Write(D[index:index+32]) h.Write(D[index : index+32])
index += lenth index += lenth
// write right child // write right child
trim_to_fr32(D[index:index+32]) trim_to_fr32(D[index : index+32])
h.Write(D[index:index+32]) h.Write(D[index : index+32])
index += lenth index += lenth
res := h.Sum(nil) res := h.Sum(nil)
......
package proof package proof
import( import (
"github.com/ipfs/go-cid" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid"
) )
type SectorInfo struct { type SectorInfo struct {
SealType abi.RegisteredSealProof // RegisteredProof used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt SealType abi.RegisteredSealProof // RegisteredProof used when sealing - needs to be mapped to PoSt registered proof when used to verify a PoSt
SectorNumber abi.SectorNumber SectorNumber abi.SectorNumber
SealedCID cid.Cid // CommR SealedCID cid.Cid // CommR
} }
type Proof []byte type Proof []byte
type SealVerifyInfo struct { type SealVerifyInfo struct {
SealType abi.RegisteredSealProof SealType abi.RegisteredSealProof
SectorID abi.SectorID SectorID abi.SectorID
DealIDs []abi.DealID DealIDs []abi.DealID
Randomness abi.SealRandomness Randomness abi.SealRandomness
InteractiveRandomness abi.InteractiveSealRandomness InteractiveRandomness abi.InteractiveSealRandomness
SealProof Proof SealProof Proof
// Safe because we get those from the miner actor // Safe because we get those from the miner actor
SealedCID cid.Cid `checked:"true"` // CommR SealedCID cid.Cid `checked:"true"` // CommR
UnsealedCID cid.Cid `checked:"true"` // CommD UnsealedCID cid.Cid `checked:"true"` // CommD
} }
type AggregateSealVerifyInfo struct { type AggregateSealVerifyInfo struct {
Number abi.SectorNumber Number abi.SectorNumber
Randomness abi.SealRandomness Randomness abi.SealRandomness
InteractiveRandomness abi.InteractiveSealRandomness InteractiveRandomness abi.InteractiveSealRandomness
// Safe because we get those from the miner actor // Safe because we get those from the miner actor
SealedCID cid.Cid `checked:"true"` // CommR SealedCID cid.Cid `checked:"true"` // CommR
UnsealedCID cid.Cid `checked:"true"` // CommD UnsealedCID cid.Cid `checked:"true"` // CommD
} }
type AggregateSealVerifyProofAndInfos struct { type AggregateSealVerifyProofAndInfos struct {
Miner abi.ActorID Miner abi.ActorID
SealType abi.RegisteredSealProof SealType abi.RegisteredSealProof
AggregateType abi.RegisteredAggregationProof AggregateType abi.RegisteredAggregationProof
AggregateProof Proof AggregateProof Proof
Infos []AggregateSealVerifyInfo Infos []AggregateSealVerifyInfo
} }
type PoStProof struct { type PoStProof struct {
PoStProof abi.RegisteredPoStProof PoStProof abi.RegisteredPoStProof
ProofBytes Proof ProofBytes Proof
} }
type WinningPoStVerifyInfo struct { type WinningPoStVerifyInfo struct {
Randomness abi.PoStRandomness Randomness abi.PoStRandomness
Proofs []PoStProof Proofs []PoStProof
ChallengedSectors []SectorInfo ChallengedSectors []SectorInfo
Prover abi.ActorID // used to derive 32-byte prover ID Prover abi.ActorID // used to derive 32-byte prover ID
} }
type WindowPoStVerifyInfo struct { type WindowPoStVerifyInfo struct {
Randomness abi.PoStRandomness Randomness abi.PoStRandomness
Proofs []PoStProof Proof PoStProof
ChallengedSectors []SectorInfo ChallengedSectors []SectorInfo
Prover abi.ActorID // used to derive 32-byte prover ID Prover abi.ActorID // used to derive 32-byte prover ID
} }
type AggregateWindowPostInfos struct{ type AggregateWindowPostInfos struct {
PoStType abi.RegisteredPoStProof PoStType abi.RegisteredPoStProof
AggregateType abi.RegisteredAggregationProof AggregateType abi.RegisteredAggregationProof
AggregateProof Proof AggregateProof PoStProof
ChallengedSectors []SectorInfo ChallengedSectors []SectorInfo
SectorCount []uint SectorCount []uint
Randomnesses []abi.PoStRandomness Randomnesses []abi.PoStRandomness
Prover abi.ActorID Prover abi.ActorID
} }
\ No newline at end of file
package build package build
import ( import (
"fmt" "fmt"
"math/big" "math/big"
) )
var byteSizeUnits = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"} var byteSizeUnits = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB"}
func SizeStr(bi *big.Int) string { func SizeStr(bi *big.Int) string {
r := new(big.Rat).SetInt(bi) r := new(big.Rat).SetInt(bi)
den := big.NewRat(1, 1024) den := big.NewRat(1, 1024)
var i int var i int
for f, _ := r.Float64(); f >= 1024 && i+1 < len(byteSizeUnits); f, _ = r.Float64() { for f, _ := r.Float64(); f >= 1024 && i+1 < len(byteSizeUnits); f, _ = r.Float64() {
i++ i++
r = r.Mul(r, den) r = r.Mul(r, den)
} }
f, _ := r.Float64() f, _ := r.Float64()
return fmt.Sprintf("%.4g %s", f, byteSizeUnits[i]) return fmt.Sprintf("%.4g %s", f, byteSizeUnits[i])
} }
\ No newline at end of file
package storage package storage
import ( import (
"io"
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"io"
"golang.org/x/xerrors" "golang.org/x/xerrors"
...@@ -41,20 +41,20 @@ type SectorCids struct { ...@@ -41,20 +41,20 @@ type SectorCids struct {
type Piece struct { type Piece struct {
Commitment Hash Commitment Hash
Size abi.UnpaddedPieceSize Size abi.UnpaddedPieceSize
} }
type DecodedData struct { type DecodedData struct {
HasPre bool HasPre bool
PreHash Hash PreHash Hash
Data []byte Data []byte
PieceHash []Hash PieceHash []Hash
HashData []byte HashData []byte
} }
func (data *DecodedData)Serialize() ([]byte, error) { func (data *DecodedData) Serialize() ([]byte, error) {
var buf []byte var buf []byte
MetaLen := uint32(len(data.Data)) MetaLen := uint32(len(data.Data))
CommLen := uint32(len(data.HashData)) CommLen := uint32(len(data.HashData))
...@@ -62,22 +62,22 @@ func (data *DecodedData)Serialize() ([]byte, error) { ...@@ -62,22 +62,22 @@ func (data *DecodedData)Serialize() ([]byte, error) {
if MetaLen > 0 { if MetaLen > 0 {
return nil, xerrors.Errorf("") return nil, xerrors.Errorf("")
} }
buf = make([]byte, nextUppandedPowerOfTwo(40 + CommLen)) buf = make([]byte, nextUppandedPowerOfTwo(40+CommLen))
binary.BigEndian.PutUint32(buf[:4], 0x80000000) binary.BigEndian.PutUint32(buf[:4], 0x80000000)
binary.BigEndian.PutUint32(buf[4:8], CommLen) binary.BigEndian.PutUint32(buf[4:8], CommLen)
copy(buf[8:40], data.PreHash[:]) copy(buf[8:40], data.PreHash[:])
copy(buf[40:], data.HashData[:]) copy(buf[40:], data.HashData[:])
} else { } else {
buf = make([]byte, nextUppandedPowerOfTwo(8 + MetaLen + CommLen)) buf = make([]byte, nextUppandedPowerOfTwo(8+MetaLen+CommLen))
binary.BigEndian.PutUint32(buf[:4], MetaLen) binary.BigEndian.PutUint32(buf[:4], MetaLen)
binary.BigEndian.PutUint32(buf[4:8], CommLen) binary.BigEndian.PutUint32(buf[4:8], CommLen)
copy(buf[8:8 + MetaLen], data.Data[:]) copy(buf[8:8+MetaLen], data.Data[:])
copy(buf[8 + MetaLen:], data.HashData[:]) copy(buf[8+MetaLen:], data.HashData[:])
} }
return buf, nil return buf, nil
} }
func (data *DecodedData)Deserialize(buf []byte) error { func (data *DecodedData) Deserialize(buf []byte) error {
var err error var err error
var MetaLen uint32 var MetaLen uint32
var CommLen uint32 var CommLen uint32
...@@ -92,7 +92,7 @@ func (data *DecodedData)Deserialize(buf []byte) error { ...@@ -92,7 +92,7 @@ func (data *DecodedData)Deserialize(buf []byte) error {
data.HasPre = (MetaLen >> 31) != 0 data.HasPre = (MetaLen >> 31) != 0
MetaLen = MetaLen & 0x7fffffff MetaLen = MetaLen & 0x7fffffff
rbuf := buf[8:read] rbuf := buf[8:read]
if data.HasPre{ if data.HasPre {
if read < 40 { if read < 40 {
return xerrors.Errorf("can't read the pre-piece-hash") return xerrors.Errorf("can't read the pre-piece-hash")
} }
...@@ -102,7 +102,7 @@ func (data *DecodedData)Deserialize(buf []byte) error { ...@@ -102,7 +102,7 @@ func (data *DecodedData)Deserialize(buf []byte) error {
if uint32(len(rbuf)) <= MetaLen { if uint32(len(rbuf)) <= MetaLen {
data.Data = rbuf[:] data.Data = rbuf[:]
} else if uint32(len(rbuf)) <= CommLen + MetaLen { } else if uint32(len(rbuf)) <= CommLen+MetaLen {
data.Data = rbuf[:MetaLen] data.Data = rbuf[:MetaLen]
data.PieceHash, err = to32ByteHash(rbuf[MetaLen:]) data.PieceHash, err = to32ByteHash(rbuf[MetaLen:])
if err != nil { if err != nil {
...@@ -110,7 +110,7 @@ func (data *DecodedData)Deserialize(buf []byte) error { ...@@ -110,7 +110,7 @@ func (data *DecodedData)Deserialize(buf []byte) error {
} }
} else { } else {
data.Data = rbuf[:MetaLen] data.Data = rbuf[:MetaLen]
data.PieceHash, err = to32ByteHash(rbuf[MetaLen:CommLen + MetaLen]) data.PieceHash, err = to32ByteHash(rbuf[MetaLen : CommLen+MetaLen])
if err != nil { if err != nil {
return err return err
} }
...@@ -119,7 +119,7 @@ func (data *DecodedData)Deserialize(buf []byte) error { ...@@ -119,7 +119,7 @@ func (data *DecodedData)Deserialize(buf []byte) error {
} }
func to32ByteHash(in []byte) ([]Hash, error) { func to32ByteHash(in []byte) ([]Hash, error) {
if len(in) % 32 != 0 { if len(in)%32 != 0 {
return nil, xerrors.Errorf("lenth of the hash arr must be multiple of 32") return nil, xerrors.Errorf("lenth of the hash arr must be multiple of 32")
} }
hash := make([]Hash, len(in)/32) hash := make([]Hash, len(in)/32)
...@@ -132,8 +132,8 @@ func to32ByteHash(in []byte) ([]Hash, error) { ...@@ -132,8 +132,8 @@ func to32ByteHash(in []byte) ([]Hash, error) {
func nextUppandedPowerOfTwo(index uint32) abi.UnpaddedPieceSize { func nextUppandedPowerOfTwo(index uint32) abi.UnpaddedPieceSize {
index-- index--
power := 0 power := 0
for index = index / 254; index != 0 ; power += 1 { for index = index / 254; index != 0; power += 1 {
index >>= 1 index >>= 1
} }
return abi.UnpaddedPieceSize(254 * (1 << power)) return abi.UnpaddedPieceSize(254 * (1 << power))
} }
\ No newline at end of file
This diff is collapsed.
package main package main
import( import (
"os" "os"
"github.com/urfave/cli/v2"
"github.com/docker/go-units" "github.com/docker/go-units"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
"fil_integrate/seal" "fil_integrate/seal"
) )
var log = logging.Logger("bench") var log = logging.Logger("bench")
...@@ -37,18 +36,18 @@ func main() { ...@@ -37,18 +36,18 @@ func main() {
} }
var testSealAndWindowPoSt = &cli.Command{ var testSealAndWindowPoSt = &cli.Command{
Name: "test-all", Name: "test-all",
Usage: "Test Seal the sectors and generate window post", Usage: "Test Seal the sectors and generate window post",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "sector-size", Name: "sector-size",
Value: "8MiB", Value: "8MiB",
Usage: "size of the sectors in bytes", Usage: "size of the sectors in bytes",
}, },
&cli.IntFlag{ &cli.IntFlag{
Name: "num-agg", Name: "num-agg",
Value: 8, Value: 8,
Usage: "How many window-post proofs used to aggregate", Usage: "How many window-post proofs used to aggregate",
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
...@@ -67,8 +66,8 @@ var testSealAndWindowPoSt = &cli.Command{ ...@@ -67,8 +66,8 @@ var testSealAndWindowPoSt = &cli.Command{
} }
var testSealCmd = &cli.Command{ var testSealCmd = &cli.Command{
Name: "test-seal", Name: "test-seal",
Usage: "Test sealing the sectors", Usage: "Test sealing the sectors",
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
// Test 8MiB sector // Test 8MiB sector
err := seal.TestSealAndUnseal() err := seal.TestSealAndUnseal()
...@@ -80,18 +79,18 @@ var testSealCmd = &cli.Command{ ...@@ -80,18 +79,18 @@ var testSealCmd = &cli.Command{
} }
var testSplitDataCmd = &cli.Command{ var testSplitDataCmd = &cli.Command{
Name: "test-split", Name: "test-split",
Usage: "Test encode data into pieces", Usage: "Test encode data into pieces",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "sector-size", Name: "sector-size",
Value: "8MiB", Value: "8MiB",
Usage: "size of the sectors in bytes", Usage: "size of the sectors in bytes",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "data-size", Name: "data-size",
Value: "256MiB", Value: "256MiB",
Usage: "size of the input file in bytes", Usage: "size of the input file in bytes",
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
...@@ -111,4 +110,4 @@ var testSplitDataCmd = &cli.Command{ ...@@ -111,4 +110,4 @@ var testSplitDataCmd = &cli.Command{
} }
return nil return nil
}, },
} }
\ No newline at end of file
...@@ -139,15 +139,15 @@ func GenerateWindowPoStWithVanilla( ...@@ -139,15 +139,15 @@ func GenerateWindowPoStWithVanilla(
minerID abi.ActorID, minerID abi.ActorID,
randomness abi.PoStRandomness, randomness abi.PoStRandomness,
proofs [][]byte, proofs [][]byte,
) ([]proof.PoStProof, error) { ) (proof.PoStProof, error) {
pp, err := toFilRegisteredPoStProof(proofType) pp, err := toFilRegisteredPoStProof(proofType)
if err != nil { if err != nil {
return nil, err return proof.PoStProof{}, err
} }
proverID, err := toProverID(minerID) proverID, err := toProverID(minerID)
if err != nil { if err != nil {
return nil, err return proof.PoStProof{}, err
} }
fproofs, discard := toVanillaProofs(proofs) fproofs, discard := toVanillaProofs(proofs)
defer discard() defer discard()
...@@ -159,18 +159,16 @@ func GenerateWindowPoStWithVanilla( ...@@ -159,18 +159,16 @@ func GenerateWindowPoStWithVanilla(
fproofs, uint(len(proofs)), fproofs, uint(len(proofs)),
) )
resp.Deref() resp.Deref()
resp.ProofsPtr = make([]generated.FilPoStProof, resp.ProofsLen)
resp.Deref()
defer generated.FilDestroyGenerateWindowPostResponse(resp) defer generated.FilDestroyGenerateWindowPostResponse(resp)
if resp.StatusCode != generated.FCPResponseStatusFCPNoError { if resp.StatusCode != generated.FCPResponseStatusFCPNoError {
return nil, errors.New(generated.RawString(resp.ErrorMsg).Copy()) return proof.PoStProof{}, errors.New(generated.RawString(resp.ErrorMsg).Copy())
} }
out, err := fromFilPoStProofs(resp.ProofsPtr) out, err := fromFilPoStProof(resp.Proof)
if err != nil { if err != nil {
return nil, err return proof.PoStProof{}, err
} }
return out, nil return out, nil
......
...@@ -1805,13 +1805,9 @@ func (x *FilGenerateWindowPoStResponse) PassRef() (*C.fil_GenerateWindowPoStResp ...@@ -1805,13 +1805,9 @@ func (x *FilGenerateWindowPoStResponse) PassRef() (*C.fil_GenerateWindowPoStResp
ref2a5f3ba8.error_msg, cerror_msg_allocs = unpackPCharString(x.ErrorMsg) ref2a5f3ba8.error_msg, cerror_msg_allocs = unpackPCharString(x.ErrorMsg)
allocs2a5f3ba8.Borrow(cerror_msg_allocs) allocs2a5f3ba8.Borrow(cerror_msg_allocs)
var cproofs_len_allocs *cgoAllocMap var cproof_allocs *cgoAllocMap
ref2a5f3ba8.proofs_len, cproofs_len_allocs = (C.size_t)(x.ProofsLen), cgoAllocsUnknown ref2a5f3ba8.proof, cproof_allocs = x.Proof.PassValue()
allocs2a5f3ba8.Borrow(cproofs_len_allocs) allocs2a5f3ba8.Borrow(cproof_allocs)
var cproofs_ptr_allocs *cgoAllocMap
ref2a5f3ba8.proofs_ptr, cproofs_ptr_allocs = unpackSFilPoStProof(x.ProofsPtr)
allocs2a5f3ba8.Borrow(cproofs_ptr_allocs)
var cfaulty_sectors_len_allocs *cgoAllocMap var cfaulty_sectors_len_allocs *cgoAllocMap
ref2a5f3ba8.faulty_sectors_len, cfaulty_sectors_len_allocs = (C.size_t)(x.FaultySectorsLen), cgoAllocsUnknown ref2a5f3ba8.faulty_sectors_len, cfaulty_sectors_len_allocs = (C.size_t)(x.FaultySectorsLen), cgoAllocsUnknown
...@@ -1848,7 +1844,8 @@ func (x *FilGenerateWindowPoStResponse) Deref() { ...@@ -1848,7 +1844,8 @@ func (x *FilGenerateWindowPoStResponse) Deref() {
} }
x.ErrorMsg = packPCharString(x.ref2a5f3ba8.error_msg) x.ErrorMsg = packPCharString(x.ref2a5f3ba8.error_msg)
x.ProofsLen = (uint)(x.ref2a5f3ba8.proofs_len) x.ProofsLen = (uint)(x.ref2a5f3ba8.proofs_len)
packSFilPoStProof(x.ProofsPtr, x.ref2a5f3ba8.proofs_ptr) x.Proof = *NewFilPoStProofRef(unsafe.Pointer(&x.ref2a5f3ba8.proofs_ptr))
// packSFilPoStProof(x.ProofsPtr, x.ref2a5f3ba8.proofs_ptr)
x.FaultySectorsLen = (uint)(x.ref2a5f3ba8.faulty_sectors_len) x.FaultySectorsLen = (uint)(x.ref2a5f3ba8.faulty_sectors_len)
hxf0d18b7 := (*sliceHeader)(unsafe.Pointer(&x.FaultySectorsPtr)) hxf0d18b7 := (*sliceHeader)(unsafe.Pointer(&x.FaultySectorsPtr))
hxf0d18b7.Data = unsafe.Pointer(x.ref2a5f3ba8.faulty_sectors_ptr) hxf0d18b7.Data = unsafe.Pointer(x.ref2a5f3ba8.faulty_sectors_ptr)
......
...@@ -889,18 +889,15 @@ func FilVerifySeal(registeredProof FilRegisteredSealProof, commR Fil32ByteArray, ...@@ -889,18 +889,15 @@ func FilVerifySeal(registeredProof FilRegisteredSealProof, commR Fil32ByteArray,
} }
// FilVerifyWindowPost function as declared in filecoin-ffi/filcrypto.h:817 // FilVerifyWindowPost function as declared in filecoin-ffi/filcrypto.h:817
func FilVerifyWindowPoSt(randomness Fil32ByteArray, replicasPtr []FilPublicReplicaInfo, replicasLen uint, proofsPtr []FilPoStProof, proofsLen uint, proverId Fil32ByteArray) *FilVerifyWindowPoStResponse { func FilVerifyWindowPoSt(randomness Fil32ByteArray, replicasPtr []FilPublicReplicaInfo, replicasLen uint, proof FilPoStProof, proverId Fil32ByteArray) *FilVerifyWindowPoStResponse {
crandomness, crandomnessAllocMap := randomness.PassValue() crandomness, crandomnessAllocMap := randomness.PassValue()
creplicasPtr, creplicasPtrAllocMap := unpackArgSFilPublicReplicaInfo(replicasPtr) creplicasPtr, creplicasPtrAllocMap := unpackArgSFilPublicReplicaInfo(replicasPtr)
creplicasLen, creplicasLenAllocMap := (C.size_t)(replicasLen), cgoAllocsUnknown creplicasLen, creplicasLenAllocMap := (C.size_t)(replicasLen), cgoAllocsUnknown
cproofsPtr, cproofsPtrAllocMap := unpackArgSFilPoStProof(proofsPtr) cproof, cproofAllocMap := proof.PassValue()
cproofsLen, cproofsLenAllocMap := (C.size_t)(proofsLen), cgoAllocsUnknown
cproverId, cproverIdAllocMap := proverId.PassValue() cproverId, cproverIdAllocMap := proverId.PassValue()
__ret := C.fil_verify_window_post(crandomness, creplicasPtr, creplicasLen, cproofsPtr, cproofsLen, cproverId) __ret := C.fil_verify_window_post(crandomness, creplicasPtr, creplicasLen, cproof, cproverId)
runtime.KeepAlive(cproverIdAllocMap) runtime.KeepAlive(cproverIdAllocMap)
runtime.KeepAlive(cproofsLenAllocMap) runtime.KeepAlive(cproofAllocMap)
packSFilPoStProof(proofsPtr, cproofsPtr)
runtime.KeepAlive(cproofsPtrAllocMap)
runtime.KeepAlive(creplicasLenAllocMap) runtime.KeepAlive(creplicasLenAllocMap)
packSFilPublicReplicaInfo(replicasPtr, creplicasPtr) packSFilPublicReplicaInfo(replicasPtr, creplicasPtr)
runtime.KeepAlive(creplicasPtrAllocMap) runtime.KeepAlive(creplicasPtrAllocMap)
......
...@@ -160,8 +160,7 @@ type FilPoStProof struct { ...@@ -160,8 +160,7 @@ type FilPoStProof struct {
// FilGenerateWindowPoStResponse as declared in filecoin-ffi/filcrypto.h:177 // FilGenerateWindowPoStResponse as declared in filecoin-ffi/filcrypto.h:177
type FilGenerateWindowPoStResponse struct { type FilGenerateWindowPoStResponse struct {
ErrorMsg string ErrorMsg string
ProofsLen uint Proof FilPoStProof
ProofsPtr []FilPoStProof
FaultySectorsLen uint FaultySectorsLen uint
FaultySectorsPtr []uint64 FaultySectorsPtr []uint64
StatusCode FCPResponseStatus StatusCode FCPResponseStatus
......
...@@ -160,11 +160,11 @@ func VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error) { ...@@ -160,11 +160,11 @@ func VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error) {
return false, errors.Wrap(err, "failed to create public replica info array for FFI") return false, errors.Wrap(err, "failed to create public replica info array for FFI")
} }
filPoStProofs, filPoStProofsLen, free, err := toFilPoStProofs(info.Proofs) filPoStProof, _, err := toFilPoStProof(info.Proof)
if err != nil { if err != nil {
return false, errors.Wrap(err, "failed to create PoSt proofs array for FFI") return false, errors.Wrap(err, "failed to create PoSt proofs array for FFI")
} }
defer free() // defer free()
proverID, err := toProverID(info.Prover) proverID, err := toProverID(info.Prover)
if err != nil { if err != nil {
...@@ -174,7 +174,7 @@ func VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error) { ...@@ -174,7 +174,7 @@ func VerifyWindowPoSt(info spproof.WindowPoStVerifyInfo) (bool, error) {
resp := generated.FilVerifyWindowPoSt( resp := generated.FilVerifyWindowPoSt(
to32ByteArray(info.Randomness), to32ByteArray(info.Randomness),
filPublicReplicaInfos, filPublicReplicaInfosLen, filPublicReplicaInfos, filPublicReplicaInfosLen,
filPoStProofs, filPoStProofsLen, filPoStProof,
proverID, proverID,
) )
resp.Deref() resp.Deref()
...@@ -225,8 +225,8 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn ...@@ -225,8 +225,8 @@ func VerifyAggregateWindowPostProofs(aggregateInfo spproof.AggregateWindowPostIn
sp, sp,
rap, rap,
proverID, proverID,
aggregateInfo.AggregateProof, aggregateInfo.AggregateProof.ProofBytes,
uint(len(aggregateInfo.AggregateProof)), uint(len(aggregateInfo.AggregateProof.ProofBytes)),
randomnesses, randomnesses,
uint(len(randomnesses)), uint(len(randomnesses)),
filPublicReplicaInfos, filPublicReplicaInfos,
...@@ -742,47 +742,46 @@ func GenerateWindowPoSt( ...@@ -742,47 +742,46 @@ func GenerateWindowPoSt(
minerID abi.ActorID, minerID abi.ActorID,
privateSectorInfo SortedPrivateSectorInfo, privateSectorInfo SortedPrivateSectorInfo,
randomness abi.PoStRandomness, randomness abi.PoStRandomness,
) ([]spproof.PoStProof, []abi.SectorNumber, error) { ) (spproof.PoStProof, []abi.SectorNumber, error) {
filReplicas, filReplicasLen, free, err := toFilPrivateReplicaInfos(privateSectorInfo.Values(), "window") filReplicas, filReplicasLen, free, err := toFilPrivateReplicaInfos(privateSectorInfo.Values(), "window")
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "failed to create private replica info array for FFI") return spproof.PoStProof{}, nil, errors.Wrap(err, "failed to create private replica info array for FFI")
} }
defer free() defer free()
proverID, err := toProverID(minerID) proverID, err := toProverID(minerID)
if err != nil { if err != nil {
return nil, nil, err return spproof.PoStProof{}, nil, err
} }
resp := generated.FilGenerateWindowPost(to32ByteArray(randomness), filReplicas, filReplicasLen, proverID) resp := generated.FilGenerateWindowPost(to32ByteArray(randomness), filReplicas, filReplicasLen, proverID)
resp.Deref() resp.Deref()
resp.ProofsPtr = make([]generated.FilPoStProof, resp.ProofsLen)
resp.Deref()
resp.FaultySectorsPtr = resp.FaultySectorsPtr[:resp.FaultySectorsLen] resp.FaultySectorsPtr = resp.FaultySectorsPtr[:resp.FaultySectorsLen]
defer generated.FilDestroyGenerateWindowPostResponse(resp) defer generated.FilDestroyGenerateWindowPostResponse(resp)
faultySectors, err := fromFilPoStFaultySectors(resp.FaultySectorsPtr, resp.FaultySectorsLen) faultySectors, err := fromFilPoStFaultySectors(resp.FaultySectorsPtr, resp.FaultySectorsLen)
if err != nil { if err != nil {
return nil, nil, xerrors.Errorf("failed to parse faulty sectors list: %w", err) return spproof.PoStProof{}, nil, xerrors.Errorf("failed to parse faulty sectors list: %w", err)
} }
if resp.StatusCode != generated.FCPResponseStatusFCPNoError { if resp.StatusCode != generated.FCPResponseStatusFCPNoError {
return nil, faultySectors, errors.New(generated.RawString(resp.ErrorMsg).Copy()) return spproof.PoStProof{}, faultySectors, errors.New(generated.RawString(resp.ErrorMsg).Copy())
} }
proofs, err := fromFilPoStProofs(resp.ProofsPtr) proof, err := fromFilPoStProof(resp.Proof)
if err != nil { if err != nil {
return nil, nil, err return spproof.PoStProof{}, nil, err
} }
return proofs, faultySectors, nil return proof, faultySectors, nil
} }
// GenerateWindowPoSt // GenerateWindowPoSt
func AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) ([]byte, error) { func AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.PoStProof, error) {
rap, err := toFilRegisteredAggregationProof(aggregateInfo.AggregateType) rap, err := toFilRegisteredAggregationProof(aggregateInfo.AggregateType)
if err != nil { if err != nil {
return nil, err return spproof.PoStProof{}, err
} }
randomnesses := make([]generated.Fil32ByteArray, len(aggregateInfo.Randomnesses)) randomnesses := make([]generated.Fil32ByteArray, len(aggregateInfo.Randomnesses))
...@@ -793,7 +792,7 @@ func AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, p ...@@ -793,7 +792,7 @@ func AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, p
filPoStProofs, filPoStProofsLen, free, err := toFilPoStProofs(proofs) filPoStProofs, filPoStProofsLen, free, err := toFilPoStProofs(proofs)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to create PoSt proofs array for FFI") return spproof.PoStProof{}, errors.Wrap(err, "failed to create PoSt proofs array for FFI")
} }
defer free() defer free()
...@@ -803,10 +802,14 @@ func AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, p ...@@ -803,10 +802,14 @@ func AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, p
defer generated.FilDestroyAggregateProof(resp) defer generated.FilDestroyAggregateProof(resp)
if resp.StatusCode != generated.FCPResponseStatusFCPNoError { if resp.StatusCode != generated.FCPResponseStatusFCPNoError {
return nil, errors.New(generated.RawString(resp.ErrorMsg).Copy()) return spproof.PoStProof{}, errors.New(generated.RawString(resp.ErrorMsg).Copy())
} }
return copyBytes(resp.ProofPtr, resp.ProofLen), nil return spproof.PoStProof{
PoStProof: aggregateInfo.PoStType,
ProofBytes: copyBytes(resp.ProofPtr, resp.ProofLen),
}, nil
} }
// GetGPUDevices produces a slice of strings, each representing the name of a // GetGPUDevices produces a slice of strings, each representing the name of a
...@@ -1061,9 +1064,24 @@ func fromFilPoStFaultySectors(ptr []uint64, l uint) ([]abi.SectorNumber, error) ...@@ -1061,9 +1064,24 @@ func fromFilPoStFaultySectors(ptr []uint64, l uint) ([]abi.SectorNumber, error)
return snums, nil return snums, nil
} }
func fromFilPoStProof(src generated.FilPoStProof) (spproof.PoStProof, error) {
src.Deref()
pp, err := fromFilRegisteredPoStProof(src.RegisteredProof)
if err != nil {
return spproof.PoStProof{}, err
}
out := spproof.PoStProof{
PoStProof: pp,
ProofBytes: copyBytes(src.ProofPtr, src.ProofLen),
}
return out, nil
}
func fromFilPoStProofs(src []generated.FilPoStProof) ([]spproof.PoStProof, error) { func fromFilPoStProofs(src []generated.FilPoStProof) ([]spproof.PoStProof, error) {
out := make([]spproof.PoStProof, len(src)) out := make([]spproof.PoStProof, len(src))
for idx := range out { for idx := range out {
src[idx].Deref() src[idx].Deref()
...@@ -1081,6 +1099,22 @@ func fromFilPoStProofs(src []generated.FilPoStProof) ([]spproof.PoStProof, error ...@@ -1081,6 +1099,22 @@ func fromFilPoStProofs(src []generated.FilPoStProof) ([]spproof.PoStProof, error
return out, nil return out, nil
} }
func toFilPoStProof(src spproof.PoStProof) (generated.FilPoStProof, func(), error) {
pp, err := toFilRegisteredPoStProof(src.PoStProof)
if err != nil {
return generated.FilPoStProof{}, func() {}, err
}
out := generated.FilPoStProof{
RegisteredProof: pp,
ProofLen: uint(len(src.ProofBytes)),
ProofPtr: src.ProofBytes,
}
_, allocs := out.PassRef()
return out, allocs.Free, nil
}
func toFilPoStProofs(src []spproof.PoStProof) ([]generated.FilPoStProof, uint, func(), error) { func toFilPoStProofs(src []spproof.PoStProof) ([]generated.FilPoStProof, uint, func(), error) {
allocs := make([]AllocationManager, len(src)) allocs := make([]AllocationManager, len(src))
......
...@@ -1075,26 +1075,36 @@ pub unsafe extern "C" fn fil_generate_window_post_with_vanilla( ...@@ -1075,26 +1075,36 @@ pub unsafe extern "C" fn fil_generate_window_post_with_vanilla(
match result { match result {
Ok(output) => { Ok(output) => {
let mapped: Vec<fil_PoStProof> = output let (t, proof) = output;
.iter() let postProof = fil_PoStProof{
.cloned() registered_proof: (t).into(),
.map(|(t, proof)| { proof_len: proof.len(),
let out = fil_PoStProof { proof_ptr: proof.as_ptr(),
registered_proof: (t).into(), };
proof_len: proof.len(), mem::forget(proof);
proof_ptr: proof.as_ptr(),
};
mem::forget(proof);
out
})
.collect();
response.status_code = FCPResponseStatus::FCPNoError; response.status_code = FCPResponseStatus::FCPNoError;
response.proofs_ptr = mapped.as_ptr(); response.proof = postProof;
response.proofs_len = mapped.len(); // let mapped: Vec<fil_PoStProof> = output
mem::forget(mapped); // .iter()
// .cloned()
// .map(|(t, proof)| {
// let out = fil_PoStProof {
// registered_proof: (t).into(),
// proof_len: proof.len(),
// proof_ptr: proof.as_ptr(),
// };
// mem::forget(proof);
// out
// })
// .collect();
// response.status_code = FCPResponseStatus::FCPNoError;
// response.proofs_ptr = mapped.as_ptr();
// response.proofs_len = mapped.len();
// mem::forget(mapped);
} }
Err(err) => { Err(err) => {
// If there were faulty sectors, add them to the response // If there were faulty sectors, add them to the response
...@@ -1143,26 +1153,36 @@ pub unsafe extern "C" fn fil_generate_window_post( ...@@ -1143,26 +1153,36 @@ pub unsafe extern "C" fn fil_generate_window_post(
match result { match result {
Ok(output) => { Ok(output) => {
let mapped: Vec<fil_PoStProof> = output let (t, proof) = output;
.iter() let postProof = fil_PoStProof{
.cloned() registered_proof: (t).into(),
.map(|(t, proof)| { proof_len: proof.len(),
let out = fil_PoStProof { proof_ptr: proof.as_ptr(),
registered_proof: (t).into(), };
proof_len: proof.len(), mem::forget(proof);
proof_ptr: proof.as_ptr(),
};
mem::forget(proof);
out
})
.collect();
response.status_code = FCPResponseStatus::FCPNoError; response.status_code = FCPResponseStatus::FCPNoError;
response.proofs_ptr = mapped.as_ptr(); response.proof = postProof;
response.proofs_len = mapped.len(); // let mapped: Vec<fil_PoStProof> = output
mem::forget(mapped); // .iter()
// .cloned()
// .map(|(t, proof)| {
// let out = fil_PoStProof {
// registered_proof: (t).into(),
// proof_len: proof.len(),
// proof_ptr: proof.as_ptr(),
// };
// mem::forget(proof);
// out
// })
// .collect();
// response.status_code = FCPResponseStatus::FCPNoError;
// response.proofs_ptr = mapped.as_ptr();
// response.proofs_len = mapped.len();
// mem::forget(mapped);
} }
Err(err) => { Err(err) => {
// If there were faulty sectors, add them to the response // If there were faulty sectors, add them to the response
...@@ -1195,8 +1215,7 @@ pub unsafe extern "C" fn fil_verify_window_post( ...@@ -1195,8 +1215,7 @@ pub unsafe extern "C" fn fil_verify_window_post(
randomness: fil_32ByteArray, randomness: fil_32ByteArray,
replicas_ptr: *const fil_PublicReplicaInfo, replicas_ptr: *const fil_PublicReplicaInfo,
replicas_len: libc::size_t, replicas_len: libc::size_t,
proofs_ptr: *const fil_PoStProof, post_proof: fil_PoStProof,
proofs_len: libc::size_t,
prover_id: fil_32ByteArray, prover_id: fil_32ByteArray,
) -> *mut fil_VerifyWindowPoStResponse { ) -> *mut fil_VerifyWindowPoStResponse {
catch_panic_response(|| { catch_panic_response(|| {
...@@ -1209,16 +1228,13 @@ pub unsafe extern "C" fn fil_verify_window_post( ...@@ -1209,16 +1228,13 @@ pub unsafe extern "C" fn fil_verify_window_post(
let convert = super::helpers::to_public_replica_info_map(replicas_ptr, replicas_len); let convert = super::helpers::to_public_replica_info_map(replicas_ptr, replicas_len);
let result = convert.and_then(|replicas| { let result = convert.and_then(|replicas| {
let post_proofs = c_to_rust_post_proofs(proofs_ptr, proofs_len)?; // let post_proofs = c_to_rust_post_proofs(proofs_ptr, proofs_len)?;
let proofs: Vec<(RegisteredPoStProof, &[u8])> = post_proofs let proof: (RegisteredPoStProof, &[u8]) = (post_proof.registered_proof.into(), from_raw_parts(post_proof.proof_ptr, post_proof.proof_len));
.iter()
.map(|x| (x.registered_proof, x.proof.as_ref()))
.collect();
filecoin_proofs_api::post::verify_window_post( filecoin_proofs_api::post::verify_window_post(
&randomness.inner, &randomness.inner,
&proofs, &proof,
&replicas, &replicas,
prover_id.inner, prover_id.inner,
) )
......
...@@ -277,6 +277,16 @@ pub struct fil_PoStProof { ...@@ -277,6 +277,16 @@ pub struct fil_PoStProof {
pub proof_ptr: *const u8, pub proof_ptr: *const u8,
} }
impl Default for fil_PoStProof {
fn default() -> fil_PoStProof {
fil_PoStProof {
registered_proof: fil_RegisteredPoStProof::StackedDrgWindow2KiBV1,
proof_len: 0,
proof_ptr: ptr::null(),
}
}
}
impl Drop for fil_PoStProof { impl Drop for fil_PoStProof {
fn drop(&mut self) { fn drop(&mut self) {
let _ = unsafe { let _ = unsafe {
...@@ -487,8 +497,7 @@ code_and_message_impl!(fil_GenerateWinningPoStResponse); ...@@ -487,8 +497,7 @@ code_and_message_impl!(fil_GenerateWinningPoStResponse);
#[derive(DropStructMacro)] #[derive(DropStructMacro)]
pub struct fil_GenerateWindowPoStResponse { pub struct fil_GenerateWindowPoStResponse {
pub error_msg: *const libc::c_char, pub error_msg: *const libc::c_char,
pub proofs_len: libc::size_t, pub proof: fil_PoStProof,
pub proofs_ptr: *const fil_PoStProof,
pub faulty_sectors_len: libc::size_t, pub faulty_sectors_len: libc::size_t,
pub faulty_sectors_ptr: *const u64, pub faulty_sectors_ptr: *const u64,
pub status_code: FCPResponseStatus, pub status_code: FCPResponseStatus,
...@@ -498,8 +507,7 @@ impl Default for fil_GenerateWindowPoStResponse { ...@@ -498,8 +507,7 @@ impl Default for fil_GenerateWindowPoStResponse {
fn default() -> fil_GenerateWindowPoStResponse { fn default() -> fil_GenerateWindowPoStResponse {
fil_GenerateWindowPoStResponse { fil_GenerateWindowPoStResponse {
error_msg: ptr::null(), error_msg: ptr::null(),
proofs_len: 0, proof: fil_PoStProof::default(),
proofs_ptr: ptr::null(),
faulty_sectors_len: 0, faulty_sectors_len: 0,
faulty_sectors_ptr: ptr::null(), faulty_sectors_ptr: ptr::null(),
status_code: FCPResponseStatus::FCPNoError, status_code: FCPResponseStatus::FCPNoError,
......
...@@ -317,7 +317,7 @@ pub fn generate_window_post_with_vanilla( ...@@ -317,7 +317,7 @@ pub fn generate_window_post_with_vanilla(
randomness: &ChallengeSeed, randomness: &ChallengeSeed,
prover_id: ProverId, prover_id: ProverId,
vanilla_proofs: &[VanillaProofBytes], vanilla_proofs: &[VanillaProofBytes],
) -> Result<Vec<(RegisteredPoStProof, SnarkProof)>> { ) -> Result<(RegisteredPoStProof, SnarkProof)> {
with_shape!( with_shape!(
u64::from(registered_post_proof_type.sector_size()), u64::from(registered_post_proof_type.sector_size()),
generate_window_post_with_vanilla_inner, generate_window_post_with_vanilla_inner,
...@@ -333,7 +333,7 @@ fn generate_window_post_with_vanilla_inner<Tree: 'static + MerkleTreeTrait>( ...@@ -333,7 +333,7 @@ fn generate_window_post_with_vanilla_inner<Tree: 'static + MerkleTreeTrait>(
randomness: &ChallengeSeed, randomness: &ChallengeSeed,
prover_id: ProverId, prover_id: ProverId,
vanilla_proofs: &[VanillaProofBytes], vanilla_proofs: &[VanillaProofBytes],
) -> Result<Vec<(RegisteredPoStProof, SnarkProof)>> { ) -> Result<(RegisteredPoStProof, SnarkProof)> {
ensure!( ensure!(
!vanilla_proofs.is_empty(), !vanilla_proofs.is_empty(),
"vanilla_proofs cannot be an empty list" "vanilla_proofs cannot be an empty list"
...@@ -356,14 +356,14 @@ fn generate_window_post_with_vanilla_inner<Tree: 'static + MerkleTreeTrait>( ...@@ -356,14 +356,14 @@ fn generate_window_post_with_vanilla_inner<Tree: 'static + MerkleTreeTrait>(
// once there are multiple versions, merge them before returning // once there are multiple versions, merge them before returning
Ok(vec![(registered_post_proof_type, posts_v1)]) Ok((registered_post_proof_type, posts_v1))
} }
pub fn generate_window_post( pub fn generate_window_post(
randomness: &ChallengeSeed, randomness: &ChallengeSeed,
replicas: &BTreeMap<SectorId, PrivateReplicaInfo>, replicas: &BTreeMap<SectorId, PrivateReplicaInfo>,
prover_id: ProverId, prover_id: ProverId,
) -> Result<Vec<(RegisteredPoStProof, SnarkProof)>> { ) -> Result<(RegisteredPoStProof, SnarkProof)> {
ensure!(!replicas.is_empty(), "no replicas supplied"); ensure!(!replicas.is_empty(), "no replicas supplied");
let registered_post_proof_type_v1 = replicas let registered_post_proof_type_v1 = replicas
.values() .values()
...@@ -390,7 +390,7 @@ fn generate_window_post_inner<Tree: 'static + MerkleTreeTrait>( ...@@ -390,7 +390,7 @@ fn generate_window_post_inner<Tree: 'static + MerkleTreeTrait>(
randomness: &ChallengeSeed, randomness: &ChallengeSeed,
replicas: &BTreeMap<SectorId, PrivateReplicaInfo>, replicas: &BTreeMap<SectorId, PrivateReplicaInfo>,
prover_id: ProverId, prover_id: ProverId,
) -> Result<Vec<(RegisteredPoStProof, SnarkProof)>> { ) -> Result<(RegisteredPoStProof, SnarkProof)> {
let mut replicas_v1 = BTreeMap::new(); let mut replicas_v1 = BTreeMap::new();
for (id, info) in replicas.iter() { for (id, info) in replicas.iter() {
...@@ -424,19 +424,19 @@ fn generate_window_post_inner<Tree: 'static + MerkleTreeTrait>( ...@@ -424,19 +424,19 @@ fn generate_window_post_inner<Tree: 'static + MerkleTreeTrait>(
// once there are multiple versions, merge them before returning // once there are multiple versions, merge them before returning
Ok(vec![(registered_proof_v1, posts_v1)]) Ok((registered_proof_v1, posts_v1))
} }
pub fn verify_window_post( pub fn verify_window_post(
randomness: &ChallengeSeed, randomness: &ChallengeSeed,
proofs: &[(RegisteredPoStProof, &[u8])], proof: &(RegisteredPoStProof, &[u8]),
replicas: &BTreeMap<SectorId, PublicReplicaInfo>, replicas: &BTreeMap<SectorId, PublicReplicaInfo>,
prover_id: ProverId, prover_id: ProverId,
) -> Result<bool> { ) -> Result<bool> {
ensure!(!replicas.is_empty(), "no replicas supplied"); ensure!(!replicas.is_empty(), "no replicas supplied");
ensure!(proofs.len() == 1, "only one version of PoSt supported"); // ensure!(proofs.len() == 1, "only one version of PoSt supported");
let registered_post_proof_type_v1 = proofs[0].0; let registered_post_proof_type_v1 = proof.0;
ensure!( ensure!(
registered_post_proof_type_v1.typ() == PoStType::Window, registered_post_proof_type_v1.typ() == PoStType::Window,
...@@ -452,7 +452,7 @@ pub fn verify_window_post( ...@@ -452,7 +452,7 @@ pub fn verify_window_post(
verify_window_post_inner, verify_window_post_inner,
registered_post_proof_type_v1, registered_post_proof_type_v1,
randomness, randomness,
proofs, proof,
replicas, replicas,
prover_id, prover_id,
) )
...@@ -461,7 +461,7 @@ pub fn verify_window_post( ...@@ -461,7 +461,7 @@ pub fn verify_window_post(
fn verify_window_post_inner<Tree: 'static + MerkleTreeTrait>( fn verify_window_post_inner<Tree: 'static + MerkleTreeTrait>(
registered_proof_v1: RegisteredPoStProof, registered_proof_v1: RegisteredPoStProof,
randomness: &ChallengeSeed, randomness: &ChallengeSeed,
proofs: &[(RegisteredPoStProof, &[u8])], proof: &(RegisteredPoStProof, &[u8]),
replicas: &BTreeMap<SectorId, PublicReplicaInfo>, replicas: &BTreeMap<SectorId, PublicReplicaInfo>,
prover_id: ProverId, prover_id: ProverId,
) -> Result<bool> { ) -> Result<bool> {
...@@ -487,7 +487,7 @@ fn verify_window_post_inner<Tree: 'static + MerkleTreeTrait>( ...@@ -487,7 +487,7 @@ fn verify_window_post_inner<Tree: 'static + MerkleTreeTrait>(
randomness, randomness,
&replicas_v1, &replicas_v1,
prover_id, prover_id,
proofs[0].1, proof.1,
)?; )?;
// once there are multiple versions, merge them before returning // once there are multiple versions, merge them before returning
......
module fil_integrate module fil_integrate
go 1.16 go 1.16
require ( require (
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
github.com/docker/go-units v0.4.0 github.com/docker/go-units v0.4.0
github.com/elastic/go-sysinfo v1.7.0 github.com/elastic/go-sysinfo v1.7.0
github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200910194244-f640612a1a1f github.com/filecoin-project/filecoin-ffi v0.30.4-0.20200910194244-f640612a1a1f
github.com/filecoin-project/go-bitfield v0.2.4 github.com/filecoin-project/go-bitfield v0.2.4
github.com/filecoin-project/go-fil-commcid v0.1.0 github.com/filecoin-project/go-fil-commcid v0.1.0
github.com/filecoin-project/go-state-types v0.1.1-0.20210506134452-99b279731c48 github.com/filecoin-project/go-state-types v0.1.1-0.20210506134452-99b279731c48
github.com/google/uuid v1.2.0 github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5 github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-log/v2 v2.3.0 github.com/ipfs/go-log/v2 v2.3.0
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0
github.com/whyrusleeping/cbor-gen v0.0.0-20210422071115-ad5b82622e0f github.com/whyrusleeping/cbor-gen v0.0.0-20210422071115-ad5b82622e0f
go.opencensus.io v0.23.0 go.opencensus.io v0.23.0
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
github.com/libp2p/go-libp2p-core v0.8.5 github.com/libp2p/go-libp2p-core v0.8.5
github.com/minio/sha256-simd v0.1.1 github.com/minio/sha256-simd v0.1.1
) )
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
replace github.com/filecoin-project/go-state-types => ./extern/go-state-types replace github.com/filecoin-project/go-state-types => ./extern/go-state-types
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"sync" "sync"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"fil_integrate/build/storage" "fil_integrate/build/storage"
"fil_integrate/build/storiface" "fil_integrate/build/storiface"
) )
......
This diff is collapsed.
This diff is collapsed.
package seal package seal
import( import (
"context" "context"
"io" "io"
"github.com/minio/blake2b-simd"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/minio/blake2b-simd"
spproof "fil_integrate/build/proof" spproof "fil_integrate/build/proof"
"fil_integrate/build/storage" "fil_integrate/build/storage"
...@@ -24,37 +24,37 @@ type PieceEncoder interface { ...@@ -24,37 +24,37 @@ type PieceEncoder interface {
} }
//interface //interface
type SectorSealer interface{ type SectorSealer interface {
AddPiece(ctx context.Context, sid storage.SectorRef, sortedPieces []storage.Piece) ([]abi.PieceInfo, []storage.Piece, error) AddPiece(ctx context.Context, sid storage.SectorRef, sortedPieces []storage.Piece) ([]abi.PieceInfo, []storage.Piece, error)
// run pre-commit1 and pre-commit2 phase // run pre-commit1 and pre-commit2 phase
// generate the sealed sector and sector commitment(commd, commr) // generate the sealed sector and sector commitment(commd, commr)
Sealed(ctx context.Context, sid storage.SectorRef, pieces []abi.PieceInfo) (storage.SectorCids, error) Sealed(ctx context.Context, sid storage.SectorRef, pieces []abi.PieceInfo) (storage.SectorCids, error)
// run commit1 and commit2 phase // run commit1 and commit2 phase
// generate the zk-proof of sealing // generate the zk-proof of sealing
GenerateCommitProof( ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (spproof.Proof, error) GenerateCommitProof(ctx context.Context, sid storage.SectorRef, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (spproof.Proof, error)
AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error) AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error)
UnsealedRange(ctx context.Context, sid storage.SectorRef, out io.Writer, commd cid.Cid, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error UnsealedRange(ctx context.Context, sid storage.SectorRef, out io.Writer, commd cid.Cid, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error
GenerateWindowPoStProofs(ctx context.Context, minerID abi.ActorID, sectorInfo []spproof.SectorInfo, randomness abi.PoStRandomness) ([]spproof.PoStProof, []abi.SectorID, error) GenerateWindowPoStProofs(ctx context.Context, minerID abi.ActorID, sectorInfo []spproof.SectorInfo, randomness abi.PoStRandomness) (spproof.PoStProof, []abi.SectorID, error)
AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.Proof, error) AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.PoStProof, error)
} }
type SectorVerifier interface{ type SectorVerifier interface {
VerifySeal(info spproof.SealVerifyInfo) (bool, error) VerifySeal(info spproof.SealVerifyInfo) (bool, error)
VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (bool, error) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProofAndInfos) (bool, error)
VerifyWindowPoSt(sectors []storage.SectorRef, proofs []spproof.PoStProof, randomness abi.PoStRandomness, proverID abi.ActorID) (bool, error) VerifyWindowPoSt(sectors []storage.SectorRef, proof spproof.PoStProof, randomness abi.PoStRandomness, proverID abi.ActorID) (bool, error)
VerifyAggregateWindowPostProofs(sectors [][]storage.SectorRef, proof spproof.Proof, randomnesses []abi.PoStRandomness, proverID abi.ActorID) (bool, error) VerifyAggregateWindowPostProofs(sectors [][]storage.SectorRef, proof spproof.PoStProof, randomnesses []abi.PoStRandomness, proverID abi.ActorID) (bool, error)
} }
type SectorManager interface { type SectorManager interface {
GetRoot() (string) GetRoot() string
// * returns storiface.ErrSectorNotFound if a requested existing sector doesn't exist // * returns storiface.ErrSectorNotFound if a requested existing sector doesn't exist
// * returns an error when allocate is set, and existing isn't, and the sector exists // * returns an error when allocate is set, and existing isn't, and the sector exists
AcquireUnsealed(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error) AcquireUnsealed(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error)
AcquireSector(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error) AcquireSector(ctx context.Context, id storage.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, ptype storiface.PathType) (storiface.SectorPaths, func(), error)
} }
var _ SectorManager = &basicfs.Manager{} var _ SectorManager = &basicfs.Manager{}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment