onflow / flow-evm-gateway

FlowEVM Gateway implements an Ethereum-equivalent JSON-RPC API for EVM clients to use
https://developers.flow.com/evm/about
Apache License 2.0
8 stars 5 forks source link

Index account balances #284

Open sideninja opened 3 weeks ago

sideninja commented 3 weeks ago

Currently, we use Cadence script execution to obtain an EVM account balance through the EVM address.balance() method. This works fine for the latest block, the problem is, that the EVM GW get balance API allows for specifying past EVM block heights at which we want to obtain an account balance. We solved this problem by executing the balance Cadence script at the previous Cadence block, but the problem is, that one Cadence block can contain multiple EVM blocks, and if the EVM height at which we want to obtain the balance is inside such a Cadence block with multiple heights, we will always get the state at the end of the Cadence block, resulting in wrong value.

How we can address this issue is in different ways, short-term solution is to use the transaction traces to index balance changes, longer-term solution is to use either local execution or a modified archive node that allows for EVM height-resolution script execution. This means allows for executing a script at intermediate EVM heights not just Cadence height.

sideninja commented 4 days ago

Related to: #322