Commit 46a89ea2 authored by 董子豪's avatar 董子豪

add agg window-post-api

parent 1459130b
......@@ -8,8 +8,10 @@ import (
"math/big"
"math/rand"
"os"
"os/signal"
"path/filepath"
"time"
"syscall"
saproof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof"
......@@ -22,9 +24,9 @@ import (
// "github.com/ipfs/go-cid"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/network"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/go-state-types/abi"
lcli "github.com/filecoin-project/lotus/cli"
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
"github.com/filecoin-project/specs-storage/storage"
"fil_integrate/extern/sector-storage/ffiwrapper"
......@@ -32,16 +34,12 @@ import (
"fil_integrate/extern/sector-storage/storiface"
ffi "github.com/filecoin-project/filecoin-ffi"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"fil_integrate/chain/actors/builtin/miner"
// "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
// "fil_integrate/seal"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/genesis"
"fil_integrate/build"
"fil_integrate/seal"
)
var log = logging.Logger("lotus-bench")
var NewestNetworkVersion = network.Version11
const arp = abi.RegisteredAggregationProof_SnarkPackV1
......@@ -134,12 +132,12 @@ var testCmd = &cli.Command{
Name: "interface-test",
Usage: "Test interface",
Action: func(c *cli.Context) error {
err := TestSealAndUnseal()
err := seal.TestSealAndUnseal()
if err != nil {
return err
}
return nil
}
},
}
var sealBenchCmd = &cli.Command{
......@@ -268,7 +266,7 @@ var sealBenchCmd = &cli.Command{
// Only fetch parameters if actually needed
skipc2 := c.Bool("skip-commit2")
if !skipc2 {
if err := paramfetch.GetParams(lcli.ReqContext(c), build.ParametersJSON(), build.SrsJSON(), uint64(sectorSize)); err != nil {
if err := paramfetch.GetParams(ReqContext(c), build.ParametersJSON(), build.SrsJSON(), uint64(sectorSize)); err != nil {
return xerrors.Errorf("getting params: %w", err)
}
}
......@@ -311,7 +309,7 @@ var sealBenchCmd = &cli.Command{
return err
}
var genmm map[string]genesis.Miner
var genmm map[string]build.Miner
if err := json.Unmarshal(fdata, &genmm); err != nil {
return err
}
......@@ -627,15 +625,12 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par
SealedCID: cids.Sealed,
}
seed := lapi.SealSeed{
Epoch: 101,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255},
}
seed := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255}
commitSema <- struct{}{}
commitStart := time.Now()
log.Infof("[%d] Generating PoRep for sector (1)", i)
c1o, err := sb.SealCommit1(context.TODO(), sid, ticket, seed.Value, piece, cids)
c1o, err := sb.SealCommit1(context.TODO(), sid, ticket, seed, piece, cids)
if err != nil {
return err
}
......@@ -679,7 +674,7 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par
}
infos[i] = proof5.AggregateSealVerifyInfo{
InteractiveRandomness : seed.Value,
InteractiveRandomness : seed,
SealedCID : cids.Sealed,
UnsealedCID : cids.Unsealed,
Number : i,
......@@ -699,7 +694,7 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par
Proof: proof,
DealIDs: nil,
Randomness: ticket,
InteractiveRandomness: seed.Value,
InteractiveRandomness: seed,
UnsealedCID: cids.Unsealed,
}
......@@ -854,7 +849,7 @@ var proveCmd = &cli.Command{
return xerrors.Errorf("unmarshalling input file: %w", err)
}
if err := paramfetch.GetParams(lcli.ReqContext(c), build.ParametersJSON(), build.SrsJSON(), c2in.SectorSize); err != nil {
if err := paramfetch.GetParams(ReqContext(c), build.ParametersJSON(), build.SrsJSON(), c2in.SectorSize); err != nil {
return xerrors.Errorf("getting params: %w", err)
}
......@@ -905,11 +900,11 @@ func bps(sectorSize abi.SectorSize, sectorNum int, d time.Duration) string {
bdata = bdata.Mul(bdata, big.NewInt(int64(sectorNum)))
bdata = bdata.Mul(bdata, big.NewInt(time.Second.Nanoseconds()))
bps := bdata.Div(bdata, big.NewInt(d.Nanoseconds()))
return types.SizeStr(types.BigInt{Int: bps}) + "/s"
return build.SizeStr(bps) + "/s"
}
func spt(ssize abi.SectorSize) abi.RegisteredSealProof {
spt, err := miner.SealProofTypeFromSectorSize(ssize, build.NewestNetworkVersion)
spt, err := build.SealProofTypeFromSectorSize(ssize, NewestNetworkVersion)
if err != nil {
panic(err)
}
......@@ -961,3 +956,25 @@ func readSealOut(root string) ([]SealedOut, error) {
return sealout, nil
}
func DaemonContext(cctx *cli.Context) context.Context {
if mtCtx, ok := cctx.App.Metadata["traceContext"]; ok {
return mtCtx.(context.Context)
}
return context.Background()
}
func ReqContext(cctx *cli.Context) context.Context {
tCtx := DaemonContext(cctx)
ctx, done := context.WithCancel(tCtx)
sigChan := make(chan os.Signal, 2)
go func() {
<-sigChan
done()
}()
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
return ctx
}
......@@ -5,7 +5,7 @@ import(
"io"
"io/ioutil"
"os"
"bytes"
// "bytes"
"math/rand"
saproof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof"
......@@ -15,7 +15,8 @@ import(
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir"
commcid "github.com/filecoin-project/go-fil-commcid"
// commcid "github.com/filecoin-project/go-fil-commcid"
ffi "github.com/filecoin-project/filecoin-ffi"
"fil_integrate/extern/sector-storage/ffiwrapper"
"fil_integrate/extern/sector-storage/ffiwrapper/basicfs"
"fil_integrate/extern/sector-storage/storiface"
......@@ -25,9 +26,7 @@ import(
"github.com/filecoin-project/go-state-types/network"
"github.com/ipfs/go-cid"
"github.com/minio/blake2b-simd"
"fil_integrate/chain/actors/builtin/miner"
lapi "github.com/filecoin-project/lotus/api"
"fil_integrate/build"
)
var log = logging.Logger("sealing")
......@@ -39,7 +38,14 @@ const TagLen int = 8
const NewestNetworkVersion = network.Version13
func AddPiece(sb *ffiwrapper.Sealer, ctx context.Context, sector storage.SectorRef, existingPieceSizes []abi.UnpaddedPieceSize, pieceSize abi.UnpaddedPieceSize, file storage.Data) (abi.PieceInfo, error) {
func AddPiece(
sb *ffiwrapper.Sealer,
ctx context.Context,
sector storage.SectorRef,
existingPieceSizes []abi.UnpaddedPieceSize,
pieceSize abi.UnpaddedPieceSize,
file storage.Data,
) (abi.PieceInfo, error) {
return sb.AddPiece(ctx, sector, existingPieceSizes, pieceSize, file)
......@@ -186,7 +192,55 @@ func AddPiece(sb *ffiwrapper.Sealer, ctx context.Context, sector storage.SectorR
// return piecesID, nil
// }
func CheckPieceAndDataRoot(sid storage.SectorRef, comm_d cid.Cid, pieces []abi.PieceInfo) (bool, error){
func AggregateWindowPoStProofs(
sb *ffiwrapper.Sealer,
ctx context.Context,
randomnesses []abi.SealRandomness,
aggregate abi.RegisteredAggregationProof,
windowPoStProofs []proof5.PoStProof,
sectorCount uint,
) ([]byte, error) {
return sb.AggregateWindowPoStProofs(ctx, ffi.AggregateWindowPostInfos{
Randomnesses: randomnesses,
AggregateType: aggregate,
Proofs: windowPoStProofs,
SectorCount: sectorCount,
})
}
func VerifyAggregateWindowPostProofs(
ctx context.Context,
proofType abi.RegisteredPoStProof,
aggregateType abi.RegisteredAggregationProof,
miner abi.ActorID,
aggregateProof []byte,
randomnesses []abi.SealRandomness,
sealedSectors [][]proof5.SectorInfo,
) (bool, error) {
var sectorInfos []proof5.SectorInfo
arr := make([]uint, len(sealedSectors))
for i, sectors := range(sealedSectors) {
arr[i] = uint(len(sectors))
for _, sector := range(sectors) {
sectorInfos = append(sectorInfos, sector)
}
}
return ffiwrapper.ProofVerifier.VerifyAggregateWindowPostProofs(ctx, ffi.AggregateWindowPostInfos{
PoStType: proofType,
AggregateType: aggregateType,
Miner: miner,
AggregationProof: aggregateProof,
Randomnesses: randomnesses,
ChallengedSectors: sectorInfos,
Arr: arr,
})
}
func CheckPieceAndDataRoot(
sid storage.SectorRef,
comm_d cid.Cid,
pieces []abi.PieceInfo,
) (bool, error) {
UnsealedCID, err := ffiwrapper.GenerateUnsealedCID(sid.ProofType, pieces)
if err != nil{
return false, err
......@@ -195,7 +249,14 @@ func CheckPieceAndDataRoot(sid storage.SectorRef, comm_d cid.Cid, pieces []abi.P
return comm_d == UnsealedCID, nil
}
func Sealed(sb *ffiwrapper.Sealer, ctx context.Context, sid storage.SectorRef, seed lapi.SealSeed, ticket abi.SealRandomness, pieces []abi.PieceInfo)(storage.SectorCids, storage.Proof, storage.Commit1Out, error){
func Sealed(
sb *ffiwrapper.Sealer,
ctx context.Context,
sid storage.SectorRef,
seed abi.InteractiveSealRandomness,
ticket abi.SealRandomness,
pieces []abi.PieceInfo,
) (storage.SectorCids, storage.Proof, storage.Commit1Out, error) {
// var sealedSectors saproof2.SectorInfo
log.Infof("[%d] Running replication(1)...", sid.ID.Number)
......@@ -212,7 +273,7 @@ func Sealed(sb *ffiwrapper.Sealer, ctx context.Context, sid storage.SectorRef, s
}
log.Infof("[%d] Generating PoRep for sector (1)", sid.ID.Number)
c1o, err := sb.SealCommit1(ctx, sid, ticket, seed.Value, pieces, cids)
c1o, err := sb.SealCommit1(ctx, sid, ticket, seed, pieces, cids)
if err != nil {
return storage.SectorCids{}, nil, nil, err
}
......@@ -228,15 +289,37 @@ func Sealed(sb *ffiwrapper.Sealer, ctx context.Context, sid storage.SectorRef, s
return cids, proof, c1o, nil
}
func GenProofForC2(sb *ffiwrapper.Sealer, ctx context.Context, sid storage.SectorRef, c1Out storage.Commit1Out) (storage.Proof, error) {
func GenProofForC2(
sb *ffiwrapper.Sealer,
ctx context.Context,
sid storage.SectorRef,
c1Out storage.Commit1Out,
) (storage.Proof, error) {
return sb.SealCommit2(ctx, sid, c1Out)
}
func GenProofForWindowPost(sb *ffiwrapper.Sealer, ctx context.Context, minerID abi.ActorID, sectorInfo []proof5.SectorInfo, randomness abi.PoStRandomness) ([]proof5.PoStProof, []abi.SectorID, error) {
func GenProofForWindowPost(
sb *ffiwrapper.Sealer,
ctx context.Context,
minerID abi.ActorID,
sectorInfo []proof5.SectorInfo,
randomness abi.PoStRandomness,
) ([]proof5.PoStProof, []abi.SectorID, error) {
return sb.GenerateWindowPoSt(ctx, minerID, sectorInfo, randomness)
}
func UnsealedRange(sb *ffiwrapper.Sealer, ctx context.Context, sbfs *basicfs.Provider, sid storage.SectorRef, sectorSize abi.SectorSize, ticket abi.SealRandomness, commd cid.Cid, out io.Writer, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error {
func UnsealedRange(
sb *ffiwrapper.Sealer,
ctx context.Context,
sbfs *basicfs.Provider,
sid storage.SectorRef,
sectorSize abi.SectorSize,
ticket abi.SealRandomness,
commd cid.Cid,
out io.Writer,
offset storiface.UnpaddedByteIndex,
size abi.UnpaddedPieceSize,
) error {
log.Infof("[%d] Unsealing sector", sid.ID.Number)
{
p, done, err := sbfs.AcquireSector(ctx, sid, storiface.FTUnsealed, storiface.FTNone, storiface.PathSealing)
......@@ -269,7 +352,7 @@ func UnsealedRange(sb *ffiwrapper.Sealer, ctx context.Context, sbfs *basicfs.Pro
}
func spt(ssize abi.SectorSize) abi.RegisteredSealProof {
spt, err := miner.SealProofTypeFromSectorSize(ssize, NewestNetworkVersion)
spt, err := build.SealProofTypeFromSectorSize(ssize, NewestNetworkVersion)
if err != nil {
panic(err)
}
......@@ -320,10 +403,7 @@ func TestSealAndUnseal() error {
ProofType: spt(sectorSize),
}
file := rand.New(rand.NewSource(1587))
seed := lapi.SealSeed{
Epoch: 101,
Value: []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255},
}
seed := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 255}
trand := blake2b.Sum256([]byte("ticket-preimage"))
ticket := abi.SealRandomness(trand[:])
var challenge [32]byte
......@@ -383,7 +463,7 @@ func TestSealAndUnseal() error {
Proof: proof1,
DealIDs: nil,
Randomness: ticket,
InteractiveRandomness: seed.Value,
InteractiveRandomness: seed,
UnsealedCID: cids.Unsealed,
}
......@@ -394,7 +474,7 @@ func TestSealAndUnseal() error {
Proof: proof2,
DealIDs: nil,
Randomness: ticket,
InteractiveRandomness: seed.Value,
InteractiveRandomness: seed,
UnsealedCID: cids.Unsealed,
}
......
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