Skip to content

Conversation

@nhtyy
Copy link
Contributor

@nhtyy nhtyy commented Jul 1, 2023

addresses issue #2577

todo! i need to get all the bytecodes from the db
will likely need to use an auxillary struct or add fields to the builder so i can do a dfs on the calls to track the addresses, since they arent kept around the in VmTrace

i would say this pr is at ~90% of the way done, it just needs tests and i need to fill in the (base?) gas cost of the opcode

@nhtyy nhtyy marked this pull request as ready for review July 2, 2023 17:14
@nhtyy nhtyy requested a review from mattsse as a code owner July 2, 2023 17:14
Copy link
Contributor Author

@nhtyy nhtyy Jul 2, 2023

Choose a reason for hiding this comment

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

i still need to respect the config here, but the rest of the file doesnt seem to use the config yet + logging

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

good start - supportive of this. thank you for taking the time. anything else you'd like to add before us taking a deeper look on this?

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

tysm for taking this on, very much appreciated.

I can follow how this works but I have a few requests.

Comment on lines 32 to 35
holder.push(idx);
for child_idx in nodes[idx].children.iter() {
Self::get_all_children(nodes, holder, *child_idx);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

please no recursive calls, this can be written iteratively

Copy link
Member

Choose a reason for hiding this comment

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

yup - context is these overflow for deep traces

Copy link
Contributor Author

@nhtyy nhtyy Jul 3, 2023

Choose a reason for hiding this comment

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

got it....

I also use recursion to create the VmTrace, I should also try to change that?

Copy link
Contributor Author

@nhtyy nhtyy Jul 3, 2023

Choose a reason for hiding this comment

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

but for now will work on making the CallTraceNodeWalker iterative :)

@mattsse mattsse added the A-rpc Related to the RPC implementation label Jul 3, 2023
@onbjerg onbjerg changed the title fix: issue #2577 feat: complete vm and statediff tracers Jul 3, 2023
@onbjerg onbjerg added the C-enhancement New feature or request label Jul 3, 2023
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

great progress, left a few suggestions

btw spec_opcode_gas is public and you should be able to import it

@nhtyy
Copy link
Contributor Author

nhtyy commented Jul 5, 2023

sweeet so i was able to make everything iterative it seems!

I think is ready for more review now while i can start on testing soon (or vice versa)

also on the Walker types over CallTraceNodes that i made, i only ended up using the breadth first one but theres depth first one also, so not sure if thats something we want to keep around for whatever reasons, i just commented it out for now

also on opcode thing i dont think i can get it because its not used here and no pub mod
https://github.com/bluealloy/revm/blob/10f81ba1b3cd6171c25d3346f1800bbb04f5ead1/crates/interpreter/src/lib.rs#L20

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this looks pretty good already.

left a few nits

there are a few chunks that are commented out,
what is missing here?

I agree we can start testing this

Comment on lines 39 to 41
for child_idx in curr.children.iter() {
self.queue.push_back(*child_idx);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can use .extend here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooo nice thx fixed

};
use revm::interpreter::opcode;
use std::collections::VecDeque;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

let instructions = loop {
match current.children.get(child_idx) {
Some(child) => {
child_idx_stack.push(child_idx + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the +1 here?

Copy link
Contributor Author

@nhtyy nhtyy Jul 10, 2023

Choose a reason for hiding this comment

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

ah to read the next child when it gets popped from the stack, i could pop from the stack then increment, not sure which u prefer

Comment on lines 353 to 354
breadth_first_addresses: I,
trace: &mut VmTrace,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: swap the order here, it's better to have iter types as last argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 378 to 381
curr_ref.code = match db_acc.code {
Some(code) => code.bytecode.into(),
None => Default::default(),
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to use code_by_hash here if the code_hash is not KECCAK_EMPTY and code is none

because code is stored separately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 243 to 248
opcode::CREATE
| opcode::CREATE2
| opcode::DELEGATECALL
| opcode::CALL
| opcode::STATICCALL
| opcode::CALLCODE => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to make this a helper function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think this comment was to be on the function vm_trace in src/tracing/builder/parity? sorry i realize my fmt touched this when it shouldnt have

if u can confirm i can fix

@mattsse mattsse mentioned this pull request Jul 7, 2023
89 tasks
@gakonst gakonst requested a review from mattsse July 10, 2023 22:33
@nhtyy
Copy link
Contributor Author

nhtyy commented Jul 11, 2023

also on opcode thing i dont think i can get it because its not used here and no pub mod
https://github.com/bluealloy/revm/blob/10f81ba1b3cd6171c25d3346f1800bbb04f5ead1/crates/interpreter/src/lib.rs#L20

getting the spec gas costs from revm ^, and there is aTracingInspectorConfig that is passed to the parity builder that has fields that maybe impact some of this behavior, but its not ever read or respected by other parts of the file it seems (like getting state diff)

_config: TracingInspectorConfig,

thats it!

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

sorry for the delay, lost the notification -.-

again, tysm for doing this!!

this is awesome.

let's try this and then run a few more checks/diffs


VmInstruction {
pc: step.pc,
cost: 0, // todo::n
Copy link
Collaborator

Choose a reason for hiding this comment

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

what to do here?

this is the gas cost of the opcode?
we should be able to get this via spec_opcode_gas

I think we need to get the spec id from the env during tracing.

I can add this in a follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the gas cost of the opcode?

yessir

@mattsse mattsse enabled auto-merge July 12, 2023 17:47
@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Merging #3529 (38c1483) into main (9924090) will decrease coverage by 21.36%.
The diff coverage is 0.00%.

Impacted file tree graph

Impacted Files Coverage Δ
...revm/revm-inspectors/src/tracing/builder/parity.rs 0.00% <0.00%> (ø)
...revm/revm-inspectors/src/tracing/builder/walker.rs 0.00% <0.00%> (ø)
crates/revm/revm-inspectors/src/tracing/mod.rs 0.00% <0.00%> (ø)
crates/revm/revm-inspectors/src/tracing/types.rs 0.00% <ø> (ø)

... and 251 files with indirect coverage changes

Flag Coverage Δ
integration-tests 13.47% <0.00%> (-2.34%) ⬇️
unit-tests 43.86% <0.00%> (-20.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 17.80% <ø> (-8.49%) ⬇️
blockchain tree 29.30% <ø> (-53.41%) ⬇️
pipeline 66.86% <ø> (-20.27%) ⬇️
storage (db) 51.47% <ø> (-22.72%) ⬇️
trie 58.69% <ø> (-35.97%) ⬇️
txpool 35.62% <ø> (-13.17%) ⬇️
networking 53.51% <ø> (-24.32%) ⬇️
rpc 41.99% <ø> (-16.45%) ⬇️
consensus 42.72% <ø> (-22.15%) ⬇️
revm 21.31% <0.00%> (-13.51%) ⬇️
payload builder 6.83% <ø> (ø)
primitives 63.77% <ø> (-24.59%) ⬇️

@nhtyy
Copy link
Contributor Author

nhtyy commented Jul 12, 2023

yayy! great experience hope to be back!

@mattsse mattsse added this pull request to the merge queue Jul 12, 2023
Merged via the queue into paradigmxyz:main with commit f0cf93e Jul 12, 2023
merklefruit pushed a commit to op-rs/op-reth that referenced this pull request Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rpc Related to the RPC implementation C-enhancement New feature or request M-changelog This change should be included in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants