From c59e2fea5b8e34fab79517ca4f1ae058f37d986d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Feb 2021 18:43:49 +0100 Subject: [PATCH] Use correct contexts in storageadapter --- chain/events/events.go | 6 ++++-- markets/storageadapter/client.go | 12 ++++++++---- markets/storageadapter/provider.go | 10 +++++++--- paychmgr/settler/settler.go | 6 ++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/chain/events/events.go b/chain/events/events.go index 1dcf63423..acb65d2c1 100644 --- a/chain/events/events.go +++ b/chain/events/events.go @@ -99,11 +99,13 @@ func (e *Events) listenHeadChanges(ctx context.Context) { } else { 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()) return } - build.Clock.Sleep(time.Second) + log.Info("restarting listenHeadChanges") } } diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 0769e7ec5..c0d78a506 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -6,11 +6,12 @@ import ( "bytes" "context" - "github.com/filecoin-project/go-address" - cborutil "github.com/filecoin-project/go-cbor-util" "github.com/ipfs/go-cid" + "go.uber.org/fx" "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/storagemarket" "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/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" + "github.com/filecoin-project/lotus/node/modules/helpers" ) type ClientNodeAdapter struct { @@ -48,9 +50,11 @@ type clientApi struct { 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} - ev := events.NewEvents(context.TODO(), capi) + ctx := helpers.LifecycleCtx(mctx, lc) + + ev := events.NewEvents(ctx, capi) a := &ClientNodeAdapter{ clientApi: capi, diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 47925af5c..f81fadc32 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -9,6 +9,7 @@ import ( "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" + "go.uber.org/fx" "golang.org/x/xerrors" 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/node/config" "github.com/filecoin-project/lotus/node/modules/dtypes" + "github.com/filecoin-project/lotus/node/modules/helpers" "github.com/filecoin-project/lotus/storage/sectorblocks" ) @@ -55,9 +57,11 @@ type ProviderNodeAdapter struct { scMgr *SectorCommittedManager } -func NewProviderNodeAdapter(fc *config.MinerFeeConfig) func(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 { - ev := events.NewEvents(context.TODO(), full) +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(mctx helpers.MetricsCtx, lc fx.Lifecycle, dag dtypes.StagingDAG, secb *sectorblocks.SectorBlocks, full api.FullNode, dealPublisher *DealPublisher) storagemarket.StorageProviderNode { + ctx := helpers.LifecycleCtx(mctx, lc) + + ev := events.NewEvents(ctx, full) na := &ProviderNodeAdapter{ FullNode: full, diff --git a/paychmgr/settler/settler.go b/paychmgr/settler/settler.go index 131cd25a7..3abd136fc 100644 --- a/paychmgr/settler/settler.go +++ b/paychmgr/settler/settler.go @@ -21,6 +21,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/impl/full" payapi "github.com/filecoin-project/lotus/node/impl/paych" + "github.com/filecoin-project/lotus/node/modules/helpers" ) 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 // 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{ - OnStart: func(ctx context.Context) error { + OnStart: func(context.Context) error { pcs := newPaymentChannelSettler(ctx, &api) ev := events.NewEvents(ctx, &api) return ev.Called(pcs.check, pcs.messageHandler, pcs.revertHandler, int(build.MessageConfidence+1), events.NoTimeout, pcs.matcher)