fixup lotus-bench
This commit is contained in:
parent
df6e3e83bf
commit
e4dcb7441b
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -14,7 +13,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
|
||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
paramfetch "github.com/filecoin-project/go-paramfetch"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
@ -25,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-sectorbuilder"
|
"github.com/filecoin-project/go-sectorbuilder"
|
||||||
|
lapi "github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/genesis"
|
"github.com/filecoin-project/lotus/genesis"
|
||||||
@ -142,10 +141,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
sectorSize := abi.SectorSize(sectorSizeInt)
|
sectorSize := abi.SectorSize(sectorSizeInt)
|
||||||
|
|
||||||
|
ppt, spt, err := lapi.ProofTypeFromSectorSize(sectorSize)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
mds := datastore.NewMapDatastore()
|
mds := datastore.NewMapDatastore()
|
||||||
cfg := §orbuilder.Config{
|
cfg := §orbuilder.Config{
|
||||||
Miner: maddr,
|
Miner: maddr,
|
||||||
SectorSize: sectorSize,
|
SealProofType: spt,
|
||||||
|
PoStProofType: ppt,
|
||||||
WorkerThreads: 2,
|
WorkerThreads: 2,
|
||||||
Paths: sectorbuilder.SimplePath(sbdir),
|
Paths: sectorbuilder.SimplePath(sbdir),
|
||||||
}
|
}
|
||||||
@ -164,8 +169,15 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amid, err := address.IDFromAddress(maddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mid := abi.ActorID(amid)
|
||||||
|
|
||||||
var sealTimings []SealingResult
|
var sealTimings []SealingResult
|
||||||
var sealedSectors []ffi.PublicSectorInfo
|
var sealedSectors []abi.SectorInfo
|
||||||
numSectors := abi.SectorNumber(1)
|
numSectors := abi.SectorNumber(1)
|
||||||
for i := abi.SectorNumber(1); i <= numSectors && robench == ""; i++ {
|
for i := abi.SectorNumber(1); i <= numSectors && robench == ""; i++ {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
@ -173,7 +185,7 @@ func main() {
|
|||||||
|
|
||||||
r := rand.New(rand.NewSource(100 + int64(i)))
|
r := rand.New(rand.NewSource(100 + int64(i)))
|
||||||
|
|
||||||
pi, err := sb.AddPiece(context.TODO(), abi.UnpaddedPieceSize(sectorSize), i, r, nil)
|
pi, err := sb.AddPiece(context.TODO(), abi.PaddedPieceSize(sectorSize).Unpadded(), i, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -181,38 +193,53 @@ func main() {
|
|||||||
addpiece := time.Now()
|
addpiece := time.Now()
|
||||||
|
|
||||||
trand := sha256.Sum256([]byte(c.String("ticket-preimage")))
|
trand := sha256.Sum256([]byte(c.String("ticket-preimage")))
|
||||||
ticket := sectorbuilder.SealTicket{
|
ticket := abi.SealRandomness(trand[:])
|
||||||
TicketBytes: trand,
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Running replication...")
|
log.Info("Running replication...")
|
||||||
pieces := []sectorbuilder.PublicPieceInfo{pi}
|
pieces := []abi.PieceInfo{pi}
|
||||||
pco, err := sb.SealPreCommit(context.TODO(), i, ticket, pieces)
|
commR, commD, err := sb.SealPreCommit(context.TODO(), i, ticket, pieces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("commit: %w", err)
|
return xerrors.Errorf("commit: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
precommit := time.Now()
|
precommit := time.Now()
|
||||||
|
|
||||||
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{
|
sealedSectors = append(sealedSectors, abi.SectorInfo{
|
||||||
CommR: pco.CommR,
|
RegisteredProof: ppt,
|
||||||
SectorNum: i,
|
SectorNumber: i,
|
||||||
|
SealedCID: commR,
|
||||||
})
|
})
|
||||||
|
|
||||||
seed := sectorbuilder.SealSeed{
|
seed := lapi.SealSeed{
|
||||||
BlockHeight: 101,
|
Epoch: 101,
|
||||||
TicketBytes: [32]byte{1, 2, 3, 4, 5},
|
Value: []byte{1, 2, 3, 4, 5},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Generating PoRep for sector")
|
log.Info("Generating PoRep for sector")
|
||||||
proof, err := sb.SealCommit(context.TODO(), i, ticket, seed, pieces, pco)
|
proof, err := sb.SealCommit(context.TODO(), i, ticket, seed.Value, pieces, commR, commD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
sealcommit := time.Now()
|
sealcommit := time.Now()
|
||||||
commD := pi.CommP
|
|
||||||
ok, err := sectorbuilder.ProofVerifier.VerifySeal(sectorSize, pco.CommR[:], commD[:], maddr, ticket.TicketBytes[:], seed.TicketBytes[:], i, proof)
|
svi := abi.SealVerifyInfo{
|
||||||
|
SectorID: abi.SectorID{Miner: abi.ActorID(mid), Number: i},
|
||||||
|
OnChain: abi.OnChainSealVerifyInfo{
|
||||||
|
SealedCID: commR,
|
||||||
|
InteractiveEpoch: seed.Epoch,
|
||||||
|
RegisteredProof: ppt,
|
||||||
|
Proof: proof,
|
||||||
|
DealIDs: nil,
|
||||||
|
SectorNumber: i,
|
||||||
|
SealRandEpoch: 0,
|
||||||
|
},
|
||||||
|
Randomness: ticket,
|
||||||
|
InteractiveRandomness: seed.Value,
|
||||||
|
UnsealedCID: commD,
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := sectorbuilder.ProofVerifier.VerifySeal(svi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -224,7 +251,7 @@ func main() {
|
|||||||
|
|
||||||
if !c.Bool("skip-unseal") {
|
if !c.Bool("skip-unseal") {
|
||||||
log.Info("Unsealing sector")
|
log.Info("Unsealing sector")
|
||||||
rc, err := sb.ReadPieceFromSealedSector(context.TODO(), 1, 0, abi.UnpaddedPieceSize(sectorSize), ticket.TicketBytes[:], commD[:])
|
rc, err := sb.ReadPieceFromSealedSector(context.TODO(), 1, 0, abi.UnpaddedPieceSize(sectorSize), ticket, commD)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -270,24 +297,28 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range genm.Sectors {
|
for _, s := range genm.Sectors {
|
||||||
sealedSectors = append(sealedSectors, ffi.PublicSectorInfo{
|
sealedSectors = append(sealedSectors, abi.SectorInfo{
|
||||||
CommR: s.CommR,
|
SealedCID: s.CommR,
|
||||||
SectorNum: s.SectorID,
|
SectorNumber: s.SectorID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("generating election post candidates")
|
log.Info("generating election post candidates")
|
||||||
sinfos := sectorbuilder.NewSortedPublicSectorInfo(sealedSectors)
|
fcandidates, err := sb.GenerateEPostCandidates(sealedSectors, abi.PoStRandomness(challenge[:]), []abi.SectorNumber{})
|
||||||
candidates, err := sb.GenerateEPostCandidates(sinfos, challenge, []abi.SectorNumber{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var candidates []abi.PoStCandidate
|
||||||
|
for _, c := range fcandidates {
|
||||||
|
candidates = append(candidates, c.Candidate)
|
||||||
|
}
|
||||||
|
|
||||||
gencandidates := time.Now()
|
gencandidates := time.Now()
|
||||||
|
|
||||||
log.Info("computing election post snark (cold)")
|
log.Info("computing election post snark (cold)")
|
||||||
proof1, err := sb.ComputeElectionPoSt(sinfos, challenge[:], candidates[:1])
|
proof1, err := sb.ComputeElectionPoSt(sealedSectors, challenge[:], candidates[:1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -295,18 +326,24 @@ func main() {
|
|||||||
epost1 := time.Now()
|
epost1 := time.Now()
|
||||||
|
|
||||||
log.Info("computing election post snark (hot)")
|
log.Info("computing election post snark (hot)")
|
||||||
proof2, err := sb.ComputeElectionPoSt(sinfos, challenge[:], candidates[:1])
|
proof2, err := sb.ComputeElectionPoSt(sealedSectors, challenge[:], candidates[:1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
epost2 := time.Now()
|
epost2 := time.Now()
|
||||||
|
|
||||||
if bytes.Equal(proof1, proof2) {
|
ccount := sectorbuilder.ElectionPostChallengeCount(uint64(len(sealedSectors)), 0)
|
||||||
log.Warn("separate epost calls returned the same proof values (this might be bad)")
|
|
||||||
}
|
|
||||||
|
|
||||||
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), sectorSize, sinfos, challenge[:], proof1, candidates[:1], maddr)
|
pvi1 := abi.PoStVerifyInfo{
|
||||||
|
Randomness: abi.PoStRandomness(challenge[:]),
|
||||||
|
Candidates: candidates[:1],
|
||||||
|
Proofs: proof1,
|
||||||
|
EligibleSectors: sealedSectors,
|
||||||
|
Prover: abi.ActorID(mid),
|
||||||
|
ChallengeCount: ccount,
|
||||||
|
}
|
||||||
|
ok, err := sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), pvi1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -316,7 +353,16 @@ func main() {
|
|||||||
|
|
||||||
verifypost1 := time.Now()
|
verifypost1 := time.Now()
|
||||||
|
|
||||||
ok, err = sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), sectorSize, sinfos, challenge[:], proof2, candidates[:1], maddr)
|
pvi2 := abi.PoStVerifyInfo{
|
||||||
|
Randomness: abi.PoStRandomness(challenge[:]),
|
||||||
|
Candidates: candidates[:1],
|
||||||
|
Proofs: proof2,
|
||||||
|
EligibleSectors: sealedSectors,
|
||||||
|
Prover: abi.ActorID(mid),
|
||||||
|
ChallengeCount: ccount,
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err = sectorbuilder.ProofVerifier.VerifyElectionPost(context.TODO(), pvi2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -326,7 +372,7 @@ func main() {
|
|||||||
verifypost2 := time.Now()
|
verifypost2 := time.Now()
|
||||||
|
|
||||||
bo := BenchResults{
|
bo := BenchResults{
|
||||||
SectorSize: cfg.SectorSize,
|
SectorSize: sectorSize,
|
||||||
SealingResults: sealTimings,
|
SealingResults: sealTimings,
|
||||||
|
|
||||||
PostGenerateCandidates: gencandidates.Sub(beforePost),
|
PostGenerateCandidates: gencandidates.Sub(beforePost),
|
||||||
|
Loading…
Reference in New Issue
Block a user