-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New overlays feature for doing ad-hoc simulations of existing contracts with modified bytecode #9438
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
Conversation
Fixed CREATE2 and added some API docs to my PR: |
rebased to current devel d5502a0 |
are these overlays methods in a spec somewhere? |
turbo/jsonrpc/overlay_api.go
Outdated
signer := types.MakeSigner(chainConfig, blockNum, blockCtx.Time) | ||
rules := chainConfig.Rules(blockNum, blockCtx.Time) | ||
|
||
timeoutMilliSeconds := int64(500000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhm, shouldn't the requester or service running the node decide the timeout? maybe worth putting under a flag at least?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, added two new flags for the outer call of overlay_getLogs
and the inner call that is replaying a single block.
turbo/jsonrpc/overlay_api.go
Outdated
|
||
timeoutMilliSeconds := int64(500000) | ||
|
||
timeout := time.Millisecond * time.Duration(timeoutMilliSeconds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra note, please if you do the flag make it a Duration Flag so we don't have this.
Thanks for your review! I've added a few payload examples to my README. |
overlay_callConstructor and overlay_getLogs for submitting new contract bytecode for ad-hoc simulations.
…r and overlay_getLogs to readme.
…replayblocktimeout
rebased to devel 4369d4e |
@Giulio2002 Here's an initial README showing how overlays could be used: https://github.com/crebsy/erigon/blob/devel/turbo/jsonrpc/overlay/README.md Is there anything else I could add ? |
Not sure if this is right direction when |
Dear colleagues, I'm excited to introduce a powerful feature we've been working on- in
So, in other words, it looks like if you run Nice features we also have:
See other examples and potential use cases in @KillariDev post here Please come to our weekly discussions by Joininig our Zoom Meeting Let's join forces and create a more standardized and useful feature for all. Your insights and expertise are invaluable, and I look forward to seeing you at our weekly discussions. Together, we can make a great difference! |
i see this as complementary to |
I have to kind of agree with Banteg on this one; while I do think standardizing is a good thing, I believe that |
I, just want to point out, that while we merged this, we may or may not remove this endpoint in the future, if we either find it difficult to maintain or if as @LukaszRozmej said - |
In this PR I'm introducing so-called
overlays
for doing ad-hoc state simulations of contracts which replay the state with a modified bytecode for any given block range.The new feature adds two new RPC methods:
overlay_callConstructor
andoverlay_getLogs
I've also added a few bench tests and a new postman collection which checks both new methods for the WETH contract in original and modified version.
Motivation
Overlays allow you to add your custom logic to already deployed contracts and simulate on top of them. With overlays you can create new view functions, modify existing ones, change field visibility, emit new events and query the historical data of any contract with your modified source code.
Similar commercial products exist in the space and I believe making this feature opensource in erigon will make it easier for everyone to tinker with it and build new cool things on top of it ✨
Usage
overlay_callConstructor
with the result from 1) to receive the runtime bytecodeoverlay_getLogs
to simulate new logs, passing 2) as state overrides (example)eth_call
to simulate new view function calls passing 2) as state overridesAd-hoc query performance & historical back-filling
The current implementation for ad-hoc range queries of
overlay_getLogs
is optimized so that irrelevant blocks are skipped entirely from the simulation context. This can lead to very fast results of a few minutes or even seconds for simulating the entire historical logs of a contract which makes any infra for back-filling redundant. However, such shortcuts are only effectively working for contracts which are not touching too many blocks of the chain's history. So depending on the contract you're trying to patch, you still might need to create a custom back-filling script which simulates the new logs with e.g. 1000 or 10000 block ranges.As a reference for a "busy" contract the simulation rate for the Uniswap V2 router was ~ 280 blocks/s on a host with 24 cores. So while small block ranges returned relatively quickly, the simulation of the entire historical logs for this contract took a few hours on a single node.
I'm not collecting any perf metrics yet for this but this could be easily added in the future for tracking better implementations and insights about contract <-> block distribution.
Configuration
Enable the
ots,overlay
api namespaces by adding it to the--http.api
flagThe implementation of
overlay_getLogs
is parallelized so it's good practice to increase the--db.read.concurrency
to a higher value, e.g. 256 so other erigon goroutines are not getting blocked.Supported networks
Tested with ethereum and polygon nodes