-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WS URL can be optional when LogBroadcaster is disabled #14364
Changes from 11 commits
b05a1a7
71c84c6
e99aae0
6737f0c
8df1659
e1fa795
7f59b07
48c7f1a
515888c
9ecc624
01e9e08
4b860a1
fdc5c8c
2660903
b3e270d
ba73ef6
5bec775
9a841ce
670ebb8
799dc6c
427a8a0
7738ff0
795ee7b
3b27171
d3f523c
a71015d
7908e2a
ae09d35
fe19568
cc05a3f
d7a7719
3e92077
d7af044
4d83e3f
d5dbade
e8901e7
2713252
8a71a49
85f56ca
774d025
5b3918d
691f0d1
971e300
7cf0ba5
4502d4d
5e9e9b7
615248b
e87e3c1
d689696
b267e7a
51c5d96
c5f6b90
4c81cac
e2d7a8e
580795e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"chainlink": minor | ||
--- | ||
|
||
Make websocket URL flag `WSURL` for `EVM.Nodes`, and apply logic so that: | ||
* If WS URL was not provided, SubscribeFilterLogs should fail with an explicit error | ||
* If WS URL was not provided LogBroadcaster should be disabled | ||
#internal | ||
jmank88 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
package client | ||||||
|
||||||
import ( | ||||||
"errors" | ||||||
"fmt" | ||||||
"net/url" | ||||||
"time" | ||||||
|
@@ -15,6 +16,8 @@ import ( | |||||
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" | ||||||
) | ||||||
|
||||||
var ErrLogBroadcasterEnabledWithoutWSURL = errors.New("logbroadcaster cannot be enabled unless all nodes have WSURL provided") | ||||||
|
||||||
type NodeConfig struct { | ||||||
Name *string | ||||||
WSURL *string | ||||||
|
@@ -43,12 +46,18 @@ func NewClientConfigs( | |||||
deathDeclarationDelay time.Duration, | ||||||
noNewFinalizedHeadsThreshold time.Duration, | ||||||
finalizedBlockPollInterval time.Duration, | ||||||
LogBroadcasterEnabled bool, | ||||||
|
||||||
) (commonclient.ChainConfig, evmconfig.NodePool, []*toml.Node, error) { | ||||||
nodes, err := parseNodeConfigs(nodeCfgs) | ||||||
if err != nil { | ||||||
return nil, nil, nil, err | ||||||
} | ||||||
|
||||||
if err = verifyLogBroadcasterFlag(nodes, LogBroadcasterEnabled); err != nil { | ||||||
return nil, nil, nil, err | ||||||
} | ||||||
|
||||||
nodePool := toml.NodePool{ | ||||||
SelectionMode: selectionMode, | ||||||
LeaseDuration: commonconfig.MustNewDuration(leaseDuration), | ||||||
|
@@ -76,18 +85,37 @@ func NewClientConfigs( | |||||
return chainConfig, nodePoolCfg, nodes, nil | ||||||
} | ||||||
|
||||||
// verifyLogBroadcasterFlag checks node config and return error if LogBroadcaster enabled but some node missing WSURL | ||||||
func verifyLogBroadcasterFlag(nodes []*toml.Node, LogBroadcasterEnabled bool) error { | ||||||
dhaidashenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if !LogBroadcasterEnabled { | ||||||
return nil | ||||||
} | ||||||
for _, node := range nodes { | ||||||
if node.WSURL == nil || node.WSURL.IsZero() { | ||||||
return ErrLogBroadcasterEnabledWithoutWSURL | ||||||
} | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
func parseNodeConfigs(nodeCfgs []NodeConfig) ([]*toml.Node, error) { | ||||||
nodes := make([]*toml.Node, len(nodeCfgs)) | ||||||
for i, nodeCfg := range nodeCfgs { | ||||||
if nodeCfg.WSURL == nil || nodeCfg.HTTPURL == nil { | ||||||
return nil, fmt.Errorf("node config [%d]: missing WS or HTTP URL", i) | ||||||
var wsURL, httpURL *commonconfig.URL | ||||||
// wsUrl is optional | ||||||
if nodeCfg.WSURL != nil { | ||||||
wsURL = commonconfig.MustParseURL(*nodeCfg.WSURL) | ||||||
} | ||||||
wsUrl := commonconfig.MustParseURL(*nodeCfg.WSURL) | ||||||
httpUrl := commonconfig.MustParseURL(*nodeCfg.HTTPURL) | ||||||
|
||||||
if nodeCfg.HTTPURL == nil { | ||||||
return nil, fmt.Errorf("node config [%d]: HTTP URL", i) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
httpURL = commonconfig.MustParseURL(*nodeCfg.HTTPURL) | ||||||
node := &toml.Node{ | ||||||
Name: nodeCfg.Name, | ||||||
WSURL: wsUrl, | ||||||
HTTPURL: httpUrl, | ||||||
WSURL: wsURL, | ||||||
HTTPURL: httpURL, | ||||||
SendOnly: nodeCfg.SendOnly, | ||||||
Order: nodeCfg.Order, | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ func NewEvmClient(cfg evmconfig.NodePool, chainCfg commonclient.ChainConfig, cli | |
var sendonlys []commonclient.SendOnlyNode[*big.Int, RPCClient] | ||
largePayloadRPCTimeout, defaultRPCTimeout := getRPCTimeouts(chainType) | ||
for i, node := range nodes { | ||
if node.SendOnly != nil && *node.SendOnly { | ||
if node.WSURL == nil || (node.SendOnly != nil && *node.SendOnly) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A secondary or SendOnly node has limited functionality. It's only used to broadcast transactions (fire and forget), and we are not running health checks for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the enforcement check to |
||
rpc := NewRPCClient(lggr, empty, (*url.URL)(node.HTTPURL), *node.Name, int32(i), chainID, | ||
commonclient.Secondary, cfg.FinalizedBlockPollInterval(), largePayloadRPCTimeout, defaultRPCTimeout, chainType) | ||
sendonly := commonclient.NewSendOnlyNode(lggr, (url.URL)(*node.HTTPURL), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.