Discussions
Missing recent-ish state for archive nodes on BSC and Polygon
For requests to blocks ranging from -128 to ~-205 blocks (compared to the current highest block number), the RPC fails with the error:
missing trie node
I suspect that you are using a proxy server that redirects requests to whether an archive node or an access node based on the block number. It appears that this is broken on BSC and Polygon, as those requests should be sent to an archive node, but the access node receives it, and answers that the state is missing (as by default it only keeps 128 states).
This can be tested with this script (requires cast
from foundry
)
export ETH_RPC_URL="https://rpc.ankr.com/bsc/<API_KEY>"; bn=$(cast block-number); seq $(( $bn - 256 )) 2 $bn | xargs -P32 -I% bash -c 'r=$(cast call -b % "0xcA11bde05977b3631167028862bE2a173976CA11" "getBlockNumber()(uint256)" 2>&1 | tr "\n" " "); printf "Block %: $r\n"' | sort
It calls "getBlockNumber" method on the multicall contract at different block height in the past (from -256 to 0, with steps of 2), and prints the result, or the error if any.
Running this on BSC and Polygon shows error for the above-mentioned range.