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
feat(anvil): add load/dump state options #3730
feat(anvil): add load/dump state options #3730
Conversation
Looks good and works for our use-case (being able to gracefully stop/start anvil instances) Not in scope, but calling out here: if anvil were to be shut down with (e.g. kill -9) we would have no state since the shutdown handler doesn't run. A real "db" with a wal etc. would be great for resilience in a cloud environment. But, re-iterating that this is probably not in scope for anvil |
Good stuff! Looks like this would solve our use-case too. Thanks @mattsse! |
A couple observations after giving this a quick test spin:
|
|
thanks for this feedback, will update accordingly. perhaps we can flush this every couple minutes or so? |
Here's some background / context around my use-case: I'm trying to put together a tightly integrated local development environment for front-to-back smart contract, data pipeline & dapp development needs. Ideally, I'd like to end up with an AIO (all-in-one) service emulator running locally (similar to the likes of Let's assume you are building a project from the grounds up (or are still iterating on all of these layers). In such a scenario, you want to ...
Currently, setting up such an environment requires developers to think about a lot of infrastructure components and keep a lot of things in sync. And operate them locally! Map ports, connect things, know what to do if any of them fails, etc. It still feels that all these layers aren't as tightly knitted together within this space as I think they could be. The developer experience at the intersection between smart contracts, data and frontend is brutal. Each team out there is still doing all of that custom wiring by themselves with varying degrees of success. I want a tool stack that allows developers on all of these layers to seamlessly operate all these service dependencies locally with the ability to easily stop & restart them at will. All whilst preserving local state between restarts. Without them then having to deal with corrupted / out-of-sync state etc. The problem really is the introduction of stateful components to the stack. For instance, in case of Firehose, Substreams and Subgraphs it wouldn't be enough to periodically flush data from Anvil to disk to tick these boxes. If we kill and restart the entire stack, and upon restart, there's data in the Firehose instrumentation that's now missing in Anvil, then we've got a broken state. Furthermore, in order to allow re-indexing data that depends on eth calls on archive state, we'd need to preserve that too. I know that I'm asking for a lot here and that this is probably out of scope for this first iteration, but I wanted to provide some context regardless :-). |
Configurable flush period feels like a nice middle ground! |
@fubhy thanks so much for the additonal context. this makes a ton of sense. Could you please open another topic for 4) as this is beyond the scope of this PR? |
after reading this again I still have a question re:
the reason why I used two separate flags is so you can load from one location and set a separate for persistent otherwise you'd end up overwriting this on dump. But maybe it is easier to use only one argument for load+dump and always. That would make it easier to load and update the saved state, but harder to load and save it to another location. kill -9 is SIGKILL iirc, which you can't intercept. But perhaps you can handle this with a combination of |
Ganache has a Actually I could see these two options being useful if you want to roll back to a previously stored state snapshot between restarts... ? So you initialize the db from a backup location and afterwards dump it elsewhere or choose to not dump it at all. Could be useful. Like... A shared developer instance for your team to test stuff with... Hosted somewhere. Resets every 24 hours or so? |
I like this, let's do that, |
This would be extremely helpful for us at Optimism. For context, we're in the process of prepping for our Bedrock migration, and we'd like to run a long-lived, public fork of Goerli so forks can test things out before doing the migration for real. Since this fork would be long-lived and will see a bunch of transaction volume, it's important that data be persisted to disk rather stored in memory. We need the configurability here so that we can provision Kubernetes PVCs for state to be stored on. |
That sounds like you'd also need full persistence though (all data, not just latest state). |
@fubhy I've set the interval to 60s but perhaps we make this configurable or decrease? Update: added --state-interval option |
9f26b7c
to
693dec6
Compare
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.
Ship it and we can iterate. Foundryup will have this tonight, or you can foundryup -b master. I'm triggering a docker build rn which will be avail in ghr
Sweet. Thanks @mattsse!! |
Motivation
Closes #3665
this integrates the
loadState
dumpState
RPC calls into the config and adds--load-state <Path>
,--dump-state <Path>
cli arguments.@kahuang @fubhy wdyt?
Solution