EVM Bytecode Execution / StateManager: How to keep progress? #2338
-
Hi👋 Just a quick question, because I haven't seen examples in repo or in previous issues(or I was unattentive). Saying, we have an example like here: It's a good example to get started, but I can't understand how to save this progress of VM. Here, the code done execution and on the high level we have the next stuff in "blackbox"
So, what should I do to "save" this progress?What should I do to run the vm from some "checkpoint" next time to get the second variant of greeting? StateManager has no instructions in docs. Or maybe I should play with Thanks in advance for your reply) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, the key idea of this all is that to save the current state of the chain (so all accounts and contracts) is in a thing called the |
Beta Was this translation helpful? Give feedback.
Hi, the key idea of this all is that to save the current state of the chain (so all accounts and contracts) is in a thing called the
stateRoot
. You can think of this (high-level) as a cryptographic hash of the entire chain. To checkpoint or rollback, simply save thestateRoot
(to get this, usestateRoot = await vm.stateManager.getRoot()
) and if you want to rollback,await vm.stateManager.setRoot(stateRoot)
. If you wish to persist these changes on disk, you need to instantiate aStateManager
with aLevelDB
which saves to disk, and pass this along the VM constructor.