Skip to content

Commit ed3d782

Browse files
committed
Simplify
1 parent fce87d3 commit ed3d782

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

lib/config/network.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ type NetworkConfig struct {
4444
// RpcWsUrls is the RPC WS endpoints for each network,
4545
// key is the network name as declared in selected_networks slice
4646
RpcWsUrls map[string][]string `toml:"RpcWsUrls,omitempty"`
47-
// ForceHttp, if true, skips validation of WS endpoints, requiring only HTTP endpoints
48-
ForceHttp bool `toml:"force_http,omitempty"`
4947
// WalletKeys is the private keys for the funding wallets for each network,
5048
// key is the network name as declared in selected_networks slice
5149
WalletKeys map[string][]string `toml:"WalletKeys,omitempty"`
@@ -144,14 +142,9 @@ func (n *NetworkConfig) Validate() error {
144142
}
145143
}
146144
// if the network is not forked, we need to validate RPC endpoints and private keys
147-
if _, ok := n.RpcHttpUrls[network]; !ok {
148-
return fmt.Errorf("at least one HTTP RPC endpoint for %s network must be set", network)
149-
}
150-
151-
// Conditionally skip the WebSocket URL check if forceHttp is set to true
152-
if !n.ForceHttp {
153-
if _, ok := n.RpcWsUrls[network]; !ok {
154-
return fmt.Errorf("at least one WS RPC endpoint for %s network must be set", network)
145+
if _, httpOk := n.RpcHttpUrls[network]; !httpOk {
146+
if _, wsOk := n.RpcWsUrls[network]; !wsOk {
147+
return fmt.Errorf("at least one HTTP or WS RPC endpoint for %s network must be set", network)
155148
}
156149
}
157150

lib/networks/known_networks.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,17 +1104,15 @@ func SetNetworks(networkCfg config.NetworkConfig) ([]blockchain.EVMNetwork, erro
11041104
// if network is not simulated or forked, use the rpc urls and wallet keys from config
11051105
if !strings.Contains(networkName, "SIMULATED") && !forked {
11061106
var ok bool
1107-
// If we are forcinf htto but also have WSs available add them in case we need them
1108-
if !networkCfg.ForceHttp || (networkCfg.RpcWsUrls[selectedNetworks[i]] != nil && len(networkCfg.RpcWsUrls[selectedNetworks[i]]) > 0) {
1109-
wsUrls, ok = networkCfg.RpcWsUrls[selectedNetworks[i]]
1110-
if !ok {
1111-
return nil, fmt.Errorf("no rpc ws urls found in config for '%s' network", selectedNetworks[i])
1112-
}
1113-
}
1114-
1115-
httpUrls, ok = networkCfg.RpcHttpUrls[selectedNetworks[i]]
1116-
if !ok {
1117-
return nil, fmt.Errorf("no rpc http urls found in config for '%s' network", selectedNetworks[i])
1107+
var wsOk, httpOk bool
1108+
// Check for WS URLs
1109+
wsUrls, wsOk = networkCfg.RpcWsUrls[selectedNetworks[i]]
1110+
// Check for HTTP URLs
1111+
httpUrls, httpOk = networkCfg.RpcHttpUrls[selectedNetworks[i]]
1112+
1113+
// Ensure at least one of WS or HTTP URLs is available
1114+
if !wsOk && !httpOk {
1115+
return nil, fmt.Errorf("no RPC URLs found for '%s' network; at least one HTTP or WS RPC URL must be set", selectedNetworks[i])
11181116
}
11191117

11201118
walletKeys, ok = networkCfg.WalletKeys[selectedNetworks[i]]

lib/networks/known_networks_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func TestNewEVMNetwork(t *testing.T) {
5555
require.Equal(t, httpUrls, network.HTTPURLs)
5656
require.Equal(t, wsUrls, network.URLs)
5757
require.Equal(t, walletKeys, network.PrivateKeys)
58-
require.Equal(t, walletKeys, network.PrivateKeys)
5958
})
6059
}
6160

lib/utils/seth/seth.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ func MergeSethAndEvmNetworkConfigs(evmNetwork blockchain.EVMNetwork, sethConfig
152152
mergeSimulatedNetworks := func(evmNetwork blockchain.EVMNetwork, sethNetwork pkg_seth.Network) *pkg_seth.Network {
153153
sethNetwork.PrivateKeys = evmNetwork.PrivateKeys
154154
if len(sethNetwork.URLs) == 0 {
155-
sethNetwork.URLs = evmNetwork.URLs
155+
if len(evmNetwork.URLs) > 0 {
156+
sethNetwork.URLs = evmNetwork.URLs
157+
} else {
158+
sethNetwork.URLs = evmNetwork.HTTPURLs
159+
}
156160
}
157161
// important since Besu doesn't support EIP-1559, but other EVM clients do
158162
sethNetwork.EIP1559DynamicFees = evmNetwork.SupportsEIP1559
@@ -174,11 +178,12 @@ func MergeSethAndEvmNetworkConfigs(evmNetwork blockchain.EVMNetwork, sethConfig
174178
break
175179
} else if isSameNetwork(conf, evmNetwork) {
176180
conf.PrivateKeys = evmNetwork.PrivateKeys
177-
if sethConfig.ForceHTTP {
178-
conf.URLs = evmNetwork.HTTPURLs
179-
}
180181
if len(conf.URLs) == 0 {
181-
conf.URLs = evmNetwork.URLs
182+
if len(evmNetwork.URLs) > 0 {
183+
conf.URLs = evmNetwork.URLs
184+
} else {
185+
conf.URLs = evmNetwork.HTTPURLs
186+
}
182187
}
183188

184189
sethNetwork = conf

0 commit comments

Comments
 (0)