chore_: providers re-ordered
A new order of using providers is: 1. StatusProxy - Node Fleet 2. StatusProxy - Infura 3. Direct Infura 4. StatusProxy - Grove 5. Direct Grove
This commit is contained in:
parent
fadce938e4
commit
93e88d9774
|
@ -17,7 +17,7 @@ func TestCreateAccountAndLogin(t *testing.T) {
|
|||
|
||||
requestJSONTemplateString := `
|
||||
{
|
||||
"upstreamConfig":"https://eth-archival.rpc.grove.city/v1/3ef2018191814b7e1009b8d9",
|
||||
"upstreamConfig":"",
|
||||
"openseaAPIKey":"",
|
||||
"wakuV2Nameserver":"1.1.1.1",
|
||||
"mnemonic":null,
|
||||
|
@ -31,9 +31,9 @@ func TestCreateAccountAndLogin(t *testing.T) {
|
|||
"customizationColor":"blue",
|
||||
"emoji": "some",
|
||||
"previewPrivacy":true,
|
||||
"verifyTransactionURL":"https://eth-archival.rpc.grove.city/v1/3ef2018191814b7e1009b8d9",
|
||||
"verifyTransactionURL":"",
|
||||
"imagePath":null,
|
||||
"verifyENSURL":"https://eth-archival.rpc.grove.city/v1/3ef2018191814b7e1009b8d9",
|
||||
"verifyENSURL":"",
|
||||
"logLevel":"INFO",
|
||||
"logFilePath":"%s",
|
||||
"networkId":1
|
||||
|
|
|
@ -32,8 +32,8 @@ func mainnet(stageName string) params.Network {
|
|||
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/",
|
||||
RPCURL: "https://mainnet.infura.io/v3/",
|
||||
FallbackURL: "https://eth-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://etherscan.io/",
|
||||
IconURL: "network/Network=Ethereum",
|
||||
ChainColor: "#627EEA",
|
||||
|
@ -75,8 +75,8 @@ func sepolia(stageName string) params.Network {
|
|||
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/",
|
||||
RPCURL: "https://sepolia.infura.io/v3/",
|
||||
FallbackURL: "https://sepolia-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://sepolia.etherscan.io/",
|
||||
IconURL: "network/Network=Ethereum",
|
||||
ChainColor: "#627EEA",
|
||||
|
@ -98,8 +98,8 @@ func optimism(stageName string) params.Network {
|
|||
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/",
|
||||
RPCURL: "https://optimism-mainnet.infura.io/v3/",
|
||||
FallbackURL: "https://optimism-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://optimistic.etherscan.io",
|
||||
IconURL: "network/Network=Optimism",
|
||||
ChainColor: "#E90101",
|
||||
|
@ -141,8 +141,8 @@ func optimismSepolia(stageName string) params.Network {
|
|||
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/",
|
||||
RPCURL: "https://optimism-sepolia.infura.io/v3/",
|
||||
FallbackURL: "https://optimism-sepolia-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
|
||||
IconURL: "network/Network=Optimism",
|
||||
ChainColor: "#E90101",
|
||||
|
@ -164,8 +164,8 @@ func arbitrum(stageName string) params.Network {
|
|||
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/",
|
||||
RPCURL: "https://arbitrum-mainnet.infura.io/v3/",
|
||||
FallbackURL: "https://arbitrum-one.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://arbiscan.io/",
|
||||
IconURL: "network/Network=Arbitrum",
|
||||
ChainColor: "#51D0F0",
|
||||
|
@ -207,8 +207,8 @@ func arbitrumSepolia(stageName string) params.Network {
|
|||
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/",
|
||||
RPCURL: "https://arbitrum-sepolia.infura.io/v3/",
|
||||
FallbackURL: "https://arbitrum-sepolia-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
|
||||
IconURL: "network/Network=Arbitrum",
|
||||
ChainColor: "#51D0F0",
|
||||
|
@ -251,38 +251,35 @@ func setRPCs(networks []params.Network, request *requests.WalletSecretsConfig) [
|
|||
|
||||
var networksWithRPC []params.Network
|
||||
|
||||
const (
|
||||
infura = "infura.io/"
|
||||
grove = "grove.city/"
|
||||
)
|
||||
|
||||
appendToken := func(url string) string {
|
||||
if strings.Contains(url, infura) && request.InfuraToken != "" {
|
||||
return url + request.InfuraToken
|
||||
} else if strings.Contains(url, grove) && request.PoktToken != "" {
|
||||
return url + request.PoktToken
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
for _, n := range networks {
|
||||
|
||||
if request.InfuraToken != "" {
|
||||
if strings.Contains(n.RPCURL, "infura") {
|
||||
n.RPCURL += request.InfuraToken
|
||||
}
|
||||
if strings.Contains(n.FallbackURL, "infura") {
|
||||
n.FallbackURL += request.InfuraToken
|
||||
}
|
||||
}
|
||||
|
||||
if request.PoktToken != "" {
|
||||
if strings.Contains(n.RPCURL, "grove") {
|
||||
n.RPCURL += request.PoktToken
|
||||
}
|
||||
if strings.Contains(n.FallbackURL, "grove") {
|
||||
n.FallbackURL += request.PoktToken
|
||||
}
|
||||
|
||||
}
|
||||
n.DefaultRPCURL = appendToken(n.DefaultRPCURL)
|
||||
n.DefaultFallbackURL = appendToken(n.DefaultFallbackURL)
|
||||
n.DefaultFallbackURL2 = appendToken(n.DefaultFallbackURL2)
|
||||
n.RPCURL = appendToken(n.RPCURL)
|
||||
n.FallbackURL = appendToken(n.FallbackURL)
|
||||
|
||||
if request.GanacheURL != "" {
|
||||
n.RPCURL = request.GanacheURL
|
||||
n.FallbackURL = request.GanacheURL
|
||||
if n.ChainID == mainnetChainID {
|
||||
n.TokenOverrides = []params.TokenOverride{
|
||||
mainnetGanacheTokenOverrides,
|
||||
}
|
||||
} else if n.ChainID == goerliChainID {
|
||||
n.TokenOverrides = []params.TokenOverride{
|
||||
goerliGanacheTokenOverrides,
|
||||
}
|
||||
switch n.ChainID {
|
||||
case mainnetChainID:
|
||||
n.TokenOverrides = []params.TokenOverride{mainnetGanacheTokenOverrides}
|
||||
case goerliChainID:
|
||||
n.TokenOverrides = []params.TokenOverride{goerliGanacheTokenOverrides}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/status-im/status-go/protocol/requests"
|
||||
)
|
||||
|
||||
func TestBuildDefaultNetworks(t *testing.T) {
|
||||
poktToken := "grove-token"
|
||||
infuraToken := "infura-token"
|
||||
rpcToken := "infura-token"
|
||||
fallbackToken := ""
|
||||
stageName := "fast-n-bulbous"
|
||||
request := &requests.CreateAccount{
|
||||
WalletSecretsConfig: requests.WalletSecretsConfig{
|
||||
PoktToken: poktToken,
|
||||
InfuraToken: infuraToken,
|
||||
InfuraToken: rpcToken,
|
||||
StatusProxyStageName: stageName,
|
||||
},
|
||||
}
|
||||
|
@ -25,68 +25,42 @@ func TestBuildDefaultNetworks(t *testing.T) {
|
|||
|
||||
require.Len(t, actualNetworks, 9)
|
||||
|
||||
require.Equal(t, mainnetChainID, actualNetworks[0].ChainID)
|
||||
ignoreDefaultRPCURLCheck := false // TODO: used just because of Goerli, remove once we remove Goerli from the default networks
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[0].RPCURL, poktToken))
|
||||
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))
|
||||
for _, n := range actualNetworks {
|
||||
var err error
|
||||
switch n.ChainID {
|
||||
case mainnetChainID:
|
||||
case goerliChainID:
|
||||
ignoreDefaultRPCURLCheck = true
|
||||
case sepoliaChainID:
|
||||
case optimismChainID:
|
||||
case optimismGoerliChainID:
|
||||
ignoreDefaultRPCURLCheck = true
|
||||
case optimismSepoliaChainID:
|
||||
case arbitrumChainID:
|
||||
case arbitrumGoerliChainID:
|
||||
ignoreDefaultRPCURLCheck = true
|
||||
case arbitrumSepoliaChainID:
|
||||
default:
|
||||
err = errors.Errorf("unexpected chain id: %d", n.ChainID)
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, goerliChainID, actualNetworks[1].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[1].RPCURL, infuraToken))
|
||||
|
||||
require.Equal(t, sepoliaChainID, actualNetworks[2].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[2].RPCURL, poktToken))
|
||||
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)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[4].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[4].FallbackURL)
|
||||
|
||||
require.Equal(t, optimismSepoliaChainID, actualNetworks[5].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[5].RPCURL, poktToken))
|
||||
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)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[7].RPCURL, infuraToken))
|
||||
require.Equal(t, "", actualNetworks[7].FallbackURL)
|
||||
|
||||
require.Equal(t, arbitrumSepoliaChainID, actualNetworks[8].ChainID)
|
||||
|
||||
require.True(t, strings.Contains(actualNetworks[8].RPCURL, poktToken))
|
||||
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))
|
||||
// check default chains
|
||||
if !ignoreDefaultRPCURLCheck {
|
||||
// DefaultRPCURL and DefaultFallbackURL are mandatory
|
||||
require.True(t, strings.Contains(n.DefaultRPCURL, stageName))
|
||||
require.True(t, strings.Contains(n.DefaultFallbackURL, stageName))
|
||||
if n.DefaultFallbackURL2 != "" {
|
||||
require.True(t, strings.Contains(actualNetworks[0].DefaultFallbackURL2, stageName))
|
||||
}
|
||||
}
|
||||
|
||||
// check fallback options
|
||||
require.True(t, strings.Contains(n.RPCURL, rpcToken))
|
||||
require.True(t, strings.Contains(n.FallbackURL, fallbackToken))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildDefaultNetworksGanache(t *testing.T) {
|
||||
|
|
|
@ -36,11 +36,6 @@ const (
|
|||
// DefaultCallTimeout is a default timeout for an RPC call
|
||||
DefaultCallTimeout = time.Minute
|
||||
|
||||
// Names of providers
|
||||
providerGrove = "grove"
|
||||
providerInfura = "infura"
|
||||
ProviderStatusProxy = "status-proxy"
|
||||
|
||||
mobile = "mobile"
|
||||
desktop = "desktop"
|
||||
|
||||
|
@ -250,15 +245,6 @@ func (c *Client) getRPCRpsLimiter(key string) (*rpclimiter.RPCRpsLimiter, error)
|
|||
return limiter, nil
|
||||
}
|
||||
|
||||
func getProviderConfig(providerConfigs []params.ProviderConfig, providerName string) (params.ProviderConfig, error) {
|
||||
for _, providerConfig := range providerConfigs {
|
||||
if providerConfig.Name == providerName {
|
||||
return providerConfig, nil
|
||||
}
|
||||
}
|
||||
return params.ProviderConfig{}, fmt.Errorf("provider config not found for provider: %s", providerName)
|
||||
}
|
||||
|
||||
func (c *Client) getClientUsingCache(chainID uint64) (chain.ClientInterface, error) {
|
||||
c.rpcClientsMutex.Lock()
|
||||
defer c.rpcClientsMutex.Unlock()
|
||||
|
@ -292,46 +278,20 @@ func (c *Client) getClientUsingCache(chainID uint64) (chain.ClientInterface, err
|
|||
}
|
||||
|
||||
func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEthClientInterface {
|
||||
urls := make(map[string]string)
|
||||
keys := make([]string, 0)
|
||||
authMap := make(map[string]string)
|
||||
|
||||
// find proxy provider
|
||||
proxyProvider, err := getProviderConfig(c.providerConfigs, ProviderStatusProxy)
|
||||
if err != nil {
|
||||
c.log.Warn("could not find provider config for status-proxy", "error", err)
|
||||
}
|
||||
|
||||
if proxyProvider.Enabled {
|
||||
key := ProviderStatusProxy
|
||||
keyFallback := ProviderStatusProxy + "-fallback"
|
||||
keyFallback2 := ProviderStatusProxy + "-fallback2"
|
||||
urls[key] = network.DefaultRPCURL
|
||||
urls[keyFallback] = network.DefaultFallbackURL
|
||||
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
|
||||
urls["fallback"] = network.FallbackURL
|
||||
|
||||
ethClients := make([]ethclient.RPSLimitedEthClientInterface, 0)
|
||||
for index, key := range keys {
|
||||
|
||||
providers := c.prepareProviders(network)
|
||||
for index, provider := range providers {
|
||||
var rpcClient *gethrpc.Client
|
||||
var rpcLimiter *rpclimiter.RPCRpsLimiter
|
||||
var err error
|
||||
var hostPort string
|
||||
url := urls[key]
|
||||
|
||||
if len(url) > 0 {
|
||||
if len(provider.URL) > 0 {
|
||||
// For now, we only support auth for status-proxy.
|
||||
authStr, ok := authMap[key]
|
||||
var opts []gethrpc.ClientOption
|
||||
if ok {
|
||||
authEncoded := base64.StdEncoding.EncodeToString([]byte(authStr))
|
||||
if provider.authenticationNeeded() {
|
||||
authEncoded := base64.StdEncoding.EncodeToString([]byte(provider.Auth))
|
||||
opts = append(opts,
|
||||
gethrpc.WithHeaders(http.Header{
|
||||
"Authorization": {"Basic " + authEncoded},
|
||||
|
@ -340,16 +300,16 @@ func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEt
|
|||
)
|
||||
}
|
||||
|
||||
rpcClient, err = gethrpc.DialOptions(context.Background(), url, opts...)
|
||||
rpcClient, err = gethrpc.DialOptions(context.Background(), provider.URL, opts...)
|
||||
if err != nil {
|
||||
c.log.Error("dial server "+key, "error", err)
|
||||
c.log.Error("dial server "+provider.Key, "error", err)
|
||||
}
|
||||
|
||||
// If using the status-proxy, consider each endpoint as a separate provider
|
||||
circuitKey := fmt.Sprintf("%s-%d", key, index)
|
||||
circuitKey := fmt.Sprintf("%s-%d", provider.Key, index)
|
||||
// Otherwise host is good enough
|
||||
if !strings.Contains(url, "status.im") {
|
||||
hostPort, err = extractHostFromURL(url)
|
||||
if !strings.Contains(provider.URL, "status.im") {
|
||||
hostPort, err = extractHostFromURL(provider.URL)
|
||||
if err == nil {
|
||||
circuitKey = hostPort
|
||||
}
|
||||
|
@ -357,7 +317,7 @@ func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEt
|
|||
|
||||
rpcLimiter, err = c.getRPCRpsLimiter(circuitKey)
|
||||
if err != nil {
|
||||
c.log.Error("get RPC limiter "+key, "error", err)
|
||||
c.log.Error("get RPC limiter "+provider.Key, "error", err)
|
||||
}
|
||||
|
||||
ethClients = append(ethClients, ethclient.NewRPSLimitedEthClient(rpcClient, rpcLimiter, circuitKey))
|
||||
|
|
|
@ -131,9 +131,9 @@ func TestGetClientsUsingCache(t *testing.T) {
|
|||
// Create a new ServeMux
|
||||
mux := http.NewServeMux()
|
||||
|
||||
path1 := "/foo"
|
||||
path2 := "/bar"
|
||||
path3 := "/baz"
|
||||
path1 := "/api.status.im/nodefleet/foo"
|
||||
path2 := "/api.status.im/infura/bar"
|
||||
path3 := "/api.status.im/infura.io/baz"
|
||||
|
||||
authHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
authToken := base64.StdEncoding.EncodeToString([]byte(providerConfig.User + ":" + providerConfig.Password))
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/status-im/status-go/params"
|
||||
)
|
||||
|
||||
const (
|
||||
ProviderMain = "main"
|
||||
ProviderFallback = "fallback"
|
||||
ProviderStatusProxy = "status-proxy"
|
||||
ProviderStatusProxyFallback = ProviderStatusProxy + "-fallback"
|
||||
ProviderStatusProxyFallback2 = ProviderStatusProxy + "-fallback2"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
Key string
|
||||
URL string
|
||||
Auth string
|
||||
Priority int
|
||||
}
|
||||
|
||||
func (p Provider) authenticationNeeded() bool {
|
||||
return len(p.Auth) > 0
|
||||
}
|
||||
|
||||
func getProviderPriorityByURL(url string) int {
|
||||
// Currently we have 5 providers and we want to use them in the following order:
|
||||
// 1. StatusProxy - Node Fleet
|
||||
// 2. StatusProxy - Infura
|
||||
// 3. Direct Infura
|
||||
// 4. StatusProxy - Grove
|
||||
// 5. Direct Grove
|
||||
if strings.Contains(url, "api.status.im/nodefleet/") || strings.Contains(url, "anvil") {
|
||||
return 0
|
||||
} else if strings.Contains(url, "api.status.im/infura/") {
|
||||
return 1
|
||||
} else if strings.Contains(url, "infura.io/") {
|
||||
return 2
|
||||
} else if strings.Contains(url, "api.status.im/grove/") {
|
||||
return 3
|
||||
}
|
||||
|
||||
return 4
|
||||
}
|
||||
|
||||
func getProviderConfig(providerConfigs []params.ProviderConfig, providerName string) (params.ProviderConfig, error) {
|
||||
for _, providerConfig := range providerConfigs {
|
||||
if providerConfig.Name == providerName {
|
||||
return providerConfig, nil
|
||||
}
|
||||
}
|
||||
return params.ProviderConfig{}, fmt.Errorf("provider config not found for provider: %s", providerName)
|
||||
}
|
||||
|
||||
func createProvider(key, url, credentials string, providers *[]Provider) {
|
||||
priority := getProviderPriorityByURL(url)
|
||||
*providers = append(*providers, Provider{
|
||||
Key: key,
|
||||
URL: url,
|
||||
Auth: credentials,
|
||||
Priority: priority,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) prepareProviders(network *params.Network) []Provider {
|
||||
var providers []Provider
|
||||
|
||||
// Retrieve the proxy provider configuration
|
||||
proxyProvider, err := getProviderConfig(c.providerConfigs, ProviderStatusProxy)
|
||||
if err != nil {
|
||||
c.log.Warn("could not find provider config for status-proxy", "error", err)
|
||||
}
|
||||
|
||||
// Add main and fallback providers
|
||||
createProvider(ProviderMain, network.RPCURL, "", &providers)
|
||||
createProvider(ProviderFallback, network.FallbackURL, "", &providers)
|
||||
|
||||
// If the proxy provider is enabled, add it and its fallback options
|
||||
if proxyProvider.Enabled {
|
||||
credentials := proxyProvider.User + ":" + proxyProvider.Password
|
||||
createProvider(ProviderStatusProxy, network.DefaultRPCURL, credentials, &providers)
|
||||
createProvider(ProviderStatusProxyFallback, network.DefaultFallbackURL, credentials, &providers)
|
||||
createProvider(ProviderStatusProxyFallback2, network.DefaultFallbackURL2, credentials, &providers)
|
||||
}
|
||||
|
||||
// Sort providers by priority
|
||||
sort.Slice(providers, func(i, j int) bool {
|
||||
return providers[i].Priority < providers[j].Priority
|
||||
})
|
||||
|
||||
return providers
|
||||
}
|
|
@ -139,9 +139,8 @@ func TestAPI_GetAddressDetails(t *testing.T) {
|
|||
|
||||
networks := []params.Network{
|
||||
{
|
||||
ChainID: chainID,
|
||||
DefaultRPCURL: serverWith1SecDelay.URL,
|
||||
DefaultFallbackURL: serverWith1SecDelay.URL,
|
||||
ChainID: chainID,
|
||||
DefaultRPCURL: serverWith1SecDelay.URL + "/nodefleet/",
|
||||
},
|
||||
}
|
||||
config := rpc.ClientConfig{
|
||||
|
|
|
@ -14,8 +14,6 @@ import (
|
|||
var mainnet = params.Network{
|
||||
ChainID: walletCommon.EthereumMainnet,
|
||||
ChainName: "Mainnet",
|
||||
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://mainnet.infura.io/v3/",
|
||||
BlockExplorerURL: "https://etherscan.io/",
|
||||
IconURL: "network/Network=Ethereum",
|
||||
ChainColor: "#627EEA",
|
||||
|
@ -32,8 +30,6 @@ var mainnet = params.Network{
|
|||
var optimism = params.Network{
|
||||
ChainID: walletCommon.OptimismMainnet,
|
||||
ChainName: "Optimism",
|
||||
RPCURL: "https://optimism-mainnet.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://optimism-mainnet.infura.io/v3/",
|
||||
BlockExplorerURL: "https://optimistic.etherscan.io",
|
||||
IconURL: "network/Network=Optimism",
|
||||
ChainColor: "#E90101",
|
||||
|
|
|
@ -46,6 +46,8 @@ const (
|
|||
|
||||
testApprovalGasEstimation = 1000
|
||||
testApprovalL1Fee = 100000000000
|
||||
|
||||
stageName = "test"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -89,8 +91,11 @@ var (
|
|||
var mainnet = params.Network{
|
||||
ChainID: walletCommon.EthereumMainnet,
|
||||
ChainName: "Mainnet",
|
||||
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://mainnet.infura.io/v3/",
|
||||
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: "https://mainnet.infura.io/v3/",
|
||||
RPCURL: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/mainnet/", stageName),
|
||||
FallbackURL: "https://eth-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://etherscan.io/",
|
||||
IconURL: "network/Network=Ethereum",
|
||||
ChainColor: "#627EEA",
|
||||
|
@ -104,29 +109,14 @@ var mainnet = params.Network{
|
|||
RelatedChainID: walletCommon.EthereumMainnet,
|
||||
}
|
||||
|
||||
var sepolia = params.Network{
|
||||
ChainID: walletCommon.EthereumSepolia,
|
||||
ChainName: "Mainnet",
|
||||
RPCURL: "https://sepolia-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://sepolia.infura.io/v3/",
|
||||
BlockExplorerURL: "https://sepolia.etherscan.io/",
|
||||
IconURL: "network/Network=Ethereum",
|
||||
ChainColor: "#627EEA",
|
||||
ShortName: "eth",
|
||||
NativeCurrencyName: "Ether",
|
||||
NativeCurrencySymbol: "ETH",
|
||||
NativeCurrencyDecimals: 18,
|
||||
IsTest: true,
|
||||
Layer: 1,
|
||||
Enabled: true,
|
||||
RelatedChainID: walletCommon.EthereumMainnet,
|
||||
}
|
||||
|
||||
var optimism = params.Network{
|
||||
ChainID: walletCommon.OptimismMainnet,
|
||||
ChainName: "Optimism",
|
||||
RPCURL: "https://optimism-mainnet.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://optimism-mainnet.infura.io/v3/",
|
||||
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: "https://optimism-mainnet.infura.io/v3/",
|
||||
RPCURL: fmt.Sprintf("https://%s.api.status.im/grove/optimism/mainnet/", stageName),
|
||||
FallbackURL: "https://optimism-archival.rpc.grove.city/v1/",
|
||||
BlockExplorerURL: "https://optimistic.etherscan.io",
|
||||
IconURL: "network/Network=Optimism",
|
||||
ChainColor: "#E90101",
|
||||
|
@ -140,30 +130,14 @@ var optimism = params.Network{
|
|||
RelatedChainID: walletCommon.OptimismMainnet,
|
||||
}
|
||||
|
||||
var optimismSepolia = params.Network{
|
||||
ChainID: walletCommon.OptimismSepolia,
|
||||
ChainName: "Optimism",
|
||||
RPCURL: "https://optimism-sepolia-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://optimism-sepolia.infura.io/v3/",
|
||||
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
|
||||
IconURL: "network/Network=Optimism",
|
||||
ChainColor: "#E90101",
|
||||
ShortName: "oeth",
|
||||
NativeCurrencyName: "Ether",
|
||||
NativeCurrencySymbol: "ETH",
|
||||
NativeCurrencyDecimals: 18,
|
||||
IsTest: true,
|
||||
Layer: 2,
|
||||
Enabled: false,
|
||||
RelatedChainID: walletCommon.OptimismMainnet,
|
||||
}
|
||||
|
||||
var arbitrum = params.Network{
|
||||
ChainID: walletCommon.ArbitrumMainnet,
|
||||
ChainName: "Arbitrum",
|
||||
RPCURL: "https://arbitrum-one.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://arbitrum-mainnet.infura.io/v3/",
|
||||
BlockExplorerURL: "https://arbiscan.io/",
|
||||
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: "https://arbitrum-mainnet.infura.io/v3/",
|
||||
RPCURL: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/mainnet/", stageName),
|
||||
FallbackURL: "https://arbitrum-one.rpc.grove.city/v1/",
|
||||
IconURL: "network/Network=Arbitrum",
|
||||
ChainColor: "#51D0F0",
|
||||
ShortName: "arb1",
|
||||
|
@ -176,31 +150,10 @@ var arbitrum = params.Network{
|
|||
RelatedChainID: walletCommon.ArbitrumMainnet,
|
||||
}
|
||||
|
||||
var arbitrumSepolia = params.Network{
|
||||
ChainID: walletCommon.ArbitrumSepolia,
|
||||
ChainName: "Arbitrum",
|
||||
RPCURL: "https://arbitrum-sepolia-archival.rpc.grove.city/v1/",
|
||||
FallbackURL: "https://arbitrum-sepolia.infura.io/v3/",
|
||||
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
|
||||
IconURL: "network/Network=Arbitrum",
|
||||
ChainColor: "#51D0F0",
|
||||
ShortName: "arb1",
|
||||
NativeCurrencyName: "Ether",
|
||||
NativeCurrencySymbol: "ETH",
|
||||
NativeCurrencyDecimals: 18,
|
||||
IsTest: true,
|
||||
Layer: 2,
|
||||
Enabled: false,
|
||||
RelatedChainID: walletCommon.ArbitrumMainnet,
|
||||
}
|
||||
|
||||
var defaultNetworks = []params.Network{
|
||||
mainnet,
|
||||
sepolia,
|
||||
optimism,
|
||||
optimismSepolia,
|
||||
arbitrum,
|
||||
arbitrumSepolia,
|
||||
}
|
||||
|
||||
type normalTestParams struct {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
{
|
||||
"ChainID": 31337,
|
||||
"ChainName": "Anvil",
|
||||
"DefaultRPCURL": "http://anvil:8545",
|
||||
"RPCURL": "http://anvil:8545",
|
||||
"ShortName": "eth",
|
||||
"NativeCurrencyName": "Ether",
|
||||
|
|
Loading…
Reference in New Issue