Skip to content

Commit

Permalink
Extract relay from evm (#11537)
Browse files Browse the repository at this point in the history
* Extract relay from evm

* Replace type with string

* Update helpers_test.go

* ci

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
DylanTinianov and github-actions[bot] authored Dec 14, 2023
1 parent 7dd42eb commit 3c29970
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
17 changes: 8 additions & 9 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config"
)
Expand Down Expand Up @@ -107,7 +106,7 @@ func (cs EVMConfigs) totalChains() int {
}
return total
}
func (cs EVMConfigs) Chains(ids ...relay.ChainID) (r []commontypes.ChainStatus, total int, err error) {
func (cs EVMConfigs) Chains(ids ...string) (r []commontypes.ChainStatus, total int, err error) {
total = cs.totalChains()
for _, ch := range cs {
if ch == nil {
Expand Down Expand Up @@ -154,7 +153,7 @@ func (cs EVMConfigs) NodeStatus(name string) (commontypes.NodeStatus, error) {
for i := range cs {
for _, n := range cs[i].Nodes {
if n.Name != nil && *n.Name == name {
return nodeStatus(n, relay.ChainID(cs[i].ChainID.String()))
return nodeStatus(n, cs[i].ChainID.String())
}
}
}
Expand All @@ -179,7 +178,7 @@ func legacyNode(n *Node, chainID *big.Big) (v2 types.Node) {
return
}

func nodeStatus(n *Node, chainID relay.ChainID) (commontypes.NodeStatus, error) {
func nodeStatus(n *Node, chainID string) (commontypes.NodeStatus, error) {
var s commontypes.NodeStatus
s.ChainID = chainID
s.Name = *n.Name
Expand All @@ -191,7 +190,7 @@ func nodeStatus(n *Node, chainID relay.ChainID) (commontypes.NodeStatus, error)
return s, nil
}

func (cs EVMConfigs) nodes(id relay.ChainID) (ns EVMNodes) {
func (cs EVMConfigs) nodes(id string) (ns EVMNodes) {
for _, c := range cs {
if c.ChainID.String() == id {
return c.Nodes
Expand All @@ -200,7 +199,7 @@ func (cs EVMConfigs) nodes(id relay.ChainID) (ns EVMNodes) {
return nil
}

func (cs EVMConfigs) Nodes(chainID relay.ChainID) (ns []types.Node, err error) {
func (cs EVMConfigs) Nodes(chainID string) (ns []types.Node, err error) {
evmID, err := ChainIDInt64(chainID)
if err != nil {
return nil, fmt.Errorf("invalid evm chain id %q : %w", chainID, err)
Expand All @@ -220,14 +219,14 @@ func (cs EVMConfigs) Nodes(chainID relay.ChainID) (ns []types.Node, err error) {
return
}

func (cs EVMConfigs) NodeStatuses(chainIDs ...relay.ChainID) (ns []commontypes.NodeStatus, err error) {
func (cs EVMConfigs) NodeStatuses(chainIDs ...string) (ns []commontypes.NodeStatus, err error) {
if len(chainIDs) == 0 {
for i := range cs {
for _, n := range cs[i].Nodes {
if n == nil {
continue
}
n2, err := nodeStatus(n, relay.ChainID(cs[i].ChainID.String()))
n2, err := nodeStatus(n, cs[i].ChainID.String())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -816,6 +815,6 @@ func (n *Node) SetFrom(f *Node) {
}
}

func ChainIDInt64(cid relay.ChainID) (int64, error) {
func ChainIDInt64(cid string) (int64, error) {
return strconv.ParseInt(cid, 10, 64)
}
9 changes: 7 additions & 2 deletions core/chains/evm/log/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/log"
logmocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/log/mocks"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/flux_aggregator_wrapper"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
)

type broadcasterHelper struct {
Expand Down Expand Up @@ -105,7 +105,12 @@ func newBroadcasterHelperWithEthClient(t *testing.T, ethClient evmclient.Client,
LogBroadcaster: &log.NullBroadcaster{},
MailMon: mailMon,
})
legacyChains := evmrelay.NewLegacyChainsFromRelayerExtenders(cc)

m := make(map[string]legacyevm.Chain)
for _, r := range cc.Slice() {
m[r.Chain().ID().String()] = r.Chain()
}
legacyChains := legacyevm.NewLegacyChains(m, cc.AppConfig().EVMConfigs())
pipelineHelper := cltest.NewJobPipelineV2(t, config.WebServer(), config.JobPipeline(), config.Database(), legacyChains, db, kst, nil, nil)

return &broadcasterHelper{
Expand Down
5 changes: 2 additions & 3 deletions core/chains/evm/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

type Configs interface {
Chains(ids ...relay.ChainID) ([]types.ChainStatus, int, error)
Chains(ids ...string) ([]types.ChainStatus, int, error)
Node(name string) (Node, error)
Nodes(chainID relay.ChainID) (nodes []Node, err error)
Nodes(chainID string) (nodes []Node, err error)
NodeStatus(name string) (types.NodeStatus, error)
}

Expand Down

0 comments on commit 3c29970

Please sign in to comment.