tahowallet / extension

Taho, the community owned and operated Web3 wallet.
https://taho.xyz
GNU General Public License v3.0
3.09k stars 389 forks source link

Price fetches fail when there are many tracked assets #3581

Open beemeeupnow opened 11 months ago

beemeeupnow commented 11 months ago

Discord Discussion Link

No response

What browsers are you seeing the problem on?

Chrome

What were you trying to do?

Wallet becomes sluggish and unusable when adding a few read-only addresses that have a large variety of ERC-20 tokens. (easy to find some at https://etherscan.io/accounts)

I suspect some of this may be helped by #3466, but am opening this due to a secondary issue that appears in that scenario.

What did not work?

Errors appear in console that indicate price fetches are failing.

Based on the logs, it seems we may need to adapt these API requests when there are a large number of tracked assets.

A couple of items that appeared:

More output attached, v0.44.0

Version

None

Relevant log output

logger.ts:208 Error fetching price for tokens on network. 
(291) [<many hex contract addresses redacted> …]

{name: 'Ethereum', baseAsset: {…}, chainID: '1', family: 'EVM', coingeckoPlatformID: 'ethereum'}
 Error: bad response (status=414, headers={"cf-cache-status":"MISS","cf-ray":"REDACTED","content-type":"text/html","date":"REDACTED","server":"cloudflare","vary":"Accept-Encoding"}, body="<html>\r\n<head><title>414 Request-URI Too Large</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>414 Request-URI Too Large</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n", requestBody=null, requestMethod="GET", url="https://api.coingecko.com/api/v3/simple/token_price/ethereum?vs_currencies=USD&include_last_updated_at=true&contract_addresses=<many hex contract addresses redacted>    at Logger.makeError (index.js:185:23)
    at Logger.throwError (index.js:194:20)
    at index.js:219:28
    at Generator.next (<anonymous>)
    at fulfilled (index.js:5:58)
logEvent    @   logger.ts:208
error   @   logger.ts:170
getTokenPrices  @   prices.ts:161
await in getTokenPrices (async)     
(anonymous) @   index.ts:867
getTrackedAssetsPrices  @   index.ts:865
await in getTrackedAssetsPrices (async)     
handlePriceAlarm    @   index.ts:939
(anonymous) @   index.ts:205
Promise.then (async)        
internalStartService    @   index.ts:204
await in internalStartService (async)       
(anonymous) @   base.ts:215
internalStartService    @   main.ts:549
await in internalStartService (async)       
(anonymous) @   base.ts:215
startMain   @   index.ts:57
await in startMain (async)      
6640    @   background.ts:28
__webpack_require__ @   bootstrap:19
(anonymous) @   startup:4
(anonymous) @   startup:4

...
...

logger.ts:208 Error getting token prices from coingecko 
(291) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
 Error: missing revert data in call exception (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"id\":224,\"error\":{\"code\":-32000,\"message\":\"out of gas\"}}","error":{"code":-32000},"requestBody":"{\"method\":\"eth_call\",\"params\":[{\"to\":\"0xca11bde05977b3631167028862be2a173976ca11\",\"data\":\"0x<long hex string redacted>    at Logger.makeError (index.js:185:23)
    at Logger.throwError (index.js:194:20)
    at checkError (json-rpc-provider.js:32:16)
    at SerialFallbackProvider.<anonymous> (json-rpc-provider.js:492:24)
    at Generator.throw (<anonymous>)
    at rejected (json-rpc-provider.js:6:57)
logEvent    @   logger.ts:208
error   @   logger.ts:170
getTrackedAssetsPrices  @   index.ts:917
await in getTrackedAssetsPrices (async)     
handlePriceAlarm    @   index.ts:939
handler @   index.ts:191
handleAlarm @   base.ts:155
hyphenized commented 11 months ago

This could also be related to the various metadata lookups made through alchemy during initial account load

Shadowfiend commented 11 months ago

Yep, first error is due to the querystring carrying the token addresses, with the path + querystring being typically limited to 64K max on most servers.

The second error is likely due to a multicall that exceeds EVM data or gas limits for return data.

In both cases we'll want to set a batch size for assets past which we run multiple batches instead of trying to do all tokens in one request.