Skip to content

Commit

Permalink
Move chaintype configs to evm (#13466)
Browse files Browse the repository at this point in the history
* Move chaintype configs to evm

* Add changeset
  • Loading branch information
dimriou authored Jun 10, 2024
1 parent 8c98c80 commit 4fdfffd
Show file tree
Hide file tree
Showing 41 changed files with 140 additions and 158 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-hats-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Move chaintype #internal
11 changes: 1 addition & 10 deletions common/client/mocks/config.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package mocks

import (
"time"

commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
)
import "time"

type ChainConfig struct {
IsFinalityTagEnabled bool
FinalityDepthVal uint32
NoNewHeadsThresholdVal time.Duration
ChainTypeVal commonconfig.ChainType
}

func (t ChainConfig) ChainType() commonconfig.ChainType {
return t.ChainTypeVal
}

func (t ChainConfig) NodeNoNewHeadsThreshold() time.Duration {
Expand Down
13 changes: 0 additions & 13 deletions common/client/multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/utils"

"github.com/smartcontractkit/chainlink/v2/common/config"
feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
)
Expand Down Expand Up @@ -73,7 +72,6 @@ type MultiNode[

BatchCallContextAll(ctx context.Context, b []BATCH_ELEM) error
ConfiguredChainID() CHAIN_ID
IsL2() bool
}

type multiNode[
Expand All @@ -95,7 +93,6 @@ type multiNode[
nodes []Node[CHAIN_ID, HEAD, RPC_CLIENT]
sendonlys []SendOnlyNode[CHAIN_ID, RPC_CLIENT]
chainID CHAIN_ID
chainType config.ChainType
lggr logger.SugaredLogger
selectionMode string
noNewHeadsThreshold time.Duration
Expand Down Expand Up @@ -137,7 +134,6 @@ func NewMultiNode[
nodes []Node[CHAIN_ID, HEAD, RPC_CLIENT],
sendonlys []SendOnlyNode[CHAIN_ID, RPC_CLIENT],
chainID CHAIN_ID,
chainType config.ChainType,
chainFamily string,
classifySendTxError func(tx TX, err error) SendTxReturnCode,
sendTxSoftTimeout time.Duration,
Expand All @@ -153,7 +149,6 @@ func NewMultiNode[
nodes: nodes,
sendonlys: sendonlys,
chainID: chainID,
chainType: chainType,
lggr: logger.Sugared(lggr).Named("MultiNode").With("chainID", chainID.String()),
selectionMode: selectionMode,
noNewHeadsThreshold: noNewHeadsThreshold,
Expand Down Expand Up @@ -489,10 +484,6 @@ func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OP
return n.RPC().ChainID(ctx)
}

func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT, BATCH_ELEM]) ChainType() config.ChainType {
return c.chainType
}

func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT, BATCH_ELEM]) CodeAt(ctx context.Context, account ADDR, blockNumber *big.Int) (code []byte, err error) {
n, err := c.selectNode()
if err != nil {
Expand Down Expand Up @@ -521,10 +512,6 @@ func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OP
return n.RPC().FilterEvents(ctx, query)
}

func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT, BATCH_ELEM]) IsL2() bool {
return c.ChainType().IsL2()
}

func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT, BATCH_ELEM]) LatestBlockHeight(ctx context.Context) (h *big.Int, err error) {
n, err := c.selectNode()
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions common/client/multi_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/common/types"
)

Expand All @@ -37,7 +36,6 @@ type multiNodeOpts struct {
nodes []Node[types.ID, types.Head[Hashable], multiNodeRPCClient]
sendonlys []SendOnlyNode[types.ID, multiNodeRPCClient]
chainID types.ID
chainType config.ChainType
chainFamily string
classifySendTxError func(tx any, err error) SendTxReturnCode
sendTxSoftTimeout time.Duration
Expand All @@ -51,7 +49,7 @@ func newTestMultiNode(t *testing.T, opts multiNodeOpts) testMultiNode {
result := NewMultiNode[types.ID, *big.Int, Hashable, Hashable, any, Hashable, any, any,
types.Receipt[Hashable, Hashable], Hashable, types.Head[Hashable], multiNodeRPCClient, any](opts.logger,
opts.selectionMode, opts.leaseDuration, opts.noNewHeadsThreshold, opts.nodes, opts.sendonlys,
opts.chainID, opts.chainType, opts.chainFamily, opts.classifySendTxError, opts.sendTxSoftTimeout)
opts.chainID, opts.chainFamily, opts.classifySendTxError, opts.sendTxSoftTimeout)
return testMultiNode{
result.(*multiNode[types.ID, *big.Int, Hashable, Hashable, any, Hashable, any, any,
types.Receipt[Hashable, Hashable], Hashable, types.Head[Hashable], multiNodeRPCClient, any]),
Expand Down
2 changes: 0 additions & 2 deletions common/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"

commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/common/types"
)

Expand Down Expand Up @@ -51,7 +50,6 @@ type ChainConfig interface {
NodeNoNewHeadsThreshold() time.Duration
FinalityDepth() uint32
FinalityTagEnabled() bool
ChainType() commonconfig.ChainType
}

//go:generate mockery --quiet --name Node --structname mockNode --filename "mock_node_test.go" --inpackage --case=underscore
Expand Down
10 changes: 5 additions & 5 deletions core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/logger"

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
"github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

Expand Down Expand Up @@ -117,7 +118,7 @@ type chainClient struct {
rpc.BatchElem,
]
logger logger.SugaredLogger
chainType config.ChainType
chainType chaintype.ChainType
clientErrors evmconfig.ClientErrors
}

Expand All @@ -129,7 +130,7 @@ func NewChainClient(
nodes []commonclient.Node[*big.Int, *evmtypes.Head, RPCClient],
sendonlys []commonclient.SendOnlyNode[*big.Int, RPCClient],
chainID *big.Int,
chainType config.ChainType,
chainType chaintype.ChainType,
clientErrors evmconfig.ClientErrors,
) Client {
multiNode := commonclient.NewMultiNode(
Expand All @@ -140,7 +141,6 @@ func NewChainClient(
nodes,
sendonlys,
chainID,
chainType,
"EVM",
func(tx *types.Transaction, err error) commonclient.SendTxReturnCode {
return ClassifySendError(err, clientErrors, logger.Sugared(logger.Nop()), tx, common.Address{}, chainType.IsL2())
Expand Down Expand Up @@ -254,7 +254,7 @@ func (c *chainClient) HeadByNumber(ctx context.Context, n *big.Int) (*evmtypes.H
}

func (c *chainClient) IsL2() bool {
return c.multiNode.IsL2()
return c.chainType.IsL2()
}

func (c *chainClient) LINKBalance(ctx context.Context, address common.Address, linkAddress common.Address) (*commonassets.Link, error) {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"go.uber.org/multierr"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/common/config"

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func NewClientConfigs(
chainConfig := &evmconfig.EVMConfig{
C: &toml.EVMConfig{
Chain: toml.Chain{
ChainType: config.NewChainTypeConfig(chainType),
ChainType: chaintype.NewChainTypeConfig(chainType),
FinalityDepth: finalityDepth,
FinalityTagEnabled: finalityTagEnabled,
NoNewHeadsThreshold: commonconfig.MustNewDuration(noNewHeadsThreshold),
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/config_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
)

func TestClientConfigBuilder(t *testing.T) {
Expand Down Expand Up @@ -50,13 +51,12 @@ func TestClientConfigBuilder(t *testing.T) {
require.Equal(t, *nodeConfigs[0].HTTPURL, (*nodes[0].HTTPURL).String())

// Validate chain config
require.Equal(t, chainTypeStr, string(chainCfg.ChainType()))
require.Equal(t, noNewHeadsThreshold, chainCfg.NodeNoNewHeadsThreshold())
require.Equal(t, *finalityDepth, chainCfg.FinalityDepth())
require.Equal(t, *finalityTagEnabled, chainCfg.FinalityTagEnabled())

// let combiler tell us, when we do not have sufficient data to create evm client
_ = client.NewEvmClient(nodePool, chainCfg, nil, logger.Test(t), big.NewInt(10), nodes)
_ = client.NewEvmClient(nodePool, chainCfg, nil, logger.Test(t), big.NewInt(10), nodes, chaintype.ChainType(chainTypeStr))
}

func TestNodeConfigs(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/client/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

func NewEvmClient(cfg evmconfig.NodePool, chainCfg commonclient.ChainConfig, clientErrors evmconfig.ClientErrors, lggr logger.Logger, chainID *big.Int, nodes []*toml.Node) Client {
func NewEvmClient(cfg evmconfig.NodePool, chainCfg commonclient.ChainConfig, clientErrors evmconfig.ClientErrors, lggr logger.Logger, chainID *big.Int, nodes []*toml.Node, chainType chaintype.ChainType) Client {
var empty url.URL
var primaries []commonclient.Node[*big.Int, *evmtypes.Head, RPCClient]
var sendonlys []commonclient.SendOnlyNode[*big.Int, RPCClient]
Expand All @@ -34,5 +35,5 @@ func NewEvmClient(cfg evmconfig.NodePool, chainCfg commonclient.ChainConfig, cli
}

return NewChainClient(lggr, cfg.SelectionMode(), cfg.LeaseDuration(), chainCfg.NodeNoNewHeadsThreshold(),
primaries, sendonlys, chainID, chainCfg.ChainType(), clientErrors)
primaries, sendonlys, chainID, chainType, clientErrors)
}
3 changes: 2 additions & 1 deletion core/chains/evm/client/evm_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/testutils"
)

Expand Down Expand Up @@ -36,6 +37,6 @@ func TestNewEvmClient(t *testing.T) {
pollFailureThreshold, pollInterval, syncThreshold, nodeIsSyncingEnabled, noNewHeadsThreshold, finalityDepth, finalityTagEnabled)
require.NoError(t, err)

client := client.NewEvmClient(nodePool, chainCfg, nil, logger.Test(t), testutils.FixtureChainID, nodes)
client := client.NewEvmClient(nodePool, chainCfg, nil, logger.Test(t), testutils.FixtureChainID, nodes, chaintype.ChainType(chainTypeStr))
require.NotNil(t, client)
}
8 changes: 4 additions & 4 deletions core/chains/evm/client/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
clientMocks "github.com/smartcontractkit/chainlink/v2/common/client/mocks"
commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)
Expand Down Expand Up @@ -148,7 +148,7 @@ func NewChainClientWithTestNode(
sendonlys = append(sendonlys, s)
}

var chainType commonconfig.ChainType
var chainType chaintype.ChainType
clientErrors := NewTestClientErrors()
c := NewChainClient(lggr, nodeCfg.SelectionMode(), leaseDuration, noNewHeadsThreshold, primaries, sendonlys, chainID, chainType, &clientErrors)
t.Cleanup(c.Close)
Expand All @@ -164,7 +164,7 @@ func NewChainClientWithEmptyNode(
) Client {
lggr := logger.Test(t)

var chainType commonconfig.ChainType
var chainType chaintype.ChainType
c := NewChainClient(lggr, selectionMode, leaseDuration, noNewHeadsThreshold, nil, nil, chainID, chainType, nil)
t.Cleanup(c.Close)
return c
Expand All @@ -180,7 +180,7 @@ func NewChainClientWithMockedRpc(
) Client {
lggr := logger.Test(t)

var chainType commonconfig.ChainType
var chainType chaintype.ChainType

cfg := TestNodePoolConfig{
NodeSelectionMode: commonclient.NodeSelectionModeRoundRobin,
Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/client/tx_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/v2/common/config"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
)

type simulatorClient interface {
Expand All @@ -17,7 +18,7 @@ type simulatorClient interface {
// ZK chains can return an out-of-counters error
// This method allows a caller to determine if a tx would fail due to OOC error by simulating the transaction
// Used as an entry point in case custom simulation is required across different chains
func SimulateTransaction(ctx context.Context, client simulatorClient, lggr logger.SugaredLogger, chainType config.ChainType, msg ethereum.CallMsg) *SendError {
func SimulateTransaction(ctx context.Context, client simulatorClient, lggr logger.SugaredLogger, chainType chaintype.ChainType, msg ethereum.CallMsg) *SendError {
err := simulateTransactionDefault(ctx, client, msg)
return NewSendError(err)
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/chain_scoped.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/logger"

commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
)

Expand Down Expand Up @@ -124,7 +124,7 @@ func (e *EVMConfig) BlockEmissionIdleWarningThreshold() time.Duration {
return e.C.NoNewHeadsThreshold.Duration()
}

func (e *EVMConfig) ChainType() commonconfig.ChainType {
func (e *EVMConfig) ChainType() chaintype.ChainType {
if e.C.ChainType == nil {
return ""
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package chaintype

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"

commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

Expand All @@ -29,7 +29,7 @@ type EVM interface {
BlockBackfillSkip() bool
BlockEmissionIdleWarningThreshold() time.Duration
ChainID() *big.Int
ChainType() commonconfig.ChainType
ChainType() chaintype.ChainType
FinalityDepth() uint32
FinalityTagEnabled() bool
FlagsContractAddress() string
Expand Down
Loading

0 comments on commit 4fdfffd

Please sign in to comment.