chain: Benchmark chain gen
This commit is contained in:
parent
952cd288be
commit
9ea5dbf902
@ -4,13 +4,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChainGeneration(t *testing.T) {
|
func testGeneration(t testing.TB, n int) {
|
||||||
g, err := NewGenerator()
|
g, err := NewGenerator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < n; i++ {
|
||||||
b, err := g.NextBlock()
|
b, err := g.NextBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error at H:%d, %s", i, err)
|
t.Fatalf("error at H:%d, %s", i, err)
|
||||||
@ -19,5 +19,12 @@ func TestChainGeneration(t *testing.T) {
|
|||||||
t.Fatal("wrong height")
|
t.Fatal("wrong height")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChainGeneration(t *testing.T) {
|
||||||
|
testGeneration(t, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkChainGeneration(b *testing.B) {
|
||||||
|
testGeneration(b, b.N)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package gen
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
bls "github.com/filecoin-project/go-bls-sigs"
|
bls "github.com/filecoin-project/go-bls-sigs"
|
||||||
cid "github.com/ipfs/go-cid"
|
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))
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply miner reward
|
// 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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +41,6 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
|
|||||||
Height: height,
|
Height: height,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("adding %d messages to block...\n", len(msgs))
|
|
||||||
var msgCids []cid.Cid
|
var msgCids []cid.Cid
|
||||||
var blsSigs []types.Signature
|
var blsSigs []types.Signature
|
||||||
var receipts []interface{}
|
var receipts []interface{}
|
||||||
@ -59,7 +57,7 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
|
|||||||
} else {
|
} else {
|
||||||
msgCids = append(msgCids, msg.Cid())
|
msgCids = append(msgCids, msg.Cid())
|
||||||
}
|
}
|
||||||
rec, err := vm.ApplyMessage(ctx, &msg.Message)
|
rec, err := vmi.ApplyMessage(ctx, &msg.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "apply message failure")
|
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
|
next.MessageReceipts = rectroot
|
||||||
|
|
||||||
stateRoot, err := vm.Flush(context.TODO())
|
stateRoot, err := vmi.Flush(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "flushing state tree failed")
|
return nil, errors.Wrap(err, "flushing state tree failed")
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/build"
|
"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/actors"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/wallet"
|
||||||
lcli "github.com/filecoin-project/go-lotus/cli"
|
lcli "github.com/filecoin-project/go-lotus/cli"
|
||||||
"github.com/filecoin-project/go-lotus/node/repo"
|
"github.com/filecoin-project/go-lotus/node/repo"
|
||||||
)
|
)
|
||||||
@ -71,7 +71,7 @@ var initCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet, err := chain.NewWallet(ks)
|
wallet, err := wallet.NewWallet(ks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user