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 := `
|
requestJSONTemplateString := `
|
||||||
{
|
{
|
||||||
"upstreamConfig":"https://eth-archival.rpc.grove.city/v1/3ef2018191814b7e1009b8d9",
|
"upstreamConfig":"",
|
||||||
"openseaAPIKey":"",
|
"openseaAPIKey":"",
|
||||||
"wakuV2Nameserver":"1.1.1.1",
|
"wakuV2Nameserver":"1.1.1.1",
|
||||||
"mnemonic":null,
|
"mnemonic":null,
|
||||||
|
@ -31,9 +31,9 @@ func TestCreateAccountAndLogin(t *testing.T) {
|
||||||
"customizationColor":"blue",
|
"customizationColor":"blue",
|
||||||
"emoji": "some",
|
"emoji": "some",
|
||||||
"previewPrivacy":true,
|
"previewPrivacy":true,
|
||||||
"verifyTransactionURL":"https://eth-archival.rpc.grove.city/v1/3ef2018191814b7e1009b8d9",
|
"verifyTransactionURL":"",
|
||||||
"imagePath":null,
|
"imagePath":null,
|
||||||
"verifyENSURL":"https://eth-archival.rpc.grove.city/v1/3ef2018191814b7e1009b8d9",
|
"verifyENSURL":"",
|
||||||
"logLevel":"INFO",
|
"logLevel":"INFO",
|
||||||
"logFilePath":"%s",
|
"logFilePath":"%s",
|
||||||
"networkId":1
|
"networkId":1
|
||||||
|
|
|
@ -32,8 +32,8 @@ func mainnet(stageName string) params.Network {
|
||||||
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/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),
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/ethereum/mainnet/", stageName),
|
||||||
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/mainnet/", stageName),
|
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/mainnet/", stageName),
|
||||||
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
|
RPCURL: "https://mainnet.infura.io/v3/",
|
||||||
FallbackURL: "https://mainnet.infura.io/v3/",
|
FallbackURL: "https://eth-archival.rpc.grove.city/v1/",
|
||||||
BlockExplorerURL: "https://etherscan.io/",
|
BlockExplorerURL: "https://etherscan.io/",
|
||||||
IconURL: "network/Network=Ethereum",
|
IconURL: "network/Network=Ethereum",
|
||||||
ChainColor: "#627EEA",
|
ChainColor: "#627EEA",
|
||||||
|
@ -75,8 +75,8 @@ func sepolia(stageName string) params.Network {
|
||||||
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/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),
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/ethereum/sepolia/", stageName),
|
||||||
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/sepolia/", stageName),
|
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/sepolia/", stageName),
|
||||||
RPCURL: "https://sepolia-archival.rpc.grove.city/v1/",
|
RPCURL: "https://sepolia.infura.io/v3/",
|
||||||
FallbackURL: "https://sepolia.infura.io/v3/",
|
FallbackURL: "https://sepolia-archival.rpc.grove.city/v1/",
|
||||||
BlockExplorerURL: "https://sepolia.etherscan.io/",
|
BlockExplorerURL: "https://sepolia.etherscan.io/",
|
||||||
IconURL: "network/Network=Ethereum",
|
IconURL: "network/Network=Ethereum",
|
||||||
ChainColor: "#627EEA",
|
ChainColor: "#627EEA",
|
||||||
|
@ -98,8 +98,8 @@ func optimism(stageName string) params.Network {
|
||||||
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/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),
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/optimism/mainnet/", stageName),
|
||||||
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/optimism/mainnet/", stageName),
|
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/optimism/mainnet/", stageName),
|
||||||
RPCURL: "https://optimism-archival.rpc.grove.city/v1/",
|
RPCURL: "https://optimism-mainnet.infura.io/v3/",
|
||||||
FallbackURL: "https://optimism-mainnet.infura.io/v3/",
|
FallbackURL: "https://optimism-archival.rpc.grove.city/v1/",
|
||||||
BlockExplorerURL: "https://optimistic.etherscan.io",
|
BlockExplorerURL: "https://optimistic.etherscan.io",
|
||||||
IconURL: "network/Network=Optimism",
|
IconURL: "network/Network=Optimism",
|
||||||
ChainColor: "#E90101",
|
ChainColor: "#E90101",
|
||||||
|
@ -141,8 +141,8 @@ func optimismSepolia(stageName string) params.Network {
|
||||||
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/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),
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/optimism/sepolia/", stageName),
|
||||||
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/optimism/sepolia/", stageName),
|
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/optimism/sepolia/", stageName),
|
||||||
RPCURL: "https://optimism-sepolia-archival.rpc.grove.city/v1/",
|
RPCURL: "https://optimism-sepolia.infura.io/v3/",
|
||||||
FallbackURL: "https://optimism-sepolia.infura.io/v3/",
|
FallbackURL: "https://optimism-sepolia-archival.rpc.grove.city/v1/",
|
||||||
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
|
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
|
||||||
IconURL: "network/Network=Optimism",
|
IconURL: "network/Network=Optimism",
|
||||||
ChainColor: "#E90101",
|
ChainColor: "#E90101",
|
||||||
|
@ -164,8 +164,8 @@ func arbitrum(stageName string) params.Network {
|
||||||
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/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),
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/arbitrum/mainnet/", stageName),
|
||||||
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/mainnet/", stageName),
|
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/mainnet/", stageName),
|
||||||
RPCURL: "https://arbitrum-one.rpc.grove.city/v1/",
|
RPCURL: "https://arbitrum-mainnet.infura.io/v3/",
|
||||||
FallbackURL: "https://arbitrum-mainnet.infura.io/v3/",
|
FallbackURL: "https://arbitrum-one.rpc.grove.city/v1/",
|
||||||
BlockExplorerURL: "https://arbiscan.io/",
|
BlockExplorerURL: "https://arbiscan.io/",
|
||||||
IconURL: "network/Network=Arbitrum",
|
IconURL: "network/Network=Arbitrum",
|
||||||
ChainColor: "#51D0F0",
|
ChainColor: "#51D0F0",
|
||||||
|
@ -207,8 +207,8 @@ func arbitrumSepolia(stageName string) params.Network {
|
||||||
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/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),
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/arbitrum/sepolia/", stageName),
|
||||||
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/sepolia/", stageName),
|
DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/arbitrum/sepolia/", stageName),
|
||||||
RPCURL: "https://arbitrum-sepolia-archival.rpc.grove.city/v1/",
|
RPCURL: "https://arbitrum-sepolia.infura.io/v3/",
|
||||||
FallbackURL: "https://arbitrum-sepolia.infura.io/v3/",
|
FallbackURL: "https://arbitrum-sepolia-archival.rpc.grove.city/v1/",
|
||||||
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
|
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
|
||||||
IconURL: "network/Network=Arbitrum",
|
IconURL: "network/Network=Arbitrum",
|
||||||
ChainColor: "#51D0F0",
|
ChainColor: "#51D0F0",
|
||||||
|
@ -251,38 +251,35 @@ func setRPCs(networks []params.Network, request *requests.WalletSecretsConfig) [
|
||||||
|
|
||||||
var networksWithRPC []params.Network
|
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 {
|
for _, n := range networks {
|
||||||
|
n.DefaultRPCURL = appendToken(n.DefaultRPCURL)
|
||||||
if request.InfuraToken != "" {
|
n.DefaultFallbackURL = appendToken(n.DefaultFallbackURL)
|
||||||
if strings.Contains(n.RPCURL, "infura") {
|
n.DefaultFallbackURL2 = appendToken(n.DefaultFallbackURL2)
|
||||||
n.RPCURL += request.InfuraToken
|
n.RPCURL = appendToken(n.RPCURL)
|
||||||
}
|
n.FallbackURL = appendToken(n.FallbackURL)
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if request.GanacheURL != "" {
|
if request.GanacheURL != "" {
|
||||||
n.RPCURL = request.GanacheURL
|
n.RPCURL = request.GanacheURL
|
||||||
n.FallbackURL = request.GanacheURL
|
n.FallbackURL = request.GanacheURL
|
||||||
if n.ChainID == mainnetChainID {
|
switch n.ChainID {
|
||||||
n.TokenOverrides = []params.TokenOverride{
|
case mainnetChainID:
|
||||||
mainnetGanacheTokenOverrides,
|
n.TokenOverrides = []params.TokenOverride{mainnetGanacheTokenOverrides}
|
||||||
}
|
case goerliChainID:
|
||||||
} else if n.ChainID == goerliChainID {
|
n.TokenOverrides = []params.TokenOverride{goerliGanacheTokenOverrides}
|
||||||
n.TokenOverrides = []params.TokenOverride{
|
|
||||||
goerliGanacheTokenOverrides,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,19 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildDefaultNetworks(t *testing.T) {
|
func TestBuildDefaultNetworks(t *testing.T) {
|
||||||
poktToken := "grove-token"
|
rpcToken := "infura-token"
|
||||||
infuraToken := "infura-token"
|
fallbackToken := ""
|
||||||
stageName := "fast-n-bulbous"
|
stageName := "fast-n-bulbous"
|
||||||
request := &requests.CreateAccount{
|
request := &requests.CreateAccount{
|
||||||
WalletSecretsConfig: requests.WalletSecretsConfig{
|
WalletSecretsConfig: requests.WalletSecretsConfig{
|
||||||
PoktToken: poktToken,
|
InfuraToken: rpcToken,
|
||||||
InfuraToken: infuraToken,
|
|
||||||
StatusProxyStageName: stageName,
|
StatusProxyStageName: stageName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -25,68 +25,42 @@ func TestBuildDefaultNetworks(t *testing.T) {
|
||||||
|
|
||||||
require.Len(t, actualNetworks, 9)
|
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))
|
for _, n := range actualNetworks {
|
||||||
require.True(t, strings.Contains(actualNetworks[0].FallbackURL, infuraToken))
|
var err error
|
||||||
require.True(t, strings.Contains(actualNetworks[0].DefaultRPCURL, stageName))
|
switch n.ChainID {
|
||||||
require.True(t, strings.Contains(actualNetworks[0].DefaultFallbackURL, stageName))
|
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)
|
||||||
|
|
||||||
|
// 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))
|
require.True(t, strings.Contains(actualNetworks[0].DefaultFallbackURL2, stageName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require.Equal(t, goerliChainID, actualNetworks[1].ChainID)
|
// check fallback options
|
||||||
|
require.True(t, strings.Contains(n.RPCURL, rpcToken))
|
||||||
require.True(t, strings.Contains(actualNetworks[1].RPCURL, infuraToken))
|
require.True(t, strings.Contains(n.FallbackURL, fallbackToken))
|
||||||
|
}
|
||||||
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))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildDefaultNetworksGanache(t *testing.T) {
|
func TestBuildDefaultNetworksGanache(t *testing.T) {
|
||||||
|
|
|
@ -36,11 +36,6 @@ const (
|
||||||
// DefaultCallTimeout is a default timeout for an RPC call
|
// DefaultCallTimeout is a default timeout for an RPC call
|
||||||
DefaultCallTimeout = time.Minute
|
DefaultCallTimeout = time.Minute
|
||||||
|
|
||||||
// Names of providers
|
|
||||||
providerGrove = "grove"
|
|
||||||
providerInfura = "infura"
|
|
||||||
ProviderStatusProxy = "status-proxy"
|
|
||||||
|
|
||||||
mobile = "mobile"
|
mobile = "mobile"
|
||||||
desktop = "desktop"
|
desktop = "desktop"
|
||||||
|
|
||||||
|
@ -250,15 +245,6 @@ func (c *Client) getRPCRpsLimiter(key string) (*rpclimiter.RPCRpsLimiter, error)
|
||||||
return limiter, nil
|
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) {
|
func (c *Client) getClientUsingCache(chainID uint64) (chain.ClientInterface, error) {
|
||||||
c.rpcClientsMutex.Lock()
|
c.rpcClientsMutex.Lock()
|
||||||
defer c.rpcClientsMutex.Unlock()
|
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 {
|
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)
|
ethClients := make([]ethclient.RPSLimitedEthClientInterface, 0)
|
||||||
for index, key := range keys {
|
|
||||||
|
providers := c.prepareProviders(network)
|
||||||
|
for index, provider := range providers {
|
||||||
var rpcClient *gethrpc.Client
|
var rpcClient *gethrpc.Client
|
||||||
var rpcLimiter *rpclimiter.RPCRpsLimiter
|
var rpcLimiter *rpclimiter.RPCRpsLimiter
|
||||||
var err error
|
var err error
|
||||||
var hostPort string
|
var hostPort string
|
||||||
url := urls[key]
|
|
||||||
|
|
||||||
if len(url) > 0 {
|
if len(provider.URL) > 0 {
|
||||||
// For now, we only support auth for status-proxy.
|
// For now, we only support auth for status-proxy.
|
||||||
authStr, ok := authMap[key]
|
|
||||||
var opts []gethrpc.ClientOption
|
var opts []gethrpc.ClientOption
|
||||||
if ok {
|
if provider.authenticationNeeded() {
|
||||||
authEncoded := base64.StdEncoding.EncodeToString([]byte(authStr))
|
authEncoded := base64.StdEncoding.EncodeToString([]byte(provider.Auth))
|
||||||
opts = append(opts,
|
opts = append(opts,
|
||||||
gethrpc.WithHeaders(http.Header{
|
gethrpc.WithHeaders(http.Header{
|
||||||
"Authorization": {"Basic " + authEncoded},
|
"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 {
|
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
|
// 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
|
// Otherwise host is good enough
|
||||||
if !strings.Contains(url, "status.im") {
|
if !strings.Contains(provider.URL, "status.im") {
|
||||||
hostPort, err = extractHostFromURL(url)
|
hostPort, err = extractHostFromURL(provider.URL)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
circuitKey = hostPort
|
circuitKey = hostPort
|
||||||
}
|
}
|
||||||
|
@ -357,7 +317,7 @@ func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEt
|
||||||
|
|
||||||
rpcLimiter, err = c.getRPCRpsLimiter(circuitKey)
|
rpcLimiter, err = c.getRPCRpsLimiter(circuitKey)
|
||||||
if err != nil {
|
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))
|
ethClients = append(ethClients, ethclient.NewRPSLimitedEthClient(rpcClient, rpcLimiter, circuitKey))
|
||||||
|
|
|
@ -131,9 +131,9 @@ func TestGetClientsUsingCache(t *testing.T) {
|
||||||
// Create a new ServeMux
|
// Create a new ServeMux
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
path1 := "/foo"
|
path1 := "/api.status.im/nodefleet/foo"
|
||||||
path2 := "/bar"
|
path2 := "/api.status.im/infura/bar"
|
||||||
path3 := "/baz"
|
path3 := "/api.status.im/infura.io/baz"
|
||||||
|
|
||||||
authHandler := func(w http.ResponseWriter, r *http.Request) {
|
authHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
authToken := base64.StdEncoding.EncodeToString([]byte(providerConfig.User + ":" + providerConfig.Password))
|
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
|
||||||
|
}
|
|
@ -140,8 +140,7 @@ func TestAPI_GetAddressDetails(t *testing.T) {
|
||||||
networks := []params.Network{
|
networks := []params.Network{
|
||||||
{
|
{
|
||||||
ChainID: chainID,
|
ChainID: chainID,
|
||||||
DefaultRPCURL: serverWith1SecDelay.URL,
|
DefaultRPCURL: serverWith1SecDelay.URL + "/nodefleet/",
|
||||||
DefaultFallbackURL: serverWith1SecDelay.URL,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
config := rpc.ClientConfig{
|
config := rpc.ClientConfig{
|
||||||
|
|
|
@ -14,8 +14,6 @@ import (
|
||||||
var mainnet = params.Network{
|
var mainnet = params.Network{
|
||||||
ChainID: walletCommon.EthereumMainnet,
|
ChainID: walletCommon.EthereumMainnet,
|
||||||
ChainName: "Mainnet",
|
ChainName: "Mainnet",
|
||||||
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
|
|
||||||
FallbackURL: "https://mainnet.infura.io/v3/",
|
|
||||||
BlockExplorerURL: "https://etherscan.io/",
|
BlockExplorerURL: "https://etherscan.io/",
|
||||||
IconURL: "network/Network=Ethereum",
|
IconURL: "network/Network=Ethereum",
|
||||||
ChainColor: "#627EEA",
|
ChainColor: "#627EEA",
|
||||||
|
@ -32,8 +30,6 @@ var mainnet = params.Network{
|
||||||
var optimism = params.Network{
|
var optimism = params.Network{
|
||||||
ChainID: walletCommon.OptimismMainnet,
|
ChainID: walletCommon.OptimismMainnet,
|
||||||
ChainName: "Optimism",
|
ChainName: "Optimism",
|
||||||
RPCURL: "https://optimism-mainnet.rpc.grove.city/v1/",
|
|
||||||
FallbackURL: "https://optimism-mainnet.infura.io/v3/",
|
|
||||||
BlockExplorerURL: "https://optimistic.etherscan.io",
|
BlockExplorerURL: "https://optimistic.etherscan.io",
|
||||||
IconURL: "network/Network=Optimism",
|
IconURL: "network/Network=Optimism",
|
||||||
ChainColor: "#E90101",
|
ChainColor: "#E90101",
|
||||||
|
|
|
@ -46,6 +46,8 @@ const (
|
||||||
|
|
||||||
testApprovalGasEstimation = 1000
|
testApprovalGasEstimation = 1000
|
||||||
testApprovalL1Fee = 100000000000
|
testApprovalL1Fee = 100000000000
|
||||||
|
|
||||||
|
stageName = "test"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -89,8 +91,11 @@ var (
|
||||||
var mainnet = params.Network{
|
var mainnet = params.Network{
|
||||||
ChainID: walletCommon.EthereumMainnet,
|
ChainID: walletCommon.EthereumMainnet,
|
||||||
ChainName: "Mainnet",
|
ChainName: "Mainnet",
|
||||||
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
|
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/ethereum/mainnet/", stageName),
|
||||||
FallbackURL: "https://mainnet.infura.io/v3/",
|
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/",
|
BlockExplorerURL: "https://etherscan.io/",
|
||||||
IconURL: "network/Network=Ethereum",
|
IconURL: "network/Network=Ethereum",
|
||||||
ChainColor: "#627EEA",
|
ChainColor: "#627EEA",
|
||||||
|
@ -104,29 +109,14 @@ var mainnet = params.Network{
|
||||||
RelatedChainID: walletCommon.EthereumMainnet,
|
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{
|
var optimism = params.Network{
|
||||||
ChainID: walletCommon.OptimismMainnet,
|
ChainID: walletCommon.OptimismMainnet,
|
||||||
ChainName: "Optimism",
|
ChainName: "Optimism",
|
||||||
RPCURL: "https://optimism-mainnet.rpc.grove.city/v1/",
|
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/optimism/mainnet/", stageName),
|
||||||
FallbackURL: "https://optimism-mainnet.infura.io/v3/",
|
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",
|
BlockExplorerURL: "https://optimistic.etherscan.io",
|
||||||
IconURL: "network/Network=Optimism",
|
IconURL: "network/Network=Optimism",
|
||||||
ChainColor: "#E90101",
|
ChainColor: "#E90101",
|
||||||
|
@ -140,30 +130,14 @@ var optimism = params.Network{
|
||||||
RelatedChainID: walletCommon.OptimismMainnet,
|
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{
|
var arbitrum = params.Network{
|
||||||
ChainID: walletCommon.ArbitrumMainnet,
|
ChainID: walletCommon.ArbitrumMainnet,
|
||||||
ChainName: "Arbitrum",
|
ChainName: "Arbitrum",
|
||||||
RPCURL: "https://arbitrum-one.rpc.grove.city/v1/",
|
DefaultRPCURL: fmt.Sprintf("https://%s.api.status.im/nodefleet/arbitrum/mainnet/", stageName),
|
||||||
FallbackURL: "https://arbitrum-mainnet.infura.io/v3/",
|
DefaultFallbackURL: fmt.Sprintf("https://%s.api.status.im/infura/arbitrum/mainnet/", stageName),
|
||||||
BlockExplorerURL: "https://arbiscan.io/",
|
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",
|
IconURL: "network/Network=Arbitrum",
|
||||||
ChainColor: "#51D0F0",
|
ChainColor: "#51D0F0",
|
||||||
ShortName: "arb1",
|
ShortName: "arb1",
|
||||||
|
@ -176,31 +150,10 @@ var arbitrum = params.Network{
|
||||||
RelatedChainID: walletCommon.ArbitrumMainnet,
|
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{
|
var defaultNetworks = []params.Network{
|
||||||
mainnet,
|
mainnet,
|
||||||
sepolia,
|
|
||||||
optimism,
|
optimism,
|
||||||
optimismSepolia,
|
|
||||||
arbitrum,
|
arbitrum,
|
||||||
arbitrumSepolia,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type normalTestParams struct {
|
type normalTestParams struct {
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
{
|
{
|
||||||
"ChainID": 31337,
|
"ChainID": 31337,
|
||||||
"ChainName": "Anvil",
|
"ChainName": "Anvil",
|
||||||
"DefaultRPCURL": "http://anvil:8545",
|
|
||||||
"RPCURL": "http://anvil:8545",
|
"RPCURL": "http://anvil:8545",
|
||||||
"ShortName": "eth",
|
"ShortName": "eth",
|
||||||
"NativeCurrencyName": "Ether",
|
"NativeCurrencyName": "Ether",
|
||||||
|
|
Loading…
Reference in New Issue