chain: Benchmark chain gen

This commit is contained in:
Łukasz Magiera 2019-07-26 14:28:29 +02:00 committed by whyrusleeping
parent 952cd288be
commit 9ea5dbf902
3 changed files with 16 additions and 11 deletions

View File

@ -4,13 +4,13 @@ import (
"testing"
)
func TestChainGeneration(t *testing.T) {
func testGeneration(t testing.TB, n int) {
g, err := NewGenerator()
if err != nil {
t.Fatal(err)
}
for i := 0; i < 10; i++ {
for i := 0; i < n; i++ {
b, err := g.NextBlock()
if err != nil {
t.Fatalf("error at H:%d, %s", i, err)
@ -19,5 +19,12 @@ func TestChainGeneration(t *testing.T) {
t.Fatal("wrong height")
}
}
}
func TestChainGeneration(t *testing.T) {
testGeneration(t, 10)
}
func BenchmarkChainGeneration(b *testing.B) {
testGeneration(b, b.N)
}

View File

@ -2,7 +2,6 @@ package gen
import (
"context"
"fmt"
bls "github.com/filecoin-project/go-bls-sigs"
cid "github.com/ipfs/go-cid"
@ -25,13 +24,13 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
height := parents.Height() + uint64(len(tickets))
vm, err := vm.NewVM(st, height, miner, cs)
vmi, err := vm.NewVM(st, height, miner, cs)
if err != nil {
return nil, err
}
// apply miner reward
if err := vm.TransferFunds(actors.NetworkAddress, miner, vm.MiningRewardForBlock(parents)); err != nil {
if err := vmi.TransferFunds(actors.NetworkAddress, miner, vm.MiningRewardForBlock(parents)); err != nil {
return nil, err
}
@ -42,7 +41,6 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
Height: height,
}
fmt.Printf("adding %d messages to block...\n", len(msgs))
var msgCids []cid.Cid
var blsSigs []types.Signature
var receipts []interface{}
@ -59,7 +57,7 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
} else {
msgCids = append(msgCids, msg.Cid())
}
rec, err := vm.ApplyMessage(ctx, &msg.Message)
rec, err := vmi.ApplyMessage(ctx, &msg.Message)
if err != nil {
return nil, errors.Wrap(err, "apply message failure")
}
@ -80,7 +78,7 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
}
next.MessageReceipts = rectroot
stateRoot, err := vm.Flush(context.TODO())
stateRoot, err := vmi.Flush(context.TODO())
if err != nil {
return nil, errors.Wrap(err, "flushing state tree failed")
}

View File

@ -6,9 +6,9 @@ import (
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain"
"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/chain/wallet"
lcli "github.com/filecoin-project/go-lotus/cli"
"github.com/filecoin-project/go-lotus/node/repo"
)
@ -71,7 +71,7 @@ var initCmd = &cli.Command{
return err
}
wallet, err := chain.NewWallet(ks)
wallet, err := wallet.NewWallet(ks)
if err != nil {
return err
}