Merge pull request #5506 from filecoin-project/fix/storageadapter-contexts

Use correct contexts in storageadapter
This commit is contained in:
Łukasz Magiera 2021-02-03 12:38:32 +01:00 committed by GitHub
commit fb6c4d5c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 11 deletions

View File

@ -99,11 +99,13 @@ func (e *Events) listenHeadChanges(ctx context.Context) {
} else { } else {
log.Warn("listenHeadChanges quit") log.Warn("listenHeadChanges quit")
} }
if ctx.Err() != nil { select {
case <-build.Clock.After(time.Second):
case <-ctx.Done():
log.Warnf("not restarting listenHeadChanges: context error: %s", ctx.Err()) log.Warnf("not restarting listenHeadChanges: context error: %s", ctx.Err())
return return
} }
build.Clock.Sleep(time.Second)
log.Info("restarting listenHeadChanges") log.Info("restarting listenHeadChanges")
} }
} }

View File

@ -6,11 +6,12 @@ import (
"bytes" "bytes"
"context" "context"
"github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"go.uber.org/fx"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/go-fil-markets/shared" "github.com/filecoin-project/go-fil-markets/shared"
"github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
@ -31,6 +32,7 @@ import (
"github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/lotus/lib/sigs"
"github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/markets/utils"
"github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/lotus/node/impl/full"
"github.com/filecoin-project/lotus/node/modules/helpers"
) )
type ClientNodeAdapter struct { type ClientNodeAdapter struct {
@ -48,9 +50,11 @@ type clientApi struct {
full.MpoolAPI full.MpoolAPI
} }
func NewClientNodeAdapter(stateapi full.StateAPI, chain full.ChainAPI, mpool full.MpoolAPI, fundmgr *market.FundManager) storagemarket.StorageClientNode { func NewClientNodeAdapter(mctx helpers.MetricsCtx, lc fx.Lifecycle, stateapi full.StateAPI, chain full.ChainAPI, mpool full.MpoolAPI, fundmgr *market.FundManager) storagemarket.StorageClientNode {
capi := &clientApi{chain, stateapi, mpool} capi := &clientApi{chain, stateapi, mpool}
ev := events.NewEvents(context.TODO(), capi) ctx := helpers.LifecycleCtx(mctx, lc)
ev := events.NewEvents(ctx, capi)
a := &ClientNodeAdapter{ a := &ClientNodeAdapter{
clientApi: capi, clientApi: capi,

View File

@ -9,6 +9,7 @@ import (
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
"go.uber.org/fx"
"golang.org/x/xerrors" "golang.org/x/xerrors"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
@ -32,6 +33,7 @@ import (
"github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/markets/utils"
"github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/filecoin-project/lotus/storage/sectorblocks" "github.com/filecoin-project/lotus/storage/sectorblocks"
) )
@ -55,9 +57,11 @@ type ProviderNodeAdapter struct {
scMgr *SectorCommittedManager scMgr *SectorCommittedManager
} }
func NewProviderNodeAdapter(fc *config.MinerFeeConfig) func(dag dtypes.StagingDAG, secb *sectorblocks.SectorBlocks, full api.FullNode, dealPublisher *DealPublisher) storagemarket.StorageProviderNode { func NewProviderNodeAdapter(fc *config.MinerFeeConfig) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, dag dtypes.StagingDAG, secb *sectorblocks.SectorBlocks, full api.FullNode, dealPublisher *DealPublisher) storagemarket.StorageProviderNode {
return func(dag dtypes.StagingDAG, secb *sectorblocks.SectorBlocks, full api.FullNode, dealPublisher *DealPublisher) storagemarket.StorageProviderNode { return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, dag dtypes.StagingDAG, secb *sectorblocks.SectorBlocks, full api.FullNode, dealPublisher *DealPublisher) storagemarket.StorageProviderNode {
ev := events.NewEvents(context.TODO(), full) ctx := helpers.LifecycleCtx(mctx, lc)
ev := events.NewEvents(ctx, full)
na := &ProviderNodeAdapter{ na := &ProviderNodeAdapter{
FullNode: full, FullNode: full,

View File

@ -21,6 +21,7 @@ import (
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/lotus/node/impl/full"
payapi "github.com/filecoin-project/lotus/node/impl/paych" payapi "github.com/filecoin-project/lotus/node/impl/paych"
"github.com/filecoin-project/lotus/node/modules/helpers"
) )
var log = logging.Logger("payment-channel-settler") var log = logging.Logger("payment-channel-settler")
@ -50,9 +51,10 @@ type paymentChannelSettler struct {
// SettlePaymentChannels checks the chain for events related to payment channels settling and // SettlePaymentChannels checks the chain for events related to payment channels settling and
// submits any vouchers for inbound channels tracked for this node // submits any vouchers for inbound channels tracked for this node
func SettlePaymentChannels(lc fx.Lifecycle, api API) error { func SettlePaymentChannels(mctx helpers.MetricsCtx, lc fx.Lifecycle, api API) error {
ctx := helpers.LifecycleCtx(mctx, lc)
lc.Append(fx.Hook{ lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error { OnStart: func(context.Context) error {
pcs := newPaymentChannelSettler(ctx, &api) pcs := newPaymentChannelSettler(ctx, &api)
ev := events.NewEvents(ctx, &api) ev := events.NewEvents(ctx, &api)
return ev.Called(pcs.check, pcs.messageHandler, pcs.revertHandler, int(build.MessageConfidence+1), events.NoTimeout, pcs.matcher) return ev.Called(pcs.check, pcs.messageHandler, pcs.revertHandler, int(build.MessageConfidence+1), events.NoTimeout, pcs.matcher)