Skip to content

Commit

Permalink
[BCF-2261] Break up config/v2 (#9697)
Browse files Browse the repository at this point in the history
* [BCF-2261] Split up config/v2; rename config/v2 -> config/toml

* Rename Env -> Var; EnvSecret -> Secret

* utils/configutils -> utils/config

* Make coreDefaultsTOML private again

* Address review comments

* LooppHostName -> LOOPPHostName
  • Loading branch information
cedric-cordenier authored Jul 10, 2023
1 parent ee5ce33 commit cef1712
Show file tree
Hide file tree
Showing 67 changed files with 388 additions and 380 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ test_need_operator_assets: ## Add blank file in web assets if operator ui has no

.PHONY: config-docs
config-docs: ## Generate core node configuration documentation
go run ./core/config/v2/docs/cmd/generate -o ./docs/
go run ./core/config/docs/cmd/generate -o ./docs/

.PHONY: golangci-lint
golangci-lint: ## Run golangci-lint for all issues.
Expand Down
2 changes: 1 addition & 1 deletion config_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/smartcontractkit/chainlink/v2/core/config/v2/docs"
"github.com/smartcontractkit/chainlink/v2/core/config/docs"
)

var (
Expand Down
20 changes: 10 additions & 10 deletions core/chains/cosmos/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@ import (

"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/cosmos/types"
v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

type CosmosConfigs []*CosmosConfig

func (cs CosmosConfigs) validateKeys() (err error) {
// Unique chain IDs
chainIDs := v2.UniqueStrings{}
chainIDs := config.UniqueStrings{}
for i, c := range cs {
if chainIDs.IsDupe(c.ChainID) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), *c.ChainID))
err = multierr.Append(err, config.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), *c.ChainID))
}
}

// Unique node names
names := v2.UniqueStrings{}
names := config.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
if names.IsDupe(n.Name) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
err = multierr.Append(err, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
}
}
}

// Unique TendermintURLs
urls := v2.UniqueStrings{}
urls := config.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
u := (*url.URL)(n.TendermintURL)
if urls.IsDupeFmt(u) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.TendermintURL", i, j), u.String()))
err = multierr.Append(err, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.TendermintURL", i, j), u.String()))
}
}
}
Expand Down Expand Up @@ -289,13 +289,13 @@ func setFromChain(c, f *coscfg.Chain) {

func (c *CosmosConfig) ValidateConfig() (err error) {
if c.ChainID == nil {
err = multierr.Append(err, v2.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
err = multierr.Append(err, config.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
} else if *c.ChainID == "" {
err = multierr.Append(err, v2.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
err = multierr.Append(err, config.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
}

if len(c.Nodes) == 0 {
err = multierr.Append(err, v2.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
err = multierr.Append(err, config.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
}

return
Expand Down
80 changes: 40 additions & 40 deletions core/chains/evm/config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/config"
v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"
configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

type HasEVMConfigs interface {
Expand All @@ -35,41 +35,41 @@ func (cs EVMConfigs) ValidateConfig() (err error) {

func (cs EVMConfigs) validateKeys() (err error) {
// Unique chain IDs
chainIDs := v2.UniqueStrings{}
chainIDs := configutils.UniqueStrings{}
for i, c := range cs {
if chainIDs.IsDupeFmt(c.ChainID) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), c.ChainID.String()))
err = multierr.Append(err, configutils.NewErrDuplicate(fmt.Sprintf("%d.ChainID", i), c.ChainID.String()))
}
}

// Unique node names
names := v2.UniqueStrings{}
names := configutils.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
if names.IsDupe(n.Name) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
err = multierr.Append(err, configutils.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.Name", i, j), *n.Name))
}
}
}

// Unique node WSURLs
wsURLs := v2.UniqueStrings{}
wsURLs := configutils.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
u := (*url.URL)(n.WSURL)
if wsURLs.IsDupeFmt(u) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.WSURL", i, j), u.String()))
err = multierr.Append(err, configutils.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.WSURL", i, j), u.String()))
}
}
}

// Unique node HTTPURLs
httpURLs := v2.UniqueStrings{}
httpURLs := configutils.UniqueStrings{}
for i, c := range cs {
for j, n := range c.Nodes {
u := (*url.URL)(n.HTTPURL)
if httpURLs.IsDupeFmt(u) {
err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.HTTPURL", i, j), u.String()))
err = multierr.Append(err, configutils.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.HTTPURL", i, j), u.String()))
}
}
}
Expand Down Expand Up @@ -273,29 +273,29 @@ func (c *EVMConfig) SetFrom(f *EVMConfig) {

func (c *EVMConfig) ValidateConfig() (err error) {
if c.ChainID == nil {
err = multierr.Append(err, v2.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
err = multierr.Append(err, configutils.ErrMissing{Name: "ChainID", Msg: "required for all chains"})
} else if c.ChainID.String() == "" {
err = multierr.Append(err, v2.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
err = multierr.Append(err, configutils.ErrEmpty{Name: "ChainID", Msg: "required for all chains"})
} else if must, ok := ChainTypeForID(c.ChainID); ok { // known chain id
if c.ChainType == nil && must != "" {
err = multierr.Append(err, v2.ErrMissing{Name: "ChainType",
err = multierr.Append(err, configutils.ErrMissing{Name: "ChainType",
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
} else if c.ChainType != nil && *c.ChainType != string(must) {
if *c.ChainType == "" {
err = multierr.Append(err, v2.ErrEmpty{Name: "ChainType",
err = multierr.Append(err, configutils.ErrEmpty{Name: "ChainType",
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
} else if must == "" {
err = multierr.Append(err, v2.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
err = multierr.Append(err, configutils.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
Msg: "must not be set with this chain id"})
} else {
err = multierr.Append(err, v2.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
err = multierr.Append(err, configutils.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
Msg: fmt.Sprintf("only %q can be used with this chain id", must)})
}
}
}

if len(c.Nodes) == 0 {
err = multierr.Append(err, v2.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
err = multierr.Append(err, configutils.ErrMissing{Name: "Nodes", Msg: "must have at least one node"})
} else {
var hasPrimary bool
for _, n := range c.Nodes {
Expand All @@ -306,7 +306,7 @@ func (c *EVMConfig) ValidateConfig() (err error) {
break
}
if !hasPrimary {
err = multierr.Append(err, v2.ErrMissing{Name: "Nodes",
err = multierr.Append(err, configutils.ErrMissing{Name: "Nodes",
Msg: "must have at least one primary node with WSURL"})
}
}
Expand Down Expand Up @@ -359,24 +359,24 @@ func (c *Chain) ValidateConfig() (err error) {
chainType = config.ChainType(*c.ChainType)
}
if !chainType.IsValid() {
err = multierr.Append(err, v2.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
err = multierr.Append(err, configutils.ErrInvalid{Name: "ChainType", Value: *c.ChainType,
Msg: config.ErrInvalidChainType.Error()})
}

if c.GasEstimator.BumpTxDepth != nil && uint32(*c.GasEstimator.BumpTxDepth) > *c.Transactions.MaxInFlight {
err = multierr.Append(err, v2.ErrInvalid{Name: "GasEstimator.BumpTxDepth", Value: *c.GasEstimator.BumpTxDepth,
err = multierr.Append(err, configutils.ErrInvalid{Name: "GasEstimator.BumpTxDepth", Value: *c.GasEstimator.BumpTxDepth,
Msg: "must be less than or equal to Transactions.MaxInFlight"})
}
if *c.HeadTracker.HistoryDepth < *c.FinalityDepth {
err = multierr.Append(err, v2.ErrInvalid{Name: "HeadTracker.HistoryDepth", Value: *c.HeadTracker.HistoryDepth,
err = multierr.Append(err, configutils.ErrInvalid{Name: "HeadTracker.HistoryDepth", Value: *c.HeadTracker.HistoryDepth,
Msg: "must be equal to or greater than FinalityDepth"})
}
if *c.FinalityDepth < 1 {
err = multierr.Append(err, v2.ErrInvalid{Name: "FinalityDepth", Value: *c.FinalityDepth,
err = multierr.Append(err, configutils.ErrInvalid{Name: "FinalityDepth", Value: *c.FinalityDepth,
Msg: "must be greater than or equal to 1"})
}
if *c.MinIncomingConfirmations < 1 {
err = multierr.Append(err, v2.ErrInvalid{Name: "MinIncomingConfirmations", Value: *c.MinIncomingConfirmations,
err = multierr.Append(err, configutils.ErrInvalid{Name: "MinIncomingConfirmations", Value: *c.MinIncomingConfirmations,
Msg: "must be greater than or equal to 1"})
}
return
Expand Down Expand Up @@ -469,36 +469,36 @@ type GasEstimator struct {

func (e *GasEstimator) ValidateConfig() (err error) {
if uint64(*e.BumpPercent) < txpool.DefaultConfig.PriceBump {
err = multierr.Append(err, v2.ErrInvalid{Name: "BumpPercent", Value: *e.BumpPercent,
err = multierr.Append(err, configutils.ErrInvalid{Name: "BumpPercent", Value: *e.BumpPercent,
Msg: fmt.Sprintf("may not be less than Geth's default of %d", txpool.DefaultConfig.PriceBump)})
}
if e.TipCapDefault.Cmp(e.TipCapMin) < 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "TipCapDefault", Value: e.TipCapDefault,
err = multierr.Append(err, configutils.ErrInvalid{Name: "TipCapDefault", Value: e.TipCapDefault,
Msg: "must be greater than or equal to TipCapMinimum"})
}
if e.FeeCapDefault.Cmp(e.TipCapDefault) < 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "FeeCapDefault", Value: e.TipCapDefault,
err = multierr.Append(err, configutils.ErrInvalid{Name: "FeeCapDefault", Value: e.TipCapDefault,
Msg: "must be greater than or equal to TipCapDefault"})
}
if *e.Mode == "FixedPrice" && *e.BumpThreshold == 0 && *e.EIP1559DynamicFees && e.FeeCapDefault.Cmp(e.PriceMax) != 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
err = multierr.Append(err, configutils.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
Msg: fmt.Sprintf("must be equal to PriceMax (%s) since you are using FixedPrice estimation with gas bumping disabled in "+
"EIP1559 mode - PriceMax will be used as the FeeCap for transactions instead of FeeCapDefault", e.PriceMax)})
} else if e.FeeCapDefault.Cmp(e.PriceMax) > 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
err = multierr.Append(err, configutils.ErrInvalid{Name: "FeeCapDefault", Value: e.FeeCapDefault,
Msg: fmt.Sprintf("must be less than or equal to PriceMax (%s)", e.PriceMax)})
}

if e.PriceMin.Cmp(e.PriceDefault) > 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "PriceMin", Value: e.PriceMin,
err = multierr.Append(err, configutils.ErrInvalid{Name: "PriceMin", Value: e.PriceMin,
Msg: "must be less than or equal to PriceDefault"})
}
if e.PriceMax.Cmp(e.PriceDefault) < 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "PriceMax", Value: e.PriceMin,
err = multierr.Append(err, configutils.ErrInvalid{Name: "PriceMax", Value: e.PriceMin,
Msg: "must be greater than or equal to PriceDefault"})
}
if *e.Mode == "BlockHistory" && *e.BlockHistory.BlockHistorySize <= 0 {
err = multierr.Append(err, v2.ErrInvalid{Name: "BlockHistory.BlockHistorySize", Value: *e.BlockHistory.BlockHistorySize,
err = multierr.Append(err, configutils.ErrInvalid{Name: "BlockHistory.BlockHistorySize", Value: *e.BlockHistory.BlockHistorySize,
Msg: "must be greater than or equal to 1 with BlockHistory Mode"})
}

Expand Down Expand Up @@ -625,7 +625,7 @@ func (ks KeySpecificConfig) ValidateConfig() (err error) {
for _, k := range ks {
addr := k.Key.String()
if _, ok := addrs[addr]; ok {
err = multierr.Append(err, v2.NewErrDuplicate("Key", addr))
err = multierr.Append(err, configutils.NewErrDuplicate("Key", addr))
} else {
addrs[addr] = struct{}{}
}
Expand Down Expand Up @@ -720,9 +720,9 @@ type Node struct {

func (n *Node) ValidateConfig() (err error) {
if n.Name == nil {
err = multierr.Append(err, v2.ErrMissing{Name: "Name", Msg: "required for all nodes"})
err = multierr.Append(err, configutils.ErrMissing{Name: "Name", Msg: "required for all nodes"})
} else if *n.Name == "" {
err = multierr.Append(err, v2.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
err = multierr.Append(err, configutils.ErrEmpty{Name: "Name", Msg: "required for all nodes"})
}

var sendOnly bool
Expand All @@ -731,34 +731,34 @@ func (n *Node) ValidateConfig() (err error) {
}
if n.WSURL == nil {
if !sendOnly {
err = multierr.Append(err, v2.ErrMissing{Name: "WSURL", Msg: "required for primary nodes"})
err = multierr.Append(err, configutils.ErrMissing{Name: "WSURL", Msg: "required for primary nodes"})
}
} else if n.WSURL.IsZero() {
if !sendOnly {
err = multierr.Append(err, v2.ErrEmpty{Name: "WSURL", Msg: "required for primary nodes"})
err = multierr.Append(err, configutils.ErrEmpty{Name: "WSURL", Msg: "required for primary nodes"})
}
} else {
switch n.WSURL.Scheme {
case "ws", "wss":
default:
err = multierr.Append(err, v2.ErrInvalid{Name: "WSURL", Value: n.WSURL.Scheme, Msg: "must be ws or wss"})
err = multierr.Append(err, configutils.ErrInvalid{Name: "WSURL", Value: n.WSURL.Scheme, Msg: "must be ws or wss"})
}
}

if n.HTTPURL == nil {
err = multierr.Append(err, v2.ErrMissing{Name: "HTTPURL", Msg: "required for all nodes"})
err = multierr.Append(err, configutils.ErrMissing{Name: "HTTPURL", Msg: "required for all nodes"})
} else if n.HTTPURL.IsZero() {
err = multierr.Append(err, v2.ErrEmpty{Name: "HTTPURL", Msg: "required for all nodes"})
err = multierr.Append(err, configutils.ErrEmpty{Name: "HTTPURL", Msg: "required for all nodes"})
} else {
switch n.HTTPURL.Scheme {
case "http", "https":
default:
err = multierr.Append(err, v2.ErrInvalid{Name: "HTTPURL", Value: n.HTTPURL.Scheme, Msg: "must be http or https"})
err = multierr.Append(err, configutils.ErrInvalid{Name: "HTTPURL", Value: n.HTTPURL.Scheme, Msg: "must be http or https"})
}
}

if n.Order != nil && (*n.Order < 1 || *n.Order > 100) {
err = multierr.Append(err, v2.ErrInvalid{Name: "Order", Value: *n.Order, Msg: "must be between 1 and 100"})
err = multierr.Append(err, configutils.ErrInvalid{Name: "Order", Value: *n.Order, Msg: "must be between 1 and 100"})
} else if n.Order == nil {
z := int32(100)
n.Order = &z
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/v2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"golang.org/x/exp/slices"

"github.com/smartcontractkit/chainlink/v2/core/config"
cfgv2 "github.com/smartcontractkit/chainlink/v2/core/config/v2"
"github.com/smartcontractkit/chainlink/v2/core/utils"
configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

var (
Expand Down Expand Up @@ -41,7 +41,7 @@ func init() {
Chain
}{}

if err := cfgv2.DecodeTOML(bytes.NewReader(b), &config); err != nil {
if err := configutils.DecodeTOML(bytes.NewReader(b), &config); err != nil {
log.Fatalf("failed to decode %q: %v", path, err)
}
if fe.Name() == "fallback.toml" {
Expand Down
Loading

0 comments on commit cef1712

Please sign in to comment.