Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for overlay_getLogs and overlay_callConstructor #6904

Open
joshstevens19 opened this issue Apr 7, 2024 · 5 comments
Open

Add support for overlay_getLogs and overlay_callConstructor #6904

joshstevens19 opened this issue Apr 7, 2024 · 5 comments

Comments

@joshstevens19
Copy link

Describe the feature

We just seen erigon just merge a PR to allow you with a single RPC request to modify the contract injecting your own events and get the new logs back.. more information on the feature: ledgerwatch/erigon#9438

Would be cool to see it here!

@LukaszRozmej
Copy link
Member

LukaszRozmej commented Apr 8, 2024

We are finishing implementing similar but more standardized (and we thing more flexible) API called eth_simulate: ethereum/execution-apis#484 code in #5530

@joshstevens19
Copy link
Author

joshstevens19 commented Apr 8, 2024

hey this topic was actually discussed in that PR see here > ledgerwatch/erigon#9438 (comment) - it feels like eth_simulate were not meant for this usecase cc @banteg

@banteg
Copy link

banteg commented Apr 8, 2024

while eth_simulate is very powerful, i understand it's meant for a different use case and replicating overlay_getLogs with it would be very cumbersome and slow. this is how it would look with eth_simulate:

  1. you would need to find all calls where your newly added code was hit, possibly using an event in the same branch of the code using eth_getLogs or all calls to your contract with trace_filter
  2. while eth_simulate allows to override the block context, the state it runs on top of comes from a single block like in eth_call. this means you can't batch all your blocks into one rpc call.
  3. to arrive at the state accurate for the transactions you have found, you would also need to replay all the preceding transactions in the blocks you have found. this is n × eth_getBlockByNumber calls.
  4. finally, you call n × eth_simulate, passing all previous transactions in each block, as well as your code override, to receive the receipts for all those transactions and your new logs.
  5. as the last step, you filter the extra receipts out, leaving you with the new event you have added.

in contrast, overlay_getLogs api is the same as eth_getLogs plus a state override from eth_call. it's also very performance in erigon, since it reuses the call trace indexes.

  1. you call overlay_getLogs with [{'address': contract, 'fromBlock': 15000000, 'toBlock': 19000000, 'topics': [topic]}, {contract: {'code': patched_runtime_code}} and receive your logs.

@LukaszRozmej
Copy link
Member

We will consider it, but we probably need to ship archive index first.

@crebsy
Copy link

crebsy commented Apr 10, 2024

hey, glad to see this issue here!

Here are some integration tests for a few contracts deployed on ethereum mainnet:
https://github.com/ledgerwatch/erigon/blob/devel/cmd/rpcdaemon/postman/Overlay_Testing.json
Anyone who plans implementing the two new rpc methods, can run those tests against an archive node with postman until they're all 🟢

There's also a minimal README for overlays: https://github.com/ledgerwatch/erigon/blob/devel/turbo/jsonrpc/overlay/README.md
but the tests are probably more fun to play with 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants