Skip to content

Inline logs#5505

Closed
aathan wants to merge 18 commits intofoundry-rs:masterfrom
aathan:inline_logs
Closed

Inline logs#5505
aathan wants to merge 18 commits intofoundry-rs:masterfrom
aathan:inline_logs

Conversation

@aathan
Copy link
Contributor

@aathan aathan commented Jul 30, 2023

Motivation

It can be very useful to see both event emits and console.log() calls be logged/printed inline vs batched at the end of contract execution, particularly when working on forge or anvil itself. The current implementation relies on a call to print_logs() after the transaction has run and all logs have been gathered by LogCollector.

Solution

I am new to Rust, so this patch may suffer from that. I saw two ways to achieve the necessary features. (1) store an additional assigned member in the LogCollector inspector and check this member every time log() and call() are called. or (2) make LogCollector a generic on a type with a trait that has an fn on_log() which gets called every time log() and call() are called on the LogCollector.

I decided to experiment and see where the latter approach took me, because it also offered the possibility of easily extending the LogCollector and/or Executor/Inspector/InspectorStack behavior beyond just ONLOG. The change had a larger footprint than I anticipated, but the real benefit, beyond the --inline-logs command line parameter, is that the core foundry evm Inspector<> is now generic and the overall codebase is now ready to receive either more generic behavior traits or to have the OnLog trait be generalized into a trait with additional notification calls. Whether this is more useful than either creating a special Inspector, or InspectorStack, is something I'm not qualified to decide on.

I left the call to print_logs() intact, and currently the printing of emit events is just via their Debug rendering. Probably, if you like this change and plan to accept it, we should remove the print_logs() call and/or option it as a --batched-logs option and/or add the emit events to its output so it mirrors what --inline-logs does but batched at the end of the transaction.

EDIT: Incorporates #5498

EDIT: We may also want to option whether emit events are logged vs remaining silent. I think hardhat does not normally print those to the console.

@aathan
Copy link
Contributor Author

aathan commented Jul 30, 2023

Not sure what to do about these clippy warnings.

warning: unknown lint: `clippy::arc_with_non_send_sync`
   --> common/src/shell.rs:219:17
    |
219 |         #[allow(clippy::arc_with_non_send_sync)]
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unknown_lints)]` on by default

@Evalir
Copy link
Member

Evalir commented Aug 2, 2023

hey @aathan would love to review this and get this in—could you fix conflicts? thank you for the contrib, slowly getting to them! 🙌

sambacha and others added 10 commits August 2, 2023 18:17
foundry-rs#5504)

* chore(update constants): increment solc versions for install_commonly_used_solc

function `install_commonly_used_solc` pre-installs commonly used solc versions

increment based of latest solc version update

* rename vars

---------

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
…oundry-rs#5507)

* fix: make evm_env() return a result to force more graceful handling of failed forks

* chore: fix related handling errors (and just panic when needed)
* Add correct processing for non-existent keys

* Fix clippy error

* chore: include changes in changelog

---------

Co-authored-by: Enrique Ortiz <hi@enriqueortiz.dev>
* Pass details on GasTooHigh

* Update anvil/src/eth/backend/mem/mod.rs

* chore: fmt/clippy

---------

Co-authored-by: AA <aa@aa>
Co-authored-by: evalir <hi@enriqueortiz.dev>
* feat: foundry-rs#5466 - Test scaffolding

* reafactor: removed return

* chore: fmt

* refactor: named imports

* refactor: std::fs -> foundry_common::fs

---------

Co-authored-by: Rahul Ravindran <ravindranrahul@users.noreply.github.com>
Co-authored-by: Enrique Ortiz <hi@enriqueortiz.dev>
…oundry-rs#5520)

* chore: disallow using vm.prank after vm.startprank

* chore: rename state single call bool

* Update evm/src/executor/inspector/cheatcodes/env.rs

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>

---------

Co-authored-by: Matt Solomon <matt@mattsolomon.dev>
… that aren't broken yet (foundry-rs#5323)

* Read shrink sequence config when assert invariants that aren't broken yet

* fmt

---------

Co-authored-by: evalir <hi@enriqueortiz.dev>
…oundry-rs#5523)

* fix(cast): continue execution of preceding transactions after revert

* chore: clippy

* chore: clippy

* chore: fmt

* chore: clippy

---------

Co-authored-by: Enrique Ortiz <hi@enriqueortiz.dev>
@aathan
Copy link
Contributor Author

aathan commented Aug 2, 2023

I think what I just submitted took care of the conflicts, but please review.
It's now back to being called logger vs log_collector at least in part because the LogCollector itself is renamed to EvmEventLogger<> in this PR ... yes, it collects logs, but its real function is more to "do bespoke things with events"

I am not going to argue over names of course. I just went with what had the smallest footprint given the already existing changes for EvmEventLogger. Please feel free to do a simple global replace to change the names to whatever you'd like.

@aathan
Copy link
Contributor Author

aathan commented Aug 2, 2023

@Evalir separately I want to get a conversation started to support polygon/bor in foundry and reth. Not sure how to engage in conversations with the paradigm and/or foundry teams on this and other points. Should I open a feature issue in both projects to discuss? I guess that would touch revm as well since bor changes some signature things.

andyrobert3 and others added 3 commits August 3, 2023 19:27
* chore: removed is_eip1559 flag

* chore: set eip1559 fields to "None" if not EIP1559 type
…pector (foundry-rs#5498)

* logs to logger when referring to LogCollector inspector

* missing file

* chore: rename to log collector

---------

Co-authored-by: AA <aa@aa>
Co-authored-by: Enrique Ortiz <hi@enriqueortiz.dev>
@aathan
Copy link
Contributor Author

aathan commented Aug 3, 2023

I'm not sure what I'm doing wrong here but I've now spent 30+ minutes trying to resolve these conflicts by fetching from foundry's origin, merging master, and resolving all conflicts, then being told I'm behind my fork's inline_logs, merging that, ... several times over. I'm currently on "rebase" merge mode. I keep having to resolve all the same conflicts over and over.

I'm going to leave things as is because it's just not clear to me what's going on with all these rebases.

Should I just diff my branch vs master and apply that diff to a completely new PR based on the current origin/master to cleanup what might now be a mess? Every now and then git trips me up...

@Evalir
Copy link
Member

Evalir commented Aug 15, 2023

Yep @aathan i think by now the rebase is just too big—let's reopen in a new branch so we can quickly review and merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants