chore(wallet)_: remove unused upstream client (#5934)

* chore(wallet)_: remove unused upstream client

fixes #5933
This commit is contained in:
Andrey Bocharnikov 2024-10-12 00:01:14 +07:00 committed by GitHub
parent 2c5737b7f6
commit 86cd41d04e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 35 additions and 258 deletions

View File

@ -288,16 +288,6 @@ func DefaultNodeConfig(installationID string, request *requests.CreateAccount, o
nodeConfig.NetworkID = nodeConfig.Networks[0].ChainID nodeConfig.NetworkID = nodeConfig.Networks[0].ChainID
} }
if request.UpstreamConfig != "" {
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
Enabled: true,
URL: request.UpstreamConfig,
}
} else {
nodeConfig.UpstreamConfig.URL = mainnet(request.WalletSecretsConfig.StatusProxyStageName).RPCURL
nodeConfig.UpstreamConfig.Enabled = true
}
nodeConfig.Name = DefaultNodeName nodeConfig.Name = DefaultNodeName
nodeConfig.NoDiscovery = true nodeConfig.NoDiscovery = true
nodeConfig.MaxPeers = DefaultMaxPeers nodeConfig.MaxPeers = DefaultMaxPeers

View File

@ -0,0 +1 @@
DROP TABLE IF EXISTS upstream_config;

View File

@ -167,7 +167,6 @@ func randomNodeConfig() *params.NodeConfig {
LogMaxSize: randomInt(math.MaxInt64), LogMaxSize: randomInt(math.MaxInt64),
LogCompressRotated: randomBool(), LogCompressRotated: randomBool(),
LogToStderr: randomBool(), LogToStderr: randomBool(),
UpstreamConfig: params.UpstreamRPCConfig{Enabled: randomBool(), URL: randomString()},
ClusterConfig: params.ClusterConfig{ ClusterConfig: params.ClusterConfig{
Enabled: randomBool(), Enabled: randomBool(),
Fleet: randomString(), Fleet: randomString(),

View File

@ -345,10 +345,6 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
nodeConfig.NetworkID = 1 nodeConfig.NetworkID = 1
nodeConfig.LogLevel = "ERROR" nodeConfig.LogLevel = "ERROR"
nodeConfig.DataDir = api.DefaultDataDir nodeConfig.DataDir = api.DefaultDataDir
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
Enabled: true,
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
}
nodeConfig.Name = "StatusIM" nodeConfig.Name = "StatusIM"
clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod") clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod")

View File

@ -393,10 +393,6 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
nodeConfig.NetworkID = 1 nodeConfig.NetworkID = 1
nodeConfig.LogLevel = "ERROR" nodeConfig.LogLevel = "ERROR"
nodeConfig.DataDir = api.DefaultDataDir nodeConfig.DataDir = api.DefaultDataDir
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
Enabled: true,
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
}
nodeConfig.Name = "StatusIM" nodeConfig.Name = "StatusIM"
clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod") clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod")

View File

@ -302,11 +302,6 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) {
// Disable to avoid errors about empty ClusterConfig.BootNodes. // Disable to avoid errors about empty ClusterConfig.BootNodes.
nodeConfig.NoDiscovery = true nodeConfig.NoDiscovery = true
nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{
Enabled: true,
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
}
nodeConfig.Name = "StatusIM" nodeConfig.Name = "StatusIM"
clusterConfig, err := params.LoadClusterConfigFromFleet("status.prod") clusterConfig, err := params.LoadClusterConfigFromFleet("status.prod")
if err != nil { if err != nil {

View File

@ -331,7 +331,7 @@ func (n *StatusNode) setupRPCClient() (err error) {
}, },
} }
n.rpcClient, err = rpc.NewClient(gethNodeClient, n.config.NetworkID, n.config.UpstreamConfig, n.config.Networks, n.appDB, providerConfigs) n.rpcClient, err = rpc.NewClient(gethNodeClient, n.config.NetworkID, n.config.Networks, n.appDB, providerConfigs)
if err != nil { if err != nil {
return return
} }

View File

@ -121,9 +121,6 @@ func TestNodeRPCClientCallOnlyPublicAPIs(t *testing.T) {
statusNode, err := createAndStartStatusNode(&params.NodeConfig{ statusNode, err := createAndStartStatusNode(&params.NodeConfig{
APIModules: "", // no whitelisted API modules; use only public APIs APIModules: "", // no whitelisted API modules; use only public APIs
UpstreamConfig: params.UpstreamRPCConfig{
URL: "https://infura.io",
Enabled: true},
WakuConfig: params.WakuConfig{ WakuConfig: params.WakuConfig{
Enabled: true, Enabled: true,
}, },

View File

@ -84,7 +84,7 @@ func (b *StatusNode) initServices(config *params.NodeConfig, mediaServer *server
setSettingsNotifier(accDB, settingsFeed) setSettingsNotifier(accDB, settingsFeed)
services := []common.StatusService{} services := []common.StatusService{}
services = appendIf(config.UpstreamConfig.Enabled, services, b.rpcFiltersService()) services = append(services, b.rpcFiltersService())
services = append(services, b.subscriptionService()) services = append(services, b.subscriptionService())
services = append(services, b.rpcStatsService()) services = append(services, b.rpcStatsService())
services = append(services, b.appmetricsService()) services = append(services, b.appmetricsService())

View File

@ -151,11 +151,6 @@ func insertClusterConfig(tx *sql.Tx, c *params.NodeConfig) error {
return err return err
} }
func insertUpstreamConfig(tx *sql.Tx, c *params.NodeConfig) error {
_, err := tx.Exec(`INSERT OR REPLACE INTO upstream_config (enabled, url, synthetic_id) VALUES (?, ?, 'id')`, c.UpstreamConfig.Enabled, c.UpstreamConfig.URL)
return err
}
func insertLightETHConfig(tx *sql.Tx, c *params.NodeConfig) error { func insertLightETHConfig(tx *sql.Tx, c *params.NodeConfig) error {
_, err := tx.Exec(`INSERT OR REPLACE INTO light_eth_config (enabled, database_cache, min_trusted_fraction, synthetic_id) VALUES (?, ?, ?, 'id')`, c.LightEthConfig.Enabled, c.LightEthConfig.DatabaseCache, c.LightEthConfig.MinTrustedFraction) _, err := tx.Exec(`INSERT OR REPLACE INTO light_eth_config (enabled, database_cache, min_trusted_fraction, synthetic_id) VALUES (?, ?, ?, 'id')`, c.LightEthConfig.Enabled, c.LightEthConfig.DatabaseCache, c.LightEthConfig.MinTrustedFraction)
return err return err
@ -336,7 +331,6 @@ func nodeConfigUpgradeInserts() []insertFn {
insertHTTPConfig, insertHTTPConfig,
insertIPCConfig, insertIPCConfig,
insertLogConfig, insertLogConfig,
insertUpstreamConfig,
insertClusterConfig, insertClusterConfig,
insertClusterConfigNodes, insertClusterConfigNodes,
insertLightETHConfig, insertLightETHConfig,
@ -360,7 +354,6 @@ func nodeConfigNormalInserts() []insertFn {
insertHTTPConfig, insertHTTPConfig,
insertIPCConfig, insertIPCConfig,
insertLogConfig, insertLogConfig,
insertUpstreamConfig,
insertClusterConfig, insertClusterConfig,
insertClusterConfigNodes, insertClusterConfigNodes,
insertLightETHConfig, insertLightETHConfig,
@ -501,11 +494,6 @@ func loadNodeConfig(tx *sql.Tx) (*params.NodeConfig, error) {
return nil, err return nil, err
} }
err = tx.QueryRow("SELECT enabled, url FROM upstream_config WHERE synthetic_id = 'id'").Scan(&nodecfg.UpstreamConfig.Enabled, &nodecfg.UpstreamConfig.URL)
if err != nil && err != sql.ErrNoRows {
return nil, err
}
rows, err = tx.Query(`SELECT rows, err = tx.Query(`SELECT
chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name, chain_id, chain_name, rpc_url, block_explorer_url, icon_url, native_currency_name,
native_currency_symbol, native_currency_decimals, is_test, layer, enabled, chain_color, short_name native_currency_symbol, native_currency_decimals, is_test, layer, enabled, chain_color, short_name

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -293,20 +292,6 @@ func NewLimits(min, max int) Limits {
} }
} }
// ----------
// UpstreamRPCConfig
// ----------
// UpstreamRPCConfig stores configuration for upstream rpc connection.
type UpstreamRPCConfig struct {
// Enabled flag specifies whether feature is enabled
Enabled bool
// URL sets the rpc upstream host address for communication with
// a non-local infura endpoint.
URL string
}
type ProviderConfig struct { type ProviderConfig struct {
// Enabled flag specifies whether feature is enabled // Enabled flag specifies whether feature is enabled
Enabled bool `validate:"required"` Enabled bool `validate:"required"`
@ -459,9 +444,6 @@ type NodeConfig struct {
// EnableStatusService should be true to enable methods under status namespace. // EnableStatusService should be true to enable methods under status namespace.
EnableStatusService bool EnableStatusService bool
// UpstreamConfig extra config for providing upstream infura server.
UpstreamConfig UpstreamRPCConfig `json:"UpstreamConfig"`
// Initial networks to load // Initial networks to load
Networks []Network Networks []Network
@ -951,9 +933,6 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
LogFile: "", LogFile: "",
LogLevel: "ERROR", LogLevel: "ERROR",
NoDiscovery: true, NoDiscovery: true,
UpstreamConfig: UpstreamRPCConfig{
URL: getUpstreamURL(networkID),
},
LightEthConfig: LightEthConfig{ LightEthConfig: LightEthConfig{
DatabaseCache: 16, DatabaseCache: 16,
}, },
@ -1061,10 +1040,6 @@ func (c *NodeConfig) Validate() error {
} }
} }
if c.UpstreamConfig.Enabled && c.LightEthConfig.Enabled {
return fmt.Errorf("both UpstreamConfig and LightEthConfig are enabled, but they are mutually exclusive")
}
if err := c.validateChildStructs(validate); err != nil { if err := c.validateChildStructs(validate); err != nil {
return err return err
} }
@ -1096,9 +1071,6 @@ func (c *NodeConfig) Validate() error {
func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error { func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error {
// Validate child structs // Validate child structs
if err := c.UpstreamConfig.Validate(validate); err != nil {
return err
}
if err := c.ClusterConfig.Validate(validate); err != nil { if err := c.ClusterConfig.Validate(validate); err != nil {
return err return err
} }
@ -1117,23 +1089,6 @@ func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error {
return nil return nil
} }
// Validate validates the UpstreamRPCConfig struct and returns an error if inconsistent values are found
func (c *UpstreamRPCConfig) Validate(validate *validator.Validate) error {
if !c.Enabled {
return nil
}
if err := validate.Struct(c); err != nil {
return err
}
if _, err := url.ParseRequestURI(c.URL); err != nil {
return fmt.Errorf("UpstreamRPCConfig.URL '%s' is invalid: %v", c.URL, err.Error())
}
return nil
}
// Validate validates the ClusterConfig struct and returns an error if inconsistent values are found // Validate validates the ClusterConfig struct and returns an error if inconsistent values are found
func (c *ClusterConfig) Validate(validate *validator.Validate) error { func (c *ClusterConfig) Validate(validate *validator.Validate) error {
if !c.Enabled { if !c.Enabled {
@ -1188,17 +1143,6 @@ func (c *TorrentConfig) Validate(validate *validator.Validate) error {
return nil return nil
} }
func getUpstreamURL(networkID uint64) string {
switch networkID {
case MainNetworkID:
return MainnetEthereumNetworkURL
case GoerliNetworkID:
return GoerliEthereumNetworkURL
}
return ""
}
// Save dumps configuration to the disk // Save dumps configuration to the disk
func (c *NodeConfig) Save() error { func (c *NodeConfig) Save() error {
data, err := json.MarshalIndent(c, "", " ") data, err := json.MarshalIndent(c, "", " ")

View File

@ -165,21 +165,6 @@ func TestNodeConfigValidate(t *testing.T) {
}`, }`,
Error: "NodeKey is invalid", Error: "NodeKey is invalid",
}, },
{
Name: "Validate that UpstreamConfig.URL is validated if UpstreamConfig is enabled",
Config: `{
"NetworkId": 1,
"DataDir": "/some/dir",
"KeyStoreDir": "/some/dir",
"KeycardPairingDataFile": "/some/dir/keycard/pairings.json",
"NoDiscovery": true,
"UpstreamConfig": {
"Enabled": true,
"URL": "[bad.url]"
}
}`,
Error: "'[bad.url]' is invalid",
},
{ {
Name: "Validate that UpstreamConfig.URL is not validated if UpstreamConfig is disabled", Name: "Validate that UpstreamConfig.URL is not validated if UpstreamConfig is disabled",
Config: `{ Config: `{

View File

@ -90,12 +90,9 @@ type ClientInterface interface {
type Client struct { type Client struct {
sync.RWMutex sync.RWMutex
upstreamEnabled bool
upstreamURL string
UpstreamChainID uint64 UpstreamChainID uint64
local *gethrpc.Client local *gethrpc.Client
upstream chain.ClientInterface
rpcClientsMutex sync.RWMutex rpcClientsMutex sync.RWMutex
rpcClients map[uint64]chain.ClientInterface rpcClients map[uint64]chain.ClientInterface
rpsLimiterMutex sync.RWMutex rpsLimiterMutex sync.RWMutex
@ -115,12 +112,11 @@ type Client struct {
// Is initialized in a build-tag-dependent module // Is initialized in a build-tag-dependent module
var verifProxyInitFn func(c *Client) var verifProxyInitFn func(c *Client)
// NewClient initializes Client and tries to connect to both, // NewClient initializes Client
// upstream and local node.
// //
// Client is safe for concurrent use and will automatically // Client is safe for concurrent use and will automatically
// reconnect to the server if connection is lost. // reconnect to the server if connection is lost.
func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.UpstreamRPCConfig, networks []params.Network, db *sql.DB, providerConfigs []params.ProviderConfig) (*Client, error) { func NewClient(client *gethrpc.Client, upstreamChainID uint64, networks []params.Network, db *sql.DB, providerConfigs []params.ProviderConfig) (*Client, error) {
var err error var err error
log := log.New("package", "status-go/rpc.Client") log := log.New("package", "status-go/rpc.Client")
@ -144,40 +140,8 @@ func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.U
providerConfigs: providerConfigs, providerConfigs: providerConfigs,
} }
var opts []gethrpc.ClientOption c.UpstreamChainID = upstreamChainID
opts = append(opts, c.router = newRouter(true)
gethrpc.WithHeaders(http.Header{
"User-Agent": {rpcUserAgentUpstreamName},
}),
)
if upstream.Enabled {
c.UpstreamChainID = upstreamChainID
c.upstreamEnabled = upstream.Enabled
c.upstreamURL = upstream.URL
upstreamClient, err := gethrpc.DialOptions(context.Background(), c.upstreamURL, opts...)
if err != nil {
return nil, fmt.Errorf("dial upstream server: %s", err)
}
limiter, err := c.getRPCRpsLimiter(c.upstreamURL)
if err != nil {
return nil, fmt.Errorf("get RPC limiter: %s", err)
}
hostPortUpstream, err := extractHostFromURL(c.upstreamURL)
if err != nil {
hostPortUpstream = "upstream"
}
// Include the chain-id in the rpc client
rpcName := fmt.Sprintf("%s-chain-id-%d", hostPortUpstream, upstreamChainID)
ethClients := []ethclient.RPSLimitedEthClientInterface{
ethclient.NewRPSLimitedEthClient(upstreamClient, limiter, rpcName),
}
c.upstream = chain.NewClient(ethClients, upstreamChainID)
}
c.router = newRouter(c.upstreamEnabled)
if verifProxyInitFn != nil { if verifProxyInitFn != nil {
verifProxyInitFn(&c) verifProxyInitFn(&c)
@ -235,9 +199,6 @@ func (c *Client) getClientUsingCache(chainID uint64) (chain.ClientInterface, err
network := c.NetworkManager.Find(chainID) network := c.NetworkManager.Find(chainID)
if network == nil { if network == nil {
if c.UpstreamChainID == chainID {
return c.upstream, nil
}
return nil, fmt.Errorf("could not find network: %d", chainID) return nil, fmt.Errorf("could not find network: %d", chainID)
} }
@ -368,36 +329,6 @@ func (c *Client) SetClient(chainID uint64, client chain.ClientInterface) {
c.rpcClients[chainID] = client c.rpcClients[chainID] = client
} }
// UpdateUpstreamURL changes the upstream RPC client URL, if the upstream is enabled.
func (c *Client) UpdateUpstreamURL(url string) error {
if c.upstream == nil {
return nil
}
rpcClient, err := gethrpc.Dial(url)
if err != nil {
return err
}
rpsLimiter, err := c.getRPCRpsLimiter(url)
if err != nil {
return err
}
c.Lock()
hostPortUpstream, err := extractHostFromURL(url)
if err != nil {
hostPortUpstream = "upstream"
}
ethClients := []ethclient.RPSLimitedEthClientInterface{
ethclient.NewRPSLimitedEthClient(rpcClient, rpsLimiter, hostPortUpstream),
}
c.upstream = chain.NewClient(ethClients, c.UpstreamChainID)
c.upstreamURL = url
c.Unlock()
return nil
}
// Call performs a JSON-RPC call with the given arguments and unmarshals into // Call performs a JSON-RPC call with the given arguments and unmarshals into
// result if no error occurred. // result if no error occurred.
// //

View File

@ -44,7 +44,7 @@ func TestBlockedRoutesCall(t *testing.T) {
gethRPCClient, err := gethrpc.Dial(ts.URL) gethRPCClient, err := gethrpc.Dial(ts.URL)
require.NoError(t, err) require.NoError(t, err)
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) c, err := NewClient(gethRPCClient, 1, []params.Network{}, db, nil)
require.NoError(t, err) require.NoError(t, err)
for _, m := range blockedMethods { for _, m := range blockedMethods {
@ -83,7 +83,7 @@ func TestBlockedRoutesRawCall(t *testing.T) {
gethRPCClient, err := gethrpc.Dial(ts.URL) gethRPCClient, err := gethrpc.Dial(ts.URL)
require.NoError(t, err) require.NoError(t, err)
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) c, err := NewClient(gethRPCClient, 1, []params.Network{}, db, nil)
require.NoError(t, err) require.NoError(t, err)
for _, m := range blockedMethods { for _, m := range blockedMethods {
@ -97,47 +97,6 @@ func TestBlockedRoutesRawCall(t *testing.T) {
} }
} }
func TestUpdateUpstreamURL(t *testing.T) {
db, close := setupTestNetworkDB(t)
defer close()
ts := createTestServer("")
defer ts.Close()
updatedUpstreamTs := createTestServer("")
defer updatedUpstreamTs.Close()
gethRPCClient, err := gethrpc.Dial(ts.URL)
require.NoError(t, err)
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: true, URL: ts.URL}, []params.Network{}, db, nil)
require.NoError(t, err)
require.Equal(t, ts.URL, c.upstreamURL)
// cache the original upstream client
originalUpstreamClient := c.upstream
err = c.UpdateUpstreamURL(updatedUpstreamTs.URL)
require.NoError(t, err)
// the upstream cleint instance should change
require.NotEqual(t, originalUpstreamClient, c.upstream)
require.Equal(t, updatedUpstreamTs.URL, c.upstreamURL)
}
func createTestServer(resp string) *httptest.Server {
if resp == "" {
resp = `{
"id": 1,
"jsonrpc": "2.0",
"result": "0x234234e22b9ffc2387e18636e0534534a3d0c56b0243567432453264c16e78a2adc"
}`
}
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, resp)
}))
}
func TestGetClientsUsingCache(t *testing.T) { func TestGetClientsUsingCache(t *testing.T) {
db, close := setupTestNetworkDB(t) db, close := setupTestNetworkDB(t)
defer close() defer close()
@ -183,7 +142,7 @@ func TestGetClientsUsingCache(t *testing.T) {
DefaultFallbackURL2: server.URL + path3, DefaultFallbackURL2: server.URL + path3,
}, },
} }
c, err := NewClient(nil, 1, params.UpstreamRPCConfig{}, networks, db, providerConfigs) c, err := NewClient(nil, 1, networks, db, providerConfigs)
require.NoError(t, err) require.NoError(t, err)
// Networks from DB must pick up DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2 // Networks from DB must pick up DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2

View File

@ -48,7 +48,7 @@ func (s *ProxySuite) startRpcClient(infuraURL string) *Client {
db, close := setupTestNetworkDB(s.T()) db, close := setupTestNetworkDB(s.T())
defer close() defer close()
c, err := NewClient(gethRPCClient, 1, params.UpstreamRPCConfig{Enabled: true, URL: infuraURL}, []params.Network{}, db) c, err := NewClient(gethRPCClient, 1, []params.Network{}, db)
require.NoError(s.T(), err) require.NoError(s.T(), err)
return c return c

View File

@ -12,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
gethrpc "github.com/ethereum/go-ethereum/rpc" gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/status-go/appdatabase" "github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/params"
statusRPC "github.com/status-im/status-go/rpc" statusRPC "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/t/helpers"
"github.com/status-im/status-go/t/utils" "github.com/status-im/status-go/t/utils"
@ -28,19 +27,13 @@ func createDB(t *testing.T) (*sql.DB, func()) {
func setupTestAPI(t *testing.T) (*API, func()) { func setupTestAPI(t *testing.T) (*API, func()) {
db, cancel := createDB(t) db, cancel := createDB(t)
// Creating a dummy status node to simulate what it's done in get_status_node.go
upstreamConfig := params.UpstreamRPCConfig{
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
Enabled: true,
}
txServiceMockCtrl := gomock.NewController(t) txServiceMockCtrl := gomock.NewController(t)
server, _ := fake.NewTestServer(txServiceMockCtrl) server, _ := fake.NewTestServer(txServiceMockCtrl)
client := gethrpc.DialInProc(server) client := gethrpc.DialInProc(server)
_ = client _ = client
rpcClient, err := statusRPC.NewClient(nil, 1, upstreamConfig, nil, db, nil) rpcClient, err := statusRPC.NewClient(nil, 1, nil, db, nil)
require.NoError(t, err) require.NoError(t, err)
// import account keys // import account keys

View File

@ -144,7 +144,7 @@ func TestAPI_GetAddressDetails(t *testing.T) {
DefaultFallbackURL: serverWith1SecDelay.URL, DefaultFallbackURL: serverWith1SecDelay.URL,
}, },
} }
c, err := rpc.NewClient(nil, chainID, params.UpstreamRPCConfig{}, networks, appDB, providerConfigs) c, err := rpc.NewClient(nil, chainID, networks, appDB, providerConfigs)
require.NoError(t, err) require.NoError(t, err)
chainClient, err := c.EthClient(chainID) chainClient, err := c.EthClient(chainID)

View File

@ -17,7 +17,6 @@ import (
gethrpc "github.com/ethereum/go-ethereum/rpc" gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/status-go/appdatabase" "github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/multiaccounts/accounts" "github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/accounts/accountsevent" "github.com/status-im/status-go/services/accounts/accountsevent"
"github.com/status-im/status-go/t/helpers" "github.com/status-im/status-go/t/helpers"
@ -405,7 +404,7 @@ func Test_removeBalanceHistoryOnEventAccountRemoved(t *testing.T) {
txServiceMockCtrl := gomock.NewController(t) txServiceMockCtrl := gomock.NewController(t)
server, _ := fake.NewTestServer(txServiceMockCtrl) server, _ := fake.NewTestServer(txServiceMockCtrl)
client := gethrpc.DialInProc(server) client := gethrpc.DialInProc(server)
rpcClient, _ := rpc.NewClient(client, chainID, params.UpstreamRPCConfig{}, nil, appDB, nil) rpcClient, _ := rpc.NewClient(client, chainID, nil, appDB, nil)
rpcClient.UpstreamChainID = chainID rpcClient.UpstreamChainID = chainID
service := NewService(walletDB, accountsDB, &accountFeed, &walletFeed, rpcClient, nil, nil, nil) service := NewService(walletDB, accountsDB, &accountFeed, &walletFeed, rpcClient, nil, nil, nil)

View File

@ -8,7 +8,6 @@ import (
"time" "time"
"github.com/status-im/status-go/appdatabase" "github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc" "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/wallet/responses" "github.com/status-im/status-go/services/wallet/responses"
"github.com/status-im/status-go/services/wallet/router/pathprocessor" "github.com/status-im/status-go/services/wallet/router/pathprocessor"
@ -92,7 +91,7 @@ func setupTestNetworkDB(t *testing.T) (*sql.DB, func()) {
func setupRouter(t *testing.T) (*Router, func()) { func setupRouter(t *testing.T) (*Router, func()) {
db, cleanTmpDb := setupTestNetworkDB(t) db, cleanTmpDb := setupTestNetworkDB(t)
client, _ := rpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, defaultNetworks, db, nil) client, _ := rpc.NewClient(nil, 1, defaultNetworks, db, nil)
router := NewRouter(client, nil, nil, nil, nil, nil, nil, nil) router := NewRouter(client, nil, nil, nil, nil, nil, nil, nil)

View File

@ -331,7 +331,7 @@ func Test_removeTokenBalanceOnEventAccountRemoved(t *testing.T) {
txServiceMockCtrl := gomock.NewController(t) txServiceMockCtrl := gomock.NewController(t)
server, _ := fake.NewTestServer(txServiceMockCtrl) server, _ := fake.NewTestServer(txServiceMockCtrl)
client := gethrpc.DialInProc(server) client := gethrpc.DialInProc(server)
rpcClient, _ := rpc.NewClient(client, chainID, params.UpstreamRPCConfig{}, nil, appDB, nil) rpcClient, _ := rpc.NewClient(client, chainID, nil, appDB, nil)
rpcClient.UpstreamChainID = chainID rpcClient.UpstreamChainID = chainID
nm := network.NewManager(appDB) nm := network.NewManager(appDB)
mediaServer, err := mediaserver.NewMediaServer(appDB, nil, nil, walletDB) mediaServer, err := mediaserver.NewMediaServer(appDB, nil, nil, walletDB)

View File

@ -1079,7 +1079,7 @@ func setupFindBlocksCommand(t *testing.T, accountAddress common.Address, fromBlo
return nil return nil
} }
client, _ := statusRpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) client, _ := statusRpc.NewClient(nil, 1, []params.Network{}, db, nil)
client.SetClient(tc.NetworkID(), tc) client.SetClient(tc.NetworkID(), tc)
tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db)) tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db))
tokenManager.SetTokens([]*token.Token{ tokenManager.SetTokens([]*token.Token{
@ -1342,7 +1342,7 @@ func TestFetchTransfersForLoadedBlocks(t *testing.T) {
currentBlock: 100, currentBlock: 100,
} }
client, _ := statusRpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) client, _ := statusRpc.NewClient(nil, 1, []params.Network{}, db, nil)
client.SetClient(tc.NetworkID(), tc) client.SetClient(tc.NetworkID(), tc)
tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db)) tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db))
@ -1466,7 +1466,7 @@ func TestFetchNewBlocksCommand_findBlocksWithEthTransfers(t *testing.T) {
currentBlock: 100, currentBlock: 100,
} }
client, _ := statusRpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) client, _ := statusRpc.NewClient(nil, 1, []params.Network{}, db, nil)
client.SetClient(tc.NetworkID(), tc) client.SetClient(tc.NetworkID(), tc)
tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db)) tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db))
@ -1546,7 +1546,7 @@ func TestFetchNewBlocksCommand_nonceDetection(t *testing.T) {
mediaServer, err := server.NewMediaServer(appdb, nil, nil, db) mediaServer, err := server.NewMediaServer(appdb, nil, nil, db)
require.NoError(t, err) require.NoError(t, err)
client, _ := statusRpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) client, _ := statusRpc.NewClient(nil, 1, []params.Network{}, db, nil)
client.SetClient(tc.NetworkID(), tc) client.SetClient(tc.NetworkID(), tc)
tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db)) tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db))
@ -1660,7 +1660,7 @@ func TestFetchNewBlocksCommand(t *testing.T) {
} }
//tc.printPreparedData = true //tc.printPreparedData = true
client, _ := statusRpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) client, _ := statusRpc.NewClient(nil, 1, []params.Network{}, db, nil)
client.SetClient(tc.NetworkID(), tc) client.SetClient(tc.NetworkID(), tc)
tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db)) tokenManager := token.NewTokenManager(db, client, community.NewManager(appdb, nil, nil), network.NewManager(appdb), appdb, mediaServer, nil, nil, nil, token.NewPersistence(db))
@ -1799,7 +1799,7 @@ func TestLoadBlocksAndTransfersCommand_FiniteFinishedInfiniteRunning(t *testing.
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{}) db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
require.NoError(t, err) require.NoError(t, err)
client, _ := statusRpc.NewClient(nil, 1, params.UpstreamRPCConfig{Enabled: false, URL: ""}, []params.Network{}, db, nil) client, _ := statusRpc.NewClient(nil, 1, []params.Network{}, db, nil)
maker, _ := contracts.NewContractMaker(client) maker, _ := contracts.NewContractMaker(client)
wdb := NewDB(db) wdb := NewDB(db)

View File

@ -35,17 +35,11 @@ func setupTestAPI(t *testing.T) (*API, func()) {
keyStoreDir := t.TempDir() keyStoreDir := t.TempDir()
// Creating a dummy status node to simulate what it's done in get_status_node.go
upstreamConfig := params.UpstreamRPCConfig{
URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938",
Enabled: true,
}
txServiceMockCtrl := gomock.NewController(t) txServiceMockCtrl := gomock.NewController(t)
server, _ := fake.NewTestServer(txServiceMockCtrl) server, _ := fake.NewTestServer(txServiceMockCtrl)
client := gethrpc.DialInProc(server) client := gethrpc.DialInProc(server)
rpcClient, err := statusRPC.NewClient(client, 1, upstreamConfig, nil, db, nil) rpcClient, err := statusRPC.NewClient(client, 1, nil, db, nil)
require.NoError(t, err) require.NoError(t, err)
// import account keys // import account keys

View File

@ -7,6 +7,10 @@ import (
"testing" "testing"
"time" "time"
"github.com/status-im/status-go/rpc/chain"
"github.com/status-im/status-go/rpc/chain/ethclient"
"github.com/status-im/status-go/rpc/chain/rpclimiter"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.uber.org/mock/gomock" "go.uber.org/mock/gomock"
@ -56,8 +60,15 @@ func (s *TransactorSuite) SetupTest() {
chainID := gethparams.AllEthashProtocolChanges.ChainID.Uint64() chainID := gethparams.AllEthashProtocolChanges.ChainID.Uint64()
db, err := sqlite.OpenUnecryptedDB(sqlite.InMemoryPath) // dummy to make rpc.Client happy db, err := sqlite.OpenUnecryptedDB(sqlite.InMemoryPath) // dummy to make rpc.Client happy
s.Require().NoError(err) s.Require().NoError(err)
rpcClient, _ := rpc.NewClient(s.client, chainID, params.UpstreamRPCConfig{}, nil, db, nil) rpcClient, _ := rpc.NewClient(s.client, chainID, nil, db, nil)
rpcClient.UpstreamChainID = chainID rpcClient.UpstreamChainID = chainID
ethClients := []ethclient.RPSLimitedEthClientInterface{
ethclient.NewRPSLimitedEthClient(s.client, rpclimiter.NewRPCRpsLimiter(), "local-1-chain-id-1"),
}
localClient := chain.NewClient(ethClients, chainID)
rpcClient.SetClient(chainID, localClient)
nodeConfig, err := utils.MakeTestNodeConfigWithDataDir("", "/tmp", chainID) nodeConfig, err := utils.MakeTestNodeConfigWithDataDir("", "/tmp", chainID)
s.Require().NoError(err) s.Require().NoError(err)
s.nodeConfig = nodeConfig s.nodeConfig = nodeConfig