Skip to content

Commit

Permalink
Config validation requires ws url when http polling disabled (#14929)
Browse files Browse the repository at this point in the history
* add test

* add more test

* add changeset
  • Loading branch information
huangzhen1997 authored Oct 24, 2024
1 parent c1a39eb commit da5910e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-kangaroos-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Add config validation so it requires ws url when http polling disabled #bugfix
17 changes: 14 additions & 3 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,31 @@ func (c *EVMConfig) ValidateConfig() (err error) {
} else {
var hasPrimary bool
var logBroadcasterEnabled bool
var newHeadsPollingInterval commonconfig.Duration
if c.LogBroadcasterEnabled != nil {
logBroadcasterEnabled = *c.LogBroadcasterEnabled
}

if c.NodePool.NewHeadsPollInterval != nil {
newHeadsPollingInterval = *c.NodePool.NewHeadsPollInterval
}

for i, n := range c.Nodes {
if n.SendOnly != nil && *n.SendOnly {
continue
}

hasPrimary = true

// if the node is a primary node, then the WS URL is required when LogBroadcaster is enabled
if logBroadcasterEnabled && (n.WSURL == nil || n.WSURL.IsZero()) {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: fmt.Sprintf("%vth node (primary) must have a valid WSURL when LogBroadcaster is enabled", i)})
// if the node is a primary node, then the WS URL is required when
// 1. LogBroadcaster is enabled
// 2. The http polling is disabled (newHeadsPollingInterval == 0)
if n.WSURL == nil || n.WSURL.IsZero() {
if logBroadcasterEnabled {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: fmt.Sprintf("%vth node (primary) must have a valid WSURL when LogBroadcaster is enabled", i)})
} else if newHeadsPollingInterval.Duration() == 0 {
err = multierr.Append(err, commonconfig.ErrMissing{Name: "Nodes", Msg: fmt.Sprintf("%vth node (primary) must have a valid WSURL when http polling is disabled", i)})
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ func TestConfig_Validate(t *testing.T) {
- LDAP.RunUserGroupCN: invalid value (<nil>): LDAP ReadUserGroupCN can not be empty
- LDAP.RunUserGroupCN: invalid value (<nil>): LDAP RunUserGroupCN can not be empty
- LDAP.ReadUserGroupCN: invalid value (<nil>): LDAP ReadUserGroupCN can not be empty
- EVM: 9 errors:
- EVM: 10 errors:
- 1.ChainID: invalid value (1): duplicate - must be unique
- 0.Nodes.1.Name: invalid value (foo): duplicate - must be unique
- 3.Nodes.4.WSURL: invalid value (ws://dupe.com): duplicate - must be unique
Expand Down Expand Up @@ -1483,6 +1483,7 @@ func TestConfig_Validate(t *testing.T) {
- ChainID: missing: required for all chains
- Nodes: missing: must have at least one node
- 5.Transactions.AutoPurge.DetectionApiUrl: invalid value (): must be set for scroll
- 6.Nodes: missing: 0th node (primary) must have a valid WSURL when http polling is disabled
- Cosmos: 5 errors:
- 1.ChainID: invalid value (Malaga-420): duplicate - must be unique
- 0.Nodes.1.Name: invalid value (test): duplicate - must be unique
Expand Down
19 changes: 19 additions & 0 deletions core/services/chainlink/testdata/config-invalid.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ Name = 'scroll node'
WSURL = 'ws://foo.bar'
HTTPURl = 'http://foo.bar'

[[EVM]]
ChainID = '100'
LogBroadcasterEnabled = false

[[EVM.Nodes]]
Name = 'failing-fake'
HTTPURl = 'http://foo.bar1'

[[EVM]]
ChainID = '101'
LogBroadcasterEnabled = false

[EVM.NodePool]
NewHeadsPollInterval = '1s'

[[EVM.Nodes]]
Name = 'passing-fake'
HTTPURl = 'http://foo.bar2'

[[Cosmos]]
ChainID = 'Malaga-420'

Expand Down

0 comments on commit da5910e

Please sign in to comment.