ethereumjs / ethereumjs-monorepo

Monorepo for the Ethereum VM TypeScript Implementation
2.59k stars 753 forks source link

VM: Optionally dump post state after running state test #614

Open s1na opened 4 years ago

s1na commented 4 years ago

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.

holgerd77 commented 3 years ago

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

holgerd77 commented 3 years ago

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

ryanio commented 3 years ago

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?

holgerd77 commented 3 years ago

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.

s1na commented 3 years ago

@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 :)

holgerd77 commented 1 week ago

@gabrocheleau can you take responsibilty for this issue, so either close or act upon? Thanks! 🙏