edr icon indicating copy to clipboard operation
edr copied to clipboard

Normalise rpc debug trace format

Open AmosAidoo opened this issue 9 months ago • 16 comments

Which issue does this PR close?

  • Closes #783

Changes

  • Moved normalisation that Hardhat does on debug trace into EDR.
  • Added new types RpcDebugTraceResult and RpcDebugTraceLogItem that conform to expected structure.
  • Added tests to validate trace structure against expected normalised structure.

How was this tested?

  • Compared trace manually with output from Geth.
  • Wrote test to validate normalised structure.
  • Ran tests and verified all tests pass including old ones.

AmosAidoo avatar Mar 23 '25 17:03 AmosAidoo

🦋 Changeset detected

Latest commit: 090729a2ab3f1369d2a795cbc595b1bd0e4d93f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/edr Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Mar 23 '25 17:03 changeset-bot[bot]

@nebasuke This is my PR for the issue. I am available anytime to make the necessary changes.

AmosAidoo avatar Mar 23 '25 18:03 AmosAidoo

Great, thank you @AmosAidoo, we appreciate the effort!

It will probably be @Wodann or @agostbiro that can take a look.

nebasuke avatar Mar 24 '25 12:03 nebasuke

cd hardhat-tests && pnpm test:ci Noticed I missed these tests. I'm taking a look.

AmosAidoo avatar Mar 25 '25 11:03 AmosAidoo

Noticed I missed these tests. I'm taking a look.

Great, thanks! I'll re-run CI when needed.

nebasuke avatar Mar 25 '25 11:03 nebasuke

the tests still expect the pass, gasUsed and opName fields so I added them in addition to the new format. Also, the tests still assume the memory and storage strings will have the leading 0x string. So I guess this PR will need a follow-up issue after this is integrated into Hardhat. The hardhat tests will then have to be updated afterwards.

AmosAidoo avatar Mar 25 '25 12:03 AmosAidoo

Great, thanks! I'll re-run CI when needed.

You can re-run the CI

AmosAidoo avatar Mar 25 '25 13:03 AmosAidoo

Can you kindly re-run

AmosAidoo avatar Mar 25 '25 14:03 AmosAidoo

Thank you for taking a stab at this. I left some requests to try and move the changes into edr_provider as the current approach goes through multiple steps of serialization and deserialization.

Perfect, thank you for the review. I'll make the changes.

AmosAidoo avatar Mar 25 '25 15:03 AmosAidoo

I made the necessary changes. Tests pass when I run them locally. Could you kindly re-trigger the ci.

AmosAidoo avatar Mar 26 '25 09:03 AmosAidoo

Seems to be looking good so far regarding the tests. Looks like the remaining failures are because of environmental variables not set as I am an external contributor.

AmosAidoo avatar Mar 26 '25 10:03 AmosAidoo

I have made some changes and replied to the questions

AmosAidoo avatar Apr 01 '25 09:04 AmosAidoo

I added some information to the original issue on how to create test vectors for your code. You can essentially use geth to create some expected output formats and do string comparison between your generated output and the expected output.

Most of the info about debug_traceCall is here, but note that they use a js lib, not the raw rpc, in the snippets. To be able to port it with confidence, we should create a few test cases using geth, and making sure we match their format.

Wodann avatar Apr 10 '25 17:04 Wodann

Noted. Thank you

AmosAidoo avatar Apr 10 '25 20:04 AmosAidoo

I added some information to the original issue on how to create test vectors for your code. You can essentially use geth to create some expected output formats and do string comparison between your generated output and the expected output.

Most of the info about debug_traceCall is here, but note that they use a js lib, not the raw rpc, in the snippets. To be able to port it with confidence, we should create a few test cases using geth, and making sure we match their format.

@Wodann is it sufficient to use geth in dev mode to generate the test cases?

AmosAidoo avatar Apr 23 '25 08:04 AmosAidoo

I added some information to the original issue on how to create test vectors for your code. You can essentially use geth to create some expected output formats and do string comparison between your generated output and the expected output.

Most of the info about debug_traceCall is here, but note that they use a js lib, not the raw rpc, in the snippets. To be able to port it with confidence, we should create a few test cases using geth, and making sure we match their format.

@Wodann is it sufficient to use geth in dev mode to generate the test cases?

I don't see why not; as long as the generated output conforms to the JSON-RPC spec.

Wodann avatar Apr 25 '25 16:04 Wodann