Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Fix forked debug_traceTransaction #420

Merged
merged 10 commits into from
Apr 30, 2019
Merged

Fix forked debug_traceTransaction #420

merged 10 commits into from
Apr 30, 2019

Conversation

davidmurdoch
Copy link
Member

Fixes #404 (again).

This fixes the following issues:

Web3 treats block numbers stored as hex as block hashes: https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-4874586eb254ab1351e089bbba5b8aecR113 and https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-cc3132bd8158377c2dc590dd722b5d0aL33

When tracing a transaction we need to make sure the forked trie is block-number aware: https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-8f55aa0c345972c969bb69ce03983e2dR900 https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-4874586eb254ab1351e089bbba5b8aecR91 https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-4874586eb254ab1351e089bbba5b8aecR341

Ensure addresses and keys are encoded properly before sending to the main node, or we may get an error back if the hex representation needs to be padded with a 0. https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-cc3132bd8158377c2dc590dd722b5d0aR61

When tracing a transaction the VM may ask for block by passing in a Buffer of the number instead of a hex string. Handle both: https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-4874586eb254ab1351e089bbba5b8aecR195

Don't even let the vm try to flush the a traced transaction's block's internal _cache to the stateTrie. When forking, some of the data that the traced function may request will exist only on the main chain. Because we pretty much lie to the VM by telling it we DO have data in our Trie, when we really don't, it gets lost during the commit phase when it traverses the "borrowed" data's trie (as it may not have a valid root). Because this is a trace, and we don't need to commit the data, duck punching the flush method (the simplest method I could find) is fine. Remove this and you may see the infamous Uncaught TypeError: Cannot read property 'pop' of undefined error!
https://github.com/trufflesuite/ganache-core/compare/fix/forking?expand=1#diff-8f55aa0c345972c969bb69ce03983e2dR956

@davidmurdoch davidmurdoch changed the title Another fix for forked debug_traceTransaction Fix forked debug_traceTransaction Apr 30, 2019
@davidmurdoch davidmurdoch merged commit 8ad1ab2 into develop Apr 30, 2019
@davidmurdoch davidmurdoch deleted the fix/forking branch May 3, 2019 15:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

debug_traceTransaction fails on forked chain
1 participant