Skip to content

Commit

Permalink
[BCF-2261] Remove evm/config/v2; replace with evm/config and evm/conf…
Browse files Browse the repository at this point in the history
…ig/toml. (#9753)

* Move NodePoolConfig to config.go

* Move chain_scoped to config package

* Rename evm/config/v2 -> evm/config/toml

* Run make generate
  • Loading branch information
cedric-cordenier committed Jul 11, 2023
1 parent b0e382f commit 6604c3f
Show file tree
Hide file tree
Showing 79 changed files with 250 additions and 251 deletions.
12 changes: 6 additions & 6 deletions core/chains/evm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
v2 "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
httypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types"
Expand Down Expand Up @@ -75,18 +75,18 @@ func (e errChainDisabled) Error() string {
return fmt.Sprintf("cannot create new chain with ID %s, the chain is disabled", e.ChainID.String())
}

func newTOMLChain(ctx context.Context, chain *v2.EVMConfig, opts ChainSetOpts) (*chain, error) {
func newTOMLChain(ctx context.Context, chain *toml.EVMConfig, opts ChainSetOpts) (*chain, error) {
chainID := chain.ChainID
l := opts.Logger.With("evmChainID", chainID.String())
if !chain.IsEnabled() {
return nil, errChainDisabled{ChainID: chainID}
}
cfg := v2.NewTOMLChainScopedConfig(opts.Config, chain, l)
cfg := evmconfig.NewTOMLChainScopedConfig(opts.Config, chain, l)
// note: per-chain validation is not ncessary at this point since everything is checked earlier on boot.
return newChain(ctx, cfg, chain.Nodes, opts)
}

func newChain(ctx context.Context, cfg evmconfig.ChainScopedConfig, nodes []*v2.Node, opts ChainSetOpts) (*chain, error) {
func newChain(ctx context.Context, cfg evmconfig.ChainScopedConfig, nodes []*toml.Node, opts ChainSetOpts) (*chain, error) {
chainID, chainType := cfg.EVM().ChainID(), cfg.EVM().ChainType()
l := opts.Logger.Named(chainID.String()).With("evmChainID", chainID.String())
var client evmclient.Client
Expand Down Expand Up @@ -279,7 +279,7 @@ func (c *chain) Logger() logger.Logger { return c.logger }
func (c *chain) BalanceMonitor() monitor.BalanceMonitor { return c.balanceMonitor }
func (c *chain) GasEstimator() gas.EvmFeeEstimator { return c.gasEstimator }

func newEthClientFromChain(cfg evmconfig.NodePool, noNewHeadsThreshold time.Duration, lggr logger.Logger, chainID *big.Int, chainType config.ChainType, nodes []*v2.Node) (evmclient.Client, error) {
func newEthClientFromChain(cfg evmconfig.NodePool, noNewHeadsThreshold time.Duration, lggr logger.Logger, chainID *big.Int, chainType config.ChainType, nodes []*toml.Node) (evmclient.Client, error) {
var primaries []evmclient.Node
var sendonlys []evmclient.SendOnlyNode
for i, node := range nodes {
Expand All @@ -297,7 +297,7 @@ func newEthClientFromChain(cfg evmconfig.NodePool, noNewHeadsThreshold time.Dura
return evmclient.NewClientWithNodes(lggr, cfg.SelectionMode(), noNewHeadsThreshold, primaries, sendonlys, chainID, chainType)
}

func newPrimary(cfg evmconfig.NodePool, noNewHeadsThreshold time.Duration, lggr logger.Logger, n *v2.Node, id int32, chainID *big.Int) (evmclient.Node, error) {
func newPrimary(cfg evmconfig.NodePool, noNewHeadsThreshold time.Duration, lggr logger.Logger, n *toml.Node, id int32, chainID *big.Int) (evmclient.Node, error) {
if n.SendOnly != nil && *n.SendOnly {
return nil, errors.New("cannot cast send-only node to primary")
}
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/chain_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
v2 "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
httypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/log"
Expand Down Expand Up @@ -242,7 +242,7 @@ func (cll *chainSet) SendTx(ctx context.Context, chainID, from, to string, amoun

type GeneralConfig interface {
config.AppConfig
v2.HasEVMConfigs
toml.HasEVMConfigs
}

type ChainSetOpts struct {
Expand Down Expand Up @@ -270,7 +270,7 @@ func NewTOMLChainSet(ctx context.Context, opts ChainSetOpts) (ChainSet, error) {
return nil, err
}
chains := opts.Config.EVMConfigs()
var enabled []*v2.EVMConfig
var enabled []*toml.EVMConfig
for i := range chains {
if chains[i].IsEnabled() {
enabled = append(enabled, chains[i])
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/chain_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks"
v2 "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
configtest "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest/v2"
Expand All @@ -28,7 +28,7 @@ func TestChainSet(t *testing.T) {
one := uint32(1)
c.EVM[0].MinIncomingConfirmations = &one
t := true
c.EVM = append(c.EVM, &v2.EVMConfig{ChainID: utils.NewBig(newId), Enabled: &t, Chain: v2.Defaults(nil)})
c.EVM = append(c.EVM, &toml.EVMConfig{ChainID: utils.NewBig(newId), Enabled: &t, Chain: toml.Defaults(nil)})
})
db := pgtest.NewSqlxDB(t)
kst := cltest.NewKeyStore(t, db, cfg.Database())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2
package config

import (
"math/big"
Expand All @@ -10,12 +10,12 @@ import (
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types"

"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
gencfg "github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func NewTOMLChainScopedConfig(genCfg gencfg.AppConfig, chain *EVMConfig, lggr logger.Logger) *ChainScoped {
func NewTOMLChainScopedConfig(genCfg gencfg.AppConfig, chain *toml.EVMConfig, lggr logger.Logger) *ChainScoped {
return &ChainScoped{AppConfig: genCfg, cfg: chain, lggr: lggr}
}

Expand All @@ -24,7 +24,7 @@ type ChainScoped struct {
gencfg.AppConfig
lggr logger.Logger

cfg *EVMConfig
cfg *toml.EVMConfig
}

func (c *ChainScoped) Validate() (err error) {
Expand All @@ -46,30 +46,30 @@ func (c *ChainScoped) Validate() (err error) {
}

type evmConfig struct {
c *EVMConfig
c *toml.EVMConfig
}

func (e *evmConfig) BalanceMonitor() config.BalanceMonitor {
func (e *evmConfig) BalanceMonitor() BalanceMonitor {
return &balanceMonitorConfig{c: e.c.BalanceMonitor}
}

func (e *evmConfig) Transactions() config.Transactions {
func (e *evmConfig) Transactions() Transactions {
return &transactionsConfig{c: e.c.Transactions}
}

func (e *evmConfig) HeadTracker() config.HeadTracker {
func (e *evmConfig) HeadTracker() HeadTracker {
return &headTrackerConfig{c: e.c.HeadTracker}
}

func (e *evmConfig) OCR() config.OCR {
func (e *evmConfig) OCR() OCR {
return &ocrConfig{c: e.c.OCR}
}

func (e *evmConfig) OCR2() config.OCR2 {
func (e *evmConfig) OCR2() OCR2 {
return &ocr2Config{c: e.c.OCR2}
}

func (e *evmConfig) GasEstimator() config.GasEstimator {
func (e *evmConfig) GasEstimator() GasEstimator {
return &gasEstimatorConfig{c: e.c.GasEstimator, blockDelay: e.c.RPCBlockQueryDelay, transactionsMaxInFlight: e.c.Transactions.MaxInFlight, k: e.c.KeySpecific}
}

Expand Down Expand Up @@ -128,15 +128,15 @@ func (e *evmConfig) MinIncomingConfirmations() uint32 {
return *e.c.MinIncomingConfirmations
}

func (e *evmConfig) NodePool() config.NodePool {
func (e *evmConfig) NodePool() NodePool {
return &nodePoolConfig{c: e.c.NodePool}
}

func (e *evmConfig) NodeNoNewHeadsThreshold() time.Duration {
return e.c.NoNewHeadsThreshold.Duration()
}

func (c *ChainScoped) EVM() config.EVM {
func (c *ChainScoped) EVM() EVM {
return &evmConfig{c: c.cfg}
}

Expand Down
11 changes: 11 additions & 0 deletions core/chains/evm/config/chain_scoped_balance_monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package config

import "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"

type balanceMonitorConfig struct {
c toml.BalanceMonitor
}

func (b *balanceMonitorConfig) Enabled() bool {
return *b.c.Enabled
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package v2
package config

import (
gethcommon "github.com/ethereum/go-ethereum/common"

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

type gasEstimatorConfig struct {
c GasEstimator
k KeySpecificConfig
c toml.GasEstimator
k toml.KeySpecificConfig
blockDelay *uint16
transactionsMaxInFlight *uint32
}
Expand All @@ -32,7 +32,7 @@ func (g *gasEstimatorConfig) PriceMaxKey(addr gethcommon.Address) *assets.Wei {
return g.c.PriceMax
}

func (g *gasEstimatorConfig) BlockHistory() config.BlockHistory {
func (g *gasEstimatorConfig) BlockHistory() BlockHistory {
return &blockHistoryConfig{c: g.c.BlockHistory, blockDelay: g.blockDelay, bumpThreshold: g.c.BumpThreshold}
}

Expand Down Expand Up @@ -104,12 +104,12 @@ func (g *gasEstimatorConfig) Mode() string {
return *g.c.Mode
}

func (g *gasEstimatorConfig) LimitJobType() config.LimitJobType {
func (g *gasEstimatorConfig) LimitJobType() LimitJobType {
return &limitJobTypeConfig{c: g.c.LimitJobType}
}

type limitJobTypeConfig struct {
c GasLimitJobType
c toml.GasLimitJobType
}

func (l *limitJobTypeConfig) OCR() *uint32 {
Expand Down Expand Up @@ -137,7 +137,7 @@ func (l *limitJobTypeConfig) VRF() *uint32 {
}

type blockHistoryConfig struct {
c BlockHistoryEstimator
c toml.BlockHistoryEstimator
blockDelay *uint16
bumpThreshold *uint32
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package v2
package config

import "time"
import (
"time"

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

type headTrackerConfig struct {
c HeadTracker
c toml.HeadTracker
}

func (h *headTrackerConfig) HistoryDepth() uint32 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package v2
package config

import (
"time"

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

type nodePoolConfig struct {
c NodePool
c toml.NodePool
}

func (n *nodePoolConfig) PollFailureThreshold() uint32 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package v2
package config

import "time"
import (
"time"

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

type ocrConfig struct {
c OCR
c toml.OCR
}

func (o *ocrConfig) ContractConfirmations() uint16 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package v2
package config

import "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
)

type ocr2Automation struct {
c Automation
c toml.Automation
}

func (o *ocr2Automation) GasLimit() uint32 {
return *o.c.GasLimit
}

type ocr2Config struct {
c OCR2
c toml.OCR2
}

func (o *ocr2Config) Automation() config.OCR2Automation {
func (o *ocr2Config) Automation() OCR2Automation {
return &ocr2Automation{c: o.c.Automation}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2_test
package config_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v2_test
package config_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package v2
package config

import "time"
import (
"time"

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

type transactionsConfig struct {
c Transactions
c toml.Transactions
}

func (t *transactionsConfig) ForwardersEnabled() bool {
Expand Down
7 changes: 7 additions & 0 deletions core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ type BlockHistory interface {
TransactionPercentile() uint16
}

type NodePool interface {
PollFailureThreshold() uint32
PollInterval() time.Duration
SelectionMode() string
SyncThreshold() uint32
}

//go:generate mockery --quiet --name ChainScopedConfig --output ./mocks/ --case=underscore
type ChainScopedConfig interface {
config.AppConfig
Expand Down
10 changes: 0 additions & 10 deletions core/chains/evm/config/config_node_pool.go

This file was deleted.

Loading

0 comments on commit 6604c3f

Please sign in to comment.