fix: paych manager dependency injection

This commit is contained in:
Dirk McCormick 2020-08-05 16:47:06 -04:00
parent aea1b0e293
commit 45d9ddc79f
2 changed files with 12 additions and 14 deletions

View File

@ -184,7 +184,7 @@ type FullNodeStruct struct {
MarketEnsureAvailable func(context.Context, address.Address, address.Address, types.BigInt) (cid.Cid, error) `perm:"sign"` MarketEnsureAvailable func(context.Context, address.Address, address.Address, types.BigInt) (cid.Cid, error) `perm:"sign"`
PaychGet func(ctx context.Context, from, to address.Address, amt types.BigInt) (*api.ChannelInfo, error) `perm:"sign"` PaychGet func(ctx context.Context, from, to address.Address, amt types.BigInt) (*api.ChannelInfo, error) `perm:"sign"`
PaychGetWaitReady func(context.Context, cid.Cid) (address.Address, error) `perm:"sign"` // TODO: is perm:"sign" correct? PaychGetWaitReady func(context.Context, cid.Cid) (address.Address, error) `perm:"sign"`
PaychList func(context.Context) ([]address.Address, error) `perm:"read"` PaychList func(context.Context) ([]address.Address, error) `perm:"read"`
PaychStatus func(context.Context, address.Address) (*api.PaychStatus, error) `perm:"read"` PaychStatus func(context.Context, address.Address) (*api.PaychStatus, error) `perm:"read"`
PaychSettle func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"` PaychSettle func(context.Context, address.Address) (cid.Cid, error) `perm:"sign"`

View File

@ -4,6 +4,8 @@ import (
"context" "context"
"sync" "sync"
"github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -58,20 +60,18 @@ type Manager struct {
state full.StateAPI state full.StateAPI
} }
type paychAPIImpl struct { func NewManager(mctx helpers.MetricsCtx, lc fx.Lifecycle, sm *stmgr.StateManager, pchstore *Store, api ManagerApi) *Manager {
full.MpoolAPI ctx := helpers.LifecycleCtx(mctx, lc)
full.StateAPI ctx, shutdown := context.WithCancel(ctx)
}
func NewManager(sm *stmgr.StateManager, pchstore *Store, api ManagerApi) *Manager {
return &Manager{ return &Manager{
ctx: ctx,
shutdown: shutdown,
store: pchstore, store: pchstore,
sm: sm, sm: sm,
sa: &stateAccessor{sm: sm}, sa: &stateAccessor{sm: sm},
channels: make(map[string]*channelAccessor), channels: make(map[string]*channelAccessor),
// TODO: Is this the correct way to do this or can I do something different pchapi: &api,
// with dependency injection?
pchapi: &paychAPIImpl{api.MpoolAPI, api.StateAPI},
mpool: api.MpoolAPI, mpool: api.MpoolAPI,
wallet: api.WalletAPI, wallet: api.WalletAPI,
@ -88,14 +88,14 @@ func newManager(sm StateManagerApi, pchstore *Store, pchapi paychApi) (*Manager,
channels: make(map[string]*channelAccessor), channels: make(map[string]*channelAccessor),
pchapi: pchapi, pchapi: pchapi,
} }
return pm, pm.Start(context.Background()) return pm, pm.Start()
} }
// HandleManager is called by dependency injection to set up hooks // HandleManager is called by dependency injection to set up hooks
func HandleManager(lc fx.Lifecycle, pm *Manager) { func HandleManager(lc fx.Lifecycle, pm *Manager) {
lc.Append(fx.Hook{ lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error { OnStart: func(ctx context.Context) error {
return pm.Start(ctx) return pm.Start()
}, },
OnStop: func(context.Context) error { OnStop: func(context.Context) error {
return pm.Stop() return pm.Stop()
@ -108,9 +108,7 @@ func HandleManager(lc fx.Lifecycle, pm *Manager) {
// Outstanding messages can occur if an add funds message was sent // Outstanding messages can occur if an add funds message was sent
// and then lotus was shut down or crashed before the result was // and then lotus was shut down or crashed before the result was
// received. // received.
func (pm *Manager) Start(ctx context.Context) error { func (pm *Manager) Start() error {
pm.ctx, pm.shutdown = context.WithCancel(ctx)
cis, err := pm.store.WithPendingAddFunds() cis, err := pm.store.WithPendingAddFunds()
if err != nil { if err != nil {
return err return err