Merge pull request #5791 from filecoin-project/feat/paychmgr-imports
move DI stuff for paychmgr into modules
This commit is contained in:
commit
067af44ed7
@ -1,4 +1,4 @@
|
|||||||
package modules
|
package rpcstmgr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/lotus/chain"
|
"github.com/filecoin-project/lotus/chain"
|
||||||
"github.com/filecoin-project/lotus/chain/exchange"
|
"github.com/filecoin-project/lotus/chain/exchange"
|
||||||
|
rpcstmgr "github.com/filecoin-project/lotus/chain/stmgr/rpc"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/vm"
|
"github.com/filecoin-project/lotus/chain/vm"
|
||||||
"github.com/filecoin-project/lotus/chain/wallet"
|
"github.com/filecoin-project/lotus/chain/wallet"
|
||||||
@ -307,9 +308,10 @@ var ChainNode = Options(
|
|||||||
Override(new(api.WalletAPI), From(new(wallet.MultiWallet))),
|
Override(new(api.WalletAPI), From(new(wallet.MultiWallet))),
|
||||||
|
|
||||||
// Service: Payment channels
|
// Service: Payment channels
|
||||||
Override(new(*paychmgr.Store), paychmgr.NewStore),
|
Override(new(paychmgr.PaychAPI), From(new(modules.PaychAPI))),
|
||||||
Override(new(*paychmgr.Manager), paychmgr.NewManager),
|
Override(new(*paychmgr.Store), modules.NewPaychStore),
|
||||||
Override(HandlePaymentChannelManagerKey, paychmgr.HandleManager),
|
Override(new(*paychmgr.Manager), modules.NewManager),
|
||||||
|
Override(HandlePaymentChannelManagerKey, modules.HandlePaychManager),
|
||||||
Override(SettlePaymentChannelsKey, settler.SettlePaymentChannels),
|
Override(SettlePaymentChannelsKey, settler.SettlePaymentChannels),
|
||||||
|
|
||||||
// Markets (common)
|
// Markets (common)
|
||||||
@ -334,7 +336,7 @@ var ChainNode = Options(
|
|||||||
Override(new(full.GasModuleAPI), From(new(api.GatewayAPI))),
|
Override(new(full.GasModuleAPI), From(new(api.GatewayAPI))),
|
||||||
Override(new(full.MpoolModuleAPI), From(new(api.GatewayAPI))),
|
Override(new(full.MpoolModuleAPI), From(new(api.GatewayAPI))),
|
||||||
Override(new(full.StateModuleAPI), From(new(api.GatewayAPI))),
|
Override(new(full.StateModuleAPI), From(new(api.GatewayAPI))),
|
||||||
Override(new(stmgr.StateManagerAPI), modules.NewRPCStateManager),
|
Override(new(stmgr.StateManagerAPI), rpcstmgr.NewRPCStateManager),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Full node API / service startup
|
// Full node API / service startup
|
||||||
|
45
node/modules/paych.go
Normal file
45
node/modules/paych.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package modules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
|
"github.com/filecoin-project/lotus/node/impl/full"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||||
|
"github.com/filecoin-project/lotus/paychmgr"
|
||||||
|
"github.com/ipfs/go-datastore"
|
||||||
|
"github.com/ipfs/go-datastore/namespace"
|
||||||
|
"go.uber.org/fx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewManager(mctx helpers.MetricsCtx, lc fx.Lifecycle, sm stmgr.StateManagerAPI, pchstore *paychmgr.Store, api paychmgr.PaychAPI) *paychmgr.Manager {
|
||||||
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||||
|
ctx, shutdown := context.WithCancel(ctx)
|
||||||
|
|
||||||
|
return paychmgr.NewManager(ctx, shutdown, sm, pchstore, api)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPaychStore(ds dtypes.MetadataDS) *paychmgr.Store {
|
||||||
|
ds = namespace.Wrap(ds, datastore.NewKey("/paych/"))
|
||||||
|
return paychmgr.NewStore(ds)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PaychAPI struct {
|
||||||
|
fx.In
|
||||||
|
|
||||||
|
full.MpoolAPI
|
||||||
|
full.StateAPI
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandlePaychManager is called by dependency injection to set up hooks
|
||||||
|
func HandlePaychManager(lc fx.Lifecycle, pm *paychmgr.Manager) {
|
||||||
|
lc.Append(fx.Hook{
|
||||||
|
OnStart: func(ctx context.Context) error {
|
||||||
|
return pm.Start()
|
||||||
|
},
|
||||||
|
OnStop: func(context.Context) error {
|
||||||
|
return pm.Stop()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
"go.uber.org/fx"
|
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -19,22 +18,12 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"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/modules/helpers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("paych")
|
var log = logging.Logger("paych")
|
||||||
|
|
||||||
var errProofNotSupported = errors.New("payment channel proof parameter is not supported")
|
var errProofNotSupported = errors.New("payment channel proof parameter is not supported")
|
||||||
|
|
||||||
// PaychAPI is used by dependency injection to pass the consituent APIs to NewManager()
|
|
||||||
type PaychAPI struct {
|
|
||||||
fx.In
|
|
||||||
|
|
||||||
full.MpoolAPI
|
|
||||||
full.StateAPI
|
|
||||||
}
|
|
||||||
|
|
||||||
// stateManagerAPI defines the methods needed from StateManager
|
// stateManagerAPI defines the methods needed from StateManager
|
||||||
type stateManagerAPI interface {
|
type stateManagerAPI interface {
|
||||||
ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error)
|
ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error)
|
||||||
@ -43,7 +32,7 @@ type stateManagerAPI interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// paychAPI defines the API methods needed by the payment channel manager
|
// paychAPI defines the API methods needed by the payment channel manager
|
||||||
type paychAPI interface {
|
type PaychAPI interface {
|
||||||
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error)
|
||||||
StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*api.MsgLookup, error)
|
StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*api.MsgLookup, error)
|
||||||
MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee *api.MessageSendSpec) (*types.SignedMessage, error)
|
MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee *api.MessageSendSpec) (*types.SignedMessage, error)
|
||||||
@ -55,13 +44,13 @@ type paychAPI interface {
|
|||||||
// managerAPI defines all methods needed by the manager
|
// managerAPI defines all methods needed by the manager
|
||||||
type managerAPI interface {
|
type managerAPI interface {
|
||||||
stateManagerAPI
|
stateManagerAPI
|
||||||
paychAPI
|
PaychAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
// managerAPIImpl is used to create a composite that implements managerAPI
|
// managerAPIImpl is used to create a composite that implements managerAPI
|
||||||
type managerAPIImpl struct {
|
type managerAPIImpl struct {
|
||||||
stmgr.StateManagerAPI
|
stmgr.StateManagerAPI
|
||||||
paychAPI
|
PaychAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
@ -77,11 +66,8 @@ type Manager struct {
|
|||||||
channels map[string]*channelAccessor
|
channels map[string]*channelAccessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(mctx helpers.MetricsCtx, lc fx.Lifecycle, sm stmgr.StateManagerAPI, pchstore *Store, api PaychAPI) *Manager {
|
func NewManager(ctx context.Context, shutdown func(), sm stmgr.StateManagerAPI, pchstore *Store, api PaychAPI) *Manager {
|
||||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
impl := &managerAPIImpl{StateManagerAPI: sm, PaychAPI: api}
|
||||||
ctx, shutdown := context.WithCancel(ctx)
|
|
||||||
|
|
||||||
impl := &managerAPIImpl{StateManagerAPI: sm, paychAPI: &api}
|
|
||||||
return &Manager{
|
return &Manager{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
shutdown: shutdown,
|
shutdown: shutdown,
|
||||||
@ -103,18 +89,6 @@ func newManager(pchstore *Store, pchapi managerAPI) (*Manager, error) {
|
|||||||
return pm, pm.Start()
|
return pm, pm.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleManager is called by dependency injection to set up hooks
|
|
||||||
func HandleManager(lc fx.Lifecycle, pm *Manager) {
|
|
||||||
lc.Append(fx.Hook{
|
|
||||||
OnStart: func(ctx context.Context) error {
|
|
||||||
return pm.Start()
|
|
||||||
},
|
|
||||||
OnStop: func(context.Context) error {
|
|
||||||
return pm.Stop()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start restarts tracking of any messages that were sent to chain.
|
// Start restarts tracking of any messages that were sent to chain.
|
||||||
func (pm *Manager) Start() error {
|
func (pm *Manager) Start() error {
|
||||||
return pm.restartPending()
|
return pm.restartPending()
|
||||||
|
@ -14,14 +14,12 @@ import (
|
|||||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-datastore"
|
"github.com/ipfs/go-datastore"
|
||||||
"github.com/ipfs/go-datastore/namespace"
|
|
||||||
dsq "github.com/ipfs/go-datastore/query"
|
dsq "github.com/ipfs/go-datastore/query"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
cborrpc "github.com/filecoin-project/go-cbor-util"
|
cborrpc "github.com/filecoin-project/go-cbor-util"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrChannelNotTracked = errors.New("channel not tracked")
|
var ErrChannelNotTracked = errors.New("channel not tracked")
|
||||||
@ -30,8 +28,7 @@ type Store struct {
|
|||||||
ds datastore.Batching
|
ds datastore.Batching
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStore(ds dtypes.MetadataDS) *Store {
|
func NewStore(ds datastore.Batching) *Store {
|
||||||
ds = namespace.Wrap(ds, datastore.NewKey("/paych/"))
|
|
||||||
return &Store{
|
return &Store{
|
||||||
ds: ds,
|
ds: ds,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user