Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline ConsoleLogger logic and state #5411

Merged
merged 4 commits into from
Jul 2, 2024

Conversation

Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Jun 19, 2024

  • Because this PR includes a bug fix, relevant tests have been included.
  • Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team.
  • I didn't do anything of this.

Part of NomicFoundation/edr#246

The starting point for this PR was analyzing how we create the Provider and how different pieces interact with each other in JS and Rust<>JS in general around the stack traces logic and tests.

This removes some of the dead or redundant code and refreshes the console.log signature lookup table generation script. If we decide to move it to Rust, we won't have to call JS anymore and move buffers around just to decode and execute the console.log formatting logic.

After moving the auxiliary script to TS I re-ran it to verify that it outputs the same code (incl. the changes from this PR).

Xanewok added 4 commits June 19, 2024 12:59
It was not type-checked previously and thus missed some renames and
dependencies' updates.
…lass

This makes it clearer what the exact logic is and if additional state is
used, which will be helpful when porting this code to Rust as we don't
want to rely on an external console.log decoding logic in JS.
@Xanewok Xanewok requested a review from fvictorio June 19, 2024 11:14
Copy link

vercel bot commented Jun 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 19, 2024 11:14am

Copy link

changeset-bot bot commented Jun 19, 2024

⚠️ No Changeset found

Latest commit: cfd0884

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@Xanewok Xanewok added the no changeset needed This PR doesn't require a changeset label Jun 19, 2024
@Xanewok Xanewok requested a review from a team June 24, 2024 07:57
@agostbiro
Copy link
Member

Hey thanks for this PR @Xanewok ! I had a look, but I don't feel qualified to review it.

Copy link
Member

@Wodann Wodann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to consoleLogger.ts look good to me.

I can't comment on anything else, as I'm not familiar enough with Hardhat's coding standard to validate it.

@Xanewok Xanewok requested a review from kanej June 25, 2024 10:14
@kanej kanej removed their assignment Jun 27, 2024
@Xanewok Xanewok requested a review from a team June 28, 2024 22:12
@fvictorio fvictorio changed the title Streamline ConsoleLogger logic and state Streamline ConsoleLogger logic and state Jul 2, 2024
@fvictorio fvictorio changed the title Streamline ConsoleLogger logic and state Streamline ConsoleLogger logic and state Jul 2, 2024
@fvictorio
Copy link
Member

Checking my understanding here. This PR has two parts:

  • The most important part is turning ConsoleLogger into a bag of static methods, because (I guess) that will make porting it easier. Is this correct?
  • The other part is migrating scripts/console-library-generator.js to typescript. I guess you did this as part of checking how the code works, and it doesn't hurt to commit it.

If this is correct, then LGTM.

@Xanewok
Copy link
Contributor Author

Xanewok commented Jul 2, 2024

That is correct:

  1. The first part isolates the logic in ConsoleLogger - the class did not in fact depend on some initial state but rather just used the selectors that are static/const and have to be generated by the script.
    After the refactor we know that we only need to depend on a single function to correctly format the logs in the EDR and it will be easier to port and use it directly rather than having to roundtrip via FFI only to format the console logs.
  2. The script that was originally used to generate the data used by the ConsoleLogger was discovered to be broken in the meantime (there's no bufferToInt anymore), so I migrated it to TS to ensure we catch any such regressions in the future (even if a short one, as we want to port it anyways) and made sure it still works as expected.

@fvictorio
Copy link
Member

Makes sense! Feel free to merge this if you want.

@Xanewok Xanewok merged commit aef55d2 into main Jul 2, 2024
95 of 98 checks passed
@Xanewok Xanewok deleted the refactor/streamline-console-logger branch July 2, 2024 11:12
Xanewok added a commit to NomicFoundation/edr that referenced this pull request Jul 31, 2024
github-merge-queue bot pushed a commit to NomicFoundation/edr that referenced this pull request Jul 31, 2024
* chore: Bump hardhat to 2.22.7

* fixup: Don't enable RIP-7212 in our tests

* Adapt for NomicFoundation/hardhat#5411
fvictorio added a commit to NomicFoundation/edr that referenced this pull request Aug 22, 2024
* edr-0.4.1

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* chore: run prettier (#535)

* test: avoid unconditional reverts in stack traces tests (#537)

* fix: allow missing nonce in remote blocks (#539)

* fix: allow missing nonce in remote blocks

* misc: add changeset

* ci: upgrade pnpm/action-setup (#541)

* ci: enable some debug logs for hardhat tests (#538)

* Sync with recent Hardhat changes and deduplicate the Hardhat dep (#544)

* chore: Explicitly depend on semver and fs-extra in hardhat-tests

Appeases ESLint. These are de facto pulled by other dependencies but
it's implicit.

* refactor: Unify ts-node and use the one currently used by Hardhat

Deduping the hardhat package makes it easier to patch it while working
on the stack trace porting feature branch.

* chore: Use the newest Hardhat 2.22.6

This will make patching the changes easier to review as we will sync
with the upstream as it has some changes already related to the stack
traces that we port.

* feat: upgrade revm dependencies (#546)

* feat: upgrade revm dependencies

* Create wild-phones-drum.md

* edr-0.4.2 (#540)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* ci: remove path checks for benchmarks (#550)

* ci: remove path restrictions for EDR jobs (#551)

* ci: check that index.d.ts is up to date (#553)

* feat: add support for RIP-7212 (#552)

* feat: add support for RIP-7212

* misc: add changelog

* fix: updated index.d.ts

* fix: revert rename of InvalidFEOpcode

* fix: set enableRip7212 in ProviderConfig

* test: validate that disabling RIP-7212 works

* refactor: use runtime variable instead of const

* Path Hardhat dev dep to work with latest EDR changes

EDR uses Hardhat as a dev dependency to run some javascript tests. The
way this works is that the tests are run using Hardhat, but we use pnpm
to override the EDR dependency in Hardhat with the local one. This works
fine as long as there are no breaking changes in EDR. When there are, we
have a circular dependency problem: we can't publish a new version of
EDR until the tests pass, but for the tests to pass we need a version of
Hardhat that works with the new version of EDR.

A temporary workaround for this is to use `pnpm patch` to temporarily
modify the Hardhat code in a way that works with the breaking change.
In this case, this just means adding the new field when constructing
the provider.

---------

Co-authored-by: Franco Victorio <victorio.franco@gmail.com>

* edr-0.5.0 (#555)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* build: upgrade revm to v12 (#557)

* build: upgrade revm to v12

* test: remove invalid test

* misc: add changeset

* fix: use remote chain id for pre-fork simulation (#567)

* fix: use remote chain id for pre-fork simulation

* Fix error message

* chore: Bump hardhat to 2.22.7 (#571)

* chore: Bump hardhat to 2.22.7

* fixup: Don't enable RIP-7212 in our tests

* Adapt for NomicFoundation/hardhat#5411

* fix: prevent crash when returning large JSON responses (#569)

* ci: update collaborator check in the benchmarks workflow (#574)

* edr-0.5.1 (#559)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: add json alias property in provider response (#582)

* fix: add json alias property in provider response

* Create empty-bobcats-refuse.md

* edr-0.5.2 (#583)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* breaking change: rename response.json to response.data (#584)

* breaking change: rename response.json to response.data

* Create sour-donkeys-draw.md

* Update sour-donkeys-draw.md

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Franco Victorio <victorio.franco@gmail.com>
Co-authored-by: Igor Matuszewski <Xanewok@gmail.com>
Co-authored-by: Agost Biro <5764438+agostbiro@users.noreply.github.com>
Co-authored-by: Piotr Galar <piotr.galar@gmail.com>
Xanewok added a commit to NomicFoundation/edr that referenced this pull request Aug 26, 2024
* fix: use remote chain id for pre-fork simulation (#567)

* fix: use remote chain id for pre-fork simulation

* Fix error message

* chore: Bump hardhat to 2.22.7 (#571)

* chore: Bump hardhat to 2.22.7

* fixup: Don't enable RIP-7212 in our tests

* Adapt for NomicFoundation/hardhat#5411

* fix: prevent crash when returning large JSON responses (#569)

* ci: update collaborator check in the benchmarks workflow (#574)

* edr-0.5.1 (#559)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: add json alias property in provider response (#582)

* fix: add json alias property in provider response

* Create empty-bobcats-refuse.md

* edr-0.5.2 (#583)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* breaking change: rename response.json to response.data (#584)

* breaking change: rename response.json to response.data

* Create sour-donkeys-draw.md

* Update sour-donkeys-draw.md

* fix: improve error message and option to skip unsupported transaction type in debug trace (#606)

* fix: improve error message and option to skip unsupported tx type in debug trace

* Address code review feedback

* Handle unsupported transaction type requested

* Fix test setup

* ci: remove review-related slack notifications (#612)

* chore: js tooling improvements (#609)

* Fix pnpm warning

* Add syncpakc

* Add syncpack

* Run syncpack format

* Run syncpack on CI

* Add setup-node action

* Fixes related to upgrading prettier

* Run prettier

* Add setup-rust action

* Run prettier in edr_napi

* Add lint scripts to packages

* Run prettier in crates/tools/js/benchmark

* Port benchmark code to typescript

* Add eslint to all packages

* Upgrade @types/node to v20

* Fix broken build:edr script

* Resolve benchmark output path

* chore: upgrade hardhat and add patch (#613)

* Upgrade Hardhat to v2.22.9

* Add patch for hardhat#5664

* chore: Bump to vanilla Hardhat 2.22.9

* chore: Regenerate the Hardhat patch to use the new EDR internals

* chore: Bump @napi-rs/cli to fix duplicated napi typedefs

See <napi-rs/napi-rs#2088>

* fixup: Prettify test.ts

* Fixes after testing in OZ (#625)

* fix: add bounds checks

* fix: check that steps is not empty before traversing it

* fixup: formatting [skip ci]

---------

Co-authored-by: Igor Matuszewski <xanewok@gmail.com>

---------

Co-authored-by: Agost Biro <5764438+agostbiro@users.noreply.github.com>
Co-authored-by: Wodann <Wodann@users.noreply.github.com>
Co-authored-by: Piotr Galar <piotr.galar@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Franco Victorio <victorio.franco@gmail.com>
github-merge-queue bot pushed a commit to NomicFoundation/edr that referenced this pull request Aug 27, 2024
* refactor: Port the codebase model construction and EVM decoding from HH

* chore: Add a script that regenerates the pnpm patch for Hardhat

* patch(hardhat): Cherry-pick and adapt for the unreleased Rip7212 PR

See NomicFoundation/hardhat@f944cd5

* patch(hardhat): Cherry-pick a stack trace cleanup PR

See NomicFoundation/hardhat@5739893

* patch(hardhat): Use the rewritten compiler to model logic from EDR

See NomicFoundation/hardhat@49c66b6

* Port `MessageTrace` and `VMTracer` machinery from Hardhat (#531)

* Some small improvements

* Port `MessageTrace` and `VMTracer` machinery from Hardhat

* Move HH-specific ExitCode logic to edr_napi

* Remove unused `ExitCode::STATIC_STATE_CHANGE`

* patch(hardhat): Re-use MessageTrace and VmTracer from EDR now

See NomicFoundation/hardhat@3aeeb56

* chore: Re-run pnpm build

* Address PR feedback

* Address PR feedback

* fixup: Apply formatting

* refactor: Port ContractsIdentifier to Rust (#562)

* chore: Port the BytecodeTrie from ContractsIdentifier

* Migrate some library utils

* Migrate some Opcode helpers

* Finish the ContractsIdentifier port

* Remove unused get_library_address_positions

* Simplify the ContractsIdentifier port

* patch(hardhat): Re-use the ContractsIdentifier from EDR

* fixup: Fix a simple test

* refactor: Port the `VmTraceDecoder` from Hardhat (#568)

* fix: Correctly deserialize BuildInfo with `_format` field

* refactor: Port the VmTraceDecoder from Hardhat

* fix(napi): Correctly encode and decode `MessageTrace` types

* refactor: Remove now unneeded functions

* patch(hardhat): Port the VmTraceDecoder from Hardhat

* Reformat and remove unused imports

* fixup: Use a more correct type for the XYZTrace::bytecode field

* fixup: Adjust test to now optional `deployedContract` property

* refactor: Port `ReturnData` and `StackTraceEntryType` (#589)

* feat: Port solidity-stack-trace.ts

* feat: Port return-data.ts

* patch(hardhat): Port return-data.ts and solidity-stack-trace.ts

* fixup: Reformat files

* fixup: let's see how tests feel about a number instead of a const enum variant

* Make the comment about Rust type alias more clear [skip ci]

* fix: Fully transpile in Mocha tests to correctly inline const enums (#594)

It seems transpile-only transpiles per module, however we need to
perform full "compilation" in order to correctly see and inline values
for const enums.

We use const enums because that's how they are emitted by napi-rs and
there's no option to change that. Rather than invest into supporting
that or working around it, let's just fully compile the test harness
once.

See https://www.typescriptlang.org/tsconfig/#isolatedModules for more
context.

* refactor: Port ErrorInferrer and SolidityTracer from Hardhat (#593)

* Start porting SolidityTracer

* Start porting ErrorInferrer

* WIP: Keep Reference in MessageTraces

* Port 99% of the ErrorInferrer

Except `ErrorInferrer.inferAfterTracing`. I discovered that the original
code creates a shallow copy of the stack trace during select heuristics
and returns the modified one or the *original* one if the heuristic does
not hit.

One could keep track of possible series of changes that would have to be
subsequently applied if the heuristic hits and returns a modified the
stack trace but instead, I want the code to do exactly what the original
code did.

Rather than wrap every entry in a shareable `Rc` (they are not
modified), I decided to make them clonable in the next PR, which means
we need to not keep the `ClassInstance` around to derive the Clone
trait.

* Port mapped-inlined-internal-functions-heuristics.ts

* refactor: Prune StackTraceEntry.message to make it clonable

See previous commit "Port 99% of the ErrorInferrer".

* refactor: Drop unused inner funcs in the ErrorInferrer

* feat: Finish porting `ErrorInferrer`

* feat: Finish porting `SolidityTracer`

* refactor: Remove now unused utils IntoEither/IntoOption

* patch(hardhat): Port ErrorInferrer and SolidityTracer

* fixup! refactor: Prune StackTraceEntry.message to make it clonable

* fixup: Reformat

* Document the unsafety surrounding napi-rs's References

* refactor: Remove some now unused functions

* Address review feedback

* fix a missing period

* fix alphabetical sorting

* refactor: Port stack-traces/debug.ts (#596)

* Port over debugging facilities from debug.ts

* patch(hardhat): Port debug.ts

* fix: Make the depth optional in printMessageTrace

* fixup: Formatting

* Merge `main` into the stack trace port feature branch (#618)

* fix: use remote chain id for pre-fork simulation (#567)

* fix: use remote chain id for pre-fork simulation

* Fix error message

* chore: Bump hardhat to 2.22.7 (#571)

* chore: Bump hardhat to 2.22.7

* fixup: Don't enable RIP-7212 in our tests

* Adapt for NomicFoundation/hardhat#5411

* fix: prevent crash when returning large JSON responses (#569)

* ci: update collaborator check in the benchmarks workflow (#574)

* edr-0.5.1 (#559)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix: add json alias property in provider response (#582)

* fix: add json alias property in provider response

* Create empty-bobcats-refuse.md

* edr-0.5.2 (#583)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* breaking change: rename response.json to response.data (#584)

* breaking change: rename response.json to response.data

* Create sour-donkeys-draw.md

* Update sour-donkeys-draw.md

* fix: improve error message and option to skip unsupported transaction type in debug trace (#606)

* fix: improve error message and option to skip unsupported tx type in debug trace

* Address code review feedback

* Handle unsupported transaction type requested

* Fix test setup

* ci: remove review-related slack notifications (#612)

* chore: js tooling improvements (#609)

* Fix pnpm warning

* Add syncpakc

* Add syncpack

* Run syncpack format

* Run syncpack on CI

* Add setup-node action

* Fixes related to upgrading prettier

* Run prettier

* Add setup-rust action

* Run prettier in edr_napi

* Add lint scripts to packages

* Run prettier in crates/tools/js/benchmark

* Port benchmark code to typescript

* Add eslint to all packages

* Upgrade @types/node to v20

* Fix broken build:edr script

* Resolve benchmark output path

* chore: upgrade hardhat and add patch (#613)

* Upgrade Hardhat to v2.22.9

* Add patch for hardhat#5664

* chore: Bump to vanilla Hardhat 2.22.9

* chore: Regenerate the Hardhat patch to use the new EDR internals

* chore: Bump @napi-rs/cli to fix duplicated napi typedefs

See <napi-rs/napi-rs#2088>

* fixup: Prettify test.ts

* Fixes after testing in OZ (#625)

* fix: add bounds checks

* fix: check that steps is not empty before traversing it

* fixup: formatting [skip ci]

---------

Co-authored-by: Igor Matuszewski <xanewok@gmail.com>

---------

Co-authored-by: Agost Biro <5764438+agostbiro@users.noreply.github.com>
Co-authored-by: Wodann <Wodann@users.noreply.github.com>
Co-authored-by: Piotr Galar <piotr.galar@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Franco Victorio <victorio.franco@gmail.com>

* chore: Restore old test.ts and remove some `as any` conversions

* WIP: Benchmark with patched Hardhat to use new EDR internals

* Revert "WIP: Benchmark with patched Hardhat to use new EDR internals"

This reverts commit ac2e012.

* Remove the gen-hardhat-patches script

---------

Co-authored-by: Agost Biro <5764438+agostbiro@users.noreply.github.com>
Co-authored-by: Wodann <Wodann@users.noreply.github.com>
Co-authored-by: Piotr Galar <piotr.galar@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Franco Victorio <victorio.franco@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
no changeset needed This PR doesn't require a changeset status:triaging
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants