Skip to content

Commit

Permalink
Merge pull request #14337 from smartcontractkit/chain-selector-fix
Browse files Browse the repository at this point in the history
core/services/relay/evm: handle error from chainselectors
  • Loading branch information
momentmaker authored Sep 6, 2024
2 parents 0359573 + bb48508 commit 5eac567
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 6 additions & 1 deletion core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ type TestApplication struct {
func NewApplicationEVMDisabled(t *testing.T) *TestApplication {
t.Helper()

c := configtest.NewGeneralConfig(t, nil)
c := configtest.NewGeneralConfig(t, func(config *chainlink.Config, secrets *chainlink.Secrets) {
f := false
for _, c := range config.EVM {
c.Enabled = &f
}
})

return NewApplicationWithConfig(t, c)
}
Expand Down
22 changes: 15 additions & 7 deletions core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math/big"
"net/http"
"strings"
"sync"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -149,8 +150,7 @@ type Relayer struct {
triggerCapability *triggers.MercuryTriggerService

// LLO/data streams
cdcFactory llo.ChannelDefinitionCacheFactory
lloORM llo.ORM
cdcFactory func() (llo.ChannelDefinitionCacheFactory, error)
}

type CSAETHKeystore interface {
Expand Down Expand Up @@ -192,17 +192,21 @@ func NewRelayer(lggr logger.Logger, chain legacyevm.Chain, opts RelayerOpts) (*R
sugared := logger.Sugared(lggr).Named("Relayer")

mercuryORM := mercury.NewORM(opts.DS)
chainSelector, err := chainselectors.SelectorFromChainId(chain.ID().Uint64())
lloORM := llo.NewORM(opts.DS, chainSelector)
cdcFactory := llo.NewChannelDefinitionCacheFactory(sugared, lloORM, chain.LogPoller(), opts.HTTPClient)
cdcFactory := sync.OnceValues(func() (llo.ChannelDefinitionCacheFactory, error) {
chainSelector, err := chainselectors.SelectorFromChainId(chain.ID().Uint64())
if err != nil {
return nil, fmt.Errorf("failed to get chain selector for chain id %s: %w", chain.ID(), err)
}
lloORM := llo.NewORM(opts.DS, chainSelector)
return llo.NewChannelDefinitionCacheFactory(sugared, lloORM, chain.LogPoller(), opts.HTTPClient), nil
})
relayer := &Relayer{
ds: opts.DS,
chain: chain,
lggr: sugared,
ks: opts.CSAETHKeystore,
mercuryPool: opts.MercuryPool,
cdcFactory: cdcFactory,
lloORM: lloORM,
mercuryORM: mercuryORM,
transmitterCfg: opts.TransmitterConfig,
capabilitiesRegistry: opts.CapabilitiesRegistry,
Expand Down Expand Up @@ -447,7 +451,11 @@ func (r *Relayer) NewLLOProvider(rargs commontypes.RelayArgs, pargs commontypes.
transmitter = llo.NewTransmitter(r.lggr, client, privKey.PublicKey)
}

cdc, err := r.cdcFactory.NewCache(lloCfg)
cdcFactory, err := r.cdcFactory()
if err != nil {
return nil, err
}
cdc, err := cdcFactory.NewCache(lloCfg)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5eac567

Please sign in to comment.