From 35b8516288f3440d51bf38af430997c79aacac17 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 13 Dec 2021 14:26:59 +0200 Subject: [PATCH] plumb more contexts in lotus --- blockstore/timed.go | 2 +- cmd/lotus/backup.go | 4 ++-- cmd/lotus/daemon.go | 4 ++-- node/modules/chain.go | 4 ++-- node/modules/client.go | 4 ++-- node/modules/genesis.go | 9 +++++---- node/modules/services.go | 2 +- node/modules/storageminer.go | 6 +++--- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/blockstore/timed.go b/blockstore/timed.go index 4fee6b6dd..8f226b0b1 100644 --- a/blockstore/timed.go +++ b/blockstore/timed.go @@ -154,7 +154,7 @@ func (t *TimedCacheBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error) return t.inactive.Has(ctx, k) } -func (t *TimedCacheBlockstore) HashOnRead(ctx context.Context, _ bool) { +func (t *TimedCacheBlockstore) HashOnRead(_ bool) { // no-op } diff --git a/cmd/lotus/backup.go b/cmd/lotus/backup.go index d41e0c098..245a3d397 100644 --- a/cmd/lotus/backup.go +++ b/cmd/lotus/backup.go @@ -111,10 +111,10 @@ func restore(cctx *cli.Context, r repo.Repo) error { log.Info("Resetting chainstore metadata") chainHead := dstore.NewKey("head") - if err := mds.Delete(chainHead); err != nil { + if err := mds.Delete(context.Background(), chainHead); err != nil { return xerrors.Errorf("clearing chain head: %w", err) } - if err := store.FlushValidationCache(mds); err != nil { + if err := store.FlushValidationCache(context.Background(), mds); err != nil { return xerrors.Errorf("clearing chain validation cache: %w", err) } diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 3f5de8138..bcf3b119e 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -506,7 +506,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool) return xerrors.Errorf("importing chain failed: %w", err) } - if err := cst.FlushValidationCache(); err != nil { + if err := cst.FlushValidationCache(context.Background()); err != nil { return xerrors.Errorf("flushing validation cache failed: %w", err) } @@ -515,7 +515,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool) return err } - err = cst.SetGenesis(gb.Blocks()[0]) + err = cst.SetGenesis(context.Background(), gb.Blocks()[0]) if err != nil { return err } diff --git a/node/modules/chain.go b/node/modules/chain.go index b5be24d5d..d79cd1038 100644 --- a/node/modules/chain.go +++ b/node/modules/chain.go @@ -59,7 +59,7 @@ func ChainBlockService(bs dtypes.ExposedBlockstore, rem dtypes.ChainBitswap) dty } func MessagePool(lc fx.Lifecycle, us stmgr.UpgradeSchedule, mpp messagepool.Provider, ds dtypes.MetadataDS, nn dtypes.NetworkName, j journal.Journal, protector dtypes.GCReferenceProtector) (*messagepool.MessagePool, error) { - mp, err := messagepool.New(mpp, ds, us, nn, j) + mp, err := messagepool.New(context.Background(), mpp, ds, us, nn, j) if err != nil { return nil, xerrors.Errorf("constructing mpool: %w", err) } @@ -83,7 +83,7 @@ func ChainStore(lc fx.Lifecycle, chain := store.NewChainStore(cbs, sbs, ds, weight, j) - if err := chain.Load(); err != nil { + if err := chain.Load(context.Background()); err != nil { log.Warnf("loading chain state from disk: %s", err) } diff --git a/node/modules/client.go b/node/modules/client.go index 4d988d98a..1de4f63e8 100644 --- a/node/modules/client.go +++ b/node/modules/client.go @@ -52,7 +52,7 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full if err != nil { return nil } - b, err := ds.Get(datastore.NewKey("/marketfunds/client")) + b, err := ds.Get(context.Background(), datastore.NewKey("/marketfunds/client")) if err != nil { if xerrors.Is(err, datastore.ErrNotFound) { return nil @@ -73,7 +73,7 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full return nil } - return ds.Delete(datastore.NewKey("/marketfunds/client")) + return ds.Delete(context.Background(), datastore.NewKey("/marketfunds/client")) }, }) } diff --git a/node/modules/genesis.go b/node/modules/genesis.go index 43443b125..77cf8e353 100644 --- a/node/modules/genesis.go +++ b/node/modules/genesis.go @@ -2,6 +2,7 @@ package modules import ( "bytes" + "context" "os" "github.com/ipfs/go-datastore" @@ -22,14 +23,14 @@ func ErrorGenesis() Genesis { func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis { return func(bs dtypes.ChainBlockstore) Genesis { return func() (header *types.BlockHeader, e error) { - c, err := car.LoadCar(bs, bytes.NewReader(genBytes)) + c, err := car.LoadCar(context.Background(), bs, bytes.NewReader(genBytes)) if err != nil { return nil, xerrors.Errorf("loading genesis car file failed: %w", err) } if len(c.Roots) != 1 { return nil, xerrors.New("expected genesis file to have one root") } - root, err := bs.Get(c.Roots[0]) + root, err := bs.Get(context.Background(), c.Roots[0]) if err != nil { return nil, err } @@ -46,7 +47,7 @@ func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis { func DoSetGenesis(_ dtypes.AfterGenesisSet) {} func SetGenesis(cs *store.ChainStore, g Genesis) (dtypes.AfterGenesisSet, error) { - genFromRepo, err := cs.GetGenesis() + genFromRepo, err := cs.GetGenesis(context.Background()) if err == nil { if os.Getenv("LOTUS_SKIP_GENESIS_CHECK") != "_yes_" { expectedGenesis, err := g() @@ -69,5 +70,5 @@ func SetGenesis(cs *store.ChainStore, g Genesis) (dtypes.AfterGenesisSet, error) return dtypes.AfterGenesisSet{}, xerrors.Errorf("genesis func failed: %w", err) } - return dtypes.AfterGenesisSet{}, cs.SetGenesis(genesis) + return dtypes.AfterGenesisSet{}, cs.SetGenesis(context.Background(), genesis) } diff --git a/node/modules/services.go b/node/modules/services.go index 17d4a7476..c832b16fc 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -229,7 +229,7 @@ func BuiltinDrandConfig() dtypes.DrandSchedule { } func RandomSchedule(p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.Schedule, error) { - gen, err := p.Cs.GetGenesis() + gen, err := p.Cs.GetGenesis(context.Background()) if err != nil { return nil, err } diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index f4d00606f..d271f974a 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -78,7 +78,7 @@ var ( ) func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) { - maddrb, err := ds.Get(datastore.NewKey("miner-address")) + maddrb, err := ds.Get(context.Background(), datastore.NewKey("miner-address")) if err != nil { return address.Undef, err } @@ -300,7 +300,7 @@ func HandleDeals(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, h sto func HandleMigrateProviderFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, node api.FullNode, minerAddress dtypes.MinerAddress) { lc.Append(fx.Hook{ OnStart: func(ctx context.Context) error { - b, err := ds.Get(datastore.NewKey("/marketfunds/provider")) + b, err := ds.Get(context.Background(), datastore.NewKey("/marketfunds/provider")) if err != nil { if xerrors.Is(err, datastore.ErrNotFound) { return nil @@ -331,7 +331,7 @@ func HandleMigrateProviderFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, node api. return nil } - return ds.Delete(datastore.NewKey("/marketfunds/provider")) + return ds.Delete(context.Background(), datastore.NewKey("/marketfunds/provider")) }, }) }