Skip to content

Commit

Permalink
BCF-2564: use chain in relayer, not chainset (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann authored Aug 24, 2023
1 parent 9b063c4 commit c6541b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
12 changes: 4 additions & 8 deletions pkg/cosmos/adapters/cosmwasm/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ type configProvider struct {
contractAddr cosmosSDK.AccAddress
}

// TODO: pass chain instead of chainSet
func NewConfigProvider(ctx context.Context, lggr logger.Logger, chainSet adapters.ChainSet, args relaytypes.RelayArgs) (*configProvider, error) {
func NewConfigProvider(ctx context.Context, lggr logger.Logger, chain adapters.Chain, args relaytypes.RelayArgs) (*configProvider, error) {
var relayConfig adapters.RelayConfig
err := json.Unmarshal(args.RelayConfig, &relayConfig)
if err != nil {
Expand All @@ -41,10 +40,7 @@ func NewConfigProvider(ctx context.Context, lggr logger.Logger, chainSet adapter
if err != nil {
return nil, err
}
chain, err := chainSet.Chain(ctx, relayConfig.ChainID)
if err != nil {
return nil, err
}

chainReader, err := chain.Reader(relayConfig.NodeName)
if err != nil {
return nil, err
Expand Down Expand Up @@ -102,8 +98,8 @@ type medianProvider struct {
transmitter types.ContractTransmitter
}

func NewMedianProvider(ctx context.Context, lggr logger.Logger, chainSet adapters.ChainSet, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MedianProvider, error) {
configProvider, err := NewConfigProvider(ctx, lggr, chainSet, rargs)
func NewMedianProvider(ctx context.Context, lggr logger.Logger, chain adapters.Chain, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MedianProvider, error) {
configProvider, err := NewConfigProvider(ctx, lggr, chain, rargs)
if err != nil {
return nil, err
}
Expand Down
39 changes: 14 additions & 25 deletions pkg/cosmos/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,26 @@ func (e *ErrMsgUnsupported) Error() string {
var _ relaytypes.Relayer = &Relayer{}

type Relayer struct {
lggr logger.Logger
chainSet adapters.ChainSet
ctx context.Context
cancel func()
lggr logger.Logger
chain adapters.Chain
ctx context.Context
cancel func()
}

// Note: constructed in core
func NewRelayer(lggr logger.Logger, chainSet adapters.ChainSet) *Relayer {
func NewRelayer(lggr logger.Logger, chain adapters.Chain) *Relayer {
ctx, cancel := context.WithCancel(context.Background())

// Initialize Cosmos SDK
// TODO: Currently only uses config from the first chain in the chain set as InitCosmosSdk can only be called once.
// To revist when LOOP plugins enable one relayer/sdk instance per Cosmos chain
chainStatuses, _, err := chainSet.ChainStatuses(ctx, 0, 1)
if err != nil {
panic(err)
}
chain, err := chainSet.Chain(ctx, chainStatuses[0].ID)
if err != nil {
panic(err)
}
params.InitCosmosSdk(
chain.Config().Bech32Prefix(),
chain.Config().FeeToken(),
)

return &Relayer{
lggr: lggr,
chainSet: chainSet,
ctx: ctx,
cancel: cancel,
lggr: lggr,
chain: chain,
ctx: ctx,
cancel: cancel,
}
}

Expand All @@ -67,7 +56,7 @@ func (r *Relayer) Name() string {

// Start starts the relayer respecting the given context.
func (r *Relayer) Start(context.Context) error {
if r.chainSet == nil {
if r.chain == nil {
return errors.New("Cosmos unavailable")
}
return nil
Expand All @@ -79,11 +68,11 @@ func (r *Relayer) Close() error {
}

func (r *Relayer) Ready() error {
return r.chainSet.Ready()
return r.chain.Ready()
}

func (r *Relayer) HealthReport() map[string]error {
return r.chainSet.HealthReport()
return r.chain.HealthReport()
}

func (r *Relayer) NewMercuryProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MercuryProvider, error) {
Expand All @@ -95,7 +84,7 @@ func (r *Relayer) NewFunctionsProvider(rargs relaytypes.RelayArgs, pargs relayty
}

func (r *Relayer) NewConfigProvider(args relaytypes.RelayArgs) (relaytypes.ConfigProvider, error) {
configProvider, err := cosmwasm.NewConfigProvider(r.ctx, r.lggr, r.chainSet, args)
configProvider, err := cosmwasm.NewConfigProvider(r.ctx, r.lggr, r.chain, args)
if err != nil {
// Never return (*configProvider)(nil)
return nil, err
Expand All @@ -104,7 +93,7 @@ func (r *Relayer) NewConfigProvider(args relaytypes.RelayArgs) (relaytypes.Confi
}

func (r *Relayer) NewMedianProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MedianProvider, error) {
configProvider, err := cosmwasm.NewMedianProvider(r.ctx, r.lggr, r.chainSet, rargs, pargs)
configProvider, err := cosmwasm.NewMedianProvider(r.ctx, r.lggr, r.chain, rargs, pargs)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c6541b2

Please sign in to comment.