plumb more contexts
This commit is contained in:
@@ -116,7 +116,7 @@ func (m *ChainModule) ChainGetBlockMessages(ctx context.Context, msg cid.Cid) (*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bmsgs, smsgs, err := m.Chain.MessagesForBlock(b)
|
||||
bmsgs, smsgs, err := m.Chain.MessagesForBlock(ctx, b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -159,7 +159,7 @@ func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cm, err := a.Chain.MessagesForTipset(pts)
|
||||
cm, err := a.Chain.MessagesForTipset(ctx, pts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -191,14 +191,14 @@ func (a *ChainAPI) ChainGetParentReceipts(ctx context.Context, bcid cid.Cid) ([]
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cm, err := a.Chain.MessagesForTipset(pts)
|
||||
cm, err := a.Chain.MessagesForTipset(ctx, pts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var out []*types.MessageReceipt
|
||||
for i := 0; i < len(cm); i++ {
|
||||
r, err := a.Chain.GetParentReceipt(b, i)
|
||||
r, err := a.Chain.GetParentReceipt(ctx, b, i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func (a *ChainAPI) ChainGetMessagesInTipset(ctx context.Context, tsk types.TipSe
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
cm, err := a.Chain.MessagesForTipset(ts)
|
||||
cm, err := a.Chain.MessagesForTipset(ctx, ts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -577,7 +577,7 @@ func (a *ChainAPI) ChainGetNode(ctx context.Context, p string) (*api.IpldObject,
|
||||
}
|
||||
|
||||
func (m *ChainModule) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error) {
|
||||
cm, err := m.Chain.GetCMessage(mc)
|
||||
cm, err := m.Chain.GetCMessage(ctx, mc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -82,14 +82,14 @@ type GasMeta struct {
|
||||
Limit int64
|
||||
}
|
||||
|
||||
func (g *GasPriceCache) GetTSGasStats(cstore *store.ChainStore, ts *types.TipSet) ([]GasMeta, error) {
|
||||
func (g *GasPriceCache) GetTSGasStats(ctx context.Context, cstore *store.ChainStore, ts *types.TipSet) ([]GasMeta, error) {
|
||||
i, has := g.c.Get(ts.Key())
|
||||
if has {
|
||||
return i.([]GasMeta), nil
|
||||
}
|
||||
|
||||
var prices []GasMeta
|
||||
msgs, err := cstore.MessagesForTipset(ts)
|
||||
msgs, err := cstore.MessagesForTipset(ctx, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("loading messages: %w", err)
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func gasEstimateGasPremium(ctx context.Context, cstore *store.ChainStore, cache
|
||||
}
|
||||
|
||||
blocks += len(pts.Blocks())
|
||||
meta, err := cache.GetTSGasStats(cstore, pts)
|
||||
meta, err := cache.GetTSGasStats(ctx, cstore, pts)
|
||||
if err != nil {
|
||||
return types.BigInt{}, err
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (a *MpoolAPI) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*ty
|
||||
|
||||
// different blocks in tipsets of the same height
|
||||
// we exclude messages that have been included in blocks in the mpool tipset
|
||||
have, err := a.Mpool.MessagesForBlocks(mpts.Blocks())
|
||||
have, err := a.Mpool.MessagesForBlocks(ctx, mpts.Blocks())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting messages for base ts: %w", err)
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func (a *MpoolAPI) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*ty
|
||||
}
|
||||
}
|
||||
|
||||
msgs, err := a.Mpool.MessagesForBlocks(ts.Blocks())
|
||||
msgs, err := a.Mpool.MessagesForBlocks(ctx, ts.Blocks())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf(": %w", err)
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@ func (m *StateModule) StateWaitMsg(ctx context.Context, msg cid.Cid, confidence
|
||||
|
||||
var returndec interface{}
|
||||
if recpt.ExitCode == 0 && len(recpt.Return) > 0 {
|
||||
cmsg, err := m.Chain.GetCMessage(msg)
|
||||
cmsg, err := m.Chain.GetCMessage(ctx, msg)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load message after successful receipt search: %w", err)
|
||||
}
|
||||
@@ -874,7 +874,7 @@ func (a *StateAPI) StateListMessages(ctx context.Context, match *api.MessageMatc
|
||||
|
||||
var out []cid.Cid
|
||||
for ts.Height() >= toheight {
|
||||
msgs, err := a.Chain.MessagesForTipset(ts)
|
||||
msgs, err := a.Chain.MessagesForTipset(ctx, ts)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get messages for tipset (%s): %w", ts.Key(), err)
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@ func (a *SyncAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) erro
|
||||
}
|
||||
|
||||
// TODO: should we have some sort of fast path to adding a local block?
|
||||
bmsgs, err := a.Syncer.ChainStore().LoadMessagesFromCids(blk.BlsMessages)
|
||||
bmsgs, err := a.Syncer.ChainStore().LoadMessagesFromCids(ctx, blk.BlsMessages)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to load bls messages: %w", err)
|
||||
}
|
||||
|
||||
smsgs, err := a.Syncer.ChainStore().LoadSignedMessagesFromCids(blk.SecpkMessages)
|
||||
smsgs, err := a.Syncer.ChainStore().LoadSignedMessagesFromCids(ctx, blk.SecpkMessages)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to load secpk message: %w", err)
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (a *SyncAPI) SyncValidateTipset(ctx context.Context, tsk types.TipSetKey) (
|
||||
return false, err
|
||||
}
|
||||
|
||||
fts, err := a.Syncer.ChainStore().TryFillTipSet(ts)
|
||||
fts, err := a.Syncer.ChainStore().TryFillTipSet(ctx, ts)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
// ChainBitswap uses a blockstore that bypasses all caches.
|
||||
func ChainBitswap(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt routing.Routing, bs dtypes.ExposedBlockstore) dtypes.ChainBitswap {
|
||||
func ChainBitswap(lc fx.Lifecycle, mctx helpers.MetricsCtx, host host.Host, rt routing.Routing, bs dtypes.ExposedBlockstore) dtypes.ChainBitswap {
|
||||
// prefix protocol for chain bitswap
|
||||
// (so bitswap uses /chain/ipfs/bitswap/1.0.0 internally for chain sync stuff)
|
||||
bitswapNetwork := network.NewFromIpfsHost(host, rt, network.Prefix("/chain"))
|
||||
@@ -58,8 +58,8 @@ func ChainBlockService(bs dtypes.ExposedBlockstore, rem dtypes.ChainBitswap) dty
|
||||
return blockservice.New(bs, rem)
|
||||
}
|
||||
|
||||
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(context.Background(), mpp, ds, us, nn, j)
|
||||
func MessagePool(lc fx.Lifecycle, mctx helpers.MetricsCtx, 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(helpers.LifecycleCtx(mctx, lc), mpp, ds, us, nn, j)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("constructing mpool: %w", err)
|
||||
}
|
||||
@@ -73,6 +73,7 @@ func MessagePool(lc fx.Lifecycle, us stmgr.UpgradeSchedule, mpp messagepool.Prov
|
||||
}
|
||||
|
||||
func ChainStore(lc fx.Lifecycle,
|
||||
mctx helpers.MetricsCtx,
|
||||
cbs dtypes.ChainBlockstore,
|
||||
sbs dtypes.StateBlockstore,
|
||||
ds dtypes.MetadataDS,
|
||||
@@ -83,7 +84,7 @@ func ChainStore(lc fx.Lifecycle,
|
||||
|
||||
chain := store.NewChainStore(cbs, sbs, ds, weight, j)
|
||||
|
||||
if err := chain.Load(context.Background()); err != nil {
|
||||
if err := chain.Load(helpers.LifecycleCtx(mctx, lc)); err != nil {
|
||||
log.Warnf("loading chain state from disk: %s", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,12 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/impl/full"
|
||||
payapi "github.com/filecoin-project/lotus/node/impl/paych"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
"github.com/filecoin-project/lotus/node/repo/imports"
|
||||
)
|
||||
|
||||
func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full.WalletAPI, fundMgr *market.FundManager) {
|
||||
func HandleMigrateClientFunds(lc fx.Lifecycle, mctx helpers.MetricsCtx, ds dtypes.MetadataDS, wallet full.WalletAPI, fundMgr *market.FundManager) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
addr, err := wallet.WalletDefaultAddress(ctx)
|
||||
@@ -52,7 +53,7 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
b, err := ds.Get(context.Background(), datastore.NewKey("/marketfunds/client"))
|
||||
b, err := ds.Get(helpers.LifecycleCtx(mctx, lc), datastore.NewKey("/marketfunds/client"))
|
||||
if err != nil {
|
||||
if xerrors.Is(err, datastore.ErrNotFound) {
|
||||
return nil
|
||||
@@ -73,7 +74,7 @@ func HandleMigrateClientFunds(lc fx.Lifecycle, ds dtypes.MetadataDS, wallet full
|
||||
return nil
|
||||
}
|
||||
|
||||
return ds.Delete(context.Background(), datastore.NewKey("/marketfunds/client"))
|
||||
return ds.Delete(helpers.LifecycleCtx(mctx, lc), datastore.NewKey("/marketfunds/client"))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
+12
-8
@@ -2,9 +2,10 @@ package modules
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"go.uber.org/fx"
|
||||
|
||||
"github.com/ipfs/go-datastore"
|
||||
"github.com/ipld/go-car"
|
||||
"golang.org/x/xerrors"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
)
|
||||
|
||||
func ErrorGenesis() Genesis {
|
||||
@@ -20,17 +22,18 @@ func ErrorGenesis() Genesis {
|
||||
}
|
||||
}
|
||||
|
||||
func LoadGenesis(genBytes []byte) func(dtypes.ChainBlockstore) Genesis {
|
||||
return func(bs dtypes.ChainBlockstore) Genesis {
|
||||
func LoadGenesis(genBytes []byte) func(fx.Lifecycle, helpers.MetricsCtx, dtypes.ChainBlockstore) Genesis {
|
||||
return func(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.ChainBlockstore) Genesis {
|
||||
return func() (header *types.BlockHeader, e error) {
|
||||
c, err := car.LoadCar(context.Background(), bs, bytes.NewReader(genBytes))
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
c, err := car.LoadCar(ctx, 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(context.Background(), c.Roots[0])
|
||||
root, err := bs.Get(ctx, c.Roots[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -46,8 +49,9 @@ 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(context.Background())
|
||||
func SetGenesis(lc fx.Lifecycle, mctx helpers.MetricsCtx, cs *store.ChainStore, g Genesis) (dtypes.AfterGenesisSet, error) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
genFromRepo, err := cs.GetGenesis(ctx)
|
||||
if err == nil {
|
||||
if os.Getenv("LOTUS_SKIP_GENESIS_CHECK") != "_yes_" {
|
||||
expectedGenesis, err := g()
|
||||
@@ -70,5 +74,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(context.Background(), genesis)
|
||||
return dtypes.AfterGenesisSet{}, cs.SetGenesis(ctx, genesis)
|
||||
}
|
||||
|
||||
@@ -228,8 +228,8 @@ func BuiltinDrandConfig() dtypes.DrandSchedule {
|
||||
return build.DrandConfigSchedule()
|
||||
}
|
||||
|
||||
func RandomSchedule(p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.Schedule, error) {
|
||||
gen, err := p.Cs.GetGenesis(context.Background())
|
||||
func RandomSchedule(lc fx.Lifecycle, mctx helpers.MetricsCtx, p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.Schedule, error) {
|
||||
gen, err := p.Cs.GetGenesis(helpers.LifecycleCtx(mctx, lc))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ var (
|
||||
)
|
||||
|
||||
func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) {
|
||||
maddrb, err := ds.Get(context.Background(), datastore.NewKey("miner-address"))
|
||||
maddrb, err := ds.Get(context.TODO(), 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(context.Background(), datastore.NewKey("/marketfunds/provider"))
|
||||
b, err := ds.Get(ctx, 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(context.Background(), datastore.NewKey("/marketfunds/provider"))
|
||||
return ds.Delete(ctx, datastore.NewKey("/marketfunds/provider"))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user