ethereumjs-monorepo icon indicating copy to clipboard operation
ethereumjs-monorepo copied to clipboard

VM: Optionally dump post state after running state test

Open s1na opened this issue 6 years ago • 6 comments

It'd be often helpful for debugging if the state test runner would optionally (e.g. given a --dumpState flag) print either the full post state (all accounts in trie and their storages) or the state diff between pre and post.

There currently exists a dumpState in tests/util.js which is not being used. One challenge is that when traversing the trie after the fact we only have access to the hash of addresses (SecureTrie stores leaves under the hash of the key), and cannot infer the preimage of the hash (i.e. account/storage address) directly.

I tried inheriting SecureTrie and CheckpointTrie to add a map of form hash: address which would allow us to recover addresses from their hashes. But because of how the old version of merkle-patricia-tree does inheritance it's hard to get it right and I ended up copying code to VM directly.

After the merkle-patricia-tree release this can be done cleanly.

s1na avatar Nov 11 '19 13:11 s1na

Update: is this still a thing? Eventually @ryanio has some opinion as the "state expert" in the team? 😄

holgerd77 avatar Jun 11 '21 11:06 holgerd77

When implementing this, also consider #560 along the way (not sure if this is meant here), will close #560 to consolidate on issues.

holgerd77 avatar Jun 11 '21 11:06 holgerd77

seems doable! we could implement this as suggested in OP by keeping track of a hash: address mapping and then iterate over that list to dump the entire state or a diff between the pre state.

@s1na do you have a fresh perspective on if this would still be valuable for you today?

@jochem-brouwer does this sound reasonable to you, would you prefer a different mechanism or would you find this helpful?

ryanio avatar Jun 11 '21 22:06 ryanio

Just an additional note here: we should be careful to not introduce any performance penalties when the flag is not used if we decide to implement.

holgerd77 avatar Jun 14 '21 08:06 holgerd77

@s1na do you have a fresh perspective on if this would still be valuable for you today?

I think I ran into this when needing to debug when some state tests were failing, but don't have a use for it now. If you've found yourself in a similar situation when the bug is just evading you then might be worth it :)

s1na avatar Jun 14 '21 14:06 s1na