diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 8e749095c..9ef959336 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -139,7 +139,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { return nil, xerrors.Errorf("failed to get metadata datastore: %w", err) } - bs, err := lr.Blockstore(repo.BlockstoreChain) + bs, err := lr.Blockstore(context.TODO(), repo.BlockstoreChain) if err != nil { return nil, err } diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index 3280a63e5..591917bd6 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -175,7 +175,7 @@ var chainBalanceStateCmd = &cli.Command{ defer lkrepo.Close() //nolint:errcheck - bs, err := lkrepo.Blockstore(repo.BlockstoreChain) + bs, err := lkrepo.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return fmt.Errorf("failed to open blockstore: %w", err) } @@ -396,7 +396,7 @@ var chainPledgeCmd = &cli.Command{ defer lkrepo.Close() //nolint:errcheck - bs, err := lkrepo.Blockstore(repo.BlockstoreChain) + bs, err := lkrepo.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return xerrors.Errorf("failed to open blockstore: %w", err) } diff --git a/cmd/lotus-shed/export.go b/cmd/lotus-shed/export.go index 9b0703445..83567add3 100644 --- a/cmd/lotus-shed/export.go +++ b/cmd/lotus-shed/export.go @@ -72,7 +72,7 @@ var exportChainCmd = &cli.Command{ defer fi.Close() //nolint:errcheck - bs, err := lr.Blockstore(repo.BlockstoreChain) + bs, err := lr.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return fmt.Errorf("failed to open blockstore: %w", err) } diff --git a/cmd/lotus-shed/import-car.go b/cmd/lotus-shed/import-car.go index 9fa853728..7f3fa7c89 100644 --- a/cmd/lotus-shed/import-car.go +++ b/cmd/lotus-shed/import-car.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/hex" "fmt" "io" @@ -24,6 +25,8 @@ var importCarCmd = &cli.Command{ return xerrors.Errorf("opening fs repo: %w", err) } + ctx := context.TODO() + exists, err := r.Exists() if err != nil { return err @@ -44,7 +47,7 @@ var importCarCmd = &cli.Command{ return xerrors.Errorf("opening the car file: %w", err) } - bs, err := lr.Blockstore(repo.BlockstoreChain) + bs, err := lr.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return err } @@ -99,6 +102,8 @@ var importObjectCmd = &cli.Command{ return xerrors.Errorf("opening fs repo: %w", err) } + ctx := context.TODO() + exists, err := r.Exists() if err != nil { return err @@ -113,7 +118,7 @@ var importObjectCmd = &cli.Command{ } defer lr.Close() //nolint:errcheck - bs, err := lr.Blockstore(repo.BlockstoreChain) + bs, err := lr.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return fmt.Errorf("failed to open blockstore: %w", err) } diff --git a/cmd/lotus-shed/pruning.go b/cmd/lotus-shed/pruning.go index 8728163c9..5def0c6b2 100644 --- a/cmd/lotus-shed/pruning.go +++ b/cmd/lotus-shed/pruning.go @@ -131,7 +131,7 @@ var stateTreePruneCmd = &cli.Command{ defer lkrepo.Close() //nolint:errcheck - bs, err := lkrepo.Blockstore(repo.BlockstoreChain) + bs, err := lkrepo.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return fmt.Errorf("failed to open blockstore: %w", err) } diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 581238d4b..006da822a 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -235,7 +235,7 @@ var DaemonCmd = &cli.Command{ issnapshot = true } - if err := ImportChain(r, chainfile, issnapshot); err != nil { + if err := ImportChain(ctx, r, chainfile, issnapshot); err != nil { return err } if cctx.Bool("halt-after-import") { @@ -370,7 +370,7 @@ func importKey(ctx context.Context, api api.FullNode, f string) error { return nil } -func ImportChain(r repo.Repo, fname string, snapshot bool) (err error) { +func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool) (err error) { var rd io.Reader var l int64 if strings.HasPrefix(fname, "http://") || strings.HasPrefix(fname, "https://") { @@ -413,7 +413,7 @@ func ImportChain(r repo.Repo, fname string, snapshot bool) (err error) { } defer lr.Close() //nolint:errcheck - bs, err := lr.Blockstore(repo.BlockstoreChain) + bs, err := lr.Blockstore(ctx, repo.BlockstoreChain) if err != nil { return xerrors.Errorf("failed to open blockstore: %w", err) } @@ -454,7 +454,7 @@ func ImportChain(r repo.Repo, fname string, snapshot bool) (err error) { return xerrors.Errorf("flushing validation cache failed: %w", err) } - gb, err := cst.GetTipsetByHeight(context.TODO(), 0, ts, true) + gb, err := cst.GetTipsetByHeight(ctx, 0, ts, true) if err != nil { return err } @@ -468,13 +468,13 @@ func ImportChain(r repo.Repo, fname string, snapshot bool) (err error) { if !snapshot { log.Infof("validating imported chain...") - if err := stm.ValidateChain(context.TODO(), ts); err != nil { + if err := stm.ValidateChain(ctx, ts); err != nil { return xerrors.Errorf("chain validation failed: %w", err) } } log.Infof("accepting %s as new head", ts.Cids()) - if err := cst.ForceHeadSilent(context.Background(), ts); err != nil { + if err := cst.ForceHeadSilent(ctx, ts); err != nil { return err } diff --git a/node/modules/chain.go b/node/modules/chain.go index 095bb501c..782e0b32f 100644 --- a/node/modules/chain.go +++ b/node/modules/chain.go @@ -77,7 +77,7 @@ func MessagePool(lc fx.Lifecycle, sm *stmgr.StateManager, ps *pubsub.PubSub, ds } func ChainRawBlockstore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo) (dtypes.ChainRawBlockstore, error) { - bs, err := r.Blockstore(repo.BlockstoreChain) + bs, err := r.Blockstore(helpers.LifecycleCtx(mctx, lc), repo.BlockstoreChain) if err != nil { return nil, err } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index e4d9b3239..b57fb64af 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -2,6 +2,7 @@ package repo import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -299,7 +300,7 @@ func (fsr *fsLockedRepo) Close() error { } // Blockstore returns a blockstore for the provided data domain. -func (fsr *fsLockedRepo) Blockstore(domain BlockstoreDomain) (blockstore.Blockstore, error) { +func (fsr *fsLockedRepo) Blockstore(ctx context.Context, domain BlockstoreDomain) (blockstore.Blockstore, error) { if domain != BlockstoreChain { return nil, ErrInvalidBlockstoreDomain } diff --git a/node/repo/interface.go b/node/repo/interface.go index 4ae68f880..564fc46c9 100644 --- a/node/repo/interface.go +++ b/node/repo/interface.go @@ -1,6 +1,7 @@ package repo import ( + "context" "errors" "github.com/filecoin-project/lotus/lib/blockstore" @@ -54,7 +55,7 @@ type LockedRepo interface { Datastore(namespace string) (datastore.Batching, error) // Blockstore returns an IPLD blockstore for the requested domain. - Blockstore(domain BlockstoreDomain) (blockstore.Blockstore, error) + Blockstore(ctx context.Context, domain BlockstoreDomain) (blockstore.Blockstore, error) // Returns config in this repo Config() (interface{}, error) diff --git a/node/repo/memrepo.go b/node/repo/memrepo.go index 88d4eccd3..06937c052 100644 --- a/node/repo/memrepo.go +++ b/node/repo/memrepo.go @@ -1,6 +1,7 @@ package repo import ( + "context" "encoding/json" "io/ioutil" "os" @@ -244,7 +245,7 @@ func (lmem *lockedMemRepo) Datastore(ns string) (datastore.Batching, error) { return namespace.Wrap(lmem.mem.datastore, datastore.NewKey(ns)), nil } -func (lmem *lockedMemRepo) Blockstore(domain BlockstoreDomain) (blockstore.Blockstore, error) { +func (lmem *lockedMemRepo) Blockstore(ctx context.Context, domain BlockstoreDomain) (blockstore.Blockstore, error) { if domain != BlockstoreChain { return nil, ErrInvalidBlockstoreDomain }