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

add new test

parent 2ecdfd25
...@@ -9,6 +9,8 @@ import ( ...@@ -9,6 +9,8 @@ import (
"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"
"fil_integrate/build/storiface"
) )
type Data = io.Reader type Data = io.Reader
...@@ -20,6 +22,14 @@ type SectorRef struct { ...@@ -20,6 +22,14 @@ type SectorRef struct {
ProofType abi.RegisteredSealProof ProofType abi.RegisteredSealProof
} }
type RangeSector struct {
Sector SectorRef
Sealed cid.Cid
Unsealed cid.Cid
Offset storiface.UnpaddedByteIndex
Size abi.UnpaddedPieceSize
}
type PreCommit1Out []byte type PreCommit1Out []byte
type Commit1Out []byte type Commit1Out []byte
......
...@@ -24,10 +24,8 @@ func main() { ...@@ -24,10 +24,8 @@ func main() {
Usage: "Benchmark performance of seal and window-post", Usage: "Benchmark performance of seal and window-post",
Version: "1.0.1", Version: "1.0.1",
Commands: []*cli.Command{ Commands: []*cli.Command{
test,
testSealAndWindowPoSt, testSealAndWindowPoSt,
testSealCmd, testSealCmd,
testAggregationCmd,
testSplitDataCmd, testSplitDataCmd,
}, },
} }
...@@ -38,15 +36,6 @@ func main() { ...@@ -38,15 +36,6 @@ func main() {
} }
} }
var test = &cli.Command{
Name: "test",
Usage: "Test interface",
Action: func(c *cli.Context) error {
seal.Test()
return nil
},
}
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",
...@@ -93,47 +82,30 @@ var testSealCmd = &cli.Command{ ...@@ -93,47 +82,30 @@ 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",
Action: func(c *cli.Context) error {
// Test 8MiB sector
err := seal.TestSplitDataInToPieces()
if err != nil {
return err
}
return nil
},
}
var testAggregationCmd = &cli.Command{
Name: "test-aggregation",
Usage: "Test aggregate some window-post proofs",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "sector-size", Name: "sector-size",
Value: "2KiB", Value: "8MiB",
Usage: "size of the sectors in bytes", Usage: "size of the sectors in bytes",
}, },
&cli.IntFlag{ &cli.StringFlag{
Name: "num-sectors", Name: "data-size",
Value: 4, Value: "256MiB",
Usage: "How many sectors used in single window post", Usage: "size of the input file in bytes",
},
&cli.IntFlag{
Name: "num-agg",
Value: 4,
Usage: "How many window-post proofs used to aggregate",
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
log.Info("testing") // Test 8MiB sector
dataSize, err := units.RAMInBytes(c.String("data-size"))
if err != nil {
return err
}
sectorSizeInt, err := units.RAMInBytes(c.String("sector-size")) sectorSizeInt, err := units.RAMInBytes(c.String("sector-size"))
if err != nil { if err != nil {
return err return err
} }
sectorSize := abi.SectorSize(sectorSizeInt) sectorSize := abi.SectorSize(sectorSizeInt)
numSectors := c.Int("num-sectors") err = seal.TestSplitDataInToPieces(sectorSize, uint64(dataSize))
numAggregate := c.Int("num-agg")
err = seal.TestAggregateWindowPoSt(sectorSize, numSectors, numAggregate)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -21,6 +21,7 @@ import( ...@@ -21,6 +21,7 @@ import(
"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"
"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/storiface"
...@@ -36,6 +37,8 @@ const TagLen uint32 = 8 ...@@ -36,6 +37,8 @@ const TagLen uint32 = 8
const NewestNetworkVersion = network.Version13 const NewestNetworkVersion = network.Version13
var PicesNotEnoughError = xerrors.Errorf("can not use the existing pieces to fill the sector")
type Encoder struct { type Encoder struct {
Root string Root string
} }
...@@ -94,6 +97,7 @@ func (sp *Encoder) EncodeDataToPieces( ...@@ -94,6 +97,7 @@ func (sp *Encoder) EncodeDataToPieces(
if err != nil { if err != nil {
return storage.Piece{}, nil, err return storage.Piece{}, nil, err
} }
// fmt.Printf("encode1: %x.dat\n", pieceHash[:])
hashData = append(hashData, pieceHash[:]...) hashData = append(hashData, pieceHash[:]...)
pieces = append(pieces, storage.Piece{ pieces = append(pieces, storage.Piece{
...@@ -158,6 +162,7 @@ func (sp *Encoder) EncodeData( ...@@ -158,6 +162,7 @@ func (sp *Encoder) EncodeData(
if err != nil { if err != nil {
return nil, err return nil, err
} }
// fmt.Printf("encode2: %x.dat\n", prePieceHash[:])
pieces = append(pieces, storage.Piece{ pieces = append(pieces, storage.Piece{
Commitment: prePieceHash, Commitment: prePieceHash,
...@@ -203,8 +208,9 @@ func New(sectors SectorManager) (*Sealer, error) { ...@@ -203,8 +208,9 @@ func New(sectors SectorManager) (*Sealer, error) {
func (sb *Sealer)AddPiece( func (sb *Sealer)AddPiece(
ctx context.Context, ctx context.Context,
sector storage.SectorRef, sector storage.SectorRef,
pieces *[]storage.Piece, sortedPieces []storage.Piece,
) ([]abi.PieceInfo, error) { ) ([]abi.PieceInfo, []storage.Piece, error) {
var index int
var addPieces []storage.Piece var addPieces []storage.Piece
var pieceSize abi.UnpaddedPieceSize var pieceSize abi.UnpaddedPieceSize
var existingPieceSizes []abi.UnpaddedPieceSize var existingPieceSizes []abi.UnpaddedPieceSize
...@@ -212,34 +218,34 @@ func (sb *Sealer)AddPiece( ...@@ -212,34 +218,34 @@ func (sb *Sealer)AddPiece(
ssize, err := sector.ProofType.SectorSize() ssize, err := sector.ProofType.SectorSize()
if err != nil { if err != nil {
return nil, err return nil, sortedPieces, err
} }
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 ;len(*pieces) > 0; { for index = 0;index < len(sortedPieces); {
pieceSize += (*pieces)[0].Size pieceSize += sortedPieces[index].Size
if pieceSize > maxPieceSize { if pieceSize > maxPieceSize {
return nil, 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")
} else if pieceSize == maxPieceSize { } else if pieceSize == maxPieceSize {
addPieces = append(addPieces, (*pieces)[0]) addPieces = append(addPieces, sortedPieces[index])
(*pieces) = (*pieces)[1:] index++
break break
} }
addPieces = append(addPieces, (*pieces)[0]) addPieces = append(addPieces, sortedPieces[index])
(*pieces) = (*pieces)[1:] index++
} }
if pieceSize != maxPieceSize { if pieceSize != maxPieceSize {
return nil, xerrors.Errorf("can not use the existing pieces to generate 8MiB piece") 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, err return nil, sortedPieces, err
} }
defer func(){ defer func(){
file.Close() file.Close()
...@@ -248,13 +254,13 @@ func (sb *Sealer)AddPiece( ...@@ -248,13 +254,13 @@ func (sb *Sealer)AddPiece(
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 {
return nil, err return nil, sortedPieces, err
} }
existingPieceSizes = append(existingPieceSizes, piece.Size) existingPieceSizes = append(existingPieceSizes, piece.Size)
piecesInfo = append(piecesInfo, pieceInfo) piecesInfo = append(piecesInfo, pieceInfo)
} }
return piecesInfo, nil return piecesInfo, sortedPieces[index:], nil
} }
func (sb *Sealer)addPiece( func (sb *Sealer)addPiece(
...@@ -502,9 +508,8 @@ func ToReadableFile(r io.Reader, n int64) (*os.File, func() error, error) { ...@@ -502,9 +508,8 @@ func ToReadableFile(r io.Reader, n int64) (*os.File, func() error, error) {
func (sb *Sealer)UnsealedRange( func (sb *Sealer)UnsealedRange(
ctx context.Context, ctx context.Context,
sid storage.SectorRef, sid storage.SectorRef,
sectorSize abi.SectorSize,
commd cid.Cid,
out io.Writer, out io.Writer,
commd cid.Cid,
offset storiface.UnpaddedByteIndex, offset storiface.UnpaddedByteIndex,
size abi.UnpaddedPieceSize, size abi.UnpaddedPieceSize,
) error { ) error {
...@@ -521,7 +526,7 @@ func (sb *Sealer)UnsealedRange( ...@@ -521,7 +526,7 @@ func (sb *Sealer)UnsealedRange(
} }
} }
err := sb.UnsealPiece(ctx, sid, 0, abi.PaddedPieceSize(sectorSize).Unpadded(), commd) err := sb.UnsealPiece(ctx, sid, offset, size, commd)
if err != nil { if err != nil {
return err return err
} }
...@@ -1033,13 +1038,13 @@ func (sb *Sealer) pubSectorToPriv(ctx context.Context, mid abi.ActorID, sectorIn ...@@ -1033,13 +1038,13 @@ func (sb *Sealer) pubSectorToPriv(ctx context.Context, mid abi.ActorID, sectorIn
} }
type Verifier struct { type Verifier struct {
Lock *sync.RWMutex lock *sync.RWMutex
SM map[abi.SectorID]storage.SectorCids sm map[abi.SectorID]storage.SectorCids
} }
var ProofVerifier = Verifier{ var ProofVerifier = Verifier{
Lock: new(sync.RWMutex), lock: new(sync.RWMutex),
SM: make(map[abi.SectorID]storage.SectorCids), sm: make(map[abi.SectorID]storage.SectorCids),
} }
var _ SectorVerifier = Verifier{} var _ SectorVerifier = Verifier{}
...@@ -1048,9 +1053,9 @@ func (v Verifier) VerifySeal(info spproof.SealVerifyInfo) (bool, error) { ...@@ -1048,9 +1053,9 @@ func (v Verifier) VerifySeal(info spproof.SealVerifyInfo) (bool, error) {
info.Randomness = Ticket info.Randomness = Ticket
ok, err := ffi.VerifySeal(info) ok, err := ffi.VerifySeal(info)
if ok && err == nil { if ok && err == nil {
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,
} }
...@@ -1064,14 +1069,14 @@ func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProo ...@@ -1064,14 +1069,14 @@ func (v Verifier) VerifyAggregateSeals(aggregate spproof.AggregateSealVerifyProo
} }
ok, err := ffi.VerifyAggregateSeals(aggregate) ok, err := ffi.VerifyAggregateSeals(aggregate)
if ok && err == nil { if ok && err == nil {
v.Lock.Lock() v.lock.Lock()
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,
} }
...@@ -1088,12 +1093,12 @@ func (v Verifier) VerifyWindowPoSt( ...@@ -1088,12 +1093,12 @@ func (v Verifier) VerifyWindowPoSt(
) (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{
...@@ -1102,7 +1107,7 @@ func (v Verifier) VerifyWindowPoSt( ...@@ -1102,7 +1107,7 @@ func (v Verifier) VerifyWindowPoSt(
SealedCID: cids.Sealed, SealedCID: cids.Sealed,
} }
} }
v.Lock.RUnlock() v.lock.RUnlock()
randomness[31] &= 0x3f randomness[31] &= 0x3f
return ffi.VerifyWindowPoSt(spproof.WindowPoStVerifyInfo{ return ffi.VerifyWindowPoSt(spproof.WindowPoStVerifyInfo{
...@@ -1121,14 +1126,14 @@ func (v Verifier)VerifyAggregateWindowPostProofs( ...@@ -1121,14 +1126,14 @@ func (v Verifier)VerifyAggregateWindowPostProofs(
) (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{
...@@ -1138,7 +1143,7 @@ func (v Verifier)VerifyAggregateWindowPostProofs( ...@@ -1138,7 +1143,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
...@@ -1163,17 +1168,13 @@ func DefaultAggregationType() abi.RegisteredAggregationProof { ...@@ -1163,17 +1168,13 @@ func DefaultAggregationType() abi.RegisteredAggregationProof {
return abi.RegisteredAggregationProof_SnarkPackV1; return abi.RegisteredAggregationProof_SnarkPackV1;
} }
func memset(dst, src []byte) int { func spt(ssize abi.SectorSize) abi.RegisteredSealProof {
if dst == nil { spt, err := build.SealProofTypeFromSectorSize(ssize, NewestNetworkVersion)
return 0 if err != nil {
} panic(err)
if src == nil {
for n := 0; n < len(dst); n++ {
dst[n] = 0
}
return len(dst)
} }
return copy(dst, src)
return spt
} }
func min(x, y uint32) uint32 { func min(x, y uint32) uint32 {
...@@ -1182,25 +1183,3 @@ func min(x, y uint32) uint32 { ...@@ -1182,25 +1183,3 @@ func min(x, y uint32) uint32 {
} }
return y return y
} }
\ No newline at end of file
func check(in, out []byte) (bool, error){
if len(in) != len(out) {
return false, xerrors.Errorf("the %d output data and %d input data do not match", len(out), len(in))
}
for index := 0; index < len(in); index++ {
if in[index] != out[index] {
return false, xerrors.Errorf("the output data and input data do not match at: %d input is %u, output is %u",index,in[index],out[index])
}
}
return true, nil
}
// func nextUppandedPowerOfTwo(index uint32) abi.UnpaddedPieceSize {
// power := 0
// for index = index / 254; index != 0 ; power += 1 {
// index >>= 1
// }
// return abi.UnpaddedPieceSize(254 * (1 << power))
// }
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -25,7 +25,7 @@ type PieceEncoder interface { ...@@ -25,7 +25,7 @@ type PieceEncoder interface {
//interface //interface
type SectorSealer interface{ type SectorSealer interface{
AddPiece(context.Context, storage.SectorRef, *[]storage.Piece) ([]abi.PieceInfo, 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)
...@@ -35,7 +35,7 @@ type SectorSealer interface{ ...@@ -35,7 +35,7 @@ type SectorSealer interface{
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, sectorSize abi.SectorSize, commd cid.Cid, out io.Writer, 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.Proof, error)
......
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