plumb more contexts in lotus

This commit is contained in:
vyzo 2021-12-13 14:26:59 +02:00
parent 7ed40c1ec7
commit 84710cf27e
8 changed files with 18 additions and 17 deletions

View File

@ -154,7 +154,7 @@ func (t *TimedCacheBlockstore) Has(ctx context.Context, k cid.Cid) (bool, error)
return t.inactive.Has(ctx, k) return t.inactive.Has(ctx, k)
} }
func (t *TimedCacheBlockstore) HashOnRead(ctx context.Context, _ bool) { func (t *TimedCacheBlockstore) HashOnRead(_ bool) {
// no-op // no-op
} }

View File

@ -111,10 +111,10 @@ func restore(cctx *cli.Context, r repo.Repo) error {
log.Info("Resetting chainstore metadata") log.Info("Resetting chainstore metadata")
chainHead := dstore.NewKey("head") 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) 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) return xerrors.Errorf("clearing chain validation cache: %w", err)
} }

View File

@ -506,7 +506,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
return xerrors.Errorf("importing chain failed: %w", err) 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) 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 return err
} }
err = cst.SetGenesis(gb.Blocks()[0]) err = cst.SetGenesis(context.Background(), gb.Blocks()[0])
if err != nil { if err != nil {
return err return err
} }

View File

@ -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) { 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 { if err != nil {
return nil, xerrors.Errorf("constructing mpool: %w", err) 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) 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) log.Warnf("loading chain state from disk: %s", err)
} }

View File

@ -52,7 +52,7 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full
if err != nil { if err != nil {
return 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 err != nil {
if xerrors.Is(err, datastore.ErrNotFound) { if xerrors.Is(err, datastore.ErrNotFound) {
return nil return nil
@ -73,7 +73,7 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full
return nil return nil
} }
return ds.Delete(datastore.NewKey("/marketfunds/client")) return ds.Delete(context.Background(), datastore.NewKey("/marketfunds/client"))
}, },
}) })
} }

View File

@ -2,6 +2,7 @@ package modules
import ( import (
"bytes" "bytes"
"context"
"os" "os"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
@ -22,14 +23,14 @@ func ErrorGenesis() Genesis {
func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis { func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis {
return func(bs dtypes.ChainBlockstore) Genesis { return func(bs dtypes.ChainBlockstore) Genesis {
return func() (header *types.BlockHeader, e error) { 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 { if err != nil {
return nil, xerrors.Errorf("loading genesis car file failed: %w", err) return nil, xerrors.Errorf("loading genesis car file failed: %w", err)
} }
if len(c.Roots) != 1 { if len(c.Roots) != 1 {
return nil, xerrors.New("expected genesis file to have one root") 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 { if err != nil {
return nil, err return nil, err
} }
@ -46,7 +47,7 @@ func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis {
func DoSetGenesis(_ dtypes.AfterGenesisSet) {} func DoSetGenesis(_ dtypes.AfterGenesisSet) {}
func SetGenesis(cs *store.ChainStore, g Genesis) (dtypes.AfterGenesisSet, error) { func SetGenesis(cs *store.ChainStore, g Genesis) (dtypes.AfterGenesisSet, error) {
genFromRepo, err := cs.GetGenesis() genFromRepo, err := cs.GetGenesis(context.Background())
if err == nil { if err == nil {
if os.Getenv("LOTUS_SKIP_GENESIS_CHECK") != "_yes_" { if os.Getenv("LOTUS_SKIP_GENESIS_CHECK") != "_yes_" {
expectedGenesis, err := g() 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{}, xerrors.Errorf("genesis func failed: %w", err)
} }
return dtypes.AfterGenesisSet{}, cs.SetGenesis(genesis) return dtypes.AfterGenesisSet{}, cs.SetGenesis(context.Background(), genesis)
} }

View File

@ -229,7 +229,7 @@ func BuiltinDrandConfig() dtypes.DrandSchedule {
} }
func RandomSchedule(p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.Schedule, error) { func RandomSchedule(p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.Schedule, error) {
gen, err := p.Cs.GetGenesis() gen, err := p.Cs.GetGenesis(context.Background())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -78,7 +78,7 @@ var (
) )
func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) { 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 { if err != nil {
return address.Undef, err 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) { func HandleMigrateProviderFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, node api.FullNode, minerAddress dtypes.MinerAddress) {
lc.Append(fx.Hook{ lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error { 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 err != nil {
if xerrors.Is(err, datastore.ErrNotFound) { if xerrors.Is(err, datastore.ErrNotFound) {
return nil return nil
@ -331,7 +331,7 @@ func HandleMigrateProviderFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, node api.
return nil return nil
} }
return ds.Delete(datastore.NewKey("/marketfunds/provider")) return ds.Delete(context.Background(), datastore.NewKey("/marketfunds/provider"))
}, },
}) })
} }