Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore_: network providers reorder #5941

Merged
merged 2 commits into from
Oct 21, 2024
Merged

chore_: network providers reorder #5941

merged 2 commits into from
Oct 21, 2024

Conversation

saledjenic
Copy link
Contributor

@saledjenic saledjenic commented Oct 14, 2024

A new order of using providers is:

  1. StatusProxy - Node Fleet
  2. StatusProxy - Infura
  3. Direct Infura
  4. StatusProxy - Grove
  5. Direct Grove

Closes #5944

@saledjenic saledjenic requested review from alaibe, shivekkhurana and a team October 14, 2024 09:14
@status-im-auto
Copy link
Member

status-im-auto commented Oct 14, 2024

Jenkins Builds

Click to see older builds (47)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 8c4ba20 #1 2024-10-14 09:20:27 ~5 min linux 📦zip
✔️ 8c4ba20 #1 2024-10-14 09:20:27 ~5 min tests-rpc 📄log
✔️ 8c4ba20 #1 2024-10-14 09:20:41 ~5 min ios 📦zip
✔️ 8c4ba20 #1 2024-10-14 09:21:03 ~6 min android 📦aar
✔️ 8c4ba20 #1 2024-10-14 09:49:16 ~34 min tests 📄log
✔️ e9c6173 #2 2024-10-14 14:42:45 ~2 min android 📦aar
✔️ e9c6173 #2 2024-10-14 14:43:09 ~2 min linux 📦zip
✔️ e9c6173 #2 2024-10-14 14:44:15 ~4 min ios 📦zip
✔️ e9c6173 #2 2024-10-14 14:45:23 ~5 min tests-rpc 📄log
✖️ e9c6173 #2 2024-10-14 15:12:29 ~32 min tests 📄log
✔️ 937aada #3 2024-10-14 19:50:54 ~2 min android 📦aar
✔️ 937aada #3 2024-10-14 19:51:21 ~2 min linux 📦zip
✔️ 937aada #3 2024-10-14 19:52:11 ~3 min ios 📦zip
✖️ 937aada #3 2024-10-14 19:53:41 ~5 min tests-rpc 📄log
✖️ 937aada #3 2024-10-14 20:21:36 ~33 min tests 📄log
✖️ 937aada #4 2024-10-15 06:25:52 ~1 min tests-rpc 📄log
✖️ 937aada #4 2024-10-15 06:57:05 ~32 min tests 📄log
✔️ 53db1bb #4 2024-10-15 08:02:35 ~2 min android 📦aar
✔️ 53db1bb #4 2024-10-15 08:03:05 ~2 min linux 📦zip
✔️ 53db1bb #4 2024-10-15 08:04:19 ~4 min ios 📦zip
✖️ 53db1bb #5 2024-10-15 08:05:14 ~5 min tests-rpc 📄log
✖️ 53db1bb #5 2024-10-15 08:33:25 ~33 min tests 📄log
✔️ 66c7bb8 #5 2024-10-15 08:51:15 ~1 min android 📦aar
✔️ 66c7bb8 #5 2024-10-15 08:51:59 ~2 min linux 📦zip
✔️ 66c7bb8 #5 2024-10-15 08:52:42 ~3 min ios 📦zip
✖️ 66c7bb8 #6 2024-10-15 08:54:24 ~4 min tests-rpc 📄log
✔️ 66c7bb8 #6 2024-10-15 09:22:06 ~32 min tests 📄log
✔️ 4add067 #6 2024-10-15 09:43:19 ~2 min android 📦aar
✔️ 4add067 #6 2024-10-15 09:43:40 ~2 min linux 📦zip
✔️ 4add067 #6 2024-10-15 09:45:02 ~4 min ios 📦zip
✔️ 4add067 #7 2024-10-15 09:46:00 ~5 min tests-rpc 📄log
✔️ 4add067 #7 2024-10-15 10:13:07 ~32 min tests 📄log
✖️ da4d225 #8 2024-10-15 13:00:44 ~1 min tests 📄log
✔️ da4d225 #7 2024-10-15 13:01:29 ~2 min android 📦aar
✔️ da4d225 #7 2024-10-15 13:02:03 ~2 min linux 📦zip
✔️ da4d225 #7 2024-10-15 13:02:54 ~3 min ios 📦zip
✔️ da4d225 #8 2024-10-15 13:04:30 ~5 min tests-rpc 📄log
✔️ 2226a8a #8 2024-10-15 13:03:31 ~1 min android 📦aar
✔️ 2226a8a #8 2024-10-15 13:05:01 ~2 min linux 📦zip
✔️ 2226a8a #8 2024-10-15 13:07:05 ~3 min ios 📦zip
✔️ 2226a8a #9 2024-10-15 13:10:15 ~5 min tests-rpc 📄log
✔️ 2226a8a #9 2024-10-15 13:32:56 ~32 min tests 📄log
✔️ 6979a9b #9 2024-10-15 13:13:04 ~2 min android 📦aar
✔️ 6979a9b #9 2024-10-15 13:14:22 ~3 min ios 📦zip
✔️ 6979a9b #9 2024-10-15 13:15:03 ~4 min linux 📦zip
✔️ 6979a9b #10 2024-10-15 13:15:55 ~5 min tests-rpc 📄log
✔️ 6979a9b #10 2024-10-15 14:05:56 ~32 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 93e88d9 #10 2024-10-16 09:48:52 ~2 min android 📦aar
✔️ 93e88d9 #10 2024-10-16 09:49:27 ~3 min linux 📦zip
✔️ 93e88d9 #10 2024-10-16 09:50:32 ~4 min ios 📦zip
✔️ 93e88d9 #11 2024-10-16 09:51:39 ~5 min tests-rpc 📄log
✔️ 93e88d9 #11 2024-10-16 10:19:08 ~32 min tests 📄log
b0375be #11 2024-10-21 13:02:23 ~12 sec linux 📄log
✔️ b0375be #11 2024-10-21 13:06:48 ~4 min ios 📦zip
✔️ b0375be #11 2024-10-21 13:07:06 ~5 min android 📦aar
✔️ b0375be #12 2024-10-21 13:07:26 ~5 min tests-rpc 📄log
b0375be #12 2024-10-21 13:09:02 ~11 sec linux 📄log
b0375be #13 2024-10-21 13:18:30 ~11 sec linux 📄log
b0375be #14 2024-10-21 13:26:25 ~11 sec linux 📄log
b0375be #15 2024-10-21 13:35:09 ~13 sec linux 📄log
✔️ b0375be #12 2024-10-21 13:35:47 ~33 min tests 📄log
b0375be #16 2024-10-21 13:37:42 ~10 sec linux 📄log
b0375be #17 2024-10-21 13:39:55 ~10 sec linux 📄log
b0375be #18 2024-10-21 13:48:28 ~8.6 sec linux 📄log
b0375be #19 2024-10-21 13:49:40 ~11 sec linux 📄log
b0375be #20 2024-10-21 13:58:34 ~10 sec linux 📄log
b0375be #21 2024-10-21 13:59:21 ~11 sec linux 📄log
b0375be #22 2024-10-21 14:30:31 ~11 sec linux 📄log
✔️ b0375be #23 2024-10-21 15:30:26 ~4 min linux 📦zip

Copy link

codecov bot commented Oct 14, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2903 1 2902 29
View the full list of 1 ❄️ flaky tests
github.com/status-im/status-go/protocol TestMessengerCommunitiesTokenPermissionsSuite

Flake rate in main: 91.01% (Passed 93 times, Failed 942 times)

Stack Traces | 81s run time
=== RUN   TestMessengerCommunitiesTokenPermissionsSuite
2024-10-21T13:21:03.688Z	DEBUG	p2p-config	config/log.go:21	[Fx] HOOK OnStop		github..../p2p/transport/quicreuse.(*ConnManager).Close-fm() called by github..../libp2p/go-libp2p/config.(*Config).addTransports.func9 ran successfully in 6.23µs
2024-10-21T13:22:01.208Z	DEBUG	p2p-config	config/log.go:21	[Fx] HOOK OnStop		github..../libp2p/go-libp2p/config.(*Config).addAutoNAT.func2.1() called by github..../libp2p/go-libp2p/config.(*Config).addAutoNAT.func2 ran successfully in 4.77µs
2024-10-21T13:22:09.327Z	DEBUG	p2p-config	config/log.go:21	[Fx] HOOK OnStop		github..../libp2p/go-libp2p/config.(*Config).addAutoNAT.func2.1() called by github..../libp2p/go-libp2p/config.(*Config).addAutoNAT.func2 ran successfully in 3.52µs
--- FAIL: TestMessengerCommunitiesTokenPermissionsSuite (80.96s)


To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@shivekkhurana
Copy link
Contributor

We should keep Grove because it's the only decentralised provider we have. And it doesn't cost us anything to run.

We can change the order of fallback so the requests don't go there, but if there is a state banning event on Infura (or our proxy), Grove can potentially keep the app usable.

@saledjenic
Copy link
Contributor Author

@shivekkhurana I am not sure why we would like to keep Grove, as an option, if we proved multiple times that it's unreliable, not only that it returns errors where it should not, but also that it returns inaccurate responses and that's more dangerous.

@saledjenic
Copy link
Contributor Author

@status-im/status-go-guild what do you think of updating Networks type and instead of having properties DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2, RPCURL, FallbackURL is better to have an array of rpc URL and use that order?

@shivekkhurana
Copy link
Contributor

shivekkhurana commented Oct 14, 2024

@shivekkhurana I am not sure why we would like to keep Grove, as an option, if we proved multiple times that it's unreliable, not only that it returns errors where it should not, but also that it returns inaccurate responses and that's more dangerous.

As discussed on the call. Grove is the most low prio RPC for doomsday scenarios.

DefaultFallbackURL2: fmt.Sprintf("https://%s.api.status.im/grove/ethereum/mainnet/", stageName),
RPCURL: "https://eth-archival.rpc.grove.city/v1/",
FallbackURL: "https://mainnet.infura.io/v3/",
DefaultFallbackURL2: "https://mainnet.infura.io/v3/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	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

We do not use authentication for RPCURL. If I understand correctly it should be:

		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/",
		BlockExplorerURL:       "https://etherscan.io/",
StatusProxy - Node Fleet
StatusProxy - Infura
Direct Infura
StatusProxy - Grove
Direct Grove

and if we need to have proxy-grove lower than direct-infura, then we should probably add "priority" field to params.network, and respect it in rpc/client.go getEthClients method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@friofry good point, I missed that usage. Thanks.
Need to think a bit about how to do it painless for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now should be good, providers priority is determined by the getProviderPriorityByURL function.

@friofry
Copy link
Contributor

friofry commented Oct 14, 2024

@status-im/status-go-guild what do you think of updating Networks type and instead of having properties DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2, RPCURL, FallbackURL is better to have an array of rpc URL and use that order?

I think it would be great to introduce a one-to-many relationship between Network and Provider. But I would suggest to make it out of the scope of this task

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))
ignoreDefaultRPCURLCheck := false // TODO: used just because of Goerli, remove once we remove Goerli from the default networks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to leave it if removing Goerli now will introduce too much complexity in this PR, there's 0 reason to have it since none of the providers we use support it still.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a new PR that removes Goerli from the code #5945

@saledjenic saledjenic changed the title chore_: grove provider removal Network providers reorder Oct 15, 2024
@saledjenic saledjenic changed the title Network providers reorder chore: network providers reorder Oct 15, 2024
infura = "infura.io/"
grove = "grove.city/"
)

for _, n := range networks {
Copy link
Contributor

@friofry friofry Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion is to add a functor to make it a bit shorter and avoid duplication:

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
	}

	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
			switch n.ChainID {
			case mainnetChainID:
				n.TokenOverrides = []params.TokenOverride{mainnetGanacheTokenOverrides}
			case goerliChainID:
				n.TokenOverrides = []params.TokenOverride{goerliGanacheTokenOverrides}
			}
		}

		networksWithRPC = append(networksWithRPC, n)
	}

	return networksWithRPC
}

rpc/client.go Outdated
func (c *Client) getEthClients(network *params.Network) []ethclient.RPSLimitedEthClientInterface {
// Keys are defining the order of providers being used
Copy link
Contributor

@friofry friofry Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 2 problems:

  • if the same key priority is used
  • some code duplication

my suggestion to add something like this:

type Provider struct {
	Key      string
	URL      string
	Auth     string
	Priority int
}

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
}

and use it in getEthClients

@saledjenic
Copy link
Contributor Author

@friofry thanks for the suggestions, I agree it's better, but I wanted to do it with minimal changes to the current code, that's why I introduced getProviderPriorityByURL. Also as mentioned above leave all those optimizations and improvements for the moment when we're going to remove props DefaultRPCURL, DefaultFallbackURL, DefaultFallbackURL2... and switch to array or map of providers with all necessary fields and proper validations, including priority property.

@saledjenic
Copy link
Contributor Author

if the same key priority is used

That's possible if the same URLs are used for different networks, but that check should be part of the config validation process.

@saledjenic
Copy link
Contributor Author

@friofry updated the code as you suggested. Thanks.

@friofry
Copy link
Contributor

friofry commented Oct 15, 2024

ee it's better, but I wanted to do it with minimal changes to the current code, that's why I introduced getProviderPriorityByURL. Also as mentioned above leave al

Yeah, I realised that too and deleted my comment :)

rpc/provider.go Outdated
ProviderFallback = "fallback"
ProviderStatusProxy = "status-proxy"
ProviderStatusProxyFallback = ProviderStatusProxy + "-fallback"
ProviderStatusProxyFallback2 = ProviderStatusProxy + "-fallback"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's a typo, should befallback2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were faster in commenting on that than me updating it. :)
Thanks, updated.

Copy link
Contributor

@friofry friofry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

A new order of using providers is:
1. StatusProxy - Node Fleet
2. StatusProxy - Infura
3. Direct Infura
4. StatusProxy - Grove
5. Direct Grove
@dlipicar dlipicar changed the title chore: network providers reorder chore_: network providers reorder Oct 21, 2024
@alaibe alaibe merged commit 3179532 into develop Oct 21, 2024
18 checks passed
@alaibe alaibe deleted the remove-grove branch October 21, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set a new order of providers being used
6 participants