Skip to content

Commit

Permalink
chore_: add a status proxy to the nodefleet rpc as a primary service …
Browse files Browse the repository at this point in the history
…provider

fixes #5901
  • Loading branch information
friofry committed Oct 2, 2024
1 parent 2c0178c commit 5af4e1b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
18 changes: 12 additions & 6 deletions api/default_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func mainnet(stageName string) params.Network {
return params.Network{
ChainID: mainnetChainID,
ChainName: "Mainnet",
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/mainnet/", stageName),
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/ethereum/mainnet/", stageName),
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/ethereum/mainnet/", stageName),
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/mainnet/", stageName),
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
FallbackURL: "https://mainnet.infura.io/v3/",
BlockExplorerURL: "https://etherscan.io/",
Expand Down Expand Up @@ -71,8 +72,9 @@ func sepolia(stageName string) params.Network {
return params.Network{
ChainID: sepoliaChainID,
ChainName: "Mainnet",
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/sepolia/", stageName),
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/ethereum/sepolia/", stageName),
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/ethereum/sepolia/", stageName),
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/sepolia/", stageName),
RPCURL: "https://sepolia-archival.rpc.grove.city/v1/",
FallbackURL: "https://sepolia.infura.io/v3/",
BlockExplorerURL: "https://sepolia.etherscan.io/",
Expand All @@ -93,8 +95,9 @@ func optimism(stageName string) params.Network {
return params.Network{
ChainID: optimismChainID,
ChainName: "Optimism",
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/grove/optimism/mainnet/", stageName),
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/optimism/mainnet/", stageName),
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/optimism/mainnet/", stageName),
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/optimism/mainnet/", stageName),
RPCURL: "https://optimism-archival.rpc.grove.city/v1/",
FallbackURL: "https://optimism-mainnet.infura.io/v3/",
BlockExplorerURL: "https://optimistic.etherscan.io",
Expand Down Expand Up @@ -135,8 +138,9 @@ func optimismSepolia(stageName string) params.Network {
return params.Network{
ChainID: optimismSepoliaChainID,
ChainName: "Optimism",
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/grove/optimism/sepolia/", stageName),
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/optimism/sepolia/", stageName),
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/optimism/sepolia/", stageName),
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/optimism/sepolia/", stageName),
RPCURL: "https://optimism-sepolia-archival.rpc.grove.city/v1/",
FallbackURL: "https://optimism-sepolia.infura.io/v3/",
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
Expand All @@ -157,8 +161,9 @@ func arbitrum(stageName string) params.Network {
return params.Network{
ChainID: arbitrumChainID,
ChainName: "Arbitrum",
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/mainnet/", stageName),
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/arbitrum/mainnet/", stageName),
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/arbitrum/mainnet/", stageName),
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/mainnet/", stageName),
RPCURL: "https://arbitrum-one.rpc.grove.city/v1/",
FallbackURL: "https://arbitrum-mainnet.infura.io/v3/",
BlockExplorerURL: "https://arbiscan.io/",
Expand Down Expand Up @@ -199,8 +204,9 @@ func arbitrumSepolia(stageName string) params.Network {
return params.Network{
ChainID: arbitrumSepoliaChainID,
ChainName: "Arbitrum",
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/sepolia/", stageName),
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/arbitrum/sepolia/", stageName),
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/arbitrum/sepolia/", stageName),
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/sepolia/", stageName),
RPCURL: "https://arbitrum-sepolia-archival.rpc.grove.city/v1/",
FallbackURL: "https://arbitrum-sepolia.infura.io/v3/",
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
Expand Down
6 changes: 6 additions & 0 deletions api/default_networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestBuildDefaultNetworks(t *testing.T) {
require.True(t, strings.Contains(actualNetworks[0].FallbackURL, infuraToken))
require.True(t, strings.Contains(actualNetworks[0].DefaultRPCURL, stageName))
require.True(t, strings.Contains(actualNetworks[0].DefaultFallbackURL, stageName))
require.True(t, strings.Contains(actualNetworks[0].DefaultFallbackURL2, stageName))

require.Equal(t, goerliChainID, actualNetworks[1].ChainID)

Expand All @@ -42,13 +43,15 @@ func TestBuildDefaultNetworks(t *testing.T) {
require.True(t, strings.Contains(actualNetworks[2].FallbackURL, infuraToken))
require.True(t, strings.Contains(actualNetworks[2].DefaultRPCURL, stageName))
require.True(t, strings.Contains(actualNetworks[2].DefaultFallbackURL, stageName))
require.True(t, strings.Contains(actualNetworks[2].DefaultFallbackURL2, stageName))

require.Equal(t, optimismChainID, actualNetworks[3].ChainID)

require.True(t, strings.Contains(actualNetworks[3].RPCURL, poktToken))
require.True(t, strings.Contains(actualNetworks[3].FallbackURL, infuraToken))
require.True(t, strings.Contains(actualNetworks[3].DefaultRPCURL, stageName))
require.True(t, strings.Contains(actualNetworks[3].DefaultFallbackURL, stageName))
require.True(t, strings.Contains(actualNetworks[3].DefaultFallbackURL2, stageName))

require.Equal(t, optimismGoerliChainID, actualNetworks[4].ChainID)

Expand All @@ -61,13 +64,15 @@ func TestBuildDefaultNetworks(t *testing.T) {
require.True(t, strings.Contains(actualNetworks[5].FallbackURL, infuraToken))
require.True(t, strings.Contains(actualNetworks[5].DefaultRPCURL, stageName))
require.True(t, strings.Contains(actualNetworks[5].DefaultFallbackURL, stageName))
require.True(t, strings.Contains(actualNetworks[5].DefaultFallbackURL2, stageName))

require.Equal(t, arbitrumChainID, actualNetworks[6].ChainID)

require.True(t, strings.Contains(actualNetworks[6].RPCURL, poktToken))
require.True(t, strings.Contains(actualNetworks[6].FallbackURL, infuraToken))
require.True(t, strings.Contains(actualNetworks[6].DefaultRPCURL, stageName))
require.True(t, strings.Contains(actualNetworks[6].DefaultFallbackURL, stageName))
require.True(t, strings.Contains(actualNetworks[6].DefaultFallbackURL2, stageName))

require.Equal(t, arbitrumGoerliChainID, actualNetworks[7].ChainID)

Expand All @@ -80,6 +85,7 @@ func TestBuildDefaultNetworks(t *testing.T) {
require.True(t, strings.Contains(actualNetworks[8].FallbackURL, infuraToken))
require.True(t, strings.Contains(actualNetworks[8].DefaultRPCURL, stageName))
require.True(t, strings.Contains(actualNetworks[8].DefaultFallbackURL, stageName))
require.True(t, strings.Contains(actualNetworks[8].DefaultFallbackURL2, stageName))

}

Expand Down
5 changes: 3 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,9 @@ type TokenOverride struct {
type Network struct {
ChainID uint64 `json:"chainId"`
ChainName string `json:"chainName"`
DefaultRPCURL string `json:"defaultRpcUrl"` // proxy rpc url
DefaultFallbackURL string `json:"defaultFallbackURL"` // proxy fallback url
DefaultRPCURL string `json:"defaultRpcUrl"` // proxy rpc url
DefaultFallbackURL string `json:"defaultFallbackURL"` // proxy fallback url
DefaultFallbackURL2 string `json:"defaultFallbackURL2"` // second proxy fallback url
RPCURL string `json:"rpcUrl"`
OriginalRPCURL string `json:"originalRpcUrl"`
FallbackURL string `json:"fallbackURL"`
Expand Down
5 changes: 4 additions & 1 deletion rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,14 @@ func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEt
if proxyProvider.Enabled {
key := ProviderStatusProxy
keyFallback := ProviderStatusProxy + "-fallback"
keyFallback2 := ProviderStatusProxy + "-fallback2"
urls[key] = network.DefaultRPCURL
urls[keyFallback] = network.DefaultFallbackURL
keys = []string{key, keyFallback}
urls[keyFallback2] = network.DefaultFallbackURL2
keys = []string{key, keyFallback, keyFallback2}
authMap[key] = proxyProvider.User + ":" + proxyProvider.Password
authMap[keyFallback] = authMap[key]
authMap[keyFallback2] = authMap[key]
}
keys = append(keys, []string{"main", "fallback"}...)
urls["main"] = network.RPCURL
Expand Down
27 changes: 14 additions & 13 deletions rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,41 +151,42 @@ func TestGetClientsUsingCache(t *testing.T) {
providerConfigs := []params.ProviderConfig{providerConfig}

var wg sync.WaitGroup
wg.Add(2) // 2 providers
wg.Add(3) // 3 providers

// Create a new ServeMux
mux := http.NewServeMux()

path1 := "/foo"
path2 := "/bar"
// Register handlers for different URL paths
mux.HandleFunc(path1, func(w http.ResponseWriter, r *http.Request) {
authToken := base64.StdEncoding.EncodeToString([]byte(providerConfig.User + ":" + providerConfig.Password))
require.Equal(t, fmt.Sprintf("Basic %s", authToken), r.Header.Get("Authorization"))
wg.Done()
})
path3 := "/baz"

mux.HandleFunc(path2, func(w http.ResponseWriter, r *http.Request) {
authHandler := func(w http.ResponseWriter, r *http.Request) {
authToken := base64.StdEncoding.EncodeToString([]byte(providerConfig.User + ":" + providerConfig.Password))
require.Equal(t, fmt.Sprintf("Basic %s", authToken), r.Header.Get("Authorization"))
wg.Done()
})
}

// Register handlers for different URL paths
mux.HandleFunc(path1, authHandler)
mux.HandleFunc(path2, authHandler)
mux.HandleFunc(path3, authHandler)

// Create a new server with the mux as the handler
server := httptest.NewServer(mux)
defer server.Close()

networks := []params.Network{
{
ChainID: 1,
DefaultRPCURL: server.URL + path1,
DefaultFallbackURL: server.URL + path2,
ChainID: 1,
DefaultRPCURL: server.URL + path1,
DefaultFallbackURL: server.URL + path2,
DefaultFallbackURL2: server.URL + path3,
},
}
c, err := NewClient(nil, 1, params.UpstreamRPCConfig{}, networks, db, providerConfigs)
require.NoError(t, err)

// Networks from DB must pick up DefaultRPCURL and DefaultFallbackURL
// Networks from DB must pick up DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2
chainClient, err := c.getClientUsingCache(networks[0].ChainID)
require.NoError(t, err)
require.NotNil(t, chainClient)
Expand Down
1 change: 1 addition & 0 deletions rpc/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ func findNetwork(networks []params.Network, chainID uint64) (params.Network, err
func addDefaultRPCURL(target *params.Network, source params.Network) {
target.DefaultRPCURL = source.DefaultRPCURL
target.DefaultFallbackURL = source.DefaultFallbackURL
target.DefaultFallbackURL2 = source.DefaultFallbackURL2
}

func setDefaultRPCURL(target []*params.Network, source []params.Network) {
Expand Down

0 comments on commit 5af4e1b

Please sign in to comment.