add context to ChainStore.

This commit is contained in:
Raúl Kripalani 2020-11-16 15:52:19 +00:00
parent 87d6daf745
commit d7b4f92f1f
13 changed files with 22 additions and 19 deletions

View File

@ -245,7 +245,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
return nil, xerrors.Errorf("make genesis block failed: %w", err) return nil, xerrors.Errorf("make genesis block failed: %w", err)
} }
cs := store.NewChainStore(bs, bs, ds, sys, j) cs := store.NewChainStore(context.Background(), bs, bs, ds, sys, j)
genfb := &types.FullBlock{Header: genb.Genesis} genfb := &types.FullBlock{Header: genb.Genesis}
gents := store.NewFullTipSet([]*types.FullBlock{genfb}) gents := store.NewFullTipSet([]*types.FullBlock{genfb})

View File

@ -482,7 +482,7 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto
} }
// temp chainstore // temp chainstore
cs := store.NewChainStore(bs, bs, datastore.NewMapDatastore(), sys, j) cs := store.NewChainStore(context.Background(), bs, bs, datastore.NewMapDatastore(), sys, j)
// Verify PreSealed Data // Verify PreSealed Data
stateroot, err = VerifyPreSealedData(ctx, cs, stateroot, template, keyIDs) stateroot, err = VerifyPreSealedData(ctx, cs, stateroot, template, keyIDs)

View File

@ -31,7 +31,7 @@ func TestIndexSeeks(t *testing.T) {
ctx := context.TODO() ctx := context.TODO()
nbs := blockstore.NewTemporarySync() nbs := blockstore.NewTemporarySync()
cs := store.NewChainStore(nbs, nbs, syncds.MutexWrap(datastore.NewMapDatastore()), nil, nil) cs := store.NewChainStore(context.Background(), nbs, nbs, syncds.MutexWrap(datastore.NewMapDatastore()), nil, nil)
_, err = cs.Import(bytes.NewReader(gencar)) _, err = cs.Import(bytes.NewReader(gencar))
if err != nil { if err != nil {

View File

@ -137,7 +137,7 @@ type ChainStore struct {
} }
// localbs is guaranteed to fail Get* if requested block isn't stored locally // localbs is guaranteed to fail Get* if requested block isn't stored locally
func NewChainStore(bs bstore.Blockstore, localbs bstore.Blockstore, ds dstore.Batching, vmcalls vm.SyscallBuilder, j journal.Journal) *ChainStore { func NewChainStore(ctx context.Context, bs bstore.Blockstore, localbs bstore.Blockstore, ds dstore.Batching, vmcalls vm.SyscallBuilder, j journal.Journal) *ChainStore {
c, _ := lru.NewARC(DefaultMsgMetaCacheSize) c, _ := lru.NewARC(DefaultMsgMetaCacheSize)
tsc, _ := lru.NewARC(DefaultTipSetCacheSize) tsc, _ := lru.NewARC(DefaultTipSetCacheSize)
if j == nil { if j == nil {
@ -191,7 +191,6 @@ func NewChainStore(bs bstore.Blockstore, localbs bstore.Blockstore, ds dstore.Ba
} }
hcmetric := func(rev, app []*types.TipSet) error { hcmetric := func(rev, app []*types.TipSet) error {
ctx := context.Background()
for _, r := range app { for _, r := range app {
stats.Record(ctx, metrics.ChainNodeHeight.M(int64(r.Height()))) stats.Record(ctx, metrics.ChainNodeHeight.M(int64(r.Height())))
} }
@ -199,7 +198,7 @@ func NewChainStore(bs bstore.Blockstore, localbs bstore.Blockstore, ds dstore.Ba
} }
cs.reorgNotifeeCh = make(chan ReorgNotifee) cs.reorgNotifeeCh = make(chan ReorgNotifee)
cs.reorgCh = cs.reorgWorker(context.TODO(), []ReorgNotifee{hcnf, hcmetric}) cs.reorgCh = cs.reorgWorker(ctx, []ReorgNotifee{hcnf, hcmetric})
return cs return cs
} }

View File

@ -70,7 +70,7 @@ func BenchmarkGetRandomness(b *testing.B) {
b.Fatal(err) b.Fatal(err)
} }
cs := store.NewChainStore(bs, bs, mds, nil, nil) cs := store.NewChainStore(context.Background(), bs, bs, mds, nil, nil)
b.ResetTimer() b.ResetTimer()
@ -104,7 +104,7 @@ func TestChainExportImport(t *testing.T) {
} }
nbs := blockstore.NewTemporary() nbs := blockstore.NewTemporary()
cs := store.NewChainStore(nbs, nbs, datastore.NewMapDatastore(), nil, nil) cs := store.NewChainStore(context.Background(), nbs, nbs, datastore.NewMapDatastore(), nil, nil)
root, err := cs.Import(buf) root, err := cs.Import(buf)
if err != nil { if err != nil {
@ -138,7 +138,7 @@ func TestChainExportImportFull(t *testing.T) {
} }
nbs := blockstore.NewTemporary() nbs := blockstore.NewTemporary()
cs := store.NewChainStore(nbs, nbs, datastore.NewMapDatastore(), nil, nil) cs := store.NewChainStore(context.Background(), nbs, nbs, datastore.NewMapDatastore(), nil, nil)
root, err := cs.Import(buf) root, err := cs.Import(buf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -262,7 +262,7 @@ var importBenchCmd = &cli.Command{
} }
metadataDs := datastore.NewMapDatastore() metadataDs := datastore.NewMapDatastore()
cs := store.NewChainStore(bs, bs, metadataDs, vm.Syscalls(verifier), nil) cs := store.NewChainStore(context.Background(), bs, bs, metadataDs, vm.Syscalls(verifier), nil)
stm := stmgr.NewStateManager(cs) stm := stmgr.NewStateManager(cs)
startTime := time.Now() startTime := time.Now()

View File

@ -188,7 +188,7 @@ var chainBalanceStateCmd = &cli.Command{
return err return err
} }
cs := store.NewChainStore(bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), nil) cs := store.NewChainStore(context.Background(), bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), nil)
cst := cbor.NewCborStore(bs) cst := cbor.NewCborStore(bs)
store := adt.WrapStore(ctx, cst) store := adt.WrapStore(ctx, cst)
@ -408,7 +408,7 @@ var chainPledgeCmd = &cli.Command{
return err return err
} }
cs := store.NewChainStore(bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), nil) cs := store.NewChainStore(context.Background(), bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), nil)
cst := cbor.NewCborStore(bs) cst := cbor.NewCborStore(bs)
store := adt.WrapStore(ctx, cst) store := adt.WrapStore(ctx, cst)

View File

@ -90,7 +90,7 @@ var exportChainCmd = &cli.Command{
return err return err
} }
cs := store.NewChainStore(bs, bs, mds, nil, nil) cs := store.NewChainStore(context.Background(), bs, bs, mds, nil, nil)
if err := cs.Load(); err != nil { if err := cs.Load(); err != nil {
return err return err
} }

View File

@ -52,7 +52,7 @@ var genesisVerifyCmd = &cli.Command{
} }
bs := blockstore.NewBlockstore(datastore.NewMapDatastore()) bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
cs := store.NewChainStore(bs, bs, datastore.NewMapDatastore(), nil, nil) cs := store.NewChainStore(context.Background(), bs, bs, datastore.NewMapDatastore(), nil, nil)
cf := cctx.Args().Get(0) cf := cctx.Args().Get(0)
f, err := os.Open(cf) f, err := os.Open(cf)

View File

@ -169,7 +169,7 @@ var stateTreePruneCmd = &cli.Command{
return nil return nil
} }
cs := store.NewChainStore(bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), nil) cs := store.NewChainStore(context.Background(), bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), nil)
if err := cs.Load(); err != nil { if err := cs.Load(); err != nil {
return fmt.Errorf("loading chainstore: %w", err) return fmt.Errorf("loading chainstore: %w", err)
} }

View File

@ -419,7 +419,10 @@ func ImportChain(r repo.Repo, fname string, snapshot bool) (err error) {
if err != nil { if err != nil {
return xerrors.Errorf("failed to open journal: %w", err) return xerrors.Errorf("failed to open journal: %w", err)
} }
cst := store.NewChainStore(bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), j)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cst := store.NewChainStore(ctx, bs, bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), j)
log.Infof("importing chain from %s...", fname) log.Infof("importing chain from %s...", fname)

View File

@ -87,7 +87,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, preroot
syscalls = vm.Syscalls(ffiwrapper.ProofVerifier) syscalls = vm.Syscalls(ffiwrapper.ProofVerifier)
vmRand = NewFixedRand() vmRand = NewFixedRand()
cs = store.NewChainStore(bs, bs, ds, syscalls, nil) cs = store.NewChainStore(context.Background(), bs, bs, ds, syscalls, nil)
sm = stmgr.NewStateManager(cs) sm = stmgr.NewStateManager(cs)
) )

View File

@ -111,8 +111,9 @@ func SetupFallbackBlockstore(cbs dtypes.ChainBlockstore, rem dtypes.ChainBitswap
return nil return nil
} }
func ChainStore(bs dtypes.ChainBlockstore, lbs dtypes.ChainRawBlockstore, ds dtypes.MetadataDS, syscalls vm.SyscallBuilder, j journal.Journal) *store.ChainStore { func ChainStore(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.ChainBlockstore, lbs dtypes.ChainRawBlockstore, ds dtypes.MetadataDS, syscalls vm.SyscallBuilder, j journal.Journal) *store.ChainStore {
chain := store.NewChainStore(bs, lbs, ds, syscalls, j) ctx := helpers.LifecycleCtx(mctx, lc)
chain := store.NewChainStore(ctx, bs, lbs, ds, syscalls, j)
if err := chain.Load(); err != nil { if err := chain.Load(); err != nil {
log.Warnf("loading chain state from disk: %s", err) log.Warnf("loading chain state from disk: %s", err)