From 952cd288bec957a7798a4f925cf0ece09688cbf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 26 Jul 2019 14:19:27 +0200 Subject: [PATCH] chain: fix NewGenerator --- chain/gen/gen.go | 11 ++++++++++- chain/gen/gen_test.go | 2 +- chain/gen/mining.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 7f9e940f1..5d7b223ca 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -8,8 +8,9 @@ import ( "github.com/filecoin-project/go-lotus/chain/types" "github.com/filecoin-project/go-lotus/chain/wallet" "github.com/filecoin-project/go-lotus/node/repo" + block "github.com/ipfs/go-block-format" - cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-cid" blockstore "github.com/ipfs/go-ipfs-blockstore" logging "github.com/ipfs/go-log" ) @@ -93,6 +94,10 @@ func NewGenerator() (*ChainGen, error) { genfb := &types.FullBlock{Header: genb.Genesis} + if err := cs.SetGenesis(genb.Genesis); err != nil { + return nil, err + } + gen := &ChainGen{ bs: bs, cs: cs, @@ -131,6 +136,10 @@ func (cg *ChainGen) NextBlock() (*types.FullBlock, error) { return nil, err } + if err := cg.cs.AddBlock(fblk.Header); err != nil { + return nil, err + } + cg.curBlock = fblk return fblk, nil diff --git a/chain/gen/gen_test.go b/chain/gen/gen_test.go index 486778eac..b78cf77e1 100644 --- a/chain/gen/gen_test.go +++ b/chain/gen/gen_test.go @@ -13,7 +13,7 @@ func TestChainGeneration(t *testing.T) { for i := 0; i < 10; i++ { b, err := g.NextBlock() if err != nil { - t.Fatal(err) + t.Fatalf("error at H:%d, %s", i, err) } if b.Header.Height != uint64(i+1) { t.Fatal("wrong height") diff --git a/chain/gen/mining.go b/chain/gen/mining.go index ccab07ae3..54aeca5ff 100644 --- a/chain/gen/mining.go +++ b/chain/gen/mining.go @@ -42,7 +42,7 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A Height: height, } - fmt.Printf("adding %d messages to block...", len(msgs)) + fmt.Printf("adding %d messages to block...\n", len(msgs)) var msgCids []cid.Cid var blsSigs []types.Signature var receipts []interface{}