fallback provider / better error handling #1664
Replies: 1 comment 1 reply
-
There are two issues really we are dealing with: One is RPC related, the Second is the nature of events themselves. We maintain an extensive test suite against every worthwhile RPC provider for Ethereum (we use it for securerpc.com conformance testing). Here are some of the more notable provider quirks as it relates to Warning The most restrictive RPC endpoint I have seen for QuicknodeErrors -32002, Infurasee https://docs.infura.io/api/networks/ethereum/json-rpc-methods/eth_getlogs#constraints -32005 code: -32005 AlchemyAPI
Other Encountered Errorscode: -3200 Code: 4200 Code: -32601 indexed vs non-indexed signature collisions2This one is quite problematic. Let's examine again the ubiquitous However it also corresponds to the nowadays popular ERC721 Transfer(address indexed from, address indexed to, uint256 indexed tokenId) NFT transfer event. The issue is that the indexed parameter attribute also gets erased from the event signature before applying the keccak256. It is not possible to guess which signature is the "correct" by just looking at the hash. The consequences are catastrophic, because the indexed attribute determines where you should look at when decoding the value. safeBlockInThePastWe set this as the furthest block you could possibly query for our own services. Its a sane value. We have had issues where DApps (notably Sushiswap frontend) where they would erroneously query from genesis block to latest. This value /**
* @export safeBlockInThePast
* @summary This is UniswapV2 Initial Deployment Block. Note that there is a gap between when it was deployed and when it saw any sort of meaningful use.
* @link https://github.com/NomicFoundation/hardhat/blob/master/packages/hardhat-core/test/internal/hardhat-network/provider/interval-mining-provider.ts#L15
*/
export const safeBlockInThePast = 11_200_000; TLDR:Really restrict getLogs to an epoch's worth of blocks IMHO.
Footnotes |
Beta Was this translation helpful? Give feedback.
-
Hello,
i've been using viem for a while now and one thing that (to me) feels really complicated is rpc error handling.
There#s a lot of cases that need manual intervention, but imo should be somewhat automatic.
Errors i faced in the past that are not handled by fallback:
I guess one option could be to have a per rpc config where you can specify methods that are not supported (kind of a filter), so that for operation x, always a rpc supporting operation x is chosen.
For getLogs limitations, perhaps sth similar could work. You specify a
maxBlockRange
and the fallback would throw some sort of error if non of the provided rpcs support that range? Idk.Would be curious if anyone has been able to "properly" solve this as it's a quite annoying issue with viem (same is true for ethers).
Beta Was this translation helpful? Give feedback.
All reactions