Skip to content

Commit

Permalink
chore(config)_: Integration of new RPC Provider configurations
Browse files Browse the repository at this point in the history
* default_networks.go
  * explicit provider initialization with more granular config (rps limiter, order)
  * token overrides made more flexible, support not only infura and grove
* get_status_node.go
  * override status-proxy auth instead of passing override config to rpc/client.go
* config.go
  * ProviderConfig removed
* client.go
  * Now any provider can be enabled/disabled (if user wants to use only his custom RPC urls)
  * Use bearer auth instead of URL auth
  * Provider order is defined by default_networks.go
  • Loading branch information
friofry committed Dec 6, 2024
1 parent 50ee868 commit e0e484f
Show file tree
Hide file tree
Showing 23 changed files with 585 additions and 748 deletions.
188 changes: 110 additions & 78 deletions api/default_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package api

import (
"fmt"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/params/networkhelper"
"github.com/status-im/status-go/protocol/requests"
)

Expand All @@ -22,15 +21,29 @@ const (

var ganacheTokenAddress = common.HexToAddress("0x8571Ddc46b10d31EF963aF49b6C7799Ea7eff818")

func proxyUrl(stageName, provider, chainName, networkName string) string {
return fmt.Sprintf("https://%s.api.status.im/%s/%s/%s/", stageName, provider, chainName, networkName)
}

func mainnet(stageName string) params.Network {
chainID := mainnetChainID
chainName := "ethereum"
networkName := "mainnet"

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),
// 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),
}

return params.Network{
ChainID: mainnetChainID,
ChainID: chainID,
ChainName: "Mainnet",
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://mainnet.infura.io/v3/",
FallbackURL: "https://eth-archival.rpc.grove.city/v1/",
RpcProviders: rpcProviders,
BlockExplorerURL: "https://etherscan.io/",
IconURL: "network/Network=Ethereum",
ChainColor: "#627EEA",
Expand All @@ -44,16 +57,25 @@ func mainnet(stageName string) params.Network {
RelatedChainID: sepoliaChainID,
}
}

func sepolia(stageName string) params.Network {
chainID := sepoliaChainID
chainName := "ethereum"
networkName := "sepolia"

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),
// 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),
}

return params.Network{
ChainID: sepoliaChainID,
ChainName: "Mainnet",
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.infura.io/v3/",
FallbackURL: "https://sepolia-archival.rpc.grove.city/v1/",
ChainID: chainID,
ChainName: "Sepolia",
RpcProviders: rpcProviders,
BlockExplorerURL: "https://sepolia.etherscan.io/",
IconURL: "network/Network=Ethereum",
ChainColor: "#627EEA",
Expand All @@ -67,16 +89,25 @@ func sepolia(stageName string) params.Network {
RelatedChainID: mainnetChainID,
}
}

func optimism(stageName string) params.Network {
chainID := optimismChainID
chainName := "optimism"
networkName := "mainnet"

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),
// 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),
}

return params.Network{
ChainID: optimismChainID,
ChainID: chainID,
ChainName: "Optimism",
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-mainnet.infura.io/v3/",
FallbackURL: "https://optimism-archival.rpc.grove.city/v1/",
RpcProviders: rpcProviders,
BlockExplorerURL: "https://optimistic.etherscan.io",
IconURL: "network/Network=Optimism",
ChainColor: "#E90101",
Expand All @@ -90,16 +121,25 @@ func optimism(stageName string) params.Network {
RelatedChainID: optimismSepoliaChainID,
}
}

func optimismSepolia(stageName string) params.Network {
chainID := optimismSepoliaChainID
chainName := "optimism"
networkName := "sepolia"

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),
// 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),
}

return params.Network{
ChainID: optimismSepoliaChainID,
ChainID: chainID,
ChainName: "Optimism",
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.infura.io/v3/",
FallbackURL: "https://optimism-sepolia-archival.rpc.grove.city/v1/",
RpcProviders: rpcProviders,
BlockExplorerURL: "https://sepolia-optimism.etherscan.io/",
IconURL: "network/Network=Optimism",
ChainColor: "#E90101",
Expand All @@ -113,16 +153,25 @@ func optimismSepolia(stageName string) params.Network {
RelatedChainID: optimismChainID,
}
}

func arbitrum(stageName string) params.Network {
chainID := arbitrumChainID
chainName := "arbitrum"
networkName := "mainnet"

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),
// 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),
}

return params.Network{
ChainID: arbitrumChainID,
ChainID: chainID,
ChainName: "Arbitrum",
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-mainnet.infura.io/v3/",
FallbackURL: "https://arbitrum-one.rpc.grove.city/v1/",
RpcProviders: rpcProviders,
BlockExplorerURL: "https://arbiscan.io/",
IconURL: "network/Network=Arbitrum",
ChainColor: "#51D0F0",
Expand All @@ -136,16 +185,25 @@ func arbitrum(stageName string) params.Network {
RelatedChainID: arbitrumSepoliaChainID,
}
}

func arbitrumSepolia(stageName string) params.Network {
chainID := arbitrumSepoliaChainID
chainName := "arbitrum"
networkName := "sepolia"

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),
// 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),
}

return params.Network{
ChainID: arbitrumSepoliaChainID,
ChainID: chainID,
ChainName: "Arbitrum",
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.infura.io/v3/",
FallbackURL: "https://arbitrum-sepolia-archival.rpc.grove.city/v1/",
RpcProviders: rpcProviders,
BlockExplorerURL: "https://sepolia-explorer.arbitrum.io/",
IconURL: "network/Network=Arbitrum",
ChainColor: "#51D0F0",
Expand Down Expand Up @@ -177,44 +235,18 @@ var mainnetGanacheTokenOverrides = params.TokenOverride{
}

func setRPCs(networks []params.Network, request *requests.WalletSecretsConfig) []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
authTokens := map[string]string{
"infura.io": request.InfuraToken,
"grove.city": request.PoktToken,
}

for _, n := range networks {
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,
}
}
}

networksWithRPC = append(networksWithRPC, n)
updatedNetworks := networkhelper.OverrideDirectProvidersAuth(networks, authTokens)

if request.GanacheURL != "" {
updatedNetworks = networkhelper.OverrideGanacheToken(updatedNetworks, request.GanacheURL, mainnetChainID, mainnetGanacheTokenOverrides)
}

return networksWithRPC
return updatedNetworks
}

func BuildDefaultNetworks(walletSecretsConfig *requests.WalletSecretsConfig) []params.Network {
Expand Down
21 changes: 10 additions & 11 deletions node/get_status_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"reflect"
"sync"

"github.com/status-im/status-go/params/networkhelper"

"github.com/syndtr/goleveldb/leveldb"
"go.uber.org/zap"

Expand Down Expand Up @@ -336,25 +338,22 @@ func (n *StatusNode) setupRPCClient() (err error) {
return
}

// ProviderConfigs should be passed not in wallet secrets config on login
// Proxy AuthConfigs should be passed not in wallet secrets config on login
// but some other way, as it's not wallet specific and should not be passed with login request
// but currently there is no other way to pass it
providerConfigs := []params.ProviderConfig{
{
Enabled: n.config.WalletConfig.StatusProxyEnabled,
Name: rpc.ProviderStatusProxy,
User: n.config.WalletConfig.StatusProxyBlockchainUser,
Password: n.config.WalletConfig.StatusProxyBlockchainPassword,
},
}
// (maybe move to default_networks.go)
networks := networkhelper.OverrideEmbeddedProxyProviders(
n.config.Networks,
n.config.WalletConfig.StatusProxyEnabled,
n.config.WalletConfig.StatusProxyBlockchainUser,
n.config.WalletConfig.StatusProxyBlockchainPassword)

config := rpc.ClientConfig{
Client: gethNodeClient,
UpstreamChainID: n.config.NetworkID,
Networks: n.config.Networks,
Networks: networks,
DB: n.appDB,
WalletFeed: &n.walletFeed,
ProviderConfigs: providerConfigs,
}
n.rpcClient, err = rpc.NewClient(config)
n.rpcClient.Start(context.Background())
Expand Down
15 changes: 0 additions & 15 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,6 @@ func NewLimits(min, max int) Limits {
}
}

type ProviderConfig struct {
// Enabled flag specifies whether feature is enabled
Enabled bool `validate:"required"`

// To identify provider
Name string `validate:"required"`

// URL sets the rpc upstream host address for communication with
// a non-local infura endpoint.
User string `json:",omitempty"`
Password string `json:",omitempty"`
APIKey string `json:"APIKey,omitempty"`
APIKeySecret string `json:"APIKeySecret,omitempty"`
}

// ----------
// NodeConfig
// ----------
Expand Down
Loading

0 comments on commit e0e484f

Please sign in to comment.