From c6541b2b007040d1406cd73059a2375a853d1557 Mon Sep 17 00:00:00 2001 From: krehermann Date: Thu, 24 Aug 2023 08:53:05 -0600 Subject: [PATCH] BCF-2564: use chain in relayer, not chainset (#362) --- pkg/cosmos/adapters/cosmwasm/relay.go | 12 +++------ pkg/cosmos/relay.go | 39 ++++++++++----------------- 2 files changed, 18 insertions(+), 33 deletions(-) diff --git a/pkg/cosmos/adapters/cosmwasm/relay.go b/pkg/cosmos/adapters/cosmwasm/relay.go index fa3f2fa59..0626f8c3d 100644 --- a/pkg/cosmos/adapters/cosmwasm/relay.go +++ b/pkg/cosmos/adapters/cosmwasm/relay.go @@ -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 { @@ -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 @@ -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 } diff --git a/pkg/cosmos/relay.go b/pkg/cosmos/relay.go index 0673af85f..b5f894c76 100644 --- a/pkg/cosmos/relay.go +++ b/pkg/cosmos/relay.go @@ -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, } } @@ -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 @@ -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) { @@ -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 @@ -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 }