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

feat(cli): count the appearances of opcode and opcode sets #5211

Closed
wants to merge 14 commits into from

Conversation

thedevbirb
Copy link

Closes #5067. This PR co-authored by @alessandromazza98 introduces a new command called count-opcodes that returns the take top occurrences of opcodes and tuples of opcodes.

Here below is an example of the result of running this command on a few blocks on Sepolia:
image

Lorenzo Feroleto and others added 4 commits October 26, 2023 16:59
Co-authored-by: Alessandro Mazza <[email protected]>
Co-authored-by: Alessandro Mazza <[email protected]>
test_bytecode
}

fn all_opcodes_test_string() -> String {
Copy link
Author

Choose a reason for hiding this comment

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

This can be quite noisy in the file, however we wanted to make it as easy as possible to read and modify this test opcodes string if needed

@@ -163,6 +164,9 @@ pub enum Commands<Ext: RethCliExt = ()> {
/// Scripts for node recovery
#[command(name = "recover")]
Recover(recover::Command),
/// Script for counting opcodes occurrencies
#[command(name = "count-opcodes")]
CountOpcodes(count_opcodes::Command),
Copy link
Member

Choose a reason for hiding this comment

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

I'd put this under debug or something like that since it's not really relevant to normal node ops


let mut opcode_counter = OpCodeCounter::new();

info!("start opcodes processing...");
Copy link
Member

Choose a reason for hiding this comment

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

These info!'s are not rly necessary, I imagine it doesn't take a long time?

}

fn print_counts(&self, size: usize) {
println!("Single opcodes:");
Copy link
Member

Choose a reason for hiding this comment

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

nit: we can use the table layout that we also use for the db commands here 😄

@onbjerg onbjerg added C-enhancement New feature or request A-cli Related to the reth CLI labels Oct 30, 2023
@thedevbirb
Copy link
Author

Hey @onbjerg, we should have addressed all your reviews. Now tables are printed using ComfyTable which seems to be what other commands use

Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

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

lgtm

bin/reth/src/debug_cmd/count_opcodes.rs Outdated Show resolved Hide resolved
bin/reth/src/debug_cmd/count_opcodes.rs Outdated Show resolved Hide resolved
@thedevbirb
Copy link
Author

Hi @DaniPopes! Thanks for the review, now it should be better.

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

lgtm

bin/reth/src/debug_cmd/count_opcodes.rs Outdated Show resolved Hide resolved
@thedevbirb
Copy link
Author

Hey, sorry to bother you. Is there anything left we may do for this PR?

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.

Nit: Can you extract this to an example/ of using the node as a library, with the OpcodeCounter in a separate file and some explanation on the motivation of why opcode occurences are useful? cc @sslivkoff for parquet

@sslivkoff
Copy link
Member

something similar is available in the geth trigram / bigram / unigram tracer with debug_traceX rpc methods (not available in reth) https://geth.ethereum.org/docs/developers/evm-tracing/built-in-tracers#trigram

would love to have this new implementation accessible over rpc somehow

@thedevbirb
Copy link
Author

Thanks! We'll look into it

@alessandromazza98
Copy link
Contributor

I moved it into the example folder and add a little explanation of it. Right now the example (as I wrote in the code) requires the users to have a sepolia db into the default folder for MacOS, but it can be easily changed to the folder the user wants. He just has to edit one line

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Dec 13, 2023
@github-actions github-actions bot closed this Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Related to the reth CLI C-enhancement New feature or request S-stale This issue/PR is stale and will close with no further activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Count the appearances of opcode and opcode sets
6 participants