tradingstrategy-ai / web3-ethereum-defi

A Python library for trading automation on DeFi, data research and integration. Supporting Uniswap, Aave, Chainlink, USDC and other protocols.
https://tradingstrategy.ai
MIT License
604 stars 129 forks source link

Work around BadFunctionCallOutput: Insufficient bytes error #157

Closed miohtama closed 1 year ago

miohtama commented 1 year ago

A special case of eth_call returning an empty result.

This happens if you call a smart contract for a block number for which the node does not yet have data or is still processing data. This happens often on low-quality RPC providers (Ankr) that route your call between different nodes between subsequent calls, and those nodes see a different state of EVM. Down the line, not in the middleware stack, this would lead to BadFunctionCallOutput output. We work around this by detecting this condition in the middleware stack and triggering the middleware fall-over node switch if the condition is detected.