2019-11-27 02:47:08 +00:00
package main
import (
2019-11-28 01:43:36 +00:00
"context"
2019-11-27 02:47:08 +00:00
"crypto/sha256"
2019-12-10 13:22:39 +00:00
"encoding/json"
2019-11-27 02:47:08 +00:00
"fmt"
"io/ioutil"
2019-12-10 19:53:39 +00:00
"math/big"
2019-11-27 02:47:08 +00:00
"math/rand"
"os"
"path/filepath"
"time"
2019-12-16 13:49:58 +00:00
"github.com/docker/go-units"
2020-01-08 19:10:57 +00:00
logging "github.com/ipfs/go-log/v2"
2019-11-27 02:47:08 +00:00
"github.com/mitchellh/go-homedir"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
2019-12-19 20:13:17 +00:00
"github.com/filecoin-project/go-address"
2020-03-15 17:48:27 +00:00
paramfetch "github.com/filecoin-project/go-paramfetch"
2020-01-07 16:18:35 +00:00
"github.com/filecoin-project/go-sectorbuilder"
2020-03-15 17:48:27 +00:00
"github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-storage/storage"
2020-02-28 18:06:59 +00:00
2020-02-27 22:23:05 +00:00
lapi "github.com/filecoin-project/lotus/api"
2019-11-27 02:47:08 +00:00
"github.com/filecoin-project/lotus/build"
2019-12-10 19:53:39 +00:00
"github.com/filecoin-project/lotus/chain/types"
2019-12-10 13:22:39 +00:00
"github.com/filecoin-project/lotus/genesis"
2019-11-27 02:47:08 +00:00
)
var log = logging . Logger ( "lotus-bench" )
type BenchResults struct {
2020-02-10 19:16:36 +00:00
SectorSize abi . SectorSize
2019-11-27 02:47:08 +00:00
SealingResults [ ] SealingResult
PostGenerateCandidates time . Duration
2019-11-29 18:48:07 +00:00
PostEProofCold time . Duration
PostEProofHot time . Duration
VerifyEPostCold time . Duration
VerifyEPostHot time . Duration
2019-11-27 02:47:08 +00:00
}
type SealingResult struct {
2020-02-28 18:06:59 +00:00
AddPiece time . Duration
PreCommit1 time . Duration
PreCommit2 time . Duration
Commit1 time . Duration
Commit2 time . Duration
Verify time . Duration
Unseal time . Duration
2019-11-27 02:47:08 +00:00
}
2020-02-29 02:31:25 +00:00
type Commit2In struct {
2020-03-01 02:52:23 +00:00
SectorNum int64
Phase1Out [ ] byte
SectorSize uint64
2020-02-29 02:31:25 +00:00
}
2019-11-27 02:47:08 +00:00
func main ( ) {
logging . SetLogLevel ( "*" , "INFO" )
log . Info ( "Starting lotus-bench" )
2020-02-28 00:12:52 +00:00
build . SectorSizes = append ( build . SectorSizes , 2048 )
2019-12-17 19:59:14 +00:00
2019-11-27 02:47:08 +00:00
app := & cli . App {
Name : "lotus-bench" ,
Usage : "Benchmark performance of lotus on your hardware" ,
2019-12-11 22:00:39 +00:00
Version : build . UserVersion ,
2020-03-01 02:52:23 +00:00
Commands : [ ] * cli . Command {
proveCmd ,
} ,
2019-11-27 02:47:08 +00:00
Flags : [ ] cli . Flag {
& cli . StringFlag {
Name : "storage-dir" ,
Value : "~/.lotus-bench" ,
Usage : "Path to the storage directory that will store sectors long term" ,
} ,
2019-12-11 02:06:28 +00:00
& cli . StringFlag {
2019-11-27 02:47:08 +00:00
Name : "sector-size" ,
2020-02-28 18:06:59 +00:00
Value : "512MiB" ,
2019-12-11 02:06:28 +00:00
Usage : "size of the sectors in bytes, i.e. 32GiB" ,
2019-11-27 02:47:08 +00:00
} ,
2019-12-02 19:25:10 +00:00
& cli . BoolFlag {
Name : "no-gpu" ,
Usage : "disable gpu usage for the benchmark run" ,
} ,
2019-12-10 13:22:39 +00:00
& cli . StringFlag {
Name : "miner-addr" ,
Usage : "pass miner address (only necessary if using existing sectorbuilder)" ,
2020-02-28 18:06:59 +00:00
Value : "t01000" ,
2019-12-10 13:22:39 +00:00
} ,
2019-12-10 13:01:17 +00:00
& cli . StringFlag {
Name : "benchmark-existing-sectorbuilder" ,
Usage : "pass a directory to run election-post timings on an existing sectorbuilder" ,
} ,
2019-12-10 14:05:41 +00:00
& cli . BoolFlag {
Name : "json-out" ,
Usage : "output results in json format" ,
} ,
2020-03-15 17:48:27 +00:00
& cli . BoolFlag {
Name : "skip-commit2" ,
Usage : "skip the commit2 (snark) portion of the benchmark" ,
} ,
2019-12-19 19:45:15 +00:00
& cli . BoolFlag {
Name : "skip-unseal" ,
Usage : "skip the unseal portion of the benchmark" ,
} ,
2020-02-29 02:31:25 +00:00
& cli . StringFlag {
Name : "save-commit2-input" ,
Usage : "Save commit2 input to a file" ,
} ,
2019-11-27 02:47:08 +00:00
} ,
Action : func ( c * cli . Context ) error {
2019-12-02 19:25:10 +00:00
if c . Bool ( "no-gpu" ) {
os . Setenv ( "BELLMAN_NO_GPU" , "1" )
}
2019-11-27 02:47:08 +00:00
2019-12-10 13:01:17 +00:00
robench := c . String ( "benchmark-existing-sectorbuilder" )
2019-11-27 02:47:08 +00:00
2019-12-10 13:01:17 +00:00
var sbdir string
if robench == "" {
sdir , err := homedir . Expand ( c . String ( "storage-dir" ) )
if err != nil {
return err
}
os . MkdirAll ( sdir , 0775 )
tsdir , err := ioutil . TempDir ( sdir , "bench" )
if err != nil {
return err
2019-11-27 02:47:08 +00:00
}
2019-12-10 13:01:17 +00:00
defer func ( ) {
if err := os . RemoveAll ( tsdir ) ; err != nil {
log . Warn ( "remove all: " , err )
}
} ( )
sbdir = tsdir
} else {
2019-12-10 13:47:49 +00:00
exp , err := homedir . Expand ( robench )
if err != nil {
return err
}
sbdir = exp
2019-12-10 13:01:17 +00:00
}
2019-11-27 02:47:08 +00:00
2019-12-10 13:22:39 +00:00
maddr , err := address . NewFromString ( c . String ( "miner-addr" ) )
2019-11-27 02:47:08 +00:00
if err != nil {
return err
}
2019-12-16 19:44:48 +00:00
sectorSizeInt , err := units . RAMInBytes ( c . String ( "sector-size" ) )
2019-12-11 02:06:28 +00:00
if err != nil {
return err
}
2020-02-10 19:16:36 +00:00
sectorSize := abi . SectorSize ( sectorSizeInt )
2019-11-28 01:43:36 +00:00
2020-02-27 22:23:05 +00:00
ppt , spt , err := lapi . ProofTypeFromSectorSize ( sectorSize )
if err != nil {
return err
}
2019-11-27 02:47:08 +00:00
cfg := & sectorbuilder . Config {
Miner : maddr ,
2020-02-27 22:23:05 +00:00
SealProofType : spt ,
PoStProofType : ppt ,
2019-11-27 02:47:08 +00:00
}
2019-12-10 13:01:17 +00:00
if robench == "" {
2019-12-16 13:49:58 +00:00
if err := os . MkdirAll ( sbdir , 0775 ) ; err != nil {
return err
2019-11-27 02:47:08 +00:00
}
}
2020-03-15 17:48:27 +00:00
if ! c . Bool ( "skip-commit2" ) {
if err := paramfetch . GetParams ( build . ParametersJson ( ) , uint64 ( sectorSize ) ) ; err != nil {
return xerrors . Errorf ( "getting params: %w" , err )
}
2019-11-27 02:47:08 +00:00
}
2020-02-28 18:06:59 +00:00
sbfs := & fs . Basic {
2020-03-06 19:01:28 +00:00
Miner : maddr ,
Root : sbdir ,
2020-02-28 18:06:59 +00:00
}
sb , err := sectorbuilder . New ( sbfs , cfg )
2019-11-27 02:47:08 +00:00
if err != nil {
return err
}
2020-02-27 22:23:05 +00:00
amid , err := address . IDFromAddress ( maddr )
if err != nil {
return err
}
mid := abi . ActorID ( amid )
2019-11-27 02:47:08 +00:00
var sealTimings [ ] SealingResult
2020-02-27 22:23:05 +00:00
var sealedSectors [ ] abi . SectorInfo
2020-02-10 19:16:36 +00:00
numSectors := abi . SectorNumber ( 1 )
for i := abi . SectorNumber ( 1 ) ; i <= numSectors && robench == "" ; i ++ {
2019-11-27 02:47:08 +00:00
start := time . Now ( )
log . Info ( "Writing piece into sector..." )
2019-12-01 22:37:53 +00:00
r := rand . New ( rand . NewSource ( 100 + int64 ( i ) ) )
2020-03-06 05:30:47 +00:00
pi , err := sb . AddPiece ( context . TODO ( ) , i , nil , abi . PaddedPieceSize ( sectorSize ) . Unpadded ( ) , r )
2019-11-27 02:47:08 +00:00
if err != nil {
return err
}
addpiece := time . Now ( )
trand := sha256 . Sum256 ( [ ] byte ( c . String ( "ticket-preimage" ) ) )
2020-02-27 22:23:05 +00:00
ticket := abi . SealRandomness ( trand [ : ] )
2019-11-27 02:47:08 +00:00
2020-02-28 18:06:59 +00:00
log . Info ( "Running replication(1)..." )
2020-02-27 22:23:05 +00:00
pieces := [ ] abi . PieceInfo { pi }
2020-02-28 18:06:59 +00:00
pc1o , err := sb . SealPreCommit1 ( context . TODO ( ) , i , ticket , pieces )
2019-11-27 02:47:08 +00:00
if err != nil {
return xerrors . Errorf ( "commit: %w" , err )
}
2020-02-28 18:06:59 +00:00
precommit1 := time . Now ( )
log . Info ( "Running replication(2)..." )
commR , commD , err := sb . SealPreCommit2 ( context . TODO ( ) , i , pc1o )
if err != nil {
return xerrors . Errorf ( "commit: %w" , err )
}
precommit2 := time . Now ( )
2019-11-27 02:47:08 +00:00
2020-02-27 22:23:05 +00:00
sealedSectors = append ( sealedSectors , abi . SectorInfo {
2020-03-01 21:05:13 +00:00
RegisteredProof : spt ,
2020-02-27 22:23:05 +00:00
SectorNumber : i ,
SealedCID : commR ,
2019-11-27 02:47:08 +00:00
} )
2020-02-27 22:23:05 +00:00
seed := lapi . SealSeed {
Epoch : 101 ,
2020-02-28 20:52:14 +00:00
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 } ,
2019-11-27 02:47:08 +00:00
}
2020-02-28 18:06:59 +00:00
log . Info ( "Generating PoRep for sector (1)" )
c1o , err := sb . SealCommit1 ( context . TODO ( ) , i , ticket , seed . Value , pieces , commR , commD )
if err != nil {
return err
}
sealcommit1 := time . Now ( )
log . Info ( "Generating PoRep for sector (2)" )
2020-02-29 02:31:25 +00:00
if c . String ( "save-commit2-input" ) != "" {
c2in := Commit2In {
2020-03-01 02:52:23 +00:00
SectorNum : int64 ( i ) ,
2020-02-29 02:31:25 +00:00
Phase1Out : c1o ,
2020-03-01 04:26:10 +00:00
SectorSize : uint64 ( sectorSize ) ,
2020-02-29 02:31:25 +00:00
}
b , err := json . Marshal ( & c2in )
if err != nil {
return err
}
if err := ioutil . WriteFile ( c . String ( "save-commit2-input" ) , b , 0664 ) ; err != nil {
log . Warnf ( "%+v" , err )
}
}
2020-03-15 17:48:27 +00:00
var proof storage . Proof
if ! c . Bool ( "skip-commit2" ) {
proof , err = sb . SealCommit2 ( context . TODO ( ) , i , c1o )
if err != nil {
return err
}
2019-11-27 02:47:08 +00:00
}
2020-02-28 18:06:59 +00:00
sealcommit2 := time . Now ( )
2020-02-27 22:23:05 +00:00
2020-03-15 17:48:27 +00:00
if ! c . Bool ( "skip-commit2" ) {
svi := abi . SealVerifyInfo {
SectorID : abi . SectorID { Miner : mid , Number : i } ,
OnChain : abi . OnChainSealVerifyInfo {
SealedCID : commR ,
InteractiveEpoch : seed . Epoch ,
RegisteredProof : spt ,
Proof : proof ,
DealIDs : nil ,
SectorNumber : i ,
SealRandEpoch : 0 ,
} ,
Randomness : ticket ,
InteractiveRandomness : seed . Value ,
UnsealedCID : commD ,
}
2020-02-27 22:23:05 +00:00
2020-03-15 17:48:27 +00:00
ok , err := sectorbuilder . ProofVerifier . VerifySeal ( svi )
if err != nil {
return err
}
if ! ok {
return xerrors . Errorf ( "porep proof for sector %d was invalid" , i )
}
2019-11-29 18:48:07 +00:00
}
2019-11-28 01:43:36 +00:00
verifySeal := time . Now ( )
2019-11-27 02:47:08 +00:00
2019-12-19 19:45:15 +00:00
if ! c . Bool ( "skip-unseal" ) {
log . Info ( "Unsealing sector" )
2020-03-15 17:48:27 +00:00
// TODO: RM unsealed sector first
2020-02-27 22:23:05 +00:00
rc , err := sb . ReadPieceFromSealedSector ( context . TODO ( ) , 1 , 0 , abi . UnpaddedPieceSize ( sectorSize ) , ticket , commD )
2019-12-19 19:45:15 +00:00
if err != nil {
return err
}
2019-12-01 22:37:53 +00:00
2019-12-19 19:45:15 +00:00
if err := rc . Close ( ) ; err != nil {
return err
}
2019-12-01 22:37:53 +00:00
}
2019-12-19 19:45:15 +00:00
unseal := time . Now ( )
2019-12-01 22:37:53 +00:00
2019-11-27 02:47:08 +00:00
sealTimings = append ( sealTimings , SealingResult {
2020-02-28 18:06:59 +00:00
AddPiece : addpiece . Sub ( start ) ,
PreCommit1 : precommit1 . Sub ( addpiece ) ,
PreCommit2 : precommit2 . Sub ( precommit1 ) ,
Commit1 : sealcommit1 . Sub ( precommit2 ) ,
Commit2 : sealcommit2 . Sub ( sealcommit1 ) ,
Verify : verifySeal . Sub ( sealcommit2 ) ,
Unseal : unseal . Sub ( verifySeal ) ,
2019-11-27 02:47:08 +00:00
} )
}
beforePost := time . Now ( )
var challenge [ 32 ] byte
rand . Read ( challenge [ : ] )
2019-12-10 13:22:39 +00:00
if robench != "" {
// TODO: this assumes we only ever benchmark a preseal
// sectorbuilder directory... we need a better way to handle
// this in other cases
fdata , err := ioutil . ReadFile ( filepath . Join ( sbdir , "pre-seal-" + maddr . String ( ) + ".json" ) )
if err != nil {
return err
}
2020-02-25 21:09:22 +00:00
var genmm map [ string ] genesis . Miner
2019-12-10 13:22:39 +00:00
if err := json . Unmarshal ( fdata , & genmm ) ; err != nil {
return err
}
genm , ok := genmm [ maddr . String ( ) ]
if ! ok {
return xerrors . Errorf ( "preseal file didnt have expected miner in it" )
}
for _ , s := range genm . Sectors {
2020-02-27 22:23:05 +00:00
sealedSectors = append ( sealedSectors , abi . SectorInfo {
SealedCID : s . CommR ,
SectorNumber : s . SectorID ,
2019-12-10 13:22:39 +00:00
} )
}
}
2020-03-15 17:48:27 +00:00
bo := BenchResults {
SectorSize : sectorSize ,
SealingResults : sealTimings ,
2019-11-27 02:47:08 +00:00
}
2020-03-15 17:48:27 +00:00
if ! c . Bool ( "skip-commit2" ) {
log . Info ( "generating election post candidates" )
fcandidates , err := sb . GenerateEPostCandidates ( sealedSectors , challenge [ : ] , [ ] abi . SectorNumber { } )
if err != nil {
return err
}
2020-02-27 22:23:05 +00:00
2020-03-15 17:48:27 +00:00
var candidates [ ] abi . PoStCandidate
for _ , c := range fcandidates {
c . Candidate . RegisteredProof = ppt
candidates = append ( candidates , c . Candidate )
}
2019-11-27 02:47:08 +00:00
2020-03-15 17:48:27 +00:00
gencandidates := time . Now ( )
2019-11-29 18:48:07 +00:00
2020-03-15 17:48:27 +00:00
log . Info ( "computing election post snark (cold)" )
proof1 , err := sb . ComputeElectionPoSt ( sealedSectors , challenge [ : ] , candidates [ : 1 ] )
if err != nil {
return err
}
2019-11-29 18:48:07 +00:00
2020-03-15 17:48:27 +00:00
epost1 := time . Now ( )
2019-11-27 02:47:08 +00:00
2020-03-15 17:48:27 +00:00
log . Info ( "computing election post snark (hot)" )
proof2 , err := sb . ComputeElectionPoSt ( sealedSectors , challenge [ : ] , candidates [ : 1 ] )
if err != nil {
return err
}
2019-11-27 02:47:08 +00:00
2020-03-15 17:48:27 +00:00
epost2 := time . Now ( )
2019-11-29 18:48:07 +00:00
2020-03-15 17:48:27 +00:00
ccount := sectorbuilder . ElectionPostChallengeCount ( uint64 ( len ( sealedSectors ) ) , 0 )
2019-11-28 01:43:36 +00:00
2020-03-15 17:48:27 +00:00
pvi1 := abi . PoStVerifyInfo {
Randomness : abi . PoStRandomness ( challenge [ : ] ) ,
Candidates : candidates [ : 1 ] ,
Proofs : proof1 ,
EligibleSectors : sealedSectors ,
Prover : mid ,
ChallengeCount : ccount ,
}
ok , err := sectorbuilder . ProofVerifier . VerifyElectionPost ( context . TODO ( ) , pvi1 )
if err != nil {
return err
}
if ! ok {
log . Error ( "post verification failed" )
}
2019-11-29 18:48:07 +00:00
2020-03-15 17:48:27 +00:00
verifypost1 := time . Now ( )
2020-02-27 22:23:05 +00:00
2020-03-15 17:48:27 +00:00
pvi2 := abi . PoStVerifyInfo {
Randomness : abi . PoStRandomness ( challenge [ : ] ) ,
Candidates : candidates [ : 1 ] ,
Proofs : proof2 ,
EligibleSectors : sealedSectors ,
Prover : mid ,
ChallengeCount : ccount ,
}
2019-11-28 01:43:36 +00:00
2020-03-15 17:48:27 +00:00
ok , err = sectorbuilder . ProofVerifier . VerifyElectionPost ( context . TODO ( ) , pvi2 )
if err != nil {
return err
}
if ! ok {
log . Error ( "post verification failed" )
}
verifypost2 := time . Now ( )
bo . PostGenerateCandidates = gencandidates . Sub ( beforePost )
bo . PostEProofCold = epost1 . Sub ( gencandidates )
bo . PostEProofHot = epost2 . Sub ( epost1 )
bo . VerifyEPostCold = verifypost1 . Sub ( epost2 )
bo . VerifyEPostHot = verifypost2 . Sub ( verifypost1 )
}
2019-11-27 02:47:08 +00:00
2019-12-10 14:05:41 +00:00
if c . Bool ( "json-out" ) {
2019-12-10 18:04:13 +00:00
data , err := json . MarshalIndent ( bo , "" , " " )
2019-12-10 14:05:41 +00:00
if err != nil {
return err
}
fmt . Println ( string ( data ) )
} else {
2020-03-15 17:48:27 +00:00
fmt . Printf ( "----\nresults (v24) (%d)\n" , sectorSize )
2019-12-10 14:05:41 +00:00
if robench == "" {
2019-12-10 18:04:13 +00:00
fmt . Printf ( "seal: addPiece: %s (%s)\n" , bo . SealingResults [ 0 ] . AddPiece , bps ( bo . SectorSize , bo . SealingResults [ 0 ] . AddPiece ) ) // TODO: average across multiple sealings
2020-02-28 18:06:59 +00:00
fmt . Printf ( "seal: preCommit phase 1: %s (%s)\n" , bo . SealingResults [ 0 ] . PreCommit1 , bps ( bo . SectorSize , bo . SealingResults [ 0 ] . PreCommit1 ) )
fmt . Printf ( "seal: preCommit phase 2: %s (%s)\n" , bo . SealingResults [ 0 ] . PreCommit2 , bps ( bo . SectorSize , bo . SealingResults [ 0 ] . PreCommit2 ) )
fmt . Printf ( "seal: commit phase 1: %s (%s)\n" , bo . SealingResults [ 0 ] . Commit1 , bps ( bo . SectorSize , bo . SealingResults [ 0 ] . Commit1 ) )
fmt . Printf ( "seal: commit phase 2: %s (%s)\n" , bo . SealingResults [ 0 ] . Commit2 , bps ( bo . SectorSize , bo . SealingResults [ 0 ] . Commit2 ) )
2019-12-10 18:04:13 +00:00
fmt . Printf ( "seal: verify: %s\n" , bo . SealingResults [ 0 ] . Verify )
2020-01-19 14:56:37 +00:00
if ! c . Bool ( "skip-unseal" ) {
fmt . Printf ( "unseal: %s (%s)\n" , bo . SealingResults [ 0 ] . Unseal , bps ( bo . SectorSize , bo . SealingResults [ 0 ] . Unseal ) )
}
2019-12-10 14:05:41 +00:00
}
2020-03-15 17:48:27 +00:00
if ! c . Bool ( "skip-commit2" ) {
fmt . Printf ( "generate candidates: %s (%s)\n" , bo . PostGenerateCandidates , bps ( bo . SectorSize * abi . SectorSize ( len ( bo . SealingResults ) ) , bo . PostGenerateCandidates ) )
fmt . Printf ( "compute epost proof (cold): %s\n" , bo . PostEProofCold )
fmt . Printf ( "compute epost proof (hot): %s\n" , bo . PostEProofHot )
fmt . Printf ( "verify epost proof (cold): %s\n" , bo . VerifyEPostCold )
fmt . Printf ( "verify epost proof (hot): %s\n" , bo . VerifyEPostHot )
}
2019-12-10 13:01:17 +00:00
}
2019-11-27 02:47:08 +00:00
return nil
} ,
}
if err := app . Run ( os . Args ) ; err != nil {
2020-03-06 22:26:22 +00:00
log . Warnf ( "%+v" , err )
2019-11-27 02:47:08 +00:00
return
}
}
2019-12-10 18:04:13 +00:00
2020-03-01 02:52:23 +00:00
var proveCmd = & cli . Command {
Name : "prove" ,
Usage : "Benchmark a proof computation" ,
Flags : [ ] cli . Flag {
& cli . BoolFlag {
Name : "no-gpu" ,
Usage : "disable gpu usage for the benchmark run" ,
} ,
} ,
Action : func ( c * cli . Context ) error {
if c . Bool ( "no-gpu" ) {
os . Setenv ( "BELLMAN_NO_GPU" , "1" )
}
if ! c . Args ( ) . Present ( ) {
return xerrors . Errorf ( "Usage: lotus-bench prove [input.json]" )
}
inb , err := ioutil . ReadFile ( c . Args ( ) . First ( ) )
if err != nil {
return xerrors . Errorf ( "reading input file: %w" , err )
}
var c2in Commit2In
if err := json . Unmarshal ( inb , & c2in ) ; err != nil {
return xerrors . Errorf ( "unmarshalling input file: %w" , err )
}
if err := paramfetch . GetParams ( build . ParametersJson ( ) , c2in . SectorSize ) ; err != nil {
return xerrors . Errorf ( "getting params: %w" , err )
}
maddr , err := address . NewFromString ( c . String ( "miner-addr" ) )
if err != nil {
return err
}
ppt , spt , err := lapi . ProofTypeFromSectorSize ( abi . SectorSize ( c2in . SectorSize ) )
if err != nil {
return err
}
cfg := & sectorbuilder . Config {
Miner : maddr ,
SealProofType : spt ,
PoStProofType : ppt ,
}
sb , err := sectorbuilder . New ( nil , cfg )
if err != nil {
return err
}
start := time . Now ( )
proof , err := sb . SealCommit2 ( context . TODO ( ) , abi . SectorNumber ( c2in . SectorNum ) , c2in . Phase1Out )
if err != nil {
return err
}
sealCommit2 := time . Now ( )
fmt . Printf ( "proof: %x\n" , proof )
fmt . Printf ( "----\nresults (v23) (%d)\n" , c2in . SectorSize )
dur := sealCommit2 . Sub ( start )
fmt . Printf ( "seal: commit phase 2: %s (%s)\n" , dur , bps ( abi . SectorSize ( c2in . SectorSize ) , dur ) )
return nil
} ,
}
2020-02-10 19:16:36 +00:00
func bps ( data abi . SectorSize , d time . Duration ) string {
bdata := new ( big . Int ) . SetUint64 ( uint64 ( data ) )
2019-12-10 19:53:39 +00:00
bdata = bdata . Mul ( bdata , big . NewInt ( time . Second . Nanoseconds ( ) ) )
bps := bdata . Div ( bdata , big . NewInt ( d . Nanoseconds ( ) ) )
2020-02-10 19:16:36 +00:00
return types . SizeStr ( types . BigInt { bps } ) + "/s"
2019-12-10 18:04:13 +00:00
}