From cef1712d52bb849c3a535f468befc375b6acc5cd Mon Sep 17 00:00:00 2001 From: Cedric Date: Mon, 10 Jul 2023 16:08:28 +0100 Subject: [PATCH] [BCF-2261] Break up config/v2 (#9697) * [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 --- GNUmakefile | 2 +- config_docs_test.go | 2 +- core/chains/cosmos/config.go | 20 +-- core/chains/evm/config/v2/config.go | 80 ++++++------ core/chains/evm/config/v2/defaults.go | 4 +- core/chains/solana/config.go | 20 +-- core/chains/starknet/config.go | 20 +-- core/cmd/app.go | 4 +- core/cmd/app_test.go | 35 +++--- core/cmd/shell.go | 6 +- core/config/{v2 => }/docs/README.md | 0 core/config/{v2 => }/docs/chains-cosmos.toml | 0 core/config/{v2 => }/docs/chains-evm.toml | 0 core/config/{v2 => }/docs/chains-solana.toml | 0 .../config/{v2 => }/docs/chains-starknet.toml | 0 .../config/{v2 => }/docs/cmd/generate/main.go | 2 +- core/config/{v2 => }/docs/core.toml | 0 core/config/docs/defaults.go | 27 ++++ core/config/docs/defaults_test.go | 11 ++ core/config/{v2 => }/docs/docs.go | 0 core/config/{v2 => }/docs/docs_test.go | 32 ++--- core/config/{v2 => }/docs/example-config.toml | 0 .../config/{v2 => }/docs/example-secrets.toml | 0 core/config/{v2 => }/docs/extended.go | 0 core/config/docs/helpers_test.go | 3 + core/config/{v2 => }/docs/secrets.toml | 2 +- core/config/{v2 => }/docs/testdata/example.md | 0 .../{v2 => }/docs/testdata/example.toml | 0 core/config/env/env.go | 52 ++++++++ core/config/{v2 => toml}/types.go | 51 +++----- core/config/{v2 => toml}/types_test.go | 7 +- core/config/v2/env.go | 52 -------- core/internal/testutils/pgtest/txdb.go | 8 +- core/services/chainlink/config.go | 39 +++--- .../services/chainlink/config_audit_logger.go | 4 +- core/services/chainlink/config_auto_pprof.go | 4 +- core/services/chainlink/config_database.go | 14 +-- core/services/chainlink/config_explorer.go | 4 +- core/services/chainlink/config_feature.go | 4 +- .../services/chainlink/config_flux_monitor.go | 4 +- core/services/chainlink/config_general.go | 7 +- .../chainlink/config_general_state.go | 4 +- .../services/chainlink/config_general_test.go | 12 +- core/services/chainlink/config_insecure.go | 4 +- .../services/chainlink/config_job_pipeline.go | 4 +- core/services/chainlink/config_keeper.go | 6 +- core/services/chainlink/config_log.go | 6 +- core/services/chainlink/config_mercury.go | 4 +- core/services/chainlink/config_ocr.go | 4 +- core/services/chainlink/config_ocr2.go | 4 +- core/services/chainlink/config_p2p.go | 8 +- core/services/chainlink/config_prometheus.go | 4 +- core/services/chainlink/config_pyroscope.go | 6 +- core/services/chainlink/config_sentry.go | 4 +- .../chainlink/config_telemetry_ingress.go | 4 +- core/services/chainlink/config_test.go | 117 +++++++++--------- core/services/chainlink/config_threshold.go | 4 +- core/services/chainlink/config_web_server.go | 10 +- core/services/ocr2/plugins/median/services.go | 4 +- .../plugins/ocr2keeper/integration_test.go | 4 +- core/services/periodicbackup/backup_test.go | 14 +-- core/{config/v2 => utils/config}/toml.go | 4 +- core/{config/v2 => utils/config}/validate.go | 2 +- core/web/eth_keys_controller.go | 4 +- core/web/log_controller_test.go | 4 +- core/web/loop_registry.go | 6 +- integration-tests/go.mod | 1 - 67 files changed, 388 insertions(+), 380 deletions(-) rename core/config/{v2 => }/docs/README.md (100%) rename core/config/{v2 => }/docs/chains-cosmos.toml (100%) rename core/config/{v2 => }/docs/chains-evm.toml (100%) rename core/config/{v2 => }/docs/chains-solana.toml (100%) rename core/config/{v2 => }/docs/chains-starknet.toml (100%) rename core/config/{v2 => }/docs/cmd/generate/main.go (93%) rename core/config/{v2 => }/docs/core.toml (100%) create mode 100644 core/config/docs/defaults.go create mode 100644 core/config/docs/defaults_test.go rename core/config/{v2 => }/docs/docs.go (100%) rename core/config/{v2 => }/docs/docs_test.go (85%) rename core/config/{v2 => }/docs/example-config.toml (100%) rename core/config/{v2 => }/docs/example-secrets.toml (100%) rename core/config/{v2 => }/docs/extended.go (100%) create mode 100644 core/config/docs/helpers_test.go rename core/config/{v2 => }/docs/secrets.toml (99%) rename core/config/{v2 => }/docs/testdata/example.md (100%) rename core/config/{v2 => }/docs/testdata/example.toml (100%) create mode 100644 core/config/env/env.go rename core/config/{v2 => toml}/types.go (92%) rename core/config/{v2 => toml}/types_test.go (95%) delete mode 100644 core/config/v2/env.go rename core/{config/v2 => utils/config}/toml.go (92%) rename core/{config/v2 => utils/config}/validate.go (99%) diff --git a/GNUmakefile b/GNUmakefile index 4c0710140c7..7668d2544b4 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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. diff --git a/config_docs_test.go b/config_docs_test.go index 5e568499529..c9576cf10cd 100644 --- a/config_docs_test.go +++ b/config_docs_test.go @@ -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 ( diff --git a/core/chains/cosmos/config.go b/core/chains/cosmos/config.go index d84064e0c7b..10ce2fbce22 100644 --- a/core/chains/cosmos/config.go +++ b/core/chains/cosmos/config.go @@ -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())) } } } @@ -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 diff --git a/core/chains/evm/config/v2/config.go b/core/chains/evm/config/v2/config.go index 08eaba6e7dc..2d486c141f4 100644 --- a/core/chains/evm/config/v2/config.go +++ b/core/chains/evm/config/v2/config.go @@ -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 { @@ -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())) } } } @@ -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 { @@ -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"}) } } @@ -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 @@ -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"}) } @@ -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{}{} } @@ -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 @@ -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 diff --git a/core/chains/evm/config/v2/defaults.go b/core/chains/evm/config/v2/defaults.go index 0e63faef9ef..c7530942516 100644 --- a/core/chains/evm/config/v2/defaults.go +++ b/core/chains/evm/config/v2/defaults.go @@ -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 ( @@ -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" { diff --git a/core/chains/solana/config.go b/core/chains/solana/config.go index a13c10d4960..d4c49c7195e 100644 --- a/core/chains/solana/config.go +++ b/core/chains/solana/config.go @@ -18,9 +18,9 @@ import ( soldb "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" "github.com/smartcontractkit/chainlink/v2/core/chains" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/pg" + "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) type SolanaConfigs []*SolanaConfig @@ -31,30 +31,30 @@ func (cs SolanaConfigs) ValidateConfig() (err error) { func (cs SolanaConfigs) 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 URLs - urls := v2.UniqueStrings{} + urls := config.UniqueStrings{} for i, c := range cs { for j, n := range c.Nodes { u := (*url.URL)(n.URL) if urls.IsDupeFmt(u) { - err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.URL", i, j), u.String())) + err = multierr.Append(err, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.URL", i, j), u.String())) } } } @@ -288,13 +288,13 @@ func setFromChain(c, f *solcfg.Chain) { func (c *SolanaConfig) 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 } diff --git a/core/chains/starknet/config.go b/core/chains/starknet/config.go index b506e36b4a4..1c306e7b342 100644 --- a/core/chains/starknet/config.go +++ b/core/chains/starknet/config.go @@ -15,7 +15,7 @@ import ( "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/db" "github.com/smartcontractkit/chainlink/v2/core/chains" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) type StarknetConfigs []*StarknetConfig @@ -26,30 +26,30 @@ func (cs StarknetConfigs) ValidateConfig() (err error) { func (cs StarknetConfigs) 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 URLs - urls := v2.UniqueStrings{} + urls := config.UniqueStrings{} for i, c := range cs { for j, n := range c.Nodes { u := (*url.URL)(n.URL) if urls.IsDupeFmt(u) { - err = multierr.Append(err, v2.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.URL", i, j), u.String())) + err = multierr.Append(err, config.NewErrDuplicate(fmt.Sprintf("%d.Nodes.%d.URL", i, j), u.String())) } } } @@ -237,13 +237,13 @@ func setFromChain(c, f *stkcfg.Chain) { func (c *StarknetConfig) 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 diff --git a/core/cmd/app.go b/core/cmd/app.go index 144c4333bb8..79240d8b4bb 100644 --- a/core/cmd/app.go +++ b/core/cmd/app.go @@ -11,7 +11,7 @@ import ( "github.com/urfave/cli" "github.com/smartcontractkit/chainlink/v2/core/build" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/static" @@ -322,7 +322,7 @@ func initServerConfig(opts *chainlink.GeneralConfigOpts, configFiles []string, s configs = append(configs, string(b)) } - if configTOML := v2.EnvConfig.Get(); configTOML != "" { + if configTOML := env.Config.Get(); configTOML != "" { configs = append(configs, configTOML) } diff --git a/core/cmd/app_test.go b/core/cmd/app_test.go index df09e507eab..2d3db93cd82 100644 --- a/core/cmd/app_test.go +++ b/core/cmd/app_test.go @@ -6,11 +6,12 @@ import ( "path/filepath" "testing" - "github.com/pelletier/go-toml/v2" + gotoml "github.com/pelletier/go-toml/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) @@ -22,10 +23,10 @@ var ( testEnvContents = fmt.Sprintf("P2P.V2.AnnounceAddresses = ['%s']", setInEnv) testConfigFileContents = chainlink.Config{ - Core: v2.Core{ + Core: toml.Core{ RootDir: &setInFile, - P2P: v2.P2P{ - V2: v2.P2PV2{ + P2P: toml.P2P{ + V2: toml.P2PV2{ AnnounceAddresses: &[]string{setInFile}, ListenAddresses: &[]string{setInFile}, }, @@ -34,16 +35,16 @@ var ( } testSecretsFileContents = chainlink.Secrets{ - Secrets: v2.Secrets{ - Prometheus: v2.PrometheusSecrets{ + Secrets: toml.Secrets{ + Prometheus: toml.PrometheusSecrets{ AuthToken: models.NewSecret("PROM_TOKEN"), }, }, } testSecretsRedactedContents = chainlink.Secrets{ - Secrets: v2.Secrets{ - Prometheus: v2.PrometheusSecrets{ + Secrets: toml.Secrets{ + Prometheus: toml.PrometheusSecrets{ AuthToken: models.NewSecret("xxxxx"), }, }, @@ -54,7 +55,7 @@ func makeTestFile(t *testing.T, contents any, fileName string) string { d := t.TempDir() p := filepath.Join(d, fileName) - b, err := toml.Marshal(contents) + b, err := gotoml.Marshal(contents) require.NoError(t, err) require.NoError(t, os.WriteFile(p, b, 0777)) @@ -87,9 +88,9 @@ func Test_initServerConfig(t *testing.T) { envVar: testEnvContents, }, wantCfg: withDefaults(t, chainlink.Config{ - Core: v2.Core{ - P2P: v2.P2P{ - V2: v2.P2PV2{ + Core: toml.Core{ + P2P: toml.P2P{ + V2: toml.P2PV2{ AnnounceAddresses: &[]string{setInEnv}, }, }, @@ -120,10 +121,10 @@ func Test_initServerConfig(t *testing.T) { envVar: testEnvContents, }, wantCfg: withDefaults(t, chainlink.Config{ - Core: v2.Core{ + Core: toml.Core{ RootDir: &setInFile, - P2P: v2.P2P{ - V2: v2.P2PV2{ + P2P: toml.P2P{ + V2: toml.P2PV2{ // env should override this specific field AnnounceAddresses: &[]string{setInEnv}, ListenAddresses: &[]string{setInFile}, @@ -154,7 +155,7 @@ func Test_initServerConfig(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if tt.args.envVar != "" { - t.Setenv(string(v2.EnvConfig), tt.args.envVar) + t.Setenv(string(env.Config), tt.args.envVar) } cfg, err := initServerConfig(tt.args.opts, tt.args.fileNames, tt.args.secretsFile) if (err != nil) != tt.wantErr { diff --git a/core/cmd/shell.go b/core/cmd/shell.go index b9cb37394f6..e6f00bf79f6 100644 --- a/core/cmd/shell.go +++ b/core/cmd/shell.go @@ -42,7 +42,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/solana" "github.com/smartcontractkit/chainlink/v2/core/chains/starknet" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/logger/audit" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" @@ -271,7 +271,7 @@ func (r relayerFactory) NewSolana(ks keystore.Solana) (loop.Relayer, error) { } } - if cmdName := v2.EnvSolanaPluginCmd.Get(); cmdName != "" { + if cmdName := env.SolanaPluginCmd.Get(); cmdName != "" { // setup the solana relayer to be a LOOP tomls, err := toml.Marshal(struct { Solana solana.SolanaConfigs @@ -322,7 +322,7 @@ func (r relayerFactory) NewStarkNet(ks keystore.StarkNet) (loop.Relayer, error) } } - if cmdName := v2.EnvStarknetPluginCmd.Get(); cmdName != "" { + if cmdName := env.StarknetPluginCmd.Get(); cmdName != "" { // setup the starknet relayer to be a LOOP tomls, err := toml.Marshal(struct { Starknet starknet.StarknetConfigs diff --git a/core/config/v2/docs/README.md b/core/config/docs/README.md similarity index 100% rename from core/config/v2/docs/README.md rename to core/config/docs/README.md diff --git a/core/config/v2/docs/chains-cosmos.toml b/core/config/docs/chains-cosmos.toml similarity index 100% rename from core/config/v2/docs/chains-cosmos.toml rename to core/config/docs/chains-cosmos.toml diff --git a/core/config/v2/docs/chains-evm.toml b/core/config/docs/chains-evm.toml similarity index 100% rename from core/config/v2/docs/chains-evm.toml rename to core/config/docs/chains-evm.toml diff --git a/core/config/v2/docs/chains-solana.toml b/core/config/docs/chains-solana.toml similarity index 100% rename from core/config/v2/docs/chains-solana.toml rename to core/config/docs/chains-solana.toml diff --git a/core/config/v2/docs/chains-starknet.toml b/core/config/docs/chains-starknet.toml similarity index 100% rename from core/config/v2/docs/chains-starknet.toml rename to core/config/docs/chains-starknet.toml diff --git a/core/config/v2/docs/cmd/generate/main.go b/core/config/docs/cmd/generate/main.go similarity index 93% rename from core/config/v2/docs/cmd/generate/main.go rename to core/config/docs/cmd/generate/main.go index 5cc8d42cc04..49bb1bb6eab 100644 --- a/core/config/v2/docs/cmd/generate/main.go +++ b/core/config/docs/cmd/generate/main.go @@ -8,7 +8,7 @@ import ( "os" "path" - "github.com/smartcontractkit/chainlink/v2/core/config/v2/docs" + "github.com/smartcontractkit/chainlink/v2/core/config/docs" ) var outDir = flag.String("o", "", "output directory") diff --git a/core/config/v2/docs/core.toml b/core/config/docs/core.toml similarity index 100% rename from core/config/v2/docs/core.toml rename to core/config/docs/core.toml diff --git a/core/config/docs/defaults.go b/core/config/docs/defaults.go new file mode 100644 index 00000000000..f0af4fe457c --- /dev/null +++ b/core/config/docs/defaults.go @@ -0,0 +1,27 @@ +package docs + +import ( + "log" + "strings" + + "github.com/smartcontractkit/chainlink/v2/core/config/toml" + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" + "github.com/smartcontractkit/chainlink/v2/core/store/dialects" + "github.com/smartcontractkit/chainlink/v2/core/utils/config" +) + +var ( + defaults toml.Core +) + +func init() { + if err := cfgtest.DocDefaultsOnly(strings.NewReader(coreTOML), &defaults, config.DecodeTOML); err != nil { + log.Fatalf("Failed to initialize defaults from docs: %v", err) + } +} + +func CoreDefaults() (c toml.Core) { + c.SetFrom(&defaults) + c.Database.Dialect = dialects.Postgres // not user visible - overridden for tests only + return +} diff --git a/core/config/docs/defaults_test.go b/core/config/docs/defaults_test.go new file mode 100644 index 00000000000..b3312e9ee15 --- /dev/null +++ b/core/config/docs/defaults_test.go @@ -0,0 +1,11 @@ +package docs + +import ( + "testing" + + "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" +) + +func TestCoreDefaults_notNil(t *testing.T) { + cfgtest.AssertFieldsNotNil(t, CoreDefaults()) +} diff --git a/core/config/v2/docs/docs.go b/core/config/docs/docs.go similarity index 100% rename from core/config/v2/docs/docs.go rename to core/config/docs/docs.go diff --git a/core/config/v2/docs/docs_test.go b/core/config/docs/docs_test.go similarity index 85% rename from core/config/v2/docs/docs_test.go rename to core/config/docs/docs_test.go index 8dbdb2218de..0c5e40d11a4 100644 --- a/core/config/v2/docs/docs_test.go +++ b/core/config/docs/docs_test.go @@ -1,4 +1,4 @@ -package docs +package docs_test import ( _ "embed" @@ -6,7 +6,7 @@ import ( "testing" "github.com/kylelemons/godebug/diff" - "github.com/pelletier/go-toml/v2" + gotoml "github.com/pelletier/go-toml/v2" "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -16,18 +16,19 @@ import ( evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/v2" "github.com/smartcontractkit/chainlink/v2/core/chains/solana" "github.com/smartcontractkit/chainlink/v2/core/chains/starknet" - config "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/docs" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" + "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) func TestDoc(t *testing.T) { - d := toml.NewDecoder(strings.NewReader(docsTOML)) + d := gotoml.NewDecoder(strings.NewReader(docs.DocsTOML)) d.DisallowUnknownFields() // Ensure no extra fields var c chainlink.Config err := d.Decode(&c) - var strict *toml.StrictMissingError + var strict *gotoml.StrictMissingError if err != nil && strings.Contains(err.Error(), "undecoded keys: ") { t.Errorf("Docs contain extra fields: %v", err) } else if errors.As(err, &strict) { @@ -39,7 +40,7 @@ func TestDoc(t *testing.T) { cfgtest.AssertFieldsNotNil(t, c) var defaults chainlink.Config - require.NoError(t, cfgtest.DocDefaultsOnly(strings.NewReader(docsTOML), &defaults, config.DecodeTOML)) + require.NoError(t, cfgtest.DocDefaultsOnly(strings.NewReader(docs.DocsTOML), &defaults, config.DecodeTOML)) t.Run("EVM", func(t *testing.T) { fallbackDefaults := evmcfg.Defaults(nil) @@ -109,25 +110,10 @@ func assertTOML[T any](t *testing.T, fallback, docs T) { t.Helper() t.Logf("fallback: %#v", fallback) t.Logf("docs: %#v", docs) - fb, err := toml.Marshal(fallback) + fb, err := gotoml.Marshal(fallback) require.NoError(t, err) - db, err := toml.Marshal(docs) + db, err := gotoml.Marshal(docs) require.NoError(t, err) fs, ds := string(fb), string(db) assert.Equal(t, fs, ds, diff.Diff(fs, ds)) } - -var ( - //go:embed testdata/example.toml - exampleTOML string - //go:embed testdata/example.md - exampleMarkdown string -) - -func Test_generateDocs(t *testing.T) { - got, err := generateDocs(exampleTOML, `[//]: # (Generated - DO NOT EDIT.) -`, `Bar = 7 # Required -`) - require.NoError(t, err) - assert.Equal(t, exampleMarkdown, got) -} diff --git a/core/config/v2/docs/example-config.toml b/core/config/docs/example-config.toml similarity index 100% rename from core/config/v2/docs/example-config.toml rename to core/config/docs/example-config.toml diff --git a/core/config/v2/docs/example-secrets.toml b/core/config/docs/example-secrets.toml similarity index 100% rename from core/config/v2/docs/example-secrets.toml rename to core/config/docs/example-secrets.toml diff --git a/core/config/v2/docs/extended.go b/core/config/docs/extended.go similarity index 100% rename from core/config/v2/docs/extended.go rename to core/config/docs/extended.go diff --git a/core/config/docs/helpers_test.go b/core/config/docs/helpers_test.go new file mode 100644 index 00000000000..96f96ee7dbb --- /dev/null +++ b/core/config/docs/helpers_test.go @@ -0,0 +1,3 @@ +package docs + +var DocsTOML = docsTOML diff --git a/core/config/v2/docs/secrets.toml b/core/config/docs/secrets.toml similarity index 99% rename from core/config/v2/docs/secrets.toml rename to core/config/docs/secrets.toml index 45195b53ada..de097e50a0e 100644 --- a/core/config/v2/docs/secrets.toml +++ b/core/config/docs/secrets.toml @@ -56,4 +56,4 @@ URL = "https://example.com" # Example [Threshold] # ThresholdKeyShare used by the threshold decryption OCR plugin -ThresholdKeyShare = "A-Threshold-Decryption-Key-Share" # Example \ No newline at end of file +ThresholdKeyShare = "A-Threshold-Decryption-Key-Share" # Example diff --git a/core/config/v2/docs/testdata/example.md b/core/config/docs/testdata/example.md similarity index 100% rename from core/config/v2/docs/testdata/example.md rename to core/config/docs/testdata/example.md diff --git a/core/config/v2/docs/testdata/example.toml b/core/config/docs/testdata/example.toml similarity index 100% rename from core/config/v2/docs/testdata/example.toml rename to core/config/docs/testdata/example.toml diff --git a/core/config/env/env.go b/core/config/env/env.go new file mode 100644 index 00000000000..6a09ff452e2 --- /dev/null +++ b/core/config/env/env.go @@ -0,0 +1,52 @@ +package env + +import ( + "os" + "strings" + + "github.com/smartcontractkit/chainlink/v2/core/store/models" +) + +var ( + Config = Var("CL_CONFIG") + + // LOOPP commands and vars + MedianPluginCmd = Var("CL_MEDIAN_CMD") + SolanaPluginCmd = Var("CL_SOLANA_CMD") + StarknetPluginCmd = Var("CL_STARKNET_CMD") + // PrometheusDiscoveryHostName is the externally accessible hostname + // published by the node in the `/discovery` endpoint. Generally, it is expected to match + // the public hostname of node. + // Cluster step up like kubernetes may need to set this explicitly to ensure + // that Prometheus can discovery LOOPps. + // In house we observed that the resolved value of os.Hostname was not accessible to + // outside of the given pod + PrometheusDiscoveryHostName = Var("CL_PROMETHEUS_DISCOVERY_HOSTNAME") + // EnvLooopHostName is the hostname used for HTTP communication between the + // node and LOOPps. In most cases this does not need to be set explicitly. + LOOPPHostName = Var("CL_LOOPP_HOSTNAME") + + DatabaseAllowSimplePasswords = Var("CL_DATABASE_ALLOW_SIMPLE_PASSWORDS") + DatabaseURL = Secret("CL_DATABASE_URL") + DatabaseBackupURL = Secret("CL_DATABASE_BACKUP_URL") + ExplorerAccessKey = Secret("CL_EXPLORER_ACCESS_KEY") + ExplorerSecret = Secret("CL_EXPLORER_SECRET") + PasswordKeystore = Secret("CL_PASSWORD_KEYSTORE") + PasswordVRF = Secret("CL_PASSWORD_VRF") + PyroscopeAuthToken = Secret("CL_PYROSCOPE_AUTH_TOKEN") + PrometheusAuthToken = Secret("CL_PROMETHEUS_AUTH_TOKEN") + ThresholdKeyShare = Secret("CL_THRESHOLD_KEY_SHARE") +) + +type Var string + +func (e Var) Get() string { return os.Getenv(string(e)) } + +// Lookup wraps [os.LookupEnv] +func (e Var) Lookup() (string, bool) { return os.LookupEnv(string(e)) } + +func (e Var) IsTrue() bool { return strings.ToLower(e.Get()) == "true" } + +type Secret string + +func (e Secret) Get() models.Secret { return models.Secret(os.Getenv(string(e))) } diff --git a/core/config/v2/types.go b/core/config/toml/types.go similarity index 92% rename from core/config/v2/types.go rename to core/config/toml/types.go index ebbecb77f79..c29a2a88346 100644 --- a/core/config/v2/types.go +++ b/core/config/toml/types.go @@ -1,10 +1,9 @@ -package v2 +package toml import ( _ "embed" "errors" "fmt" - "log" "net" "net/url" "strings" @@ -19,12 +18,12 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/build" "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/config/parse" - "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" "github.com/smartcontractkit/chainlink/v2/core/store/dialects" "github.com/smartcontractkit/chainlink/v2/core/store/models" "github.com/smartcontractkit/chainlink/v2/core/utils" + configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) var ErrUnsupported = errors.New("unsupported with config v2") @@ -56,24 +55,6 @@ type Core struct { Insecure Insecure `toml:",omitempty"` } -var ( - //go:embed docs/core.toml - defaultsTOML string - defaults Core -) - -func init() { - if err := cfgtest.DocDefaultsOnly(strings.NewReader(defaultsTOML), &defaults, DecodeTOML); err != nil { - log.Fatalf("Failed to initialize defaults from docs: %v", err) - } -} - -func CoreDefaults() (c Core) { - c.SetFrom(&defaults) - c.Database.Dialect = dialects.Postgres // not user visible - overridden for tests only - return -} - // SetFrom updates c with any non-nil values from f. (currently TOML field only!) func (c *Core) SetFrom(f *Core) { if v := f.ExplorerURL; v != nil { @@ -113,7 +94,7 @@ func (c *Core) SetFrom(f *Core) { func (c *Core) ValidateConfig() (err error) { _, verr := parse.HomeDir(*c.RootDir) if err != nil { - err = multierr.Append(err, ErrInvalid{Name: "RootDir", Value: true, Msg: fmt.Sprintf("Failed to expand RootDir. Please use an explicit path: %s", verr)}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "RootDir", Value: true, Msg: fmt.Sprintf("Failed to expand RootDir. Please use an explicit path: %s", verr)}) } return err @@ -166,15 +147,15 @@ func validateDBURL(dbURI url.URL) error { func (d *DatabaseSecrets) ValidateConfig() (err error) { if d.URL == nil || (*url.URL)(d.URL).String() == "" { - err = multierr.Append(err, ErrEmpty{Name: "URL", Msg: "must be provided and non-empty"}) + err = multierr.Append(err, configutils.ErrEmpty{Name: "URL", Msg: "must be provided and non-empty"}) } else if !d.AllowSimplePasswords { if verr := validateDBURL((url.URL)(*d.URL)); verr != nil { - err = multierr.Append(err, ErrInvalid{Name: "URL", Value: "*****", Msg: dbURLPasswordComplexity(verr)}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "URL", Value: "*****", Msg: dbURLPasswordComplexity(verr)}) } } if d.BackupURL != nil && !d.AllowSimplePasswords { if verr := validateDBURL((url.URL)(*d.BackupURL)); verr != nil { - err = multierr.Append(err, ErrInvalid{Name: "BackupURL", Value: "*****", Msg: dbURLPasswordComplexity(verr)}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "BackupURL", Value: "*****", Msg: dbURLPasswordComplexity(verr)}) } } return err @@ -192,7 +173,7 @@ type Passwords struct { func (p *Passwords) ValidateConfig() (err error) { if p.Keystore == nil || *p.Keystore == "" { - err = multierr.Append(err, ErrEmpty{Name: "Keystore", Msg: "must be provided and non-empty"}) + err = multierr.Append(err, configutils.ErrEmpty{Name: "Keystore", Msg: "must be provided and non-empty"}) } return err } @@ -298,7 +279,7 @@ func (l *DatabaseLock) Mode() string { func (l *DatabaseLock) ValidateConfig() (err error) { if l.LeaseRefreshInterval.Duration() > l.LeaseDuration.Duration()/2 { - err = multierr.Append(err, ErrInvalid{Name: "LeaseRefreshInterval", Value: l.LeaseRefreshInterval.String(), + err = multierr.Append(err, configutils.ErrInvalid{Name: "LeaseRefreshInterval", Value: l.LeaseRefreshInterval.String(), Msg: fmt.Sprintf("must be less than or equal to half of LeaseDuration (%s)", l.LeaseDuration.String())}) } return @@ -830,7 +811,7 @@ type P2PV1 struct { func (p *P2PV1) ValidateConfig() (err error) { //TODO or empty? if p.AnnouncePort != nil && p.AnnounceIP == nil { - err = multierr.Append(err, ErrMissing{Name: "AnnounceIP", Msg: fmt.Sprintf("required when AnnouncePort is set: %d", *p.AnnouncePort)}) + err = multierr.Append(err, configutils.ErrMissing{Name: "AnnounceIP", Msg: fmt.Sprintf("required when AnnouncePort is set: %d", *p.AnnouncePort)}) } return } @@ -1064,17 +1045,17 @@ func (ins *Insecure) ValidateConfig() (err error) { return } if ins.DevWebServer != nil && *ins.DevWebServer { - err = multierr.Append(err, ErrInvalid{Name: "DevWebServer", Value: *ins.DevWebServer, Msg: "insecure configs are not allowed on secure builds"}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "DevWebServer", Value: *ins.DevWebServer, Msg: "insecure configs are not allowed on secure builds"}) } // OCRDevelopmentMode is allowed on test builds. if ins.OCRDevelopmentMode != nil && *ins.OCRDevelopmentMode && !build.IsTest() { - err = multierr.Append(err, ErrInvalid{Name: "OCRDevelopmentMode", Value: *ins.OCRDevelopmentMode, Msg: "insecure configs are not allowed on secure builds"}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "OCRDevelopmentMode", Value: *ins.OCRDevelopmentMode, Msg: "insecure configs are not allowed on secure builds"}) } if ins.InfiniteDepthQueries != nil && *ins.InfiniteDepthQueries { - err = multierr.Append(err, ErrInvalid{Name: "InfiniteDepthQueries", Value: *ins.InfiniteDepthQueries, Msg: "insecure configs are not allowed on secure builds"}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "InfiniteDepthQueries", Value: *ins.InfiniteDepthQueries, Msg: "insecure configs are not allowed on secure builds"}) } if ins.DisableRateLimiting != nil && *ins.DisableRateLimiting { - err = multierr.Append(err, ErrInvalid{Name: "DisableRateLimiting", Value: *ins.DisableRateLimiting, Msg: "insecure configs are not allowed on secure builds"}) + err = multierr.Append(err, configutils.ErrInvalid{Name: "DisableRateLimiting", Value: *ins.DisableRateLimiting, Msg: "insecure configs are not allowed on secure builds"}) } return err } @@ -1108,15 +1089,15 @@ func (m *MercurySecrets) ValidateConfig() (err error) { urls := make(map[string]struct{}, len(m.Credentials)) for name, creds := range m.Credentials { if name == "" { - err = multierr.Append(err, ErrEmpty{Name: "Name", Msg: "must be provided and non-empty"}) + err = multierr.Append(err, configutils.ErrEmpty{Name: "Name", Msg: "must be provided and non-empty"}) } if creds.URL == nil || creds.URL.URL() == nil { - err = multierr.Append(err, ErrMissing{Name: "URL", Msg: "must be provided and non-empty"}) + err = multierr.Append(err, configutils.ErrMissing{Name: "URL", Msg: "must be provided and non-empty"}) continue } s := creds.URL.URL().String() if _, exists := urls[s]; exists { - err = multierr.Append(err, NewErrDuplicate("URL", s)) + err = multierr.Append(err, configutils.NewErrDuplicate("URL", s)) } urls[s] = struct{}{} } diff --git a/core/config/v2/types_test.go b/core/config/toml/types_test.go similarity index 95% rename from core/config/v2/types_test.go rename to core/config/toml/types_test.go index 0dfa223502f..a85138c91b3 100644 --- a/core/config/v2/types_test.go +++ b/core/config/toml/types_test.go @@ -1,4 +1,4 @@ -package v2 +package toml import ( "fmt" @@ -7,15 +7,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" "github.com/smartcontractkit/chainlink/v2/core/store/models" "github.com/smartcontractkit/chainlink/v2/core/utils" ) -func TestCoreDefaults_notNil(t *testing.T) { - cfgtest.AssertFieldsNotNil(t, &defaults) -} - func TestMercurySecrets_valid(t *testing.T) { ms := MercurySecrets{ Credentials: map[string]MercuryCredentials{ diff --git a/core/config/v2/env.go b/core/config/v2/env.go deleted file mode 100644 index d14d08f3a92..00000000000 --- a/core/config/v2/env.go +++ /dev/null @@ -1,52 +0,0 @@ -package v2 - -import ( - "os" - "strings" - - "github.com/smartcontractkit/chainlink/v2/core/store/models" -) - -var ( - EnvConfig = Env("CL_CONFIG") - - // LOOPP commands and vars - EnvMedianPluginCmd = Env("CL_MEDIAN_CMD") - EnvSolanaPluginCmd = Env("CL_SOLANA_CMD") - EnvStarknetPluginCmd = Env("CL_STARKNET_CMD") - // EnvPrometheusDiscoveryHostName is the externally accessible hostname - // published by the node in the `/discovery` endpoint. Generally, it is expected to match - // the public hostname of node. - // Cluster step up like kubernetes may need to set this explicitly to ensure - // that Prometheus can discovery LOOPps. - // In house we observed that the resolved value of os.Hostname was not accessible to - // outside of the given pod - EnvPrometheusDiscoveryHostName = Env("CL_PROMETHEUS_DISCOVERY_HOSTNAME") - // EnvLooopHostName is the hostname used for HTTP communication between the - // node and LOOPps. In most cases this does not need to be set explicitly. - EnvLooppHostName = Env("CL_LOOPP_HOSTNAME") - - EnvDatabaseAllowSimplePasswords = Env("CL_DATABASE_ALLOW_SIMPLE_PASSWORDS") - EnvDatabaseURL = EnvSecret("CL_DATABASE_URL") - EnvDatabaseBackupURL = EnvSecret("CL_DATABASE_BACKUP_URL") - EnvExplorerAccessKey = EnvSecret("CL_EXPLORER_ACCESS_KEY") - EnvExplorerSecret = EnvSecret("CL_EXPLORER_SECRET") - EnvPasswordKeystore = EnvSecret("CL_PASSWORD_KEYSTORE") - EnvPasswordVRF = EnvSecret("CL_PASSWORD_VRF") - EnvPyroscopeAuthToken = EnvSecret("CL_PYROSCOPE_AUTH_TOKEN") - EnvPrometheusAuthToken = EnvSecret("CL_PROMETHEUS_AUTH_TOKEN") - EnvThresholdKeyShare = EnvSecret("CL_THRESHOLD_KEY_SHARE") -) - -type Env string - -func (e Env) Get() string { return os.Getenv(string(e)) } - -// Lookup wraps [os.LookupEnv] -func (e Env) Lookup() (string, bool) { return os.LookupEnv(string(e)) } - -func (e Env) IsTrue() bool { return strings.ToLower(e.Get()) == "true" } - -type EnvSecret string - -func (e EnvSecret) Get() models.Secret { return models.Secret(os.Getenv(string(e))) } diff --git a/core/internal/testutils/pgtest/txdb.go b/core/internal/testutils/pgtest/txdb.go index 8d08ac9e79f..1e65b1797b7 100644 --- a/core/internal/testutils/pgtest/txdb.go +++ b/core/internal/testutils/pgtest/txdb.go @@ -15,7 +15,7 @@ import ( "github.com/smartcontractkit/sqlx" "go.uber.org/multierr" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/store/dialects" ) @@ -44,7 +44,7 @@ func init() { // -short tests don't need a DB return } - dbURL := string(v2.EnvDatabaseURL.Get()) + dbURL := string(env.DatabaseURL.Get()) if dbURL == "" { panic("you must provide a CL_DATABASE_URL environment variable") } @@ -54,11 +54,11 @@ func init() { panic(err) } if parsed.Path == "" { - msg := fmt.Sprintf("invalid %[1]s: `%[2]s`. You must set %[1]s env var to point to your test database. Note that the test database MUST end in `_test` to differentiate from a possible production DB. HINT: Try %[1]s=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable", v2.EnvDatabaseURL, parsed.String()) + msg := fmt.Sprintf("invalid %[1]s: `%[2]s`. You must set %[1]s env var to point to your test database. Note that the test database MUST end in `_test` to differentiate from a possible production DB. HINT: Try %[1]s=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable", env.DatabaseURL, parsed.String()) panic(msg) } if !strings.HasSuffix(parsed.Path, "_test") { - msg := fmt.Sprintf("cannot run tests against database named `%s`. Note that the test database MUST end in `_test` to differentiate from a possible production DB. HINT: Try %s=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable", parsed.Path[1:], v2.EnvDatabaseURL) + msg := fmt.Sprintf("cannot run tests against database named `%s`. Note that the test database MUST end in `_test` to differentiate from a possible production DB. HINT: Try %s=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable", parsed.Path[1:], env.DatabaseURL) panic(msg) } name := string(dialects.TransactionWrappedPostgres) diff --git a/core/services/chainlink/config.go b/core/services/chainlink/config.go index b98883e6769..3ab9676dd80 100644 --- a/core/services/chainlink/config.go +++ b/core/services/chainlink/config.go @@ -7,15 +7,18 @@ import ( "go.uber.org/multierr" - "github.com/pelletier/go-toml/v2" + gotoml "github.com/pelletier/go-toml/v2" "github.com/smartcontractkit/chainlink/v2/core/chains/cosmos" "github.com/smartcontractkit/chainlink/v2/core/chains/starknet" "github.com/smartcontractkit/chainlink/v2/core/utils" + "github.com/smartcontractkit/chainlink/v2/core/utils/config" evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/v2" "github.com/smartcontractkit/chainlink/v2/core/chains/solana" - config "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/docs" + "github.com/smartcontractkit/chainlink/v2/core/config/env" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) @@ -30,7 +33,7 @@ import ( // - std lib types that don't implement encoding.TextMarshaler/TextUnmarshaler (time.Duration, url.URL, big.Int) won't // work as expected, and require wrapper types. See models.Duration, models.URL, utils.Big. type Config struct { - config.Core + toml.Core EVM evmcfg.EVMConfigs `toml:",omitempty"` @@ -43,7 +46,7 @@ type Config struct { // TOMLString returns a TOML encoded string. func (c *Config) TOMLString() (string, error) { - b, err := toml.Marshal(c) + b, err := gotoml.Marshal(c) if err != nil { return "", err } @@ -59,7 +62,7 @@ func (c *Config) Validate() error { // setDefaults initializes unset fields with default values. func (c *Config) setDefaults() { - core := config.CoreDefaults() + core := docs.CoreDefaults() core.SetFrom(&c.Core) c.Core = core @@ -118,12 +121,12 @@ func (c *Config) SetFrom(f *Config) (err error) { } type Secrets struct { - config.Secrets + toml.Secrets } // TOMLString returns a TOML encoded string with secret values redacted. func (s *Secrets) TOMLString() (string, error) { - b, err := toml.Marshal(s) + b, err := gotoml.Marshal(s) if err != nil { return "", err } @@ -152,7 +155,7 @@ func (s *Secrets) ValidateDB() error { type dbValidationType struct { // choose field name to match that of Secrets.Database so we have // consistent error messages. - Database config.DatabaseSecrets + Database toml.DatabaseSecrets } v := &dbValidationType{s.Database} @@ -164,40 +167,40 @@ func (s *Secrets) ValidateDB() error { // setEnv overrides fields from ENV vars, if present. func (s *Secrets) setEnv() error { - if dbURL := config.EnvDatabaseURL.Get(); dbURL != "" { + if dbURL := env.DatabaseURL.Get(); dbURL != "" { s.Database.URL = new(models.SecretURL) if err := s.Database.URL.UnmarshalText([]byte(dbURL)); err != nil { return err } } - if dbBackupUrl := config.EnvDatabaseBackupURL.Get(); dbBackupUrl != "" { + if dbBackupUrl := env.DatabaseBackupURL.Get(); dbBackupUrl != "" { s.Database.BackupURL = new(models.SecretURL) if err := s.Database.BackupURL.UnmarshalText([]byte(dbBackupUrl)); err != nil { return err } } - if config.EnvDatabaseAllowSimplePasswords.IsTrue() { + if env.DatabaseAllowSimplePasswords.IsTrue() { s.Database.AllowSimplePasswords = true } - if explorerKey := config.EnvExplorerAccessKey.Get(); explorerKey != "" { + if explorerKey := env.ExplorerAccessKey.Get(); explorerKey != "" { s.Explorer.AccessKey = &explorerKey } - if explorerSecret := config.EnvExplorerSecret.Get(); explorerSecret != "" { + if explorerSecret := env.ExplorerSecret.Get(); explorerSecret != "" { s.Explorer.Secret = &explorerSecret } - if keystorePassword := config.EnvPasswordKeystore.Get(); keystorePassword != "" { + if keystorePassword := env.PasswordKeystore.Get(); keystorePassword != "" { s.Password.Keystore = &keystorePassword } - if vrfPassword := config.EnvPasswordVRF.Get(); vrfPassword != "" { + if vrfPassword := env.PasswordVRF.Get(); vrfPassword != "" { s.Password.VRF = &vrfPassword } - if pyroscopeAuthToken := config.EnvPyroscopeAuthToken.Get(); pyroscopeAuthToken != "" { + if pyroscopeAuthToken := env.PyroscopeAuthToken.Get(); pyroscopeAuthToken != "" { s.Pyroscope.AuthToken = &pyroscopeAuthToken } - if prometheusAuthToken := config.EnvPrometheusAuthToken.Get(); prometheusAuthToken != "" { + if prometheusAuthToken := env.PrometheusAuthToken.Get(); prometheusAuthToken != "" { s.Prometheus.AuthToken = &prometheusAuthToken } - if thresholdKeyShare := config.EnvThresholdKeyShare.Get(); thresholdKeyShare != "" { + if thresholdKeyShare := env.ThresholdKeyShare.Get(); thresholdKeyShare != "" { s.Threshold.ThresholdKeyShare = &thresholdKeyShare } return nil diff --git a/core/services/chainlink/config_audit_logger.go b/core/services/chainlink/config_audit_logger.go index 2924f257a3c..1593f3887fb 100644 --- a/core/services/chainlink/config_audit_logger.go +++ b/core/services/chainlink/config_audit_logger.go @@ -2,12 +2,12 @@ package chainlink import ( "github.com/smartcontractkit/chainlink/v2/core/build" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) type auditLoggerConfig struct { - c v2.AuditLogger + c toml.AuditLogger } func (a auditLoggerConfig) Enabled() bool { diff --git a/core/services/chainlink/config_auto_pprof.go b/core/services/chainlink/config_auto_pprof.go index 7de6972181c..8cc5f2dd3e8 100644 --- a/core/services/chainlink/config_auto_pprof.go +++ b/core/services/chainlink/config_auto_pprof.go @@ -4,7 +4,7 @@ import ( "path/filepath" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -12,7 +12,7 @@ import ( var _ config.AutoPprof = (*autoPprofConfig)(nil) type autoPprofConfig struct { - c v2.AutoPprof + c toml.AutoPprof rootDir func() string } diff --git a/core/services/chainlink/config_database.go b/core/services/chainlink/config_database.go index 8d0068bb797..fe10c63f71b 100644 --- a/core/services/chainlink/config_database.go +++ b/core/services/chainlink/config_database.go @@ -5,13 +5,13 @@ import ( "time" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/dialects" ) type backupConfig struct { - c v2.DatabaseBackup - s v2.DatabaseSecrets + c toml.DatabaseBackup + s toml.DatabaseSecrets } func (b *backupConfig) Dir() string { @@ -35,7 +35,7 @@ func (b *backupConfig) URL() *url.URL { } type lockConfig struct { - c v2.DatabaseLock + c toml.DatabaseLock } func (l *lockConfig) LockingMode() string { @@ -51,7 +51,7 @@ func (l *lockConfig) LeaseRefreshInterval() time.Duration { } type listenerConfig struct { - c v2.DatabaseListener + c toml.DatabaseListener } func (l *listenerConfig) MaxReconnectDuration() time.Duration { @@ -69,8 +69,8 @@ func (l *listenerConfig) FallbackPollInterval() time.Duration { var _ config.Database = (*databaseConfig)(nil) type databaseConfig struct { - c v2.Database - s v2.DatabaseSecrets + c toml.Database + s toml.DatabaseSecrets logSQL func() bool } diff --git a/core/services/chainlink/config_explorer.go b/core/services/chainlink/config_explorer.go index ba6d8c16bf1..ce6001de195 100644 --- a/core/services/chainlink/config_explorer.go +++ b/core/services/chainlink/config_explorer.go @@ -3,13 +3,13 @@ package chainlink import ( "net/url" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) type explorerConfig struct { explorerURL *models.URL - s v2.ExplorerSecrets + s toml.ExplorerSecrets } func (e *explorerConfig) URL() *url.URL { diff --git a/core/services/chainlink/config_feature.go b/core/services/chainlink/config_feature.go index 50239293869..2e968df052d 100644 --- a/core/services/chainlink/config_feature.go +++ b/core/services/chainlink/config_feature.go @@ -1,9 +1,9 @@ package chainlink -import v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" +import "github.com/smartcontractkit/chainlink/v2/core/config/toml" type featureConfig struct { - c v2.Feature + c toml.Feature } func (f *featureConfig) FeedsManager() bool { diff --git a/core/services/chainlink/config_flux_monitor.go b/core/services/chainlink/config_flux_monitor.go index bc5eae95569..ccf72c93b34 100644 --- a/core/services/chainlink/config_flux_monitor.go +++ b/core/services/chainlink/config_flux_monitor.go @@ -1,9 +1,9 @@ package chainlink -import v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" +import "github.com/smartcontractkit/chainlink/v2/core/config/toml" type fluxMonitorConfig struct { - c v2.FluxMonitor + c toml.FluxMonitor } func (f *fluxMonitorConfig) DefaultTransactionQueueDepth() uint32 { diff --git a/core/services/chainlink/config_general.go b/core/services/chainlink/config_general.go index d866cef0d24..4b2309171ee 100644 --- a/core/services/chainlink/config_general.go +++ b/core/services/chainlink/config_general.go @@ -24,10 +24,11 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/config" coreconfig "github.com/smartcontractkit/chainlink/v2/core/config" "github.com/smartcontractkit/chainlink/v2/core/config/parse" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + v2 "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" "github.com/smartcontractkit/chainlink/v2/core/store/models" "github.com/smartcontractkit/chainlink/v2/core/utils" + configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) // generalConfig is a wrapper to adapt Config to the config.GeneralConfig interface. @@ -67,7 +68,7 @@ type GeneralConfigOpts struct { // parseConfig sets Config from the given TOML string, overriding any existing duplicate Config fields. func (o *GeneralConfigOpts) parseConfig(config string) error { var c Config - if err2 := v2.DecodeTOML(strings.NewReader(config), &c); err2 != nil { + if err2 := configutils.DecodeTOML(strings.NewReader(config), &c); err2 != nil { return fmt.Errorf("failed to decode config TOML: %w", err2) } @@ -80,7 +81,7 @@ func (o *GeneralConfigOpts) parseConfig(config string) error { // parseSecrets sets Secrets from the given TOML string. func (o *GeneralConfigOpts) parseSecrets() (err error) { - if err2 := v2.DecodeTOML(strings.NewReader(o.SecretsString), &o.Secrets); err2 != nil { + if err2 := configutils.DecodeTOML(strings.NewReader(o.SecretsString), &o.Secrets); err2 != nil { return fmt.Errorf("failed to decode secrets TOML: %w", err2) } return nil diff --git a/core/services/chainlink/config_general_state.go b/core/services/chainlink/config_general_state.go index 4855b0bcf48..dd2d033f348 100644 --- a/core/services/chainlink/config_general_state.go +++ b/core/services/chainlink/config_general_state.go @@ -4,7 +4,7 @@ import ( "github.com/google/uuid" "go.uber.org/zap/zapcore" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) @@ -27,7 +27,7 @@ func (g *generalConfig) logLevel() (ll zapcore.Level) { func (g *generalConfig) SetLogLevel(lvl zapcore.Level) error { g.logMu.Lock() - g.c.Log.Level = (*v2.LogLevel)(&lvl) + g.c.Log.Level = (*toml.LogLevel)(&lvl) g.logMu.Unlock() return nil } diff --git a/core/services/chainlink/config_general_test.go b/core/services/chainlink/config_general_test.go index 596cee7df7c..6f9f6b9f384 100644 --- a/core/services/chainlink/config_general_test.go +++ b/core/services/chainlink/config_general_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" ) func TestTOMLGeneralConfig_Defaults(t *testing.T) { @@ -78,10 +78,10 @@ func TestTOMLGeneralConfig_InsecureConfig(t *testing.T) { } func TestValidateDB(t *testing.T) { - t.Setenv(string(v2.EnvConfig), "") + t.Setenv(string(env.Config), "") t.Run("unset db url", func(t *testing.T) { - t.Setenv(string(v2.EnvDatabaseURL), "") + t.Setenv(string(env.DatabaseURL), "") config, err := GeneralConfigOpts{}.New() require.NoError(t, err) @@ -91,7 +91,7 @@ func TestValidateDB(t *testing.T) { }) t.Run("garbage db url", func(t *testing.T) { - t.Setenv(string(v2.EnvDatabaseURL), "garbage") + t.Setenv(string(env.DatabaseURL), "garbage") config, err := GeneralConfigOpts{}.New() require.NoError(t, err) @@ -101,7 +101,7 @@ func TestValidateDB(t *testing.T) { }) t.Run("dev url", func(t *testing.T) { - t.Setenv(string(v2.EnvDatabaseURL), "postgres://postgres:admin@localhost:5432/chainlink_dev_test?sslmode=disable") + t.Setenv(string(env.DatabaseURL), "postgres://postgres:admin@localhost:5432/chainlink_dev_test?sslmode=disable") config, err := GeneralConfigOpts{}.New() require.NoError(t, err) @@ -110,7 +110,7 @@ func TestValidateDB(t *testing.T) { }) t.Run("bad password url", func(t *testing.T) { - t.Setenv(string(v2.EnvDatabaseURL), "postgres://postgres:pwdToShort@localhost:5432/chainlink_dev_prod?sslmode=disable") + t.Setenv(string(env.DatabaseURL), "postgres://postgres:pwdToShort@localhost:5432/chainlink_dev_prod?sslmode=disable") config, err := GeneralConfigOpts{}.New() require.NoError(t, err) diff --git a/core/services/chainlink/config_insecure.go b/core/services/chainlink/config_insecure.go index ade22d70ad5..a41b5473291 100644 --- a/core/services/chainlink/config_insecure.go +++ b/core/services/chainlink/config_insecure.go @@ -2,11 +2,11 @@ package chainlink import ( "github.com/smartcontractkit/chainlink/v2/core/build" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) type insecureConfig struct { - c v2.Insecure + c toml.Insecure } func (i *insecureConfig) DevWebServer() bool { diff --git a/core/services/chainlink/config_job_pipeline.go b/core/services/chainlink/config_job_pipeline.go index 1cea01bde5b..1586cbb3574 100644 --- a/core/services/chainlink/config_job_pipeline.go +++ b/core/services/chainlink/config_job_pipeline.go @@ -4,14 +4,14 @@ import ( "time" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) var _ config.JobPipeline = (*jobPipelineConfig)(nil) type jobPipelineConfig struct { - c v2.JobPipeline + c toml.JobPipeline } func (j *jobPipelineConfig) DefaultHTTPLimit() int64 { diff --git a/core/services/chainlink/config_keeper.go b/core/services/chainlink/config_keeper.go index fa75c69da88..e56de0a69d1 100644 --- a/core/services/chainlink/config_keeper.go +++ b/core/services/chainlink/config_keeper.go @@ -4,13 +4,13 @@ import ( "time" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) var _ config.Keeper = (*keeperConfig)(nil) type registryConfig struct { - c v2.KeeperRegistry + c toml.KeeperRegistry } func (r *registryConfig) CheckGasOverhead() uint32 { @@ -34,7 +34,7 @@ func (r *registryConfig) SyncUpkeepQueueSize() uint32 { } type keeperConfig struct { - c v2.Keeper + c toml.Keeper } func (k *keeperConfig) Registry() config.Registry { diff --git a/core/services/chainlink/config_log.go b/core/services/chainlink/config_log.go index 3b16dae92ab..8004e864074 100644 --- a/core/services/chainlink/config_log.go +++ b/core/services/chainlink/config_log.go @@ -4,21 +4,21 @@ import ( "go.uber.org/zap/zapcore" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/utils" ) var _ config.Log = (*logConfig)(nil) type logConfig struct { - c v2.Log + c toml.Log rootDir func() string defaultLevel zapcore.Level level func() zapcore.Level } type fileConfig struct { - c v2.LogFile + c toml.LogFile rootDir func() string } diff --git a/core/services/chainlink/config_mercury.go b/core/services/chainlink/config_mercury.go index 85bc33decf2..93d88c689b8 100644 --- a/core/services/chainlink/config_mercury.go +++ b/core/services/chainlink/config_mercury.go @@ -1,12 +1,12 @@ package chainlink import ( - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/models" ) type mercuryConfig struct { - s v2.MercurySecrets + s toml.MercurySecrets } func (m *mercuryConfig) Credentials(credName string) *models.MercuryCredentials { diff --git a/core/services/chainlink/config_ocr.go b/core/services/chainlink/config_ocr.go index c06be77e437..072c724871a 100644 --- a/core/services/chainlink/config_ocr.go +++ b/core/services/chainlink/config_ocr.go @@ -6,14 +6,14 @@ import ( "github.com/pkg/errors" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" ) var _ config.OCR = (*ocrConfig)(nil) type ocrConfig struct { - c v2.OCR + c toml.OCR } func (o *ocrConfig) Enabled() bool { diff --git a/core/services/chainlink/config_ocr2.go b/core/services/chainlink/config_ocr2.go index 9ad5797dfef..59df8cb14eb 100644 --- a/core/services/chainlink/config_ocr2.go +++ b/core/services/chainlink/config_ocr2.go @@ -4,13 +4,13 @@ import ( "time" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) var _ config.OCR2 = (*ocr2Config)(nil) type ocr2Config struct { - c v2.OCR2 + c toml.OCR2 } func (o *ocr2Config) Enabled() bool { diff --git a/core/services/chainlink/config_p2p.go b/core/services/chainlink/config_p2p.go index 0e050bcc06c..35b80cc5f79 100644 --- a/core/services/chainlink/config_p2p.go +++ b/core/services/chainlink/config_p2p.go @@ -8,13 +8,13 @@ import ( ocrnetworking "github.com/smartcontractkit/libocr/networking" "github.com/smartcontractkit/chainlink/v2/core/config" - v2types "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) type p2p struct { - c v2types.P2P + c toml.P2P } func (p *p2p) Enabled() bool { @@ -50,7 +50,7 @@ func (p *p2p) V1() config.V1 { } type p2pv1 struct { - c v2types.P2PV1 + c toml.P2PV1 } func (v *p2pv1) Enabled() bool { @@ -103,7 +103,7 @@ func (v *p2pv1) PeerstoreWriteInterval() time.Duration { } type p2pv2 struct { - c v2types.P2PV2 + c toml.P2PV2 } func (v *p2pv2) Enabled() bool { diff --git a/core/services/chainlink/config_prometheus.go b/core/services/chainlink/config_prometheus.go index 7475f32fa0d..65a982bb6f1 100644 --- a/core/services/chainlink/config_prometheus.go +++ b/core/services/chainlink/config_prometheus.go @@ -1,11 +1,11 @@ package chainlink import ( - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) type prometheusConfig struct { - s v2.PrometheusSecrets + s toml.PrometheusSecrets } func (p *prometheusConfig) AuthToken() string { diff --git a/core/services/chainlink/config_pyroscope.go b/core/services/chainlink/config_pyroscope.go index c3dfd4d0a0b..7515ba37c6e 100644 --- a/core/services/chainlink/config_pyroscope.go +++ b/core/services/chainlink/config_pyroscope.go @@ -1,10 +1,10 @@ package chainlink -import v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" +import "github.com/smartcontractkit/chainlink/v2/core/config/toml" type pyroscopeConfig struct { - c v2.Pyroscope - s v2.PyroscopeSecrets + c toml.Pyroscope + s toml.PyroscopeSecrets } func (p *pyroscopeConfig) AuthToken() string { diff --git a/core/services/chainlink/config_sentry.go b/core/services/chainlink/config_sentry.go index 278b957dfca..58b229050d8 100644 --- a/core/services/chainlink/config_sentry.go +++ b/core/services/chainlink/config_sentry.go @@ -1,11 +1,11 @@ package chainlink import ( - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) type sentryConfig struct { - c v2.Sentry + c toml.Sentry } func (s sentryConfig) DSN() string { diff --git a/core/services/chainlink/config_telemetry_ingress.go b/core/services/chainlink/config_telemetry_ingress.go index 49d1cb8e3f6..8557bf0b02a 100644 --- a/core/services/chainlink/config_telemetry_ingress.go +++ b/core/services/chainlink/config_telemetry_ingress.go @@ -5,13 +5,13 @@ import ( "time" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" ) var _ config.TelemetryIngress = (*telemetryIngressConfig)(nil) type telemetryIngressConfig struct { - c v2.TelemetryIngress + c toml.TelemetryIngress } func (t *telemetryIngressConfig) Logging() bool { diff --git a/core/services/chainlink/config_test.go b/core/services/chainlink/config_test.go index 2029f92593b..b30be5d3f16 100644 --- a/core/services/chainlink/config_test.go +++ b/core/services/chainlink/config_test.go @@ -27,13 +27,14 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/solana" "github.com/smartcontractkit/chainlink/v2/core/chains/starknet" legacy "github.com/smartcontractkit/chainlink/v2/core/config" - config "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink/cfgtest" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" "github.com/smartcontractkit/chainlink/v2/core/store/models" "github.com/smartcontractkit/chainlink/v2/core/utils" + "github.com/smartcontractkit/chainlink/v2/core/utils/config" ) var ( @@ -43,9 +44,9 @@ var ( multiChainTOML string multiChain = Config{ - Core: config.Core{ + Core: toml.Core{ RootDir: ptr("my/root/dir"), - AuditLogger: config.AuditLogger{ + AuditLogger: toml.AuditLogger{ Enabled: ptr(true), ForwardToUrl: mustURL("http://localhost:9898"), Headers: ptr([]models.ServiceHeader{ @@ -60,35 +61,35 @@ var ( }), JsonWrapperKey: ptr("event"), }, - Database: config.Database{ - Listener: config.DatabaseListener{ + Database: toml.Database{ + Listener: toml.DatabaseListener{ FallbackPollInterval: models.MustNewDuration(2 * time.Minute), }, }, - Log: config.Log{ - Level: ptr(config.LogLevel(zapcore.PanicLevel)), + Log: toml.Log{ + Level: ptr(toml.LogLevel(zapcore.PanicLevel)), JSONConsole: ptr(true), }, - JobPipeline: config.JobPipeline{ - HTTPRequest: config.JobPipelineHTTPRequest{ + JobPipeline: toml.JobPipeline{ + HTTPRequest: toml.JobPipelineHTTPRequest{ DefaultTimeout: models.MustNewDuration(30 * time.Second), }, }, - OCR2: config.OCR2{ + OCR2: toml.OCR2{ Enabled: ptr(true), DatabaseTimeout: models.MustNewDuration(20 * time.Second), }, - OCR: config.OCR{ + OCR: toml.OCR{ Enabled: ptr(true), BlockchainTimeout: models.MustNewDuration(5 * time.Second), }, - P2P: config.P2P{ + P2P: toml.P2P{ IncomingMessageBufferSize: ptr[int64](999), }, - Keeper: config.Keeper{ + Keeper: toml.Keeper{ GasPriceBufferPercent: ptr[uint16](10), }, - AutoPprof: config.AutoPprof{ + AutoPprof: toml.AutoPprof{ CPUProfileRate: ptr[int64](7), }, }, @@ -210,12 +211,12 @@ func TestConfig_Marshal(t *testing.T) { selectionMode := client.NodeSelectionMode_HighestHead global := Config{ - Core: config.Core{ + Core: toml.Core{ ExplorerURL: mustURL("http://explorer.url"), InsecureFastScrypt: ptr(true), RootDir: ptr("test/root/dir"), ShutdownGracePeriod: models.MustNewDuration(10 * time.Second), - Insecure: config.Insecure{ + Insecure: toml.Insecure{ DevWebServer: ptr(false), OCRDevelopmentMode: ptr(false), InfiniteDepthQueries: ptr(false), @@ -230,19 +231,19 @@ func TestConfig_Marshal(t *testing.T) { {Header: "Authorization", Value: "token"}, {Header: "X-SomeOther-Header", Value: "value with spaces | and a bar+*"}, } - full.AuditLogger = config.AuditLogger{ + full.AuditLogger = toml.AuditLogger{ Enabled: ptr(true), ForwardToUrl: mustURL("http://localhost:9898"), Headers: ptr(serviceHeaders), JsonWrapperKey: ptr("event"), } - full.Feature = config.Feature{ + full.Feature = toml.Feature{ FeedsManager: ptr(true), LogPoller: ptr(true), UICSAKeys: ptr(true), } - full.Database = config.Database{ + full.Database = toml.Database{ DefaultIdleInTxSessionTimeout: models.MustNewDuration(time.Minute), DefaultLockTimeout: models.MustNewDuration(time.Hour), DefaultQueryTimeout: models.MustNewDuration(time.Second), @@ -250,24 +251,24 @@ func TestConfig_Marshal(t *testing.T) { MigrateOnStartup: ptr(true), MaxIdleConns: ptr[int64](7), MaxOpenConns: ptr[int64](13), - Listener: config.DatabaseListener{ + Listener: toml.DatabaseListener{ MaxReconnectDuration: models.MustNewDuration(time.Minute), MinReconnectInterval: models.MustNewDuration(5 * time.Minute), FallbackPollInterval: models.MustNewDuration(2 * time.Minute), }, - Lock: config.DatabaseLock{ + Lock: toml.DatabaseLock{ Enabled: ptr(false), LeaseDuration: &minute, LeaseRefreshInterval: &second, }, - Backup: config.DatabaseBackup{ + Backup: toml.DatabaseBackup{ Dir: ptr("test/backup/dir"), Frequency: &hour, Mode: &legacy.DatabaseBackupModeFull, OnVersionUpgrade: ptr(true), }, } - full.TelemetryIngress = config.TelemetryIngress{ + full.TelemetryIngress = toml.TelemetryIngress{ UniConn: ptr(true), Logging: ptr(true), ServerPubKey: ptr("test-pub-key"), @@ -278,18 +279,18 @@ func TestConfig_Marshal(t *testing.T) { SendTimeout: models.MustNewDuration(5 * time.Second), UseBatchSend: ptr(true), } - full.Log = config.Log{ - Level: ptr(config.LogLevel(zapcore.DPanicLevel)), + full.Log = toml.Log{ + Level: ptr(toml.LogLevel(zapcore.DPanicLevel)), JSONConsole: ptr(true), UnixTS: ptr(true), - File: config.LogFile{ + File: toml.LogFile{ Dir: ptr("log/file/dir"), MaxSize: ptr[utils.FileSize](100 * utils.GB), MaxAgeDays: ptr[int64](17), MaxBackups: ptr[int64](9), }, } - full.WebServer = config.WebServer{ + full.WebServer = toml.WebServer{ AllowOrigins: ptr("*"), BridgeResponseURL: mustURL("https://bridge.response"), BridgeCacheTTL: models.MustNewDuration(10 * time.Second), @@ -301,17 +302,17 @@ func TestConfig_Marshal(t *testing.T) { HTTPMaxSize: ptr(utils.FileSize(uint64(32770))), StartTimeout: models.MustNewDuration(15 * time.Second), ListenIP: mustIP("192.158.1.37"), - MFA: config.WebServerMFA{ + MFA: toml.WebServerMFA{ RPID: ptr("test-rpid"), RPOrigin: ptr("test-rp-origin"), }, - RateLimit: config.WebServerRateLimit{ + RateLimit: toml.WebServerRateLimit{ Authenticated: ptr[int64](42), AuthenticatedPeriod: models.MustNewDuration(time.Second), Unauthenticated: ptr[int64](7), UnauthenticatedPeriod: models.MustNewDuration(time.Minute), }, - TLS: config.WebServerTLS{ + TLS: toml.WebServerTLS{ CertPath: ptr("tls/cert/path"), Host: ptr("tls-host"), KeyPath: ptr("tls/key/path"), @@ -320,23 +321,23 @@ func TestConfig_Marshal(t *testing.T) { ListenIP: mustIP("192.158.1.38"), }, } - full.JobPipeline = config.JobPipeline{ + full.JobPipeline = toml.JobPipeline{ ExternalInitiatorsEnabled: ptr(true), MaxRunDuration: models.MustNewDuration(time.Hour), MaxSuccessfulRuns: ptr[uint64](123456), ReaperInterval: models.MustNewDuration(4 * time.Hour), ReaperThreshold: models.MustNewDuration(7 * 24 * time.Hour), ResultWriteQueueDepth: ptr[uint32](10), - HTTPRequest: config.JobPipelineHTTPRequest{ + HTTPRequest: toml.JobPipelineHTTPRequest{ MaxSize: ptr[utils.FileSize](100 * utils.MB), DefaultTimeout: models.MustNewDuration(time.Minute), }, } - full.FluxMonitor = config.FluxMonitor{ + full.FluxMonitor = toml.FluxMonitor{ DefaultTransactionQueueDepth: ptr[uint32](100), SimulateTransactions: ptr(true), } - full.OCR2 = config.OCR2{ + full.OCR2 = toml.OCR2{ Enabled: ptr(true), ContractConfirmations: ptr[uint32](11), BlockchainTimeout: models.MustNewDuration(3 * time.Second), @@ -350,7 +351,7 @@ func TestConfig_Marshal(t *testing.T) { SimulateTransactions: ptr(false), TraceLogging: ptr(false), } - full.OCR = config.OCR{ + full.OCR = toml.OCR{ Enabled: ptr(true), ObservationTimeout: models.MustNewDuration(11 * time.Second), BlockchainTimeout: models.MustNewDuration(3 * time.Second), @@ -363,12 +364,12 @@ func TestConfig_Marshal(t *testing.T) { CaptureEATelemetry: ptr(false), TraceLogging: ptr(false), } - full.P2P = config.P2P{ + full.P2P = toml.P2P{ IncomingMessageBufferSize: ptr[int64](13), OutgoingMessageBufferSize: ptr[int64](17), PeerID: mustPeerID("12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw"), TraceLogging: ptr(true), - V1: config.P2PV1{ + V1: toml.P2PV1{ Enabled: ptr(false), AnnounceIP: mustIP("1.2.3.4"), AnnouncePort: ptr[uint16](1234), @@ -381,7 +382,7 @@ func TestConfig_Marshal(t *testing.T) { NewStreamTimeout: models.MustNewDuration(time.Second), PeerstoreWriteInterval: models.MustNewDuration(time.Minute), }, - V2: config.P2PV2{ + V2: toml.P2PV2{ Enabled: ptr(true), AnnounceAddresses: &[]string{"a", "b", "c"}, DefaultBootstrappers: &[]ocrcommontypes.BootstrapperLocator{ @@ -393,14 +394,14 @@ func TestConfig_Marshal(t *testing.T) { ListenAddresses: &[]string{"foo", "bar"}, }, } - full.Keeper = config.Keeper{ + full.Keeper = toml.Keeper{ DefaultTransactionQueueDepth: ptr[uint32](17), GasPriceBufferPercent: ptr[uint16](12), GasTipCapBufferPercent: ptr[uint16](43), BaseFeeBufferPercent: ptr[uint16](89), MaxGracePeriod: ptr[int64](31), TurnLookBack: ptr[int64](91), - Registry: config.KeeperRegistry{ + Registry: toml.KeeperRegistry{ CheckGasOverhead: ptr[uint32](90), PerformGasOverhead: ptr[uint32](math.MaxUint32), SyncInterval: models.MustNewDuration(time.Hour), @@ -408,7 +409,7 @@ func TestConfig_Marshal(t *testing.T) { MaxPerformDataSize: ptr[uint32](5000), }, } - full.AutoPprof = config.AutoPprof{ + full.AutoPprof = toml.AutoPprof{ Enabled: ptr(true), ProfileRoot: ptr("prof/root"), PollInterval: models.MustNewDuration(time.Minute), @@ -422,11 +423,11 @@ func TestConfig_Marshal(t *testing.T) { MemThreshold: ptr[utils.FileSize](utils.GB), GoroutineThreshold: ptr[int64](999), } - full.Pyroscope = config.Pyroscope{ + full.Pyroscope = toml.Pyroscope{ ServerAddress: ptr("http://localhost:4040"), Environment: ptr("tests"), } - full.Sentry = config.Sentry{ + full.Sentry = toml.Sentry{ Debug: ptr(true), DSN: ptr("sentry-dsn"), Environment: ptr("dev"), @@ -641,18 +642,18 @@ OCRDevelopmentMode = false InfiniteDepthQueries = false DisableRateLimiting = false `}, - {"AuditLogger", Config{Core: config.Core{AuditLogger: full.AuditLogger}}, `[AuditLogger] + {"AuditLogger", Config{Core: toml.Core{AuditLogger: full.AuditLogger}}, `[AuditLogger] Enabled = true ForwardToUrl = 'http://localhost:9898' JsonWrapperKey = 'event' Headers = ['Authorization: token', 'X-SomeOther-Header: value with spaces | and a bar+*'] `}, - {"Feature", Config{Core: config.Core{Feature: full.Feature}}, `[Feature] + {"Feature", Config{Core: toml.Core{Feature: full.Feature}}, `[Feature] FeedsManager = true LogPoller = true UICSAKeys = true `}, - {"Database", Config{Core: config.Core{Database: full.Database}}, `[Database] + {"Database", Config{Core: toml.Core{Database: full.Database}}, `[Database] DefaultIdleInTxSessionTimeout = '1m0s' DefaultLockTimeout = '1h0m0s' DefaultQueryTimeout = '1s' @@ -677,7 +678,7 @@ Enabled = false LeaseDuration = '1m0s' LeaseRefreshInterval = '1s' `}, - {"TelemetryIngress", Config{Core: config.Core{TelemetryIngress: full.TelemetryIngress}}, `[TelemetryIngress] + {"TelemetryIngress", Config{Core: toml.Core{TelemetryIngress: full.TelemetryIngress}}, `[TelemetryIngress] UniConn = true Logging = true ServerPubKey = 'test-pub-key' @@ -688,7 +689,7 @@ SendInterval = '1m0s' SendTimeout = '5s' UseBatchSend = true `}, - {"Log", Config{Core: config.Core{Log: full.Log}}, `[Log] + {"Log", Config{Core: toml.Core{Log: full.Log}}, `[Log] Level = 'crit' JSONConsole = true UnixTS = true @@ -699,7 +700,7 @@ MaxSize = '100.00gb' MaxAgeDays = 17 MaxBackups = 9 `}, - {"WebServer", Config{Core: config.Core{WebServer: full.WebServer}}, `[WebServer] + {"WebServer", Config{Core: toml.Core{WebServer: full.WebServer}}, `[WebServer] AllowOrigins = '*' BridgeResponseURL = 'https://bridge.response' BridgeCacheTTL = '10s' @@ -730,11 +731,11 @@ HTTPSPort = 6789 KeyPath = 'tls/key/path' ListenIP = '192.158.1.38' `}, - {"FluxMonitor", Config{Core: config.Core{FluxMonitor: full.FluxMonitor}}, `[FluxMonitor] + {"FluxMonitor", Config{Core: toml.Core{FluxMonitor: full.FluxMonitor}}, `[FluxMonitor] DefaultTransactionQueueDepth = 100 SimulateTransactions = true `}, - {"JobPipeline", Config{Core: config.Core{JobPipeline: full.JobPipeline}}, `[JobPipeline] + {"JobPipeline", Config{Core: toml.Core{JobPipeline: full.JobPipeline}}, `[JobPipeline] ExternalInitiatorsEnabled = true MaxRunDuration = '1h0m0s' MaxSuccessfulRuns = 123456 @@ -746,7 +747,7 @@ ResultWriteQueueDepth = 10 DefaultTimeout = '1m0s' MaxSize = '100.00mb' `}, - {"OCR", Config{Core: config.Core{OCR: full.OCR}}, `[OCR] + {"OCR", Config{Core: toml.Core{OCR: full.OCR}}, `[OCR] Enabled = true ObservationTimeout = '11s' BlockchainTimeout = '3s' @@ -759,7 +760,7 @@ TransmitterAddress = '0xa0788FC17B1dEe36f057c42B6F373A34B014687e' CaptureEATelemetry = false TraceLogging = false `}, - {"OCR2", Config{Core: config.Core{OCR2: full.OCR2}}, `[OCR2] + {"OCR2", Config{Core: toml.Core{OCR2: full.OCR2}}, `[OCR2] Enabled = true ContractConfirmations = 11 BlockchainTimeout = '3s' @@ -773,7 +774,7 @@ DefaultTransactionQueueDepth = 1 SimulateTransactions = false TraceLogging = false `}, - {"P2P", Config{Core: config.Core{P2P: full.P2P}}, `[P2P] + {"P2P", Config{Core: toml.Core{P2P: full.P2P}}, `[P2P] IncomingMessageBufferSize = 13 OutgoingMessageBufferSize = 17 PeerID = '12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw' @@ -800,7 +801,7 @@ DeltaDial = '1m0s' DeltaReconcile = '1s' ListenAddresses = ['foo', 'bar'] `}, - {"Keeper", Config{Core: config.Core{Keeper: full.Keeper}}, `[Keeper] + {"Keeper", Config{Core: toml.Core{Keeper: full.Keeper}}, `[Keeper] DefaultTransactionQueueDepth = 17 GasPriceBufferPercent = 12 GasTipCapBufferPercent = 43 @@ -815,7 +816,7 @@ MaxPerformDataSize = 5000 SyncInterval = '1h0m0s' SyncUpkeepQueueSize = 31 `}, - {"AutoPprof", Config{Core: config.Core{AutoPprof: full.AutoPprof}}, `[AutoPprof] + {"AutoPprof", Config{Core: toml.Core{AutoPprof: full.AutoPprof}}, `[AutoPprof] Enabled = true ProfileRoot = 'prof/root' PollInterval = '1m0s' @@ -829,11 +830,11 @@ MutexProfileFraction = 2 MemThreshold = '1.00gb' GoroutineThreshold = 999 `}, - {"Pyroscope", Config{Core: config.Core{Pyroscope: full.Pyroscope}}, `[Pyroscope] + {"Pyroscope", Config{Core: toml.Core{Pyroscope: full.Pyroscope}}, `[Pyroscope] ServerAddress = 'http://localhost:4040' Environment = 'tests' `}, - {"Sentry", Config{Core: config.Core{Sentry: full.Sentry}}, `[Sentry] + {"Sentry", Config{Core: toml.Core{Sentry: full.Sentry}}, `[Sentry] Debug = true DSN = 'sentry-dsn' Environment = 'dev' diff --git a/core/services/chainlink/config_threshold.go b/core/services/chainlink/config_threshold.go index 273374e461b..0c512d1b015 100644 --- a/core/services/chainlink/config_threshold.go +++ b/core/services/chainlink/config_threshold.go @@ -1,9 +1,9 @@ package chainlink -import v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" +import "github.com/smartcontractkit/chainlink/v2/core/config/toml" type thresholdConfig struct { - s v2.ThresholdKeyShareSecrets + s toml.ThresholdKeyShareSecrets } func (t *thresholdConfig) ThresholdKeyShare() string { diff --git a/core/services/chainlink/config_web_server.go b/core/services/chainlink/config_web_server.go index 200fc43fdc3..a931d67f386 100644 --- a/core/services/chainlink/config_web_server.go +++ b/core/services/chainlink/config_web_server.go @@ -10,14 +10,14 @@ import ( "github.com/gin-contrib/sessions" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/store/models" ) var _ config.WebServer = (*webServerConfig)(nil) type tlsConfig struct { - c v2.WebServerTLS + c toml.WebServerTLS rootDir func() string } @@ -65,7 +65,7 @@ func (t *tlsConfig) ListenIP() net.IP { } type rateLimitConfig struct { - c v2.WebServerRateLimit + c toml.WebServerRateLimit } func (r *rateLimitConfig) Authenticated() int64 { @@ -85,7 +85,7 @@ func (r *rateLimitConfig) UnauthenticatedPeriod() time.Duration { } type mfaConfig struct { - c v2.WebServerMFA + c toml.WebServerMFA } func (m *mfaConfig) RPID() string { @@ -97,7 +97,7 @@ func (m *mfaConfig) RPOrigin() string { } type webServerConfig struct { - c v2.WebServer + c toml.WebServer rootDir func() string } diff --git a/core/services/ocr2/plugins/median/services.go b/core/services/ocr2/plugins/median/services.go index 1bd266b53e8..ad3caecc05b 100644 --- a/core/services/ocr2/plugins/median/services.go +++ b/core/services/ocr2/plugins/median/services.go @@ -11,7 +11,7 @@ import ( "github.com/smartcontractkit/chainlink-relay/pkg/loop" "github.com/smartcontractkit/chainlink-relay/pkg/types" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services" "github.com/smartcontractkit/chainlink/v2/core/services/job" @@ -103,7 +103,7 @@ func NewMedianServices(ctx context.Context, CreatedAt: time.Now(), }, lggr) - if cmdName := v2.EnvMedianPluginCmd.Get(); cmdName != "" { + if cmdName := env.MedianPluginCmd.Get(); cmdName != "" { medianLggr := lggr.Named("Median") // use logger name to ensure unique naming cmdFn, telem, err2 := cfg.RegisterLOOP(medianLggr.Name(), cmdName) diff --git a/core/services/ocr2/plugins/ocr2keeper/integration_test.go b/core/services/ocr2/plugins/ocr2keeper/integration_test.go index 231020ebdbf..453aac147c5 100644 --- a/core/services/ocr2/plugins/ocr2keeper/integration_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/integration_test.go @@ -32,7 +32,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_forwarder" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/basic_upkeep_contract" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/keeper_registry_logic2_0" @@ -131,7 +131,7 @@ func setupNode( c.EVM[0].Transactions.ForwardersEnabled = ptr(true) c.EVM[0].GasEstimator.Mode = ptr("FixedPrice") - s.Mercury.Credentials = map[string]v2.MercuryCredentials{ + s.Mercury.Credentials = map[string]toml.MercuryCredentials{ MercuryCredName: { URL: models.MustSecretURL("https://mercury.chain.link"), Username: models.NewSecret("username1"), diff --git a/core/services/periodicbackup/backup_test.go b/core/services/periodicbackup/backup_test.go index 38559d7601e..99581e62720 100644 --- a/core/services/periodicbackup/backup_test.go +++ b/core/services/periodicbackup/backup_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/config" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/static" @@ -32,7 +32,7 @@ func must(t testing.TB, s string) *url.URL { func TestPeriodicBackup_RunBackup(t *testing.T) { backupConfig := newTestConfig(time.Minute, nil, "", config.DatabaseBackupModeFull) - periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(v2.EnvDatabaseURL.Get()))), os.TempDir(), backupConfig) + periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(env.DatabaseURL.Get()))), os.TempDir(), backupConfig) assert.False(t, periodicBackup.frequencyIsTooSmall()) result, err := periodicBackup.runBackup("0.9.9") @@ -51,7 +51,7 @@ func TestPeriodicBackup_RunBackup(t *testing.T) { func TestPeriodicBackup_RunBackupInLiteMode(t *testing.T) { backupConfig := newTestConfig(time.Minute, nil, "", config.DatabaseBackupModeLite) - periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(v2.EnvDatabaseURL.Get()))), os.TempDir(), backupConfig) + periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(env.DatabaseURL.Get()))), os.TempDir(), backupConfig) assert.False(t, periodicBackup.frequencyIsTooSmall()) result, err := periodicBackup.runBackup("0.9.9") @@ -70,7 +70,7 @@ func TestPeriodicBackup_RunBackupInLiteMode(t *testing.T) { func TestPeriodicBackup_RunBackupWithoutVersion(t *testing.T) { backupConfig := newTestConfig(time.Minute, nil, "", config.DatabaseBackupModeFull) - periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(v2.EnvDatabaseURL.Get()))), os.TempDir(), backupConfig) + periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(env.DatabaseURL.Get()))), os.TempDir(), backupConfig) assert.False(t, periodicBackup.frequencyIsTooSmall()) result, err := periodicBackup.runBackup(static.Unset) @@ -89,7 +89,7 @@ func TestPeriodicBackup_RunBackupWithoutVersion(t *testing.T) { func TestPeriodicBackup_RunBackupViaAltUrlAndMaskPassword(t *testing.T) { altUrl, _ := url.Parse("postgresql://invalid:some-pass@invalid") backupConfig := newTestConfig(time.Minute, altUrl, "", config.DatabaseBackupModeFull) - periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(v2.EnvDatabaseURL.Get()))), os.TempDir(), backupConfig) + periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(env.DatabaseURL.Get()))), os.TempDir(), backupConfig) assert.False(t, periodicBackup.frequencyIsTooSmall()) partialResult, err := periodicBackup.runBackup("") @@ -99,14 +99,14 @@ func TestPeriodicBackup_RunBackupViaAltUrlAndMaskPassword(t *testing.T) { func TestPeriodicBackup_FrequencyTooSmall(t *testing.T) { backupConfig := newTestConfig(time.Second, nil, "", config.DatabaseBackupModeFull) - periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(v2.EnvDatabaseURL.Get()))), os.TempDir(), backupConfig) + periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(env.DatabaseURL.Get()))), os.TempDir(), backupConfig) assert.True(t, periodicBackup.frequencyIsTooSmall()) } func TestPeriodicBackup_AlternativeOutputDir(t *testing.T) { backupDir := filepath.Join(os.TempDir(), "alternative") backupConfig := newTestConfig(time.Second, nil, backupDir, config.DatabaseBackupModeFull) - periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(v2.EnvDatabaseURL.Get()))), os.TempDir(), backupConfig) + periodicBackup := mustNewDatabaseBackup(t, *(must(t, string(env.DatabaseURL.Get()))), os.TempDir(), backupConfig) result, err := periodicBackup.runBackup("0.9.9") require.NoError(t, err, "error not nil for backup") diff --git a/core/config/v2/toml.go b/core/utils/config/toml.go similarity index 92% rename from core/config/v2/toml.go rename to core/utils/config/toml.go index 75d9c06f58a..f51db76365e 100644 --- a/core/config/v2/toml.go +++ b/core/utils/config/toml.go @@ -1,10 +1,10 @@ -package v2 +package config import ( + "errors" "io" "github.com/pelletier/go-toml/v2" - "github.com/pkg/errors" ) // DecodeTOML decodes toml from r in to v. diff --git a/core/config/v2/validate.go b/core/utils/config/validate.go similarity index 99% rename from core/config/v2/validate.go rename to core/utils/config/validate.go index 805b5dfc03a..798beca663d 100644 --- a/core/config/v2/validate.go +++ b/core/utils/config/validate.go @@ -1,4 +1,4 @@ -package v2 +package config import ( "fmt" diff --git a/core/web/eth_keys_controller.go b/core/web/eth_keys_controller.go index f796aefbe87..514cdaf8c7b 100644 --- a/core/web/eth_keys_controller.go +++ b/core/web/eth_keys_controller.go @@ -11,7 +11,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/assets" "github.com/smartcontractkit/chainlink/v2/core/chains/evm" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/logger/audit" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" @@ -129,7 +129,7 @@ func (ekc *ETHKeysController) Create(c *gin.Context) { } if c.Query("maxGasPriceGWei") != "" { - jsonAPIError(c, http.StatusBadRequest, v2.ErrUnsupported) + jsonAPIError(c, http.StatusBadRequest, toml.ErrUnsupported) return } diff --git a/core/web/log_controller_test.go b/core/web/log_controller_test.go index 687eefe8945..7a427bcb8ea 100644 --- a/core/web/log_controller_test.go +++ b/core/web/log_controller_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/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" @@ -34,7 +34,7 @@ func TestLogController_GetLogConfig(t *testing.T) { t.Parallel() cfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { - c.Log.Level = ptr(v2.LogLevel(zapcore.WarnLevel)) + c.Log.Level = ptr(toml.LogLevel(zapcore.WarnLevel)) c.Database.LogQueries = ptr(true) }) diff --git a/core/web/loop_registry.go b/core/web/loop_registry.go index d076eeb5186..4bbcef2b44a 100644 --- a/core/web/loop_registry.go +++ b/core/web/loop_registry.go @@ -13,7 +13,7 @@ import ( "github.com/prometheus/common/model" "github.com/prometheus/prometheus/discovery/targetgroup" - v2 "github.com/smartcontractkit/chainlink/v2/core/config/v2" + "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/plugins" @@ -112,7 +112,7 @@ func (l *LoopRegistryServer) pluginMetricHandler(gc *gin.Context) { func initHostNames() (discoveryHost, loopHost string) { var exists bool - discoveryHost, exists = v2.EnvPrometheusDiscoveryHostName.Lookup() + discoveryHost, exists = env.PrometheusDiscoveryHostName.Lookup() if !exists { var err error discoveryHost, err = os.Hostname() @@ -121,7 +121,7 @@ func initHostNames() (discoveryHost, loopHost string) { } } - loopHost, exists = v2.EnvLooppHostName.Lookup() + loopHost, exists = env.LOOPPHostName.Lookup() if !exists { // this is the expected case; no known uses for the env var other than // as an escape hatch. diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 18eaee08393..6f5a708622a 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -238,7 +238,6 @@ require ( github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect github.com/minio/sha256-simd v0.1.1 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect