From 7de2670f54bfeb134da2ce3789a6034b69ad2a94 Mon Sep 17 00:00:00 2001 From: Andrey Bocharnikov Date: Tue, 14 Jan 2025 14:28:48 +0400 Subject: [PATCH] fix_: issue from the PR --- api/default_networks.go | 72 ++++++++++++--------- api/default_networks_test.go | 13 ++-- params/network_config.go | 9 +++ params/networkhelper/provider_utils.go | 11 +--- params/networkhelper/provider_utils_test.go | 2 +- rpc/client.go | 41 +++++++++--- rpc/network/network.go | 2 +- 7 files changed, 94 insertions(+), 56 deletions(-) diff --git a/api/default_networks.go b/api/default_networks.go index dd4d91ed9..74651eab2 100644 --- a/api/default_networks.go +++ b/api/default_networks.go @@ -17,6 +17,14 @@ const ( ArbitrumSepoliaChainID uint64 = 421614 sntSymbol = "SNT" sttSymbol = "STT" + proxyNodefleet = "proxy-nodefleet" + proxyInfura = "proxy-infura" + proxyGrove = "proxy-grove" + nodefleet = "nodefleet" + infura = "infura" + grove = "grove" + directInfura = "direct-infura" + directGrove = "direct-grove" ) func proxyUrl(stageName, provider, chainName, networkName string) string { @@ -30,12 +38,12 @@ func mainnet(stageName string) params.Network { rpcProviders := []params.RpcProvider{ // Proxy providers - *params.NewProxyProvider(chainID, "proxy-nodefleet", proxyUrl(stageName, "nodefleet", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-infura", proxyUrl(stageName, "infura", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-grove", proxyUrl(stageName, "grove", chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyNodefleet, proxyUrl(stageName, nodefleet, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyInfura, proxyUrl(stageName, infura, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyGrove, proxyUrl(stageName, grove, chainName, networkName), false), // Direct providers - *params.NewDirectProvider(chainID, "direct-infura", "https://mainnet.infura.io/v3/", true), - *params.NewDirectProvider(chainID, "direct-grove", "https://eth-archival.rpc.grove.city/v1/", false), + *params.NewDirectProvider(chainID, directInfura, "https://mainnet.infura.io/v3/", true), + *params.NewDirectProvider(chainID, directGrove, "https://eth-archival.rpc.grove.city/v1/", false), } return params.Network{ @@ -63,12 +71,12 @@ func sepolia(stageName string) params.Network { rpcProviders := []params.RpcProvider{ // Proxy providers - *params.NewProxyProvider(chainID, "proxy-nodefleet", proxyUrl(stageName, "nodefleet", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-infura", proxyUrl(stageName, "infura", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-grove", proxyUrl(stageName, "grove", chainName, networkName), true), + *params.NewProxyProvider(chainID, proxyNodefleet, proxyUrl(stageName, nodefleet, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyInfura, proxyUrl(stageName, infura, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyGrove, proxyUrl(stageName, grove, chainName, networkName), true), // Direct providers - *params.NewDirectProvider(chainID, "direct-infura", "https://sepolia.infura.io/v3/", true), - *params.NewDirectProvider(chainID, "direct-grove", "https://sepolia-archival.rpc.grove.city/v1/", false), + *params.NewDirectProvider(chainID, directInfura, "https://sepolia.infura.io/v3/", true), + *params.NewDirectProvider(chainID, directGrove, "https://sepolia-archival.rpc.grove.city/v1/", false), } return params.Network{ @@ -88,6 +96,7 @@ func sepolia(stageName string) params.Network { RelatedChainID: MainnetChainID, } } + func optimism(stageName string) params.Network { chainID := OptimismChainID chainName := "optimism" @@ -95,12 +104,12 @@ func optimism(stageName string) params.Network { rpcProviders := []params.RpcProvider{ // Proxy providers - *params.NewProxyProvider(chainID, "proxy-nodefleet", proxyUrl(stageName, "nodefleet", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-infura", proxyUrl(stageName, "infura", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-grove", proxyUrl(stageName, "grove", chainName, networkName), true), + *params.NewProxyProvider(chainID, proxyNodefleet, proxyUrl(stageName, nodefleet, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyInfura, proxyUrl(stageName, infura, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyGrove, proxyUrl(stageName, grove, chainName, networkName), true), // Direct providers - *params.NewDirectProvider(chainID, "direct-infura", "https://optimism-mainnet.infura.io/v3/", true), - *params.NewDirectProvider(chainID, "direct-grove", "https://optimism-archival.rpc.grove.city/v1/", false), + *params.NewDirectProvider(chainID, directInfura, "https://optimism-mainnet.infura.io/v3/", true), + *params.NewDirectProvider(chainID, directGrove, "https://optimism-archival.rpc.grove.city/v1/", false), } return params.Network{ @@ -120,6 +129,7 @@ func optimism(stageName string) params.Network { RelatedChainID: OptimismSepoliaChainID, } } + func optimismSepolia(stageName string) params.Network { chainID := OptimismSepoliaChainID chainName := "optimism" @@ -127,12 +137,12 @@ func optimismSepolia(stageName string) params.Network { rpcProviders := []params.RpcProvider{ // Proxy providers - *params.NewProxyProvider(chainID, "proxy-nodefleet", proxyUrl(stageName, "nodefleet", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-infura", proxyUrl(stageName, "infura", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-grove", proxyUrl(stageName, "grove", chainName, networkName), true), + *params.NewProxyProvider(chainID, proxyNodefleet, proxyUrl(stageName, nodefleet, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyInfura, proxyUrl(stageName, infura, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyGrove, proxyUrl(stageName, grove, chainName, networkName), true), // Direct providers - *params.NewDirectProvider(chainID, "direct-infura", "https://optimism-sepolia.infura.io/v3/", true), - *params.NewDirectProvider(chainID, "direct-grove", "https://optimism-sepolia-archival.rpc.grove.city/v1/", false), + *params.NewDirectProvider(chainID, directInfura, "https://optimism-sepolia.infura.io/v3/", true), + *params.NewDirectProvider(chainID, directGrove, "https://optimism-sepolia-archival.rpc.grove.city/v1/", false), } return params.Network{ @@ -152,6 +162,7 @@ func optimismSepolia(stageName string) params.Network { RelatedChainID: OptimismChainID, } } + func arbitrum(stageName string) params.Network { chainID := ArbitrumChainID chainName := "arbitrum" @@ -159,12 +170,12 @@ func arbitrum(stageName string) params.Network { rpcProviders := []params.RpcProvider{ // Proxy providers - *params.NewProxyProvider(chainID, "proxy-nodefleet", proxyUrl(stageName, "nodefleet", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-infura", proxyUrl(stageName, "infura", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-grove", proxyUrl(stageName, "grove", chainName, networkName), true), + *params.NewProxyProvider(chainID, proxyNodefleet, proxyUrl(stageName, nodefleet, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyInfura, proxyUrl(stageName, infura, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyGrove, proxyUrl(stageName, grove, chainName, networkName), true), // Direct providers - *params.NewDirectProvider(chainID, "direct-infura", "https://arbitrum-mainnet.infura.io/v3/", true), - *params.NewDirectProvider(chainID, "direct-grove", "https://arbitrum-one.rpc.grove.city/v1/", false), + *params.NewDirectProvider(chainID, directInfura, "https://arbitrum-mainnet.infura.io/v3/", true), + *params.NewDirectProvider(chainID, directGrove, "https://arbitrum-one.rpc.grove.city/v1/", false), } return params.Network{ @@ -184,6 +195,7 @@ func arbitrum(stageName string) params.Network { RelatedChainID: ArbitrumSepoliaChainID, } } + func arbitrumSepolia(stageName string) params.Network { chainID := ArbitrumSepoliaChainID chainName := "arbitrum" @@ -191,12 +203,12 @@ func arbitrumSepolia(stageName string) params.Network { rpcProviders := []params.RpcProvider{ // Proxy providers - *params.NewProxyProvider(chainID, "proxy-nodefleet", proxyUrl(stageName, "nodefleet", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-infura", proxyUrl(stageName, "infura", chainName, networkName), false), - *params.NewProxyProvider(chainID, "proxy-grove", proxyUrl(stageName, "grove", chainName, networkName), true), + *params.NewProxyProvider(chainID, proxyNodefleet, proxyUrl(stageName, nodefleet, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyInfura, proxyUrl(stageName, infura, chainName, networkName), false), + *params.NewProxyProvider(chainID, proxyGrove, proxyUrl(stageName, grove, chainName, networkName), true), // Direct providers - *params.NewDirectProvider(chainID, "direct-infura", "https://arbitrum-sepolia.infura.io/v3/", true), - *params.NewDirectProvider(chainID, "direct-grove", "https://arbitrum-sepolia-archival.rpc.grove.city/v1/", false), + *params.NewDirectProvider(chainID, directInfura, "https://arbitrum-sepolia.infura.io/v3/", true), + *params.NewDirectProvider(chainID, directGrove, "https://arbitrum-sepolia-archival.rpc.grove.city/v1/", false), } return params.Network{ diff --git a/api/default_networks_test.go b/api/default_networks_test.go index e10e5b56d..3da8e21a4 100644 --- a/api/default_networks_test.go +++ b/api/default_networks_test.go @@ -63,12 +63,13 @@ func TestBuildDefaultNetworks(t *testing.T) { // Check direct providers for tokens for _, provider := range n.RpcProviders { - if provider.Type == params.EmbeddedDirectProviderType { - if strings.Contains(provider.URL, "infura.io") { - require.Equal(t, provider.AuthToken, infuraToken, "Direct provider URL should have infuraToken") - } else if strings.Contains(provider.URL, "grove.city") { - require.Equal(t, provider.AuthToken, poktToken, "Direct provider URL should have poktToken") - } + if provider.Type != params.EmbeddedDirectProviderType { + continue + } + if strings.Contains(provider.URL, "infura.io") { + require.Equal(t, provider.AuthToken, infuraToken, "Direct provider URL should have infuraToken") + } else if strings.Contains(provider.URL, "grove.city") { + require.Equal(t, provider.AuthToken, poktToken, "Direct provider URL should have poktToken") } } } diff --git a/params/network_config.go b/params/network_config.go index d9c9ad600..d27d3a0da 100644 --- a/params/network_config.go +++ b/params/network_config.go @@ -70,6 +70,15 @@ type Network struct { RelatedChainID uint64 `json:"relatedChainId" validate:"omitempty"` } +func (n *Network) DeepCopy() Network { + updatedNetwork := *n + updatedNetwork.RpcProviders = make([]RpcProvider, len(n.RpcProviders)) + copy(updatedNetwork.RpcProviders, n.RpcProviders) + updatedNetwork.TokenOverrides = make([]TokenOverride, len(n.TokenOverrides)) + copy(updatedNetwork.TokenOverrides, n.TokenOverrides) + return updatedNetwork +} + func newRpcProvider(chainID uint64, name, url string, enableRpsLimiter bool, providerType RpcProviderType) *RpcProvider { return &RpcProvider{ ChainID: chainID, diff --git a/params/networkhelper/provider_utils.go b/params/networkhelper/provider_utils.go index da6897868..1463d2568 100644 --- a/params/networkhelper/provider_utils.go +++ b/params/networkhelper/provider_utils.go @@ -118,19 +118,10 @@ func OverrideEmbeddedProxyProviders(networks []params.Network, enabled bool, use return updatedNetworks } -func DeepCopyNetwork(network params.Network) params.Network { - updatedNetwork := network - updatedNetwork.RpcProviders = make([]params.RpcProvider, len(network.RpcProviders)) - copy(updatedNetwork.RpcProviders, network.RpcProviders) - updatedNetwork.TokenOverrides = make([]params.TokenOverride, len(network.TokenOverrides)) - copy(updatedNetwork.TokenOverrides, network.TokenOverrides) - return updatedNetwork -} - func DeepCopyNetworks(networks []params.Network) []params.Network { updatedNetworks := make([]params.Network, len(networks)) for i, network := range networks { - updatedNetworks[i] = DeepCopyNetwork(network) + updatedNetworks[i] = network.DeepCopy() } return updatedNetworks } diff --git a/params/networkhelper/provider_utils_test.go b/params/networkhelper/provider_utils_test.go index 80f049405..1a9eac411 100644 --- a/params/networkhelper/provider_utils_test.go +++ b/params/networkhelper/provider_utils_test.go @@ -154,7 +154,7 @@ func TestDeepCopyNetwork(t *testing.T) { {Symbol: "token1", Address: common.HexToAddress("0x123")}, } - copiedNetwork := networkhelper.DeepCopyNetwork(*originalNetwork) + copiedNetwork := originalNetwork.DeepCopy() assert.True(t, reflect.DeepEqual(originalNetwork, &copiedNetwork), "Copied network should be deeply equal to the original") diff --git a/rpc/client.go b/rpc/client.go index 1c6e71035..7f60e6769 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -297,18 +297,43 @@ func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEt headers.Set("User-Agent", rpcUserAgentName) // Set up authentication if needed - if provider.AuthType != params.NoAuth { - switch provider.AuthType { - case params.BasicAuth: - authEncoded := base64.StdEncoding.EncodeToString([]byte(provider.AuthLogin + ":" + provider.AuthPassword)) - headers.Set("Authorization", "Basic "+authEncoded) - case params.TokenAuth: - provider.URL = provider.URL + provider.AuthToken - } + switch provider.AuthType { + case params.BasicAuth: + authEncoded := base64.StdEncoding.EncodeToString([]byte(provider.AuthLogin + ":" + provider.AuthPassword)) + headers.Set("Authorization", "Basic "+authEncoded) + case params.TokenAuth: + provider.URL = provider.URL + provider.AuthToken + case params.NoAuth: + // no-op + default: + c.logger.Error("unknown auth type", zap.String("auth_type", string(provider.AuthType))) } opts = append(opts, gethrpc.WithHeaders(headers)) + // print provider details: + c.logger.Info("RPC provider", + zap.String("name", provider.Name), + zap.String("url", provider.URL), + zap.Bool("enabled", provider.Enabled), + zap.Bool("rps_limiter", provider.EnableRPSLimiter), + // token + zap.String("auth_login", provider.AuthLogin), + zap.String("auth_password", provider.AuthPassword), + zap.String("auth_token", provider.AuthToken), + ) + // print the same with fmt.println + fmt.Println("RPC provider", + "name", provider.Name, + "url", provider.URL, + "enabled", provider.Enabled, + "rps_limiter", provider.EnableRPSLimiter, + // token + "auth_login", provider.AuthLogin, + "auth_password", provider.AuthPassword, + "auth_token", provider.AuthToken, + ) + // Dial the RPC client rpcClient, err := gethrpc.DialOptions(context.Background(), provider.URL, opts...) if err != nil { diff --git a/rpc/network/network.go b/rpc/network/network.go index 5cddb3598..ee8e302b9 100644 --- a/rpc/network/network.go +++ b/rpc/network/network.go @@ -138,7 +138,7 @@ func (nm *Manager) setEmbeddedProviders(networks []*params.Network) { // networkWithoutEmbeddedProviders returns a copy of the given network without embedded RPC providers. func (nm *Manager) networkWithoutEmbeddedProviders(network *params.Network) *params.Network { - networkCopy := networkhelper.DeepCopyNetwork(*network) + networkCopy := network.DeepCopy() networkCopy.RpcProviders = networkhelper.GetUserProviders(network.RpcProviders) return &networkCopy }