From 86cd41d04eb15ebb2698bcaabb305a34c1b48b8f Mon Sep 17 00:00:00 2001 From: Andrey Bocharnikov Date: Sat, 12 Oct 2024 00:01:14 +0700 Subject: [PATCH] chore(wallet)_: remove unused upstream client (#5934) * chore(wallet)_: remove unused upstream client fixes #5933 --- api/defaults.go | 10 --- .../1728661600_drop_upstream_config.up.sql | 1 + appdatabase/node_config_test.go | 1 - cmd/ping-community/main.go | 4 - cmd/populate-db/main.go | 4 - cmd/spiff-workflow/main.go | 5 -- node/get_status_node.go | 2 +- node/status_node_rpc_client_test.go | 3 - node/status_node_services.go | 2 +- nodecfg/node_config.go | 12 --- params/config.go | 56 -------------- params/config_test.go | 15 ---- rpc/client.go | 77 +------------------ rpc/client_test.go | 47 +---------- rpc/verif_proxy_test.go | 2 +- services/ens/api_test.go | 9 +-- services/wallet/api_test.go | 2 +- services/wallet/history/service_test.go | 3 +- services/wallet/router/router_test.go | 3 +- services/wallet/token/token_test.go | 2 +- .../transfer/commands_sequential_test.go | 12 +-- services/web3provider/api_test.go | 8 +- transactions/transactor_test.go | 13 +++- 23 files changed, 35 insertions(+), 258 deletions(-) create mode 100644 appdatabase/migrations/sql/1728661600_drop_upstream_config.up.sql diff --git a/api/defaults.go b/api/defaults.go index bbcc0c239..d891d362d 100644 --- a/api/defaults.go +++ b/api/defaults.go @@ -288,16 +288,6 @@ func DefaultNodeConfig(installationID string, request *requests.CreateAccount, o 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.NoDiscovery = true nodeConfig.MaxPeers = DefaultMaxPeers diff --git a/appdatabase/migrations/sql/1728661600_drop_upstream_config.up.sql b/appdatabase/migrations/sql/1728661600_drop_upstream_config.up.sql new file mode 100644 index 000000000..262ac17e4 --- /dev/null +++ b/appdatabase/migrations/sql/1728661600_drop_upstream_config.up.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS upstream_config; \ No newline at end of file diff --git a/appdatabase/node_config_test.go b/appdatabase/node_config_test.go index c09e6b94e..4841651e5 100644 --- a/appdatabase/node_config_test.go +++ b/appdatabase/node_config_test.go @@ -167,7 +167,6 @@ func randomNodeConfig() *params.NodeConfig { LogMaxSize: randomInt(math.MaxInt64), LogCompressRotated: randomBool(), LogToStderr: randomBool(), - UpstreamConfig: params.UpstreamRPCConfig{Enabled: randomBool(), URL: randomString()}, ClusterConfig: params.ClusterConfig{ Enabled: randomBool(), Fleet: randomString(), diff --git a/cmd/ping-community/main.go b/cmd/ping-community/main.go index 1b7b20593..7866515bd 100644 --- a/cmd/ping-community/main.go +++ b/cmd/ping-community/main.go @@ -345,10 +345,6 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) { nodeConfig.NetworkID = 1 nodeConfig.LogLevel = "ERROR" nodeConfig.DataDir = api.DefaultDataDir - nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{ - Enabled: true, - URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938", - } nodeConfig.Name = "StatusIM" clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod") diff --git a/cmd/populate-db/main.go b/cmd/populate-db/main.go index 0fc6f8aa6..338899b70 100644 --- a/cmd/populate-db/main.go +++ b/cmd/populate-db/main.go @@ -393,10 +393,6 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) { nodeConfig.NetworkID = 1 nodeConfig.LogLevel = "ERROR" nodeConfig.DataDir = api.DefaultDataDir - nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{ - Enabled: true, - URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938", - } nodeConfig.Name = "StatusIM" clusterConfig, err := params.LoadClusterConfigFromFleet("eth.prod") diff --git a/cmd/spiff-workflow/main.go b/cmd/spiff-workflow/main.go index a5a71229b..811165adf 100644 --- a/cmd/spiff-workflow/main.go +++ b/cmd/spiff-workflow/main.go @@ -302,11 +302,6 @@ func defaultNodeConfig(installationID string) (*params.NodeConfig, error) { // Disable to avoid errors about empty ClusterConfig.BootNodes. nodeConfig.NoDiscovery = true - nodeConfig.UpstreamConfig = params.UpstreamRPCConfig{ - Enabled: true, - URL: "https://mainnet.infura.io/v3/800c641949d64d768a5070a1b0511938", - } - nodeConfig.Name = "StatusIM" clusterConfig, err := params.LoadClusterConfigFromFleet("status.prod") if err != nil { diff --git a/node/get_status_node.go b/node/get_status_node.go index 44d4c51f9..ef1ac50fa 100644 --- a/node/get_status_node.go +++ b/node/get_status_node.go @@ -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 { return } diff --git a/node/status_node_rpc_client_test.go b/node/status_node_rpc_client_test.go index 1a07e4450..5484a880f 100644 --- a/node/status_node_rpc_client_test.go +++ b/node/status_node_rpc_client_test.go @@ -121,9 +121,6 @@ func TestNodeRPCClientCallOnlyPublicAPIs(t *testing.T) { statusNode, err := createAndStartStatusNode(¶ms.NodeConfig{ APIModules: "", // no whitelisted API modules; use only public APIs - UpstreamConfig: params.UpstreamRPCConfig{ - URL: "https://infura.io", - Enabled: true}, WakuConfig: params.WakuConfig{ Enabled: true, }, diff --git a/node/status_node_services.go b/node/status_node_services.go index c0b69c69b..16539d21f 100644 --- a/node/status_node_services.go +++ b/node/status_node_services.go @@ -84,7 +84,7 @@ func (b *StatusNode) initServices(config *params.NodeConfig, mediaServer *server setSettingsNotifier(accDB, settingsFeed) 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.rpcStatsService()) services = append(services, b.appmetricsService()) diff --git a/nodecfg/node_config.go b/nodecfg/node_config.go index df6fa25e4..9d5f1daa3 100644 --- a/nodecfg/node_config.go +++ b/nodecfg/node_config.go @@ -151,11 +151,6 @@ func insertClusterConfig(tx *sql.Tx, c *params.NodeConfig) error { 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 { _, 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 @@ -336,7 +331,6 @@ func nodeConfigUpgradeInserts() []insertFn { insertHTTPConfig, insertIPCConfig, insertLogConfig, - insertUpstreamConfig, insertClusterConfig, insertClusterConfigNodes, insertLightETHConfig, @@ -360,7 +354,6 @@ func nodeConfigNormalInserts() []insertFn { insertHTTPConfig, insertIPCConfig, insertLogConfig, - insertUpstreamConfig, insertClusterConfig, insertClusterConfigNodes, insertLightETHConfig, @@ -501,11 +494,6 @@ func loadNodeConfig(tx *sql.Tx) (*params.NodeConfig, error) { 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 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 diff --git a/params/config.go b/params/config.go index 2645bb9b4..fba87d195 100644 --- a/params/config.go +++ b/params/config.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - "net/url" "os" "path/filepath" "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 { // Enabled flag specifies whether feature is enabled Enabled bool `validate:"required"` @@ -459,9 +444,6 @@ type NodeConfig struct { // EnableStatusService should be true to enable methods under status namespace. EnableStatusService bool - // UpstreamConfig extra config for providing upstream infura server. - UpstreamConfig UpstreamRPCConfig `json:"UpstreamConfig"` - // Initial networks to load Networks []Network @@ -951,9 +933,6 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) { LogFile: "", LogLevel: "ERROR", NoDiscovery: true, - UpstreamConfig: UpstreamRPCConfig{ - URL: getUpstreamURL(networkID), - }, LightEthConfig: LightEthConfig{ 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 { return err } @@ -1096,9 +1071,6 @@ func (c *NodeConfig) Validate() error { func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error { // Validate child structs - if err := c.UpstreamConfig.Validate(validate); err != nil { - return err - } if err := c.ClusterConfig.Validate(validate); err != nil { return err } @@ -1117,23 +1089,6 @@ func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error { 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 func (c *ClusterConfig) Validate(validate *validator.Validate) error { if !c.Enabled { @@ -1188,17 +1143,6 @@ func (c *TorrentConfig) Validate(validate *validator.Validate) error { return nil } -func getUpstreamURL(networkID uint64) string { - switch networkID { - case MainNetworkID: - return MainnetEthereumNetworkURL - case GoerliNetworkID: - return GoerliEthereumNetworkURL - } - - return "" -} - // Save dumps configuration to the disk func (c *NodeConfig) Save() error { data, err := json.MarshalIndent(c, "", " ") diff --git a/params/config_test.go b/params/config_test.go index 89120a07b..b87cb057c 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -165,21 +165,6 @@ func TestNodeConfigValidate(t *testing.T) { }`, 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", Config: `{ diff --git a/rpc/client.go b/rpc/client.go index aebe93285..a06326282 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -90,12 +90,9 @@ type ClientInterface interface { type Client struct { sync.RWMutex - upstreamEnabled bool - upstreamURL string UpstreamChainID uint64 local *gethrpc.Client - upstream chain.ClientInterface rpcClientsMutex sync.RWMutex rpcClients map[uint64]chain.ClientInterface rpsLimiterMutex sync.RWMutex @@ -115,12 +112,11 @@ type Client struct { // Is initialized in a build-tag-dependent module var verifProxyInitFn func(c *Client) -// NewClient initializes Client and tries to connect to both, -// upstream and local node. +// NewClient initializes Client // // Client is safe for concurrent use and will automatically // 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 log := log.New("package", "status-go/rpc.Client") @@ -144,40 +140,8 @@ func NewClient(client *gethrpc.Client, upstreamChainID uint64, upstream params.U providerConfigs: providerConfigs, } - var opts []gethrpc.ClientOption - opts = append(opts, - 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) + c.UpstreamChainID = upstreamChainID + c.router = newRouter(true) if verifProxyInitFn != nil { verifProxyInitFn(&c) @@ -235,9 +199,6 @@ func (c *Client) getClientUsingCache(chainID uint64) (chain.ClientInterface, err network := c.NetworkManager.Find(chainID) if network == nil { - if c.UpstreamChainID == chainID { - return c.upstream, nil - } 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 } -// 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 // result if no error occurred. // diff --git a/rpc/client_test.go b/rpc/client_test.go index 55af2a4df..877a1af04 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -44,7 +44,7 @@ func TestBlockedRoutesCall(t *testing.T) { gethRPCClient, err := gethrpc.Dial(ts.URL) 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) for _, m := range blockedMethods { @@ -83,7 +83,7 @@ func TestBlockedRoutesRawCall(t *testing.T) { gethRPCClient, err := gethrpc.Dial(ts.URL) 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) 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) { db, close := setupTestNetworkDB(t) defer close() @@ -183,7 +142,7 @@ func TestGetClientsUsingCache(t *testing.T) { 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) // Networks from DB must pick up DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2 diff --git a/rpc/verif_proxy_test.go b/rpc/verif_proxy_test.go index 5453cf8bc..34f774a11 100644 --- a/rpc/verif_proxy_test.go +++ b/rpc/verif_proxy_test.go @@ -48,7 +48,7 @@ func (s *ProxySuite) startRpcClient(infuraURL string) *Client { db, close := setupTestNetworkDB(s.T()) 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) return c diff --git a/services/ens/api_test.go b/services/ens/api_test.go index bcdd62c1a..4deba6432 100644 --- a/services/ens/api_test.go +++ b/services/ens/api_test.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/common" gethrpc "github.com/ethereum/go-ethereum/rpc" "github.com/status-im/status-go/appdatabase" - "github.com/status-im/status-go/params" statusRPC "github.com/status-im/status-go/rpc" "github.com/status-im/status-go/t/helpers" "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()) { 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) server, _ := fake.NewTestServer(txServiceMockCtrl) client := gethrpc.DialInProc(server) _ = client - rpcClient, err := statusRPC.NewClient(nil, 1, upstreamConfig, nil, db, nil) + rpcClient, err := statusRPC.NewClient(nil, 1, nil, db, nil) require.NoError(t, err) // import account keys diff --git a/services/wallet/api_test.go b/services/wallet/api_test.go index 11817a11f..b4337bbdd 100644 --- a/services/wallet/api_test.go +++ b/services/wallet/api_test.go @@ -144,7 +144,7 @@ func TestAPI_GetAddressDetails(t *testing.T) { 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) chainClient, err := c.EthClient(chainID) diff --git a/services/wallet/history/service_test.go b/services/wallet/history/service_test.go index 248e7b4dd..97c5f4c9a 100644 --- a/services/wallet/history/service_test.go +++ b/services/wallet/history/service_test.go @@ -17,7 +17,6 @@ import ( gethrpc "github.com/ethereum/go-ethereum/rpc" "github.com/status-im/status-go/appdatabase" "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/services/accounts/accountsevent" "github.com/status-im/status-go/t/helpers" @@ -405,7 +404,7 @@ func Test_removeBalanceHistoryOnEventAccountRemoved(t *testing.T) { txServiceMockCtrl := gomock.NewController(t) server, _ := fake.NewTestServer(txServiceMockCtrl) 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 service := NewService(walletDB, accountsDB, &accountFeed, &walletFeed, rpcClient, nil, nil, nil) diff --git a/services/wallet/router/router_test.go b/services/wallet/router/router_test.go index 8990539a6..8b06ab174 100644 --- a/services/wallet/router/router_test.go +++ b/services/wallet/router/router_test.go @@ -8,7 +8,6 @@ import ( "time" "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/services/wallet/responses" "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()) { 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) diff --git a/services/wallet/token/token_test.go b/services/wallet/token/token_test.go index 51617d670..f8b01c073 100644 --- a/services/wallet/token/token_test.go +++ b/services/wallet/token/token_test.go @@ -331,7 +331,7 @@ func Test_removeTokenBalanceOnEventAccountRemoved(t *testing.T) { txServiceMockCtrl := gomock.NewController(t) server, _ := fake.NewTestServer(txServiceMockCtrl) 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 nm := network.NewManager(appDB) mediaServer, err := mediaserver.NewMediaServer(appDB, nil, nil, walletDB) diff --git a/services/wallet/transfer/commands_sequential_test.go b/services/wallet/transfer/commands_sequential_test.go index b463ada8d..8da1a4ea5 100644 --- a/services/wallet/transfer/commands_sequential_test.go +++ b/services/wallet/transfer/commands_sequential_test.go @@ -1079,7 +1079,7 @@ func setupFindBlocksCommand(t *testing.T, accountAddress common.Address, fromBlo 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) 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{ @@ -1342,7 +1342,7 @@ func TestFetchTransfersForLoadedBlocks(t *testing.T) { 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) 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, } - 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) 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) 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) 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 - 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) 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{}) 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) wdb := NewDB(db) diff --git a/services/web3provider/api_test.go b/services/web3provider/api_test.go index 1332aca66..22b5b55a3 100644 --- a/services/web3provider/api_test.go +++ b/services/web3provider/api_test.go @@ -35,17 +35,11 @@ func setupTestAPI(t *testing.T) (*API, func()) { 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) server, _ := fake.NewTestServer(txServiceMockCtrl) 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) // import account keys diff --git a/transactions/transactor_test.go b/transactions/transactor_test.go index b3be2b94c..7d6252939 100644 --- a/transactions/transactor_test.go +++ b/transactions/transactor_test.go @@ -7,6 +7,10 @@ import ( "testing" "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" "go.uber.org/mock/gomock" @@ -56,8 +60,15 @@ func (s *TransactorSuite) SetupTest() { chainID := gethparams.AllEthashProtocolChanges.ChainID.Uint64() db, err := sqlite.OpenUnecryptedDB(sqlite.InMemoryPath) // dummy to make rpc.Client happy 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 + + 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) s.Require().NoError(err) s.nodeConfig = nodeConfig