From e8d54839da4afcd5968e1b7c575a9e17d3705fce Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Mon, 8 Jul 2019 22:29:01 +0200 Subject: [PATCH] pull buffered blockstore into the lib folder --- chain/vm.go | 7 ++++--- {chain => lib/bufbstore}/buf_bstore.go | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) rename {chain => lib/bufbstore}/buf_bstore.go (95%) diff --git a/chain/vm.go b/chain/vm.go index 22a96bb91..5d7d63f8e 100644 --- a/chain/vm.go +++ b/chain/vm.go @@ -6,6 +6,7 @@ import ( "math/big" "github.com/filecoin-project/go-lotus/chain/address" + "github.com/filecoin-project/go-lotus/lib/bufbstore" bserv "github.com/ipfs/go-blockservice" cid "github.com/ipfs/go-cid" @@ -64,13 +65,13 @@ type VM struct { cstate *StateTree base cid.Cid cs *ChainStore - buf *BufferedBS + buf *bufbstore.BufferedBS blockHeight uint64 blockMiner address.Address } func NewVM(base cid.Cid, height uint64, maddr address.Address, cs *ChainStore) (*VM, error) { - buf := NewBufferedBstore(cs.bs) + buf := bufbstore.NewBufferedBstore(cs.bs) cst := hamt.CSTFromBstore(buf) state, err := LoadStateTree(cst, base) if err != nil { @@ -166,7 +167,7 @@ func (vm *VM) ApplyMessage(msg *Message) (*MessageReceipt, error) { func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) { from := dag.NewDAGService(bserv.New(vm.buf, nil)) - to := dag.NewDAGService(bserv.New(vm.buf.read, nil)) + to := dag.NewDAGService(bserv.New(vm.buf.Read(), nil)) root, err := vm.cstate.Flush() if err != nil { diff --git a/chain/buf_bstore.go b/lib/bufbstore/buf_bstore.go similarity index 95% rename from chain/buf_bstore.go rename to lib/bufbstore/buf_bstore.go index 3df152901..b3421537e 100644 --- a/chain/buf_bstore.go +++ b/lib/bufbstore/buf_bstore.go @@ -1,4 +1,4 @@ -package chain +package bufbstore import ( "context" @@ -115,3 +115,7 @@ func (bs *BufferedBS) HashOnRead(hor bool) { func (bs *BufferedBS) PutMany(blks []block.Block) error { return bs.write.PutMany(blks) } + +func (bs *BufferedBS) Read() bstore.Blockstore { + return bs.read +}