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
package build package build
import ( import (
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/network"
) )
func SealProofTypeFromSectorSize(ssize abi.SectorSize, nv network.Version) (abi.RegisteredSealProof, error) { func SealProofTypeFromSectorSize(ssize abi.SectorSize, nv network.Version) (abi.RegisteredSealProof, error) {
switch { switch {
case nv < network.Version7: case nv < network.Version7:
switch ssize { switch ssize {
case 2 << 10: case 2 << 10:
return abi.RegisteredSealProof_StackedDrg2KiBV1, nil return abi.RegisteredSealProof_StackedDrg2KiBV1, nil
case 8 << 20: case 8 << 20:
return abi.RegisteredSealProof_StackedDrg8MiBV1, nil return abi.RegisteredSealProof_StackedDrg8MiBV1, nil
case 16 << 20: case 16 << 20:
return abi.RegisteredSealProof_StackedDrg16MiBV1, nil return abi.RegisteredSealProof_StackedDrg16MiBV1, nil
case 32 << 20: case 32 << 20:
return abi.RegisteredSealProof_StackedDrg32MiBV1, nil return abi.RegisteredSealProof_StackedDrg32MiBV1, nil
case 64 << 20: case 64 << 20:
return abi.RegisteredSealProof_StackedDrg64MiBV1, nil return abi.RegisteredSealProof_StackedDrg64MiBV1, nil
case 128 << 20: case 128 << 20:
return abi.RegisteredSealProof_StackedDrg128MiBV1, nil return abi.RegisteredSealProof_StackedDrg128MiBV1, nil
case 256 << 20: case 256 << 20:
return abi.RegisteredSealProof_StackedDrg256MiBV1, nil return abi.RegisteredSealProof_StackedDrg256MiBV1, nil
case 512 << 20: case 512 << 20:
return abi.RegisteredSealProof_StackedDrg512MiBV1, nil return abi.RegisteredSealProof_StackedDrg512MiBV1, nil
case 32 << 30: case 32 << 30:
return abi.RegisteredSealProof_StackedDrg32GiBV1, nil return abi.RegisteredSealProof_StackedDrg32GiBV1, nil
case 64 << 30: case 64 << 30:
return abi.RegisteredSealProof_StackedDrg64GiBV1, nil return abi.RegisteredSealProof_StackedDrg64GiBV1, nil
default: default:
return 0, xerrors.Errorf("unsupported sector size for miner: %v", ssize) return 0, xerrors.Errorf("unsupported sector size for miner: %v", ssize)
} }
case nv >= network.Version7: case nv >= network.Version7:
switch ssize { switch ssize {
case 2 << 10: case 2 << 10:
return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil
case 8 << 20: case 8 << 20:
return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil
case 16 << 20: case 16 << 20:
return abi.RegisteredSealProof_StackedDrg16MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg16MiBV1_1, nil
case 32 << 20: case 32 << 20:
return abi.RegisteredSealProof_StackedDrg32MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg32MiBV1_1, nil
case 64 << 20: case 64 << 20:
return abi.RegisteredSealProof_StackedDrg64MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg64MiBV1_1, nil
case 128 << 20: case 128 << 20:
return abi.RegisteredSealProof_StackedDrg128MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg128MiBV1_1, nil
case 256 << 20: case 256 << 20:
return abi.RegisteredSealProof_StackedDrg256MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg256MiBV1_1, nil
case 512 << 20: case 512 << 20:
return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil
case 32 << 30: case 32 << 30:
return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil
case 64 << 30: case 64 << 30:
return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil
default: default:
return 0, xerrors.Errorf("unsupported sector size for miner: %v", ssize) return 0, xerrors.Errorf("unsupported sector size for miner: %v", ssize)
} }
} }
return 0, xerrors.Errorf("unsupported network version") return 0, xerrors.Errorf("unsupported network version")
} }
func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) {
// We added support for the new proofs in network version 7, and removed support for the old // We added support for the new proofs in network version 7, and removed support for the old
// ones in network version 8. // ones in network version 8.
if nver < network.Version7 { if nver < network.Version7 {
switch proof { switch proof {
case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1:
return abi.RegisteredSealProof_StackedDrg2KiBV1, nil return abi.RegisteredSealProof_StackedDrg2KiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1:
return abi.RegisteredSealProof_StackedDrg8MiBV1, nil return abi.RegisteredSealProof_StackedDrg8MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow16MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow16MiBV1:
return abi.RegisteredSealProof_StackedDrg16MiBV1, nil return abi.RegisteredSealProof_StackedDrg16MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow32MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow32MiBV1:
return abi.RegisteredSealProof_StackedDrg32MiBV1, nil return abi.RegisteredSealProof_StackedDrg32MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow64MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow64MiBV1:
return abi.RegisteredSealProof_StackedDrg64MiBV1, nil return abi.RegisteredSealProof_StackedDrg64MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow128MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow128MiBV1:
return abi.RegisteredSealProof_StackedDrg128MiBV1, nil return abi.RegisteredSealProof_StackedDrg128MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow256MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow256MiBV1:
return abi.RegisteredSealProof_StackedDrg256MiBV1, nil return abi.RegisteredSealProof_StackedDrg256MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1:
return abi.RegisteredSealProof_StackedDrg512MiBV1, nil return abi.RegisteredSealProof_StackedDrg512MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1:
return abi.RegisteredSealProof_StackedDrg32GiBV1, nil return abi.RegisteredSealProof_StackedDrg32GiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1:
return abi.RegisteredSealProof_StackedDrg64GiBV1, nil return abi.RegisteredSealProof_StackedDrg64GiBV1, nil
default: default:
return -1, xerrors.Errorf("unrecognized window post type: %d", proof) return -1, xerrors.Errorf("unrecognized window post type: %d", proof)
} }
} }
switch proof { switch proof {
case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1:
return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1:
return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow16MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow16MiBV1:
return abi.RegisteredSealProof_StackedDrg16MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg16MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow32MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow32MiBV1:
return abi.RegisteredSealProof_StackedDrg32MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg32MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow64MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow64MiBV1:
return abi.RegisteredSealProof_StackedDrg64MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg64MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow128MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow128MiBV1:
return abi.RegisteredSealProof_StackedDrg128MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg128MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow256MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow256MiBV1:
return abi.RegisteredSealProof_StackedDrg256MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg256MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1:
return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1:
return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil
case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1:
return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil
default: default:
return -1, xerrors.Errorf("unrecognized window post type: %d", proof) return -1, xerrors.Errorf("unrecognized window post type: %d", proof)
} }
} }
func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredPoStProof, error) { func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredPoStProof, error) {
switch proof { switch proof {
case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1: case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning8MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning8MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow16MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow16MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning16MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning16MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow32MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow32MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning32MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning32MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow64MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow64MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning64MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning64MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow128MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow128MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning128MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning128MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow256MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow256MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning256MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning256MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning512MiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning512MiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1: case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning32GiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning32GiBV1, nil
case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1:
return abi.RegisteredPoStProof_StackedDrgWinning64GiBV1, nil return abi.RegisteredPoStProof_StackedDrgWinning64GiBV1, nil
default: default:
return -1, xerrors.Errorf("unknown proof type %d", proof) return -1, xerrors.Errorf("unknown proof type %d", proof)
} }
} }
\ No newline at end of file
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"
) )
......
package seal package seal
import( import (
"bufio" "bufio"
"bytes"
"context" "context"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"runtime" "runtime"
"sync" "sync"
"path/filepath"
"bytes"
"fmt"
"golang.org/x/xerrors" "golang.org/x/xerrors"
logging "github.com/ipfs/go-log/v2"
commcid "github.com/filecoin-project/go-fil-commcid"
ffi "github.com/filecoin-project/filecoin-ffi" ffi "github.com/filecoin-project/filecoin-ffi"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/network"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"fil_integrate/build" "fil_integrate/build"
"fil_integrate/build/fr32" "fil_integrate/build/fr32"
spieces "fil_integrate/build/pieces" spieces "fil_integrate/build/pieces"
"fil_integrate/build/storiface"
"fil_integrate/build/storage"
spproof "fil_integrate/build/proof" spproof "fil_integrate/build/proof"
"fil_integrate/build/storage"
"fil_integrate/build/storiface"
) )
var log = logging.Logger("sealing") var log = logging.Logger("sealing")
...@@ -48,9 +48,9 @@ var _ PieceEncoder = &Encoder{} ...@@ -48,9 +48,9 @@ var _ PieceEncoder = &Encoder{}
// Data contains MetaData and HashData // Data contains MetaData and HashData
// Pieces structure is [ Tag | MetaData | HashData ] // Pieces structure is [ Tag | MetaData | HashData ]
func (sp *Encoder) EncodeDataToPieces( func (sp *Encoder) EncodeDataToPieces(
ctx context.Context, ctx context.Context,
sectorSize abi.SectorSize, sectorSize abi.SectorSize,
file storage.Data, file storage.Data,
) (storage.Piece, []storage.Piece, error) { ) (storage.Piece, []storage.Piece, error) {
var hashData []byte var hashData []byte
var pieces []storage.Piece var pieces []storage.Piece
...@@ -63,25 +63,25 @@ func (sp *Encoder) EncodeDataToPieces( ...@@ -63,25 +63,25 @@ func (sp *Encoder) EncodeDataToPieces(
} }
UnpaddedSectorSize := abi.PaddedPieceSize(sectorSize).Unpadded() UnpaddedSectorSize := abi.PaddedPieceSize(sectorSize).Unpadded()
DataLen := (uint32)(UnpaddedSectorSize)-TagLen DataLen := (uint32)(UnpaddedSectorSize) - TagLen
buf := make([]byte, DataLen) buf := make([]byte, DataLen)
for{ for {
MetaLen, err := file.Read(buf[:]) MetaLen, err := file.Read(buf[:])
if err != nil && err != io.EOF{ if err != nil && err != io.EOF {
return storage.Piece{}, nil, err return storage.Piece{}, nil, err
} }
if err == io.EOF || uint32(MetaLen) != DataLen{ if err == io.EOF || uint32(MetaLen) != DataLen {
//encode first sector //encode first sector
prePiece, err = sp.EncodeData(buf[:uint32(MetaLen)], sectorSize, uint32(MetaLen), DataLen, hashData) prePiece, err = sp.EncodeData(buf[:uint32(MetaLen)], sectorSize, uint32(MetaLen), DataLen, hashData)
if err != nil{ if err != nil {
return storage.Piece{}, nil, err return storage.Piece{}, nil, err
} }
break break
} }
var data *storage.DecodedData = &storage.DecodedData{ HasPre: false, Data: buf[:] } var data *storage.DecodedData = &storage.DecodedData{HasPre: false, Data: buf[:]}
dbuf, err := data.Serialize() dbuf, err := data.Serialize()
if err != nil { if err != nil {
return storage.Piece{}, nil, err return storage.Piece{}, nil, err
...@@ -102,7 +102,7 @@ func (sp *Encoder) EncodeDataToPieces( ...@@ -102,7 +102,7 @@ func (sp *Encoder) EncodeDataToPieces(
hashData = append(hashData, pieceHash[:]...) hashData = append(hashData, pieceHash[:]...)
pieces = append(pieces, storage.Piece{ pieces = append(pieces, storage.Piece{
Commitment: pieceHash, Commitment: pieceHash,
Size: UnpaddedSectorSize, Size: UnpaddedSectorSize,
}) })
} }
pieces = append(pieces, prePiece...) pieces = append(pieces, prePiece...)
...@@ -110,25 +110,25 @@ func (sp *Encoder) EncodeDataToPieces( ...@@ -110,25 +110,25 @@ func (sp *Encoder) EncodeDataToPieces(
} }
func (sp *Encoder) EncodeData( func (sp *Encoder) EncodeData(
metadata []byte, metadata []byte,
sectorSize abi.SectorSize, sectorSize abi.SectorSize,
MetaLen uint32, MetaLen uint32,
DataLen uint32, DataLen uint32,
hashData []byte, hashData []byte,
) ([]storage.Piece, error) { ) ([]storage.Piece, error) {
root := filepath.Join(sp.Root, "pieces") root := filepath.Join(sp.Root, "pieces")
var prePieceHash storage.Hash var prePieceHash storage.Hash
var pieces []storage.Piece var pieces []storage.Piece
var err error var err error
for ;len(hashData) > 0; { for len(hashData) > 0 {
var buf []byte var buf []byte
//encode next n sector //encode next n sector
if pieces != nil{ if pieces != nil {
CommLen := min(uint32(len(hashData)), ((DataLen-32)/32) * 32) CommLen := min(uint32(len(hashData)), ((DataLen-32)/32)*32)
var data *storage.DecodedData = &storage.DecodedData{ var data *storage.DecodedData = &storage.DecodedData{
HasPre: true, HasPre: true,
PreHash: prePieceHash, PreHash: prePieceHash,
HashData: hashData[:CommLen], HashData: hashData[:CommLen],
} }
buf, err = data.Serialize() buf, err = data.Serialize()
...@@ -138,10 +138,10 @@ func (sp *Encoder) EncodeData( ...@@ -138,10 +138,10 @@ func (sp *Encoder) EncodeData(
hashData = hashData[CommLen:] hashData = hashData[CommLen:]
} else { } else {
CommLen := min(uint32(len(hashData)), ((DataLen-MetaLen)/32) * 32) CommLen := min(uint32(len(hashData)), ((DataLen-MetaLen)/32)*32)
var data *storage.DecodedData = &storage.DecodedData{ var data *storage.DecodedData = &storage.DecodedData{
HasPre: false, HasPre: false,
Data: metadata, Data: metadata,
HashData: hashData[:CommLen], HashData: hashData[:CommLen],
} }
buf, err = data.Serialize() buf, err = data.Serialize()
...@@ -165,8 +165,8 @@ func (sp *Encoder) EncodeData( ...@@ -165,8 +165,8 @@ func (sp *Encoder) EncodeData(
// fmt.Printf("encode2: %x.dat\n", prePieceHash[:]) // fmt.Printf("encode2: %x.dat\n", prePieceHash[:])
pieces = append(pieces, storage.Piece{ pieces = append(pieces, storage.Piece{
Commitment: prePieceHash, Commitment: prePieceHash,
Size: abi.UnpaddedPieceSize(len(buf)), Size: abi.UnpaddedPieceSize(len(buf)),
}) })
} }
...@@ -174,15 +174,15 @@ func (sp *Encoder) EncodeData( ...@@ -174,15 +174,15 @@ func (sp *Encoder) EncodeData(
} }
func DecodePiece( func DecodePiece(
ctx context.Context, ctx context.Context,
sectorSize abi.SectorSize, sectorSize abi.SectorSize,
in io.Reader, in io.Reader,
) (storage.DecodedData, error) { ) (storage.DecodedData, error) {
unpaddedSectorSize := abi.PaddedPieceSize(sectorSize).Unpadded() unpaddedSectorSize := abi.PaddedPieceSize(sectorSize).Unpadded()
buf := make([]byte, unpaddedSectorSize) buf := make([]byte, unpaddedSectorSize)
read, err := in.Read(buf[:]) read, err := in.Read(buf[:])
if err != nil && err != io.EOF{ if err != nil && err != io.EOF {
return storage.DecodedData{}, err return storage.DecodedData{}, err
} }
...@@ -191,8 +191,9 @@ func DecodePiece( ...@@ -191,8 +191,9 @@ func DecodePiece(
return *data, err return *data, err
} }
type Sealer struct{ type Sealer struct {
sectors SectorManager sectors SectorManager
sortedPieces []storage.Piece
} }
var _ SectorSealer = &Sealer{} var _ SectorSealer = &Sealer{}
...@@ -205,10 +206,10 @@ func New(sectors SectorManager) (*Sealer, error) { ...@@ -205,10 +206,10 @@ func New(sectors SectorManager) (*Sealer, error) {
return sb, nil return sb, nil
} }
func (sb *Sealer)AddPiece( func (sb *Sealer) AddPiece(
ctx context.Context, ctx context.Context,
sector storage.SectorRef, sector storage.SectorRef,
sortedPieces []storage.Piece, sortedPieces []storage.Piece,
) ([]abi.PieceInfo, []storage.Piece, error) { ) ([]abi.PieceInfo, []storage.Piece, error) {
var index int var index int
var addPieces []storage.Piece var addPieces []storage.Piece
...@@ -224,7 +225,7 @@ func (sb *Sealer)AddPiece( ...@@ -224,7 +225,7 @@ func (sb *Sealer)AddPiece(
maxPieceSize := abi.PaddedPieceSize(ssize).Unpadded() maxPieceSize := abi.PaddedPieceSize(ssize).Unpadded()
pieceRoot := filepath.Join(sb.sectors.GetRoot(), "pieces") pieceRoot := filepath.Join(sb.sectors.GetRoot(), "pieces")
for index = 0;index < len(sortedPieces); { for index = 0; index < len(sortedPieces); {
pieceSize += sortedPieces[index].Size pieceSize += sortedPieces[index].Size
if pieceSize > maxPieceSize { if pieceSize > maxPieceSize {
return nil, sortedPieces, xerrors.Errorf("Exists a piece whose size is bigger than 8MiB or is not power of two or the pieces is not sorted") return nil, sortedPieces, xerrors.Errorf("Exists a piece whose size is bigger than 8MiB or is not power of two or the pieces is not sorted")
...@@ -241,16 +242,16 @@ func (sb *Sealer)AddPiece( ...@@ -241,16 +242,16 @@ func (sb *Sealer)AddPiece(
return nil, sortedPieces, PicesNotEnoughError return nil, sortedPieces, PicesNotEnoughError
} }
for _, piece := range(addPieces) { for _, piece := range addPieces {
filename := filepath.Join(pieceRoot, fmt.Sprintf("%x.dat", piece.Commitment[:])) filename := filepath.Join(pieceRoot, fmt.Sprintf("%x.dat", piece.Commitment[:]))
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { if err != nil {
return nil, sortedPieces, err return nil, sortedPieces, err
} }
defer func(){ defer func() {
file.Close() file.Close()
os.Remove(filename) os.Remove(filename)
} () }()
fmt.Printf("Adding %x.dat\n", piece.Commitment[:]) fmt.Printf("Adding %x.dat\n", piece.Commitment[:])
pieceInfo, err := sb.addPiece(ctx, sector, existingPieceSizes, piece.Size, file) pieceInfo, err := sb.addPiece(ctx, sector, existingPieceSizes, piece.Size, file)
if err != nil { if err != nil {
...@@ -263,12 +264,12 @@ func (sb *Sealer)AddPiece( ...@@ -263,12 +264,12 @@ func (sb *Sealer)AddPiece(
return piecesInfo, sortedPieces[index:], nil return piecesInfo, sortedPieces[index:], nil
} }
func (sb *Sealer)addPiece( func (sb *Sealer) addPiece(
ctx context.Context, ctx context.Context,
sector storage.SectorRef, sector storage.SectorRef,
existingPieceSizes []abi.UnpaddedPieceSize, existingPieceSizes []abi.UnpaddedPieceSize,
pieceSize abi.UnpaddedPieceSize, pieceSize abi.UnpaddedPieceSize,
file storage.Data, file storage.Data,
) (abi.PieceInfo, error) { ) (abi.PieceInfo, error) {
chunk := abi.PaddedPieceSize(4 << 20) chunk := abi.PaddedPieceSize(4 << 20)
parallel := runtime.NumCPU() parallel := runtime.NumCPU()
...@@ -504,14 +505,13 @@ func ToReadableFile(r io.Reader, n int64) (*os.File, func() error, error) { ...@@ -504,14 +505,13 @@ func ToReadableFile(r io.Reader, n int64) (*os.File, func() error, error) {
}, nil }, nil
} }
func (sb *Sealer) UnsealedRange(
func (sb *Sealer)UnsealedRange( ctx context.Context,
ctx context.Context, sid storage.SectorRef,
sid storage.SectorRef, out io.Writer,
out io.Writer, commd cid.Cid,
commd cid.Cid, offset storiface.UnpaddedByteIndex,
offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize,
size abi.UnpaddedPieceSize,
) error { ) error {
log.Infof("[%d] Unsealing sector", sid.ID.Number) log.Infof("[%d] Unsealing sector", sid.ID.Number)
{ {
...@@ -532,7 +532,7 @@ func (sb *Sealer)UnsealedRange( ...@@ -532,7 +532,7 @@ func (sb *Sealer)UnsealedRange(
} }
ok, err := sb.ReadPiece(ctx, out, sid, offset, size) ok, err := sb.ReadPiece(ctx, out, sid, offset, size)
if err != nil{ if err != nil {
return err return err
} }
...@@ -766,16 +766,16 @@ func (sb *Sealer) ReadPiece(ctx context.Context, writer io.Writer, sector storag ...@@ -766,16 +766,16 @@ func (sb *Sealer) ReadPiece(ctx context.Context, writer io.Writer, sector storag
} }
return true, nil return true, nil
} }
// //
func (sb *Sealer)CheckPieceAndDataRoot( func (sb *Sealer) CheckPieceAndDataRoot(
sid storage.SectorRef, sid storage.SectorRef,
commd cid.Cid, commd cid.Cid,
pieces []abi.PieceInfo, pieces []abi.PieceInfo,
) (bool, error) { ) (bool, error) {
UnsealedCID, err := ffi.GenerateUnsealedCID(sid.ProofType, pieces) UnsealedCID, err := ffi.GenerateUnsealedCID(sid.ProofType, pieces)
if err != nil{ if err != nil {
return false, err return false, err
} }
...@@ -893,9 +893,9 @@ func (sb *Sealer) SealCommit2(ctx context.Context, sector storage.SectorRef, pha ...@@ -893,9 +893,9 @@ func (sb *Sealer) SealCommit2(ctx context.Context, sector storage.SectorRef, pha
return ffi.SealCommitPhase2(phase1Out, sector.ID.Number, sector.ID.Miner) return ffi.SealCommitPhase2(phase1Out, sector.ID.Number, sector.ID.Miner)
} }
func (sb *Sealer)Sealed( func (sb *Sealer) Sealed(
ctx context.Context, ctx context.Context,
sid storage.SectorRef, sid storage.SectorRef,
pieces []abi.PieceInfo, pieces []abi.PieceInfo,
) (storage.SectorCids, error) { ) (storage.SectorCids, error) {
// var sealedSectors spproof.SectorInfo // var sealedSectors spproof.SectorInfo
...@@ -916,12 +916,12 @@ func (sb *Sealer)Sealed( ...@@ -916,12 +916,12 @@ func (sb *Sealer)Sealed(
return cids, nil return cids, nil
} }
func (sb *Sealer)GenerateCommitProof( func (sb *Sealer) GenerateCommitProof(
ctx context.Context, ctx context.Context,
sid storage.SectorRef, sid storage.SectorRef,
seed abi.InteractiveSealRandomness, seed abi.InteractiveSealRandomness,
pieces []abi.PieceInfo, pieces []abi.PieceInfo,
cids storage.SectorCids, cids storage.SectorCids,
) (spproof.Proof, error) { ) (spproof.Proof, error) {
log.Infof("[%d] Generating PoRep for sector (1)", sid.ID.Number) log.Infof("[%d] Generating PoRep for sector (1)", sid.ID.Number)
...@@ -934,25 +934,25 @@ func (sb *Sealer)GenerateCommitProof( ...@@ -934,25 +934,25 @@ func (sb *Sealer)GenerateCommitProof(
return sb.SealCommit2(ctx, sid, c1out) return sb.SealCommit2(ctx, sid, c1out)
} }
func (sb *Sealer)AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error){ func (sb *Sealer) AggregateSealProofs(aggregateInfo spproof.AggregateSealVerifyProofAndInfos, proofs []spproof.Proof) (spproof.Proof, error) {
return ffi.AggregateSealProofs(aggregateInfo, proofs) return ffi.AggregateSealProofs(aggregateInfo, proofs)
} }
func (sb *Sealer)GenerateWindowPoStProofs( func (sb *Sealer) GenerateWindowPoStProofs(
ctx context.Context, ctx context.Context,
minerID abi.ActorID, minerID abi.ActorID,
sectorInfo []spproof.SectorInfo, sectorInfo []spproof.SectorInfo,
randomness abi.PoStRandomness, randomness abi.PoStRandomness,
) ([]spproof.PoStProof, []abi.SectorID, error) { ) (spproof.PoStProof, []abi.SectorID, error) {
randomness[31] &= 0x3f randomness[31] &= 0x3f
privsectors, skipped, done, err := sb.pubSectorToPriv(ctx, minerID, sectorInfo, nil, abi.RegisteredSealProof.RegisteredWindowPoStProof) privsectors, skipped, done, err := sb.pubSectorToPriv(ctx, minerID, sectorInfo, nil, abi.RegisteredSealProof.RegisteredWindowPoStProof)
if err != nil { if err != nil {
return nil, nil, xerrors.Errorf("gathering sector info: %w", err) return spproof.PoStProof{}, nil, xerrors.Errorf("gathering sector info: %w", err)
} }
defer done() defer done()
if len(skipped) > 0 { if len(skipped) > 0 {
return nil, skipped, xerrors.Errorf("pubSectorToPriv skipped some sectors") return spproof.PoStProof{}, skipped, xerrors.Errorf("pubSectorToPriv skipped some sectors")
} }
log.Infof("Generating Window-PoSt Proof") log.Infof("Generating Window-PoSt Proof")
...@@ -969,19 +969,19 @@ func (sb *Sealer)GenerateWindowPoStProofs( ...@@ -969,19 +969,19 @@ func (sb *Sealer)GenerateWindowPoStProofs(
return proof, faultyIDs, err return proof, faultyIDs, err
} }
func (sb *Sealer)AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.Proof, error) { func (sb *Sealer) AggregateWindowPoStProofs(aggregateInfo spproof.AggregateWindowPostInfos, proofs []spproof.PoStProof) (spproof.PoStProof, error) {
if len(proofs) != len(aggregateInfo.SectorCount) { if len(proofs) != len(aggregateInfo.SectorCount) {
return nil, xerrors.Errorf("the lenth of windowPoStProofs and sectorCount is not match") return spproof.PoStProof{}, xerrors.Errorf("the lenth of windowPoStProofs and sectorCount is not match")
} }
sectorCount := aggregateInfo.SectorCount[0] sectorCount := aggregateInfo.SectorCount[0]
for _, count := range(aggregateInfo.SectorCount) { for _, count := range aggregateInfo.SectorCount {
if sectorCount != count { if sectorCount != count {
return nil, xerrors.Errorf("Window PoSt challenge count must be equal") return spproof.PoStProof{}, xerrors.Errorf("Window PoSt challenge count must be equal")
} }
} }
for i, random := range(aggregateInfo.Randomnesses) { for i, random := range aggregateInfo.Randomnesses {
aggregateInfo.Randomnesses[i][31] = random[31] & 0x3f aggregateInfo.Randomnesses[i][31] = random[31] & 0x3f
} }
return ffi.AggregateWindowPoStProofs(aggregateInfo, proofs) return ffi.AggregateWindowPoStProofs(aggregateInfo, proofs)
...@@ -1056,7 +1056,7 @@ func (v Verifier) VerifySeal(info spproof.SealVerifyInfo) (bool, error) { ...@@ -1056,7 +1056,7 @@ func (v Verifier) VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
v.lock.Lock() v.lock.Lock()
defer v.lock.Unlock() defer v.lock.Unlock()
v.sm[info.SectorID] = storage.SectorCids{ v.sm[info.SectorID] = storage.SectorCids{
Sealed: info.SealedCID, Sealed: info.SealedCID,
Unsealed: info.UnsealedCID, Unsealed: info.UnsealedCID,
} }
} }
...@@ -1073,11 +1073,11 @@ func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProo ...@@ -1073,11 +1073,11 @@ func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProo
defer v.lock.Unlock() defer v.lock.Unlock()
for _, info := range aggregate.Infos { for _, info := range aggregate.Infos {
sid := abi.SectorID{ sid := abi.SectorID{
Miner: aggregate.Miner, Miner: aggregate.Miner,
Number: info.Number, Number: info.Number,
} }
v.sm[sid] = storage.SectorCids{ v.sm[sid] = storage.SectorCids{
Sealed: info.SealedCID, Sealed: info.SealedCID,
Unsealed: info.UnsealedCID, Unsealed: info.UnsealedCID,
} }
} }
...@@ -1086,58 +1086,59 @@ func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProo ...@@ -1086,58 +1086,59 @@ func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProo
} }
func (v Verifier) VerifyWindowPoSt( func (v Verifier) VerifyWindowPoSt(
sectors []storage.SectorRef, sectors []storage.SectorRef,
proofs []spproof.PoStProof, proof spproof.PoStProof,
randomness abi.PoStRandomness, randomness abi.PoStRandomness,
proverID abi.ActorID, proverID abi.ActorID,
) (bool, error) { ) (bool, error) {
chanllendedSectors := make([]spproof.SectorInfo, len(sectors)) chanllendedSectors := make([]spproof.SectorInfo, len(sectors))
// minerID = sectors[0].ID.Miner // minerID = sectors[0].ID.Miner
v.lock.RLock() v.lock.RLock()
// defer m.Lock.RUnLock() // defer m.Lock.RUnLock()
for idx, sid := range(sectors){ for idx, sid := range sectors {
cids, ok := v.sm[sid.ID] cids, ok := v.sm[sid.ID]
if !ok { if !ok {
v.lock.RUnlock() v.lock.RUnlock()
return false, xerrors.Errorf("can not map the sectorID into sector commitment") return false, xerrors.Errorf("can not map the sectorID into sector commitment")
} }
chanllendedSectors[idx] = spproof.SectorInfo{ chanllendedSectors[idx] = spproof.SectorInfo{
SealType: sid.ProofType, SealType: sid.ProofType,
SectorNumber: sid.ID.Number, SectorNumber: sid.ID.Number,
SealedCID: cids.Sealed, SealedCID: cids.Sealed,
} }
} }
v.lock.RUnlock() v.lock.RUnlock()
randomness[31] &= 0x3f randomness[31] &= 0x3f
log.Infof("Verifying Window-PoSt Proof")
return ffi.VerifyWindowPoSt(spproof.WindowPoStVerifyInfo{ return ffi.VerifyWindowPoSt(spproof.WindowPoStVerifyInfo{
Randomness: randomness, Randomness: randomness,
Proofs: proofs, Proof: proof,
ChallengedSectors: chanllendedSectors, ChallengedSectors: chanllendedSectors,
Prover: proverID, Prover: proverID,
}) })
} }
func (v Verifier)VerifyAggregateWindowPostProofs( func (v Verifier) VerifyAggregateWindowPostProofs(
sectors [][]storage.SectorRef, sectors [][]storage.SectorRef,
proof spproof.Proof, proof spproof.PoStProof,
randomnesses []abi.PoStRandomness, randomnesses []abi.PoStRandomness,
proverID abi.ActorID, proverID abi.ActorID,
) (bool, error) { ) (bool, error) {
var sectorInfos []spproof.SectorInfo var sectorInfos []spproof.SectorInfo
sectorCount := make([]uint, len(sectors)) sectorCount := make([]uint, len(sectors))
v.lock.RLock() v.lock.RLock()
// defer v.Lock.RUnLock() // defer v.Lock.RUnLock()
for i, sectorRange := range(sectors) { for i, sectorRange := range sectors {
sectorCount[i] = uint(len(sectorRange)) sectorCount[i] = uint(len(sectorRange))
for _, sid := range(sectorRange) { for _, sid := range sectorRange {
cids, ok := v.sm[sid.ID] cids, ok := v.sm[sid.ID]
if !ok { if !ok {
v.lock.RUnlock() v.lock.RUnlock()
return false, xerrors.Errorf("can not map the sectorID into sector commitment") return false, xerrors.Errorf("can not map the sectorID into sector commitment")
} }
sectorInfos = append(sectorInfos, spproof.SectorInfo{ sectorInfos = append(sectorInfos, spproof.SectorInfo{
SealType: sid.ProofType, SealType: sid.ProofType,
SectorNumber: sid.ID.Number, SectorNumber: sid.ID.Number,
SealedCID: cids.Sealed, SealedCID: cids.Sealed,
}) })
...@@ -1145,7 +1146,7 @@ func (v Verifier)VerifyAggregateWindowPostProofs( ...@@ -1145,7 +1146,7 @@ func (v Verifier)VerifyAggregateWindowPostProofs(
} }
v.lock.RUnlock() v.lock.RUnlock()
for i, random := range(randomnesses) { for i, random := range randomnesses {
randomnesses[i][31] = random[31] & 0x3f randomnesses[i][31] = random[31] & 0x3f
} }
...@@ -1165,7 +1166,7 @@ func (v Verifier)VerifyAggregateWindowPostProofs( ...@@ -1165,7 +1166,7 @@ func (v Verifier)VerifyAggregateWindowPostProofs(
} }
func DefaultAggregationType() abi.RegisteredAggregationProof { func DefaultAggregationType() abi.RegisteredAggregationProof {
return abi.RegisteredAggregationProof_SnarkPackV1; return abi.RegisteredAggregationProof_SnarkPackV1
} }
func spt(ssize abi.SectorSize) abi.RegisteredSealProof { func spt(ssize abi.SectorSize) abi.RegisteredSealProof {
...@@ -1182,4 +1183,4 @@ func min(x, y uint32) uint32 { ...@@ -1182,4 +1183,4 @@ func min(x, y uint32) uint32 {
return x return x
} }
return y return y
} }
\ No newline at end of file
package seal package seal
import( import (
"context" "context"
"io"
"os"
"fmt" "fmt"
"time" "io"
"math/rand"
"io/ioutil" "io/ioutil"
"math/rand"
"os"
"path/filepath" "path/filepath"
"time"
"golang.org/x/xerrors"
"github.com/mitchellh/go-homedir"
"github.com/minio/md5-simd"
"github.com/minio/blake2b-simd"
"github.com/filecoin-project/go-state-types/abi"
commcid "github.com/filecoin-project/go-fil-commcid" commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-state-types/abi"
"github.com/minio/blake2b-simd"
"github.com/minio/md5-simd"
"github.com/mitchellh/go-homedir"
"golang.org/x/xerrors"
spproof "fil_integrate/build/proof" spproof "fil_integrate/build/proof"
"fil_integrate/build/storage" "fil_integrate/build/storage"
...@@ -54,14 +54,14 @@ func TestSealAndUnseal() error { ...@@ -54,14 +54,14 @@ func TestSealAndUnseal() error {
return err return err
} }
sbfs := &basicfs.Manager{ sbfs := &basicfs.Manager{
Root: tsdir, Root: tsdir,
} }
sb ,err := New(sbfs) sb, err := New(sbfs)
if err != nil{ if err != nil {
return err return err
} }
ctx := context.TODO() ctx := context.TODO()
sectorSize := abi.SectorSize(8*1024*1024) sectorSize := abi.SectorSize(8 * 1024 * 1024)
sid := storage.SectorRef{ sid := storage.SectorRef{
ID: abi.SectorID{ ID: abi.SectorID{
Miner: 1000, Miner: 1000,
...@@ -96,7 +96,7 @@ func TestSealAndUnseal() error { ...@@ -96,7 +96,7 @@ func TestSealAndUnseal() error {
existingPieceSizes = append(existingPieceSizes, piece.Size.Unpadded()) existingPieceSizes = append(existingPieceSizes, piece.Size.Unpadded())
pieces = append(pieces, piece) pieces = append(pieces, piece)
piece, err = sb.addPiece(ctx, sid, existingPieceSizes, abi.PaddedPieceSize(sectorSize/2).Unpadded(), file) piece, err = sb.addPiece(ctx, sid, existingPieceSizes, abi.PaddedPieceSize(sectorSize/2).Unpadded(), file)
if err != nil { if err != nil {
return err return err
...@@ -194,8 +194,8 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error { ...@@ -194,8 +194,8 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error {
sbfs := &basicfs.Manager{ sbfs := &basicfs.Manager{
Root: tsdir, Root: tsdir,
} }
sb ,err := New(sbfs) sb, err := New(sbfs)
if err != nil{ if err != nil {
return err return err
} }
...@@ -207,7 +207,7 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error { ...@@ -207,7 +207,7 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error {
b := []byte("random data") b := []byte("random data")
var numFile = 4 var numFile = 4
var sortedPieces []storage.Piece var sortedPieces []storage.Piece
var finalPieces = make([]storage.Piece, numFile) var finalPieces = make([]storage.Piece, numFile)
for i := 0; i < numFile; i++ { for i := 0; i < numFile; i++ {
filename := filepath.Join(tsdir, fmt.Sprintf("input-%d.dat", i)) filename := filepath.Join(tsdir, fmt.Sprintf("input-%d.dat", i))
start := time.Now() start := time.Now()
...@@ -225,7 +225,7 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error { ...@@ -225,7 +225,7 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error {
start = time.Now() start = time.Now()
finalPiece, pieces, err := sp.EncodeDataToPieces(ctx, sectorSize, in) finalPiece, pieces, err := sp.EncodeDataToPieces(ctx, sectorSize, in)
if err != nil{ if err != nil {
return err return err
} }
fmt.Printf("encode data using %s\n", time.Now().Sub(start)) fmt.Printf("encode data using %s\n", time.Now().Sub(start))
...@@ -236,10 +236,10 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error { ...@@ -236,10 +236,10 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error {
var index int var index int
var perr error var perr error
var piecesInfo []abi.PieceInfo var piecesInfo []abi.PieceInfo
for{ for {
sid := storage.SectorRef{ sid := storage.SectorRef{
ID: abi.SectorID{ ID: abi.SectorID{
Miner: minerID, Miner: minerID,
Number: abi.SectorNumber(index), Number: abi.SectorNumber(index),
}, },
ProofType: spt(sectorSize), ProofType: spt(sectorSize),
...@@ -256,7 +256,7 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error { ...@@ -256,7 +256,7 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error {
if err != nil { if err != nil {
return err return err
} }
for _, piece := range(piecesInfo) { for _, piece := range piecesInfo {
var commitHash storage.Hash var commitHash storage.Hash
commit, err := commcid.CIDToPieceCommitmentV1(piece.PieceCID) commit, err := commcid.CIDToPieceCommitmentV1(piece.PieceCID)
if err != nil { if err != nil {
...@@ -264,18 +264,18 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error { ...@@ -264,18 +264,18 @@ func TestSplitDataInToPieces(sectorSize abi.SectorSize, dataSize uint64) error {
} }
copy(commitHash[:], commit) copy(commitHash[:], commit)
hashMap[commitHash] = storage.RangeSector{ hashMap[commitHash] = storage.RangeSector{
Sector: sid, Sector: sid,
Sealed: cids.Sealed, Sealed: cids.Sealed,
Unsealed: cids.Unsealed, Unsealed: cids.Unsealed,
Offset: storiface.UnpaddedByteIndex(offset), Offset: storiface.UnpaddedByteIndex(offset),
Size: piece.Size.Unpadded(), Size: piece.Size.Unpadded(),
} }
offset += piece.Size.Unpadded() offset += piece.Size.Unpadded()
} }
index++ index++
} }
for i ,finalPiece := range(finalPieces) { for i, finalPiece := range finalPieces {
filename := filepath.Join(tsdir, fmt.Sprintf("output-%d.dat", i)) filename := filepath.Join(tsdir, fmt.Sprintf("output-%d.dat", i))
if _, err = os.Stat(filename); !os.IsNotExist(err) { if _, err = os.Stat(filename); !os.IsNotExist(err) {
os.Remove(filename) os.Remove(filename)
...@@ -333,8 +333,8 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -333,8 +333,8 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
sbfs := &basicfs.Manager{ sbfs := &basicfs.Manager{
Root: tsdir, Root: tsdir,
} }
sb ,err := New(sbfs) sb, err := New(sbfs)
if err != nil{ if err != nil {
return err return err
} }
sp := &Encoder{ sp := &Encoder{
...@@ -356,7 +356,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -356,7 +356,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
for i := 0; i < numAggregate; i++ { for i := 0; i < numAggregate; i++ {
filename := filepath.Join(tsdir, fmt.Sprintf("input-%d.dat", i)) filename := filepath.Join(tsdir, fmt.Sprintf("input-%d.dat", i))
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
Datasize := (r.Intn(1024*1024) + 1024*1024)*32 Datasize := (r.Intn(1024*1024) + 1024*1024) * 32
b, err = generateRandomData(filename, uint64(Datasize), b) b, err = generateRandomData(filename, uint64(Datasize), b)
if err != nil { if err != nil {
return err return err
...@@ -368,7 +368,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -368,7 +368,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
defer in.Close() defer in.Close()
finalPiece, pieces, err := sp.EncodeDataToPieces(ctx, sectorSize, in) finalPiece, pieces, err := sp.EncodeDataToPieces(ctx, sectorSize, in)
if err != nil{ if err != nil {
return err return err
} }
...@@ -378,7 +378,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -378,7 +378,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
} }
var perr error var perr error
for{ for {
var infos []spproof.AggregateSealVerifyInfo var infos []spproof.AggregateSealVerifyInfo
var sealedSectors []spproof.SectorInfo var sealedSectors []spproof.SectorInfo
var sectors []storage.SectorRef var sectors []storage.SectorRef
...@@ -387,7 +387,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -387,7 +387,7 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
sid := storage.SectorRef{ sid := storage.SectorRef{
ID: abi.SectorID{ ID: abi.SectorID{
Miner: minerID, Miner: minerID,
Number: abi.SectorNumber(index), Number: abi.SectorNumber(index),
}, },
ProofType: spt(sectorSize), ProofType: spt(sectorSize),
...@@ -408,18 +408,18 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -408,18 +408,18 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
return err return err
} }
infos = append(infos, spproof.AggregateSealVerifyInfo{ infos = append(infos, spproof.AggregateSealVerifyInfo{
Number: sid.ID.Number, Number: sid.ID.Number,
InteractiveRandomness: seed, InteractiveRandomness: seed,
SealedCID: cids.Sealed, SealedCID: cids.Sealed,
UnsealedCID: cids.Unsealed, UnsealedCID: cids.Unsealed,
}) })
sealedSectors = append(sealedSectors, spproof.SectorInfo{ sealedSectors = append(sealedSectors, spproof.SectorInfo{
SealType: sid.ProofType, SealType: sid.ProofType,
SectorNumber: sid.ID.Number, SectorNumber: sid.ID.Number,
SealedCID: cids.Sealed, SealedCID: cids.Sealed,
}) })
var offset abi.UnpaddedPieceSize = 0 var offset abi.UnpaddedPieceSize = 0
for _, piece := range(pieces) { for _, piece := range pieces {
var commitHash storage.Hash var commitHash storage.Hash
commit, err := commcid.CIDToPieceCommitmentV1(piece.PieceCID) commit, err := commcid.CIDToPieceCommitmentV1(piece.PieceCID)
if err != nil { if err != nil {
...@@ -427,11 +427,11 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -427,11 +427,11 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
} }
copy(commitHash[:], commit) copy(commitHash[:], commit)
hashMap[commitHash] = storage.RangeSector{ hashMap[commitHash] = storage.RangeSector{
Sector: sid, Sector: sid,
Sealed: cids.Sealed, Sealed: cids.Sealed,
Unsealed: cids.Unsealed, Unsealed: cids.Unsealed,
Offset: storiface.UnpaddedByteIndex(offset), Offset: storiface.UnpaddedByteIndex(offset),
Size: piece.Size.Unpadded(), Size: piece.Size.Unpadded(),
} }
offset += piece.Size.Unpadded() offset += piece.Size.Unpadded()
} }
...@@ -447,10 +447,10 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -447,10 +447,10 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
// //
aggregateInfo := spproof.AggregateSealVerifyProofAndInfos{ aggregateInfo := spproof.AggregateSealVerifyProofAndInfos{
Miner: minerID, Miner: minerID,
SealType: spt(sectorSize), SealType: spt(sectorSize),
AggregateType: DefaultAggregationType(), AggregateType: DefaultAggregationType(),
Infos: infos, Infos: infos,
} }
proof, err := sb.AggregateSealProofs(aggregateInfo, proofs) proof, err := sb.AggregateSealProofs(aggregateInfo, proofs)
if err != nil { if err != nil {
...@@ -470,17 +470,17 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -470,17 +470,17 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
if err != nil { if err != nil {
return err return err
} }
randomnesses = append(randomnesses, seed) randomnesses = append(randomnesses, seed)
sectorCount = append(sectorCount, uint(len(sealedSectors))) sectorCount = append(sectorCount, uint(len(sealedSectors)))
sectorsInfo = append(sectorsInfo, sectors) sectorsInfo = append(sectorsInfo, sectors)
postProofs = append(postProofs, postProof...) postProofs = append(postProofs, postProof)
} }
proof, err := sb.AggregateWindowPoStProofs(spproof.AggregateWindowPostInfos{ proof, err := sb.AggregateWindowPoStProofs(spproof.AggregateWindowPostInfos{
AggregateType: DefaultAggregationType(), AggregateType: DefaultAggregationType(),
Randomnesses: randomnesses, Randomnesses: randomnesses,
SectorCount: sectorCount, SectorCount: sectorCount,
}, postProofs) }, postProofs)
if err != nil { if err != nil {
return err return err
} }
...@@ -527,10 +527,10 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error { ...@@ -527,10 +527,10 @@ func TestSealAndWindowPoSt(sectorSize abi.SectorSize, numAggregate int) error {
return nil return nil
} }
func Insert(sortedPieces []storage.Piece, pieces []storage.Piece, finalPiece storage.Piece) ([]storage.Piece) { func Insert(sortedPieces []storage.Piece, pieces []storage.Piece, finalPiece storage.Piece) []storage.Piece {
var i int var i int
var res []storage.Piece var res []storage.Piece
for i = len(sortedPieces)-1; i >= 0; i-- { for i = len(sortedPieces) - 1; i >= 0; i-- {
if sortedPieces[i].Size >= finalPiece.Size { if sortedPieces[i].Size >= finalPiece.Size {
break break
} }
...@@ -545,10 +545,10 @@ func generateRandomData(filename string, dataSize uint64, b []byte) ([]byte, err ...@@ -545,10 +545,10 @@ func generateRandomData(filename string, dataSize uint64, b []byte) ([]byte, err
os.Remove(filename) os.Remove(filename)
} }
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
Datasize := (r.Intn(1024*1024) + 1024*1024)*32 Datasize := (r.Intn(1024*1024) + 1024*1024) * 32
var i uint64 // var i uint64
buf := make([]byte, Datasize) buf := make([]byte, Datasize)
for i = 0; i < Datasize; i += 32{ for i := 0; i < Datasize; i += 32 {
tmp := blake2b.Sum256(b) tmp := blake2b.Sum256(b)
b = tmp[:] b = tmp[:]
copy(buf[i:i+32], b[:]) copy(buf[i:i+32], b[:])
...@@ -575,11 +575,11 @@ func decodePiecesToData(sb *Sealer, ctx context.Context, tsdir string, sectorSiz ...@@ -575,11 +575,11 @@ func decodePiecesToData(sb *Sealer, ctx context.Context, tsdir string, sectorSiz
} }
piecesHash := data.PieceHash piecesHash := data.PieceHash
for ; data.HasPre; { for data.HasPre {
file, err = unseal(sb, ctx, data.PreHash) file, err = unseal(sb, ctx, data.PreHash)
data, err = DecodePiece(ctx, sectorSize, file) data, err = DecodePiece(ctx, sectorSize, file)
file.Close() file.Close()
if err != nil{ if err != nil {
return err return err
} }
piecesHash = append(data.PieceHash, piecesHash...) piecesHash = append(data.PieceHash, piecesHash...)
...@@ -595,12 +595,12 @@ func decodePiecesToData(sb *Sealer, ctx context.Context, tsdir string, sectorSiz ...@@ -595,12 +595,12 @@ func decodePiecesToData(sb *Sealer, ctx context.Context, tsdir string, sectorSiz
} }
_, err = out.Write(data.Data[:]) _, err = out.Write(data.Data[:])
if err != nil{ if err != nil {
return err return err
} }
} }
_, err = out.Write(buf[:]) _, err = out.Write(buf[:])
if err != nil{ if err != nil {
return err return err
} }
return nil return nil
...@@ -646,30 +646,29 @@ func checkDecodedFile(root string, i int) (bool, error) { ...@@ -646,30 +646,29 @@ func checkDecodedFile(root string, i int) (bool, error) {
outBuf := make([]byte, 2<<20) outBuf := make([]byte, 2<<20)
server1 := md5simd.NewServer() server1 := md5simd.NewServer()
defer server1.Close() defer server1.Close()
server2 := md5simd.NewServer() server2 := md5simd.NewServer()
defer server2.Close() defer server2.Close()
h1 := server1.NewHash() h1 := server1.NewHash()
defer h1.Close() defer h1.Close()
h2 := server2.NewHash() h2 := server2.NewHash()
defer h2.Close() defer h2.Close()
for{ for {
_, inerr := in.Read(inBuf[:]) _, inerr := in.Read(inBuf[:])
if err != nil && err != io.EOF{ if err != nil && err != io.EOF {
return false, err return false, err
} }
_, outerr := out.Read(outBuf[:]) _, outerr := out.Read(outBuf[:])
if err != nil && err != io.EOF{ if err != nil && err != io.EOF {
return false, err return false, err
} }
h1.Write(inBuf) h1.Write(inBuf)
h2.Write(outBuf) h2.Write(outBuf)
if inerr == io.EOF && outerr == io.EOF { if inerr == io.EOF && outerr == io.EOF {
hash1 := h1.Sum(nil) hash1 := h1.Sum(nil)
hash2 := h2.Sum(nil) hash2 := h2.Sum(nil)
...@@ -680,4 +679,4 @@ func checkDecodedFile(root string, i int) (bool, error) { ...@@ -680,4 +679,4 @@ func checkDecodedFile(root string, i int) (bool, error) {
} }
} }
return true, nil return true, nil
} }
\ No newline at end of file
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