From 9804bd3c4ccdb7ca069a7ce7eaf73ec8a4766ca7 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 16 May 2020 11:31:14 -0700 Subject: [PATCH] add blockstore 'Has' caching --- cmd/lotus-bench/import.go | 5 +++++ node/modules/chain.go | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index 8efe532f4..6306cd18c 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -67,6 +67,11 @@ var importBenchCmd = &cli.Command{ return err } bs := blockstore.NewBlockstore(bds) + cbs, err := blockstore.CachedBlockstore(context.TODO(), bs, blockstore.DefaultCacheOpts()) + if err != nil { + return err + } + bs = cbs ds := datastore.NewMapDatastore() cs := store.NewChainStore(bs, ds, vm.Syscalls(ffiwrapper.ProofVerifier)) stm := stmgr.NewStateManager(cs) diff --git a/node/modules/chain.go b/node/modules/chain.go index 678cca723..ca0281acf 100644 --- a/node/modules/chain.go +++ b/node/modules/chain.go @@ -60,14 +60,19 @@ func MessagePool(lc fx.Lifecycle, sm *stmgr.StateManager, ps *pubsub.PubSub, ds return mp, nil } -func ChainBlockstore(r repo.LockedRepo) (dtypes.ChainBlockstore, error) { +func ChainBlockstore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.ChainBlockstore, error) { blocks, err := r.Datastore("/blocks") if err != nil { return nil, err } bs := blockstore.NewBlockstore(blocks) - return blockstore.NewIdStore(bs), nil + cbs, err := blockstore.CachedBlockstore(helpers.LifecycleCtx(mctx, lc), bs, blockstore.DefaultCacheOpts()) + if err != nil { + return nil, err + } + + return blockstore.NewIdStore(cbs), nil } func ChainGCBlockstore(bs dtypes.ChainBlockstore, gcl dtypes.ChainGCLocker) dtypes.ChainGCBlockstore {