Skip to content

Commit

Permalink
core/services/relay: move supported list from common (#13627)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Jun 20, 2024
1 parent 26408c6 commit a95a390
Show file tree
Hide file tree
Showing 32 changed files with 148 additions and 119 deletions.
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240618210005-a88f179ffc16
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240620164046-1c03d0a97b20
github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240618210005-a88f179ffc16 h1:+0ElI3A3mKxYbw//a34d1GmLXyfWsw3IuDHv07dImWQ=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240618210005-a88f179ffc16/go.mod h1:L32xvCpk84Nglit64OhySPMP1tM3TTBK7Tw0qZl7Sd4=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240620164046-1c03d0a97b20 h1:Ea3shtV50R1qMkLbDaOwio2C+Ia1dB7pJQzpm7vHzxM=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240620164046-1c03d0a97b20/go.mod h1:L32xvCpk84Nglit64OhySPMP1tM3TTBK7Tw0qZl7Sd4=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240524214833-c362c2ebbd2d h1:5tgMC5Gi2UAOKZ+m28W8ubjLeR0pQCAcrz6eQ0rW510=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240524214833-c362c2ebbd2d/go.mod h1:0UNuO3nDt9MFsZPaHJBEUolxVkN0iC69j1ccDp95e8k=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
74 changes: 37 additions & 37 deletions core/services/chainlink/relayer_chain_interoperators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import (
solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
stkcfg "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config"

evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
"github.com/smartcontractkit/chainlink/v2/plugins"

evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
)

func TestCoreRelayerChainInteroperators(t *testing.T) {
Expand Down Expand Up @@ -217,10 +217,10 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
expectedEVMChainCnt: 2,
expectedEVMNodeCnt: 3,
expectedEVMRelayerIds: []types.RelayID{
{Network: types.NetworkEVM, ChainID: evmChainID1.String()},
{Network: types.NetworkEVM, ChainID: evmChainID2.String()},
{Network: relay.NetworkEVM, ChainID: evmChainID1.String()},
{Network: relay.NetworkEVM, ChainID: evmChainID2.String()},
},
expectedRelayerNetworks: map[string]struct{}{types.NetworkEVM: {}},
expectedRelayerNetworks: map[string]struct{}{relay.NetworkEVM: {}},
},

{name: "2 solana chain with 2 node",
Expand All @@ -233,10 +233,10 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
expectedSolanaChainCnt: 2,
expectedSolanaNodeCnt: 2,
expectedSolanaRelayerIds: []types.RelayID{
{Network: types.NetworkSolana, ChainID: solanaChainID1},
{Network: types.NetworkSolana, ChainID: solanaChainID2},
{Network: relay.NetworkSolana, ChainID: solanaChainID1},
{Network: relay.NetworkSolana, ChainID: solanaChainID2},
},
expectedRelayerNetworks: map[string]struct{}{types.NetworkSolana: {}},
expectedRelayerNetworks: map[string]struct{}{relay.NetworkSolana: {}},
},

{name: "2 starknet chain with 4 nodes",
Expand All @@ -249,10 +249,10 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
expectedStarknetChainCnt: 2,
expectedStarknetNodeCnt: 4,
expectedStarknetRelayerIds: []types.RelayID{
{Network: types.NetworkStarkNet, ChainID: starknetChainID1},
{Network: types.NetworkStarkNet, ChainID: starknetChainID2},
{Network: relay.NetworkStarkNet, ChainID: starknetChainID1},
{Network: relay.NetworkStarkNet, ChainID: starknetChainID2},
},
expectedRelayerNetworks: map[string]struct{}{types.NetworkStarkNet: {}},
expectedRelayerNetworks: map[string]struct{}{relay.NetworkStarkNet: {}},
},

{
Expand All @@ -267,10 +267,10 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
expectedCosmosChainCnt: 2,
expectedCosmosNodeCnt: 2,
expectedCosmosRelayerIds: []types.RelayID{
{Network: types.NetworkCosmos, ChainID: cosmosChainID1},
{Network: types.NetworkCosmos, ChainID: cosmosChainID2},
{Network: relay.NetworkCosmos, ChainID: cosmosChainID1},
{Network: relay.NetworkCosmos, ChainID: cosmosChainID2},
},
expectedRelayerNetworks: map[string]struct{}{types.NetworkCosmos: {}},
expectedRelayerNetworks: map[string]struct{}{relay.NetworkCosmos: {}},
},

{name: "all chains",
Expand Down Expand Up @@ -299,32 +299,32 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
expectedEVMChainCnt: 2,
expectedEVMNodeCnt: 3,
expectedEVMRelayerIds: []types.RelayID{
{Network: types.NetworkEVM, ChainID: evmChainID1.String()},
{Network: types.NetworkEVM, ChainID: evmChainID2.String()},
{Network: relay.NetworkEVM, ChainID: evmChainID1.String()},
{Network: relay.NetworkEVM, ChainID: evmChainID2.String()},
},

expectedSolanaChainCnt: 2,
expectedSolanaNodeCnt: 2,
expectedSolanaRelayerIds: []types.RelayID{
{Network: types.NetworkSolana, ChainID: solanaChainID1},
{Network: types.NetworkSolana, ChainID: solanaChainID2},
{Network: relay.NetworkSolana, ChainID: solanaChainID1},
{Network: relay.NetworkSolana, ChainID: solanaChainID2},
},

expectedStarknetChainCnt: 2,
expectedStarknetNodeCnt: 4,
expectedStarknetRelayerIds: []types.RelayID{
{Network: types.NetworkStarkNet, ChainID: starknetChainID1},
{Network: types.NetworkStarkNet, ChainID: starknetChainID2},
{Network: relay.NetworkStarkNet, ChainID: starknetChainID1},
{Network: relay.NetworkStarkNet, ChainID: starknetChainID2},
},

expectedCosmosChainCnt: 2,
expectedCosmosNodeCnt: 2,
expectedCosmosRelayerIds: []types.RelayID{
{Network: types.NetworkCosmos, ChainID: cosmosChainID1},
{Network: types.NetworkCosmos, ChainID: cosmosChainID2},
{Network: relay.NetworkCosmos, ChainID: cosmosChainID1},
{Network: relay.NetworkCosmos, ChainID: cosmosChainID2},
},

expectedRelayerNetworks: map[string]struct{}{types.NetworkEVM: {}, types.NetworkCosmos: {}, types.NetworkSolana: {}, types.NetworkStarkNet: {}},
expectedRelayerNetworks: map[string]struct{}{relay.NetworkEVM: {}, relay.NetworkCosmos: {}, relay.NetworkSolana: {}, relay.NetworkStarkNet: {}},
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -357,18 +357,18 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
}

gotRelayerNetworks := make(map[string]struct{})
for relayNetwork := range types.SupportedRelays {
for relayNetwork := range relay.SupportedNetworks {
var expectedChainCnt, expectedNodeCnt int
switch relayNetwork {
case types.NetworkEVM:
case relay.NetworkEVM:
expectedChainCnt, expectedNodeCnt = tt.expectedEVMChainCnt, tt.expectedEVMNodeCnt
case types.NetworkCosmos:
case relay.NetworkCosmos:
expectedChainCnt, expectedNodeCnt = tt.expectedCosmosChainCnt, tt.expectedCosmosNodeCnt
case types.NetworkSolana:
case relay.NetworkSolana:
expectedChainCnt, expectedNodeCnt = tt.expectedSolanaChainCnt, tt.expectedSolanaNodeCnt
case types.NetworkStarkNet:
case relay.NetworkStarkNet:
expectedChainCnt, expectedNodeCnt = tt.expectedStarknetChainCnt, tt.expectedStarknetNodeCnt
case types.NetworkAptos:
case relay.NetworkAptos:
t.Skip("aptos doesn't need a CoreRelayerChainInteroperator")

default:
Expand All @@ -382,16 +382,16 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
}

// check legacy chains for those that haven't migrated fully to the loop relayer interface
if relayNetwork == types.NetworkEVM {
_, wantEVM := tt.expectedRelayerNetworks[types.NetworkEVM]
if relayNetwork == relay.NetworkEVM {
_, wantEVM := tt.expectedRelayerNetworks[relay.NetworkEVM]
if wantEVM {
assert.Len(t, cr.LegacyEVMChains().Slice(), expectedChainCnt)
} else {
assert.Nil(t, cr.LegacyEVMChains())
}
}
if relayNetwork == types.NetworkCosmos {
_, wantCosmos := tt.expectedRelayerNetworks[types.NetworkCosmos]
if relayNetwork == relay.NetworkCosmos {
_, wantCosmos := tt.expectedRelayerNetworks[relay.NetworkCosmos]
if wantCosmos {
assert.Len(t, cr.LegacyCosmosChains().Slice(), expectedChainCnt)
} else {
Expand Down Expand Up @@ -422,13 +422,13 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, wantId.ChainID, stat.ID)
// check legacy chains for evm and cosmos
if wantId.Network == types.NetworkEVM {
if wantId.Network == relay.NetworkEVM {
c, err := cr.LegacyEVMChains().Get(wantId.ChainID)
assert.NoError(t, err)
assert.NotNil(t, c)
assert.Equal(t, wantId.ChainID, c.ID().String())
}
if wantId.Network == types.NetworkCosmos {
if wantId.Network == relay.NetworkCosmos {
c, err := cr.LegacyCosmosChains().Get(wantId.ChainID)
assert.NoError(t, err)
assert.NotNil(t, c)
Expand All @@ -437,7 +437,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) {
}
}

expectedMissing := types.RelayID{Network: types.NetworkCosmos, ChainID: "not a chain id"}
expectedMissing := types.RelayID{Network: relay.NetworkCosmos, ChainID: "not a chain id"}
unwanted, err := cr.Get(expectedMissing)
assert.Nil(t, unwanted)
assert.ErrorIs(t, err, chainlink.ErrNoSuchRelayer)
Expand Down
9 changes: 5 additions & 4 deletions core/services/chainlink/relayer_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/config/env"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
corerelay "github.com/smartcontractkit/chainlink/v2/core/services/relay"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/wsrpc"
"github.com/smartcontractkit/chainlink/v2/plugins"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (r *RelayerFactory) NewEVM(ctx context.Context, config EVMFactoryConfig) (m
}
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(evmRelayExtenders)
for _, ext := range evmRelayExtenders.Slice() {
relayID := types.RelayID{Network: types.NetworkEVM, ChainID: ext.Chain().ID().String()}
relayID := types.RelayID{Network: corerelay.NetworkEVM, ChainID: ext.Chain().ID().String()}
chain, err2 := legacyChains.Get(relayID.ChainID)
if err2 != nil {
return nil, err2
Expand Down Expand Up @@ -105,7 +106,7 @@ func (r *RelayerFactory) NewSolana(ks keystore.Solana, chainCfgs solcfg.TOMLConf
unique := make(map[string]struct{})
// create one relayer per chain id
for _, chainCfg := range chainCfgs {
relayID := types.RelayID{Network: types.NetworkSolana, ChainID: *chainCfg.ChainID}
relayID := types.RelayID{Network: corerelay.NetworkSolana, ChainID: *chainCfg.ChainID}
_, alreadyExists := unique[relayID.Name()]
if alreadyExists {
return nil, fmt.Errorf("duplicate chain definitions for %s", relayID.Name())
Expand Down Expand Up @@ -178,7 +179,7 @@ func (r *RelayerFactory) NewStarkNet(ks keystore.StarkNet, chainCfgs config.TOML
unique := make(map[string]struct{})
// create one relayer per chain id
for _, chainCfg := range chainCfgs {
relayID := types.RelayID{Network: types.NetworkStarkNet, ChainID: *chainCfg.ChainID}
relayID := types.RelayID{Network: corerelay.NetworkStarkNet, ChainID: *chainCfg.ChainID}
_, alreadyExists := unique[relayID.Name()]
if alreadyExists {
return nil, fmt.Errorf("duplicate chain definitions for %s", relayID.Name())
Expand Down Expand Up @@ -273,7 +274,7 @@ func (r *RelayerFactory) NewCosmos(config CosmosFactoryConfig) (map[types.RelayI

// create one relayer per chain id
for _, chainCfg := range config.TOMLConfigs {
relayID := types.RelayID{Network: types.NetworkCosmos, ChainID: *chainCfg.ChainID}
relayID := types.RelayID{Network: corerelay.NetworkCosmos, ChainID: *chainCfg.ChainID}

lggr := cosmosLggr.Named(relayID.ChainID)

Expand Down
9 changes: 5 additions & 4 deletions core/services/job/job_orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
ocr2validate "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/validate"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrbootstrap"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/vrf/vrfcommon"
"github.com/smartcontractkit/chainlink/v2/core/services/webhook"
Expand Down Expand Up @@ -950,7 +951,7 @@ func TestORM_ValidateKeyStoreMatch(t *testing.T) {

t.Run("test ETH key validation", func(t *testing.T) {
ctx := testutils.Context(t)
jb.OCR2OracleSpec.Relay = types.NetworkEVM
jb.OCR2OracleSpec.Relay = relay.NetworkEVM
err := job.ValidateKeyStoreMatch(ctx, jb.OCR2OracleSpec, keyStore, "bad key")
require.EqualError(t, err, "no EVM key matching: \"bad key\"")

Expand All @@ -961,7 +962,7 @@ func TestORM_ValidateKeyStoreMatch(t *testing.T) {

t.Run("test Cosmos key validation", func(t *testing.T) {
ctx := testutils.Context(t)
jb.OCR2OracleSpec.Relay = types.NetworkCosmos
jb.OCR2OracleSpec.Relay = relay.NetworkCosmos
err := job.ValidateKeyStoreMatch(ctx, jb.OCR2OracleSpec, keyStore, "bad key")
require.EqualError(t, err, "no Cosmos key matching: \"bad key\"")

Expand All @@ -973,7 +974,7 @@ func TestORM_ValidateKeyStoreMatch(t *testing.T) {

t.Run("test Solana key validation", func(t *testing.T) {
ctx := testutils.Context(t)
jb.OCR2OracleSpec.Relay = types.NetworkSolana
jb.OCR2OracleSpec.Relay = relay.NetworkSolana

err := job.ValidateKeyStoreMatch(ctx, jb.OCR2OracleSpec, keyStore, "bad key")
require.EqualError(t, err, "no Solana key matching: \"bad key\"")
Expand All @@ -986,7 +987,7 @@ func TestORM_ValidateKeyStoreMatch(t *testing.T) {

t.Run("test Starknet key validation", func(t *testing.T) {
ctx := testutils.Context(t)
jb.OCR2OracleSpec.Relay = types.NetworkStarkNet
jb.OCR2OracleSpec.Relay = relay.NetworkStarkNet
err := job.ValidateKeyStoreMatch(ctx, jb.OCR2OracleSpec, keyStore, "bad key")
require.EqualError(t, err, "no Starknet key matching: \"bad key\"")

Expand Down
3 changes: 2 additions & 1 deletion core/services/job/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/types"
pkgworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand Down Expand Up @@ -382,7 +383,7 @@ type OCR2OracleSpec struct {

func validateRelayID(id types.RelayID) error {
// only the EVM has specific requirements
if id.Network == types.NetworkEVM {
if id.Network == relay.NetworkEVM {
_, err := toml.ChainIDInt64(id.ChainID)
if err != nil {
return fmt.Errorf("invalid EVM chain id %s: %w", id.ChainID, err)
Expand Down
13 changes: 7 additions & 6 deletions core/services/job/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
pkgworkflows "github.com/smartcontractkit/chainlink-common/pkg/workflows"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -40,23 +41,23 @@ func TestOCR2OracleSpec_RelayIdentifier(t *testing.T) {
{
name: "evm explicitly configured",
fields: fields{
Relay: types.NetworkEVM,
Relay: relay.NetworkEVM,
ChainID: "1",
},
want: types.RelayID{Network: types.NetworkEVM, ChainID: "1"},
want: types.RelayID{Network: relay.NetworkEVM, ChainID: "1"},
},
{
name: "evm implicitly configured",
fields: fields{
Relay: types.NetworkEVM,
Relay: relay.NetworkEVM,
RelayConfig: map[string]any{"chainID": 1},
},
want: types.RelayID{Network: types.NetworkEVM, ChainID: "1"},
want: types.RelayID{Network: relay.NetworkEVM, ChainID: "1"},
},
{
name: "evm implicitly configured with bad value",
fields: fields{
Relay: types.NetworkEVM,
Relay: relay.NetworkEVM,
RelayConfig: map[string]any{"chainID": float32(1)},
},
want: types.RelayID{},
Expand Down Expand Up @@ -94,7 +95,7 @@ var (

func TestOCR2OracleSpec(t *testing.T) {
val := OCR2OracleSpec{
Relay: types.NetworkEVM,
Relay: relay.NetworkEVM,
PluginType: types.Median,
ContractID: "foo",
OCRKeyBundleID: null.StringFrom("bar"),
Expand Down
Loading

0 comments on commit a95a390

Please sign in to comment.