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(l1, l2, levm): make stats #1361

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ TEST_PATTERN ?= /
# For example, to run the rpc-compat suites for eth_chainId & eth_blockNumber you should run:
# `make run-hive SIMULATION=ethereum/rpc-compat TEST_PATTERN="/eth_chainId|eth_blockNumber"`
run-hive: build-image setup-hive ## 🧪 Run Hive testing suite
cd hive && ./hive --sim $(SIMULATION) --client ethrex --sim.limit "$(TEST_PATTERN)"
cd hive && ./hive --client ethrex --sim $(SIMULATION) --sim.limit "$(TEST_PATTERN)"

run-hive-debug: build-image setup-hive ## 🐞 Run Hive testing suite in debug mode
cd hive && ./hive --sim $(SIMULATION) --client ethrex --sim.limit "$(TEST_PATTERN)" --docker.output
Expand All @@ -105,3 +105,31 @@ clean-hive-logs: ## 🧹 Clean Hive logs

loc:
cargo run -p loc

hive-stats:
git clone --quiet --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive || true
cd hive && git checkout --quiet --detach $(HIVE_REVISION) && go build .
if [ "$$(cd hive && git rev-parse HEAD)" != "$(HIVE_REVISION)" ]; then \
cd hive && \
git checkout --quiet master && \
git fetch --quiet --shallow-since=$(HIVE_SHALLOW_SINCE) && \
git checkout --quiet --detach $(HIVE_REVISION) && go build . ;\
fi
make run-hive SIMULATION=ethereum/rpc-compat TEST_PATTERN="/eth_chainId|eth_getTransactionByBlockHashAndIndex|eth_getTransactionByBlockNumberAndIndex|eth_getCode|eth_getStorageAt|eth_call|eth_getTransactionByHash|eth_getBlockByHash|eth_getBlockByNumber|eth_createAccessList|eth_getBlockTransactionCountByNumber|eth_getBlockTransactionCountByHash|eth_getBlockReceipts|eth_getTransactionReceipt|eth_blobGasPrice|eth_blockNumber|ethGetTransactionCount|debug_getRawHeader|debug_getRawBlock|debug_getRawTransaction|debug_getRawReceipts|eth_estimateGas|eth_getBalance|eth_sendRawTransaction|eth_getProof|eth_getLogs"
make run-hive SIMULATION=devp2p TEST_PATTERN="discv4"
make run-hive SIMULATION=devp2p TEST_PATTERN="/AccountRange|StorageRanges|ByteCodes|TrieNodes"
make run-hive SIMULATION=devp2p TEST_PATTERN="eth/Status|GetBlockHeaders|SimultaneousRequests|SameRequestID|ZeroRequestID|GetBlockBodies|MaliciousHandshake|MaliciousStatus|Transaction|InvalidTxs"
make run-hive SIMULATION=ethereum/engine TEST_PATTERN="engine-(auth|exchange-capabilities)/"
make run-hive SIMULATION=ethereum/sync TEST_PATTERN="engine-cancun/Blob Transactions On Block 1|Blob Transaction Ordering, Single|Blob Transaction Ordering, Multiple Accounts|Replace Blob Transactions|Parallel Blob Transactions|ForkchoiceUpdatedV3 Modifies Payload ID on Different Beacon Root|NewPayloadV3 After Cancun|NewPayloadV3 Versioned Hashes|Incorrect BlobGasUsed|Bad Hash|ParentHash equals BlockHash|RPC:|in ForkchoiceState|Unknown|Invalid PayloadAttributes|Unique|ForkchoiceUpdated Version on Payload Request|Re-Execute Payload|In-Order Consecutive Payload|Multiple New Payloads|Valid NewPayload->|NewPayload with|Payload Build after|Build Payload with|Invalid Missing Ancestor ReOrg, StateRoot|Re-Org Back to|Re-org to Previously|Safe Re-Org to Side Chain|Transaction Re-Org, Re-Org Back In|Re-Org Back into Canonical Chain, Depth=5|Suggested Fee Recipient Test|PrevRandao Opcode|Invalid NewPayload, [^R][^e]|Fork ID Genesis=0, Cancun=0|Fork ID Genesis=0, Cancun=1|Fork ID Genesis=1, Cancun=0|Fork ID Genesis=1, Cancun=2, Shanghai=2"

stats:
cargo run --quiet --release -p loc -- --summary && echo
cargo test --quiet -p ef_tests-levm --test ef_tests_levm -- --summary && echo
make hive-stats
cargo run --quiet --release -p hive_report

# hive-sim-stats:
# rm -rf hive/workspace $(FILE_NAME)_logs
# make run-hive SIMULATION="$(SIMULATION)" TEST_PATTERN="$(TEST_PATTERN)"
# mkdir -p $(FILE_NAME)_logs
# mv hive/workspace/logs/*-*.json $(FILE_NAME)_logs
4 changes: 4 additions & 0 deletions cmd/loc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ edition.workspace = true
tokei = "12.1.2"
serde = "1.0.215"
serde_json = "1.0.133"
clap = { version = "4.3", features = ["derive"] }
clap_complete = "4.5.17"
colored = "2.1.0"
spinoff = "0.8.0"
162 changes: 38 additions & 124 deletions cmd/loc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use serde::{Deserialize, Serialize};
use clap::Parser;
use report::{shell_summary, LinesOfCodeReport, LinesOfCodeReporterOptions};
use spinoff::{spinners::Dots, Color, Spinner};
use std::path::PathBuf;
use tokei::{Config, LanguageType, Languages};

const CARGO_MANIFEST_DIR: &str = std::env!("CARGO_MANIFEST_DIR");
mod report;

#[derive(Default, Serialize, Deserialize, Clone, Copy)]
pub struct LinesOfCodeReport {
ethrex: usize,
ethrex_l1: usize,
ethrex_l2: usize,
levm: usize,
}
const CARGO_MANIFEST_DIR: &str = std::env!("CARGO_MANIFEST_DIR");

fn main() {
let opts = LinesOfCodeReporterOptions::parse();

let mut spinner = Spinner::new(Dots, "Counting lines of code...", Color::Cyan);

let ethrex = PathBuf::from(CARGO_MANIFEST_DIR).join("../../");
let levm = PathBuf::from(CARGO_MANIFEST_DIR).join("../../crates/vm");
let ethrex_l2 = PathBuf::from(CARGO_MANIFEST_DIR).join("../../crates/l2");
Expand All @@ -31,128 +31,42 @@ fn main() {
languages.get_statistics(&[ethrex_l2], &["tests"], &config);
let ethrex_l2_loc = &languages.get(&LanguageType::Rust).unwrap();

spinner.success("Lines of code calculated!");

let mut spinner = Spinner::new(Dots, "Generating report...", Color::Cyan);

let new_report = LinesOfCodeReport {
ethrex: ethrex_loc.code,
ethrex_l1: ethrex_loc.code - ethrex_l2_loc.code - levm_loc.code,
ethrex_l2: ethrex_l2_loc.code,
levm: levm_loc.code,
};

std::fs::write(
"loc_report.json",
serde_json::to_string(&new_report).unwrap(),
)
.expect("loc_report.json could not be written");

let old_report: LinesOfCodeReport = std::fs::read_to_string("loc_report.json.old")
.map(|s| serde_json::from_str(&s).unwrap())
.unwrap_or(new_report);

std::fs::write(
"loc_report_slack.txt",
slack_message(old_report, new_report),
)
.unwrap();
std::fs::write(
"loc_report_github.txt",
github_step_summary(old_report, new_report),
)
.unwrap();
}
if opts.summary {
spinner.success("Report generated!");
println!("{}", shell_summary(new_report));
} else {
std::fs::write(
"loc_report.json",
serde_json::to_string(&new_report).unwrap(),
)
.expect("loc_report.json could not be written");

fn slack_message(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"{{
"blocks": [
{{
"type": "header",
"text": {{
"type": "plain_text",
"text": "Daily Lines of Code Report"
}}
}},
{{
"type": "divider"
}},
{{
"type": "section",
"text": {{
"type": "mrkdwn",
"text": "*ethrex L1:* {} {}\n*ethrex L2:* {} {}\n*levm:* {} {}\n*ethrex (total):* {} {}"
}}
}}
]
}}"#,
new_report.ethrex_l1,
match new_report.ethrex_l1.cmp(&old_report.ethrex_l1) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l1_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l1_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex_l2,
match new_report.ethrex_l2.cmp(&old_report.ethrex_l2) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l2_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l2_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.levm,
match new_report.levm.cmp(&old_report.levm) {
std::cmp::Ordering::Greater => format!("(+{levm_diff})"),
std::cmp::Ordering::Less => format!("(-{levm_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex,
match new_report.ethrex.cmp(&old_report.ethrex) {
std::cmp::Ordering::Greater => format!("(+{ethrex_diff_total})"),
std::cmp::Ordering::Less => format!("(-{ethrex_diff_total})"),
std::cmp::Ordering::Equal => "".to_string(),
},
)
}
let old_report: LinesOfCodeReport = std::fs::read_to_string("loc_report.json.old")
.map(|s| serde_json::from_str(&s).unwrap())
.unwrap_or(new_report);

std::fs::write(
"loc_report_slack.txt",
report::slack_message(old_report, new_report),
)
.unwrap();
std::fs::write(
"loc_report_github.txt",
report::github_step_summary(old_report, new_report),
)
.unwrap();

fn github_step_summary(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"```
ethrex loc summary
====================
ethrex L1: {} {}
ethrex L2: {} {}
levm: {} ({})
ethrex (total): {} {}
```"#,
new_report.ethrex_l1,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_l1_diff})")
} else {
format!("(-{ethrex_l1_diff})")
},
new_report.ethrex_l2,
if new_report.ethrex_l2 > old_report.ethrex_l2 {
format!("(+{ethrex_l2_diff})")
} else {
format!("(-{ethrex_l2_diff})")
},
new_report.levm,
if new_report.levm > old_report.levm {
format!("(+{levm_diff})")
} else {
format!("(-{levm_diff})")
},
new_report.ethrex,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_diff_total})")
} else {
format!("(-{ethrex_diff_total})")
},
)
spinner.success("Report generated!");
}
}
130 changes: 130 additions & 0 deletions cmd/loc/src/report.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
use clap::Parser;
use colored::Colorize;
use serde::{Deserialize, Serialize};

#[derive(Parser)]
pub struct LinesOfCodeReporterOptions {
#[arg(short, long, value_name = "SUMMARY", default_value = "false")]
pub summary: bool,
}

#[derive(Default, Serialize, Deserialize, Clone, Copy)]
pub struct LinesOfCodeReport {
pub ethrex: usize,
pub ethrex_l1: usize,
pub ethrex_l2: usize,
pub levm: usize,
}

pub fn slack_message(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"{{
"blocks": [
{{
"type": "header",
"text": {{
"type": "plain_text",
"text": "Daily Lines of Code Report"
}}
}},
{{
"type": "divider"
}},
{{
"type": "section",
"text": {{
"type": "mrkdwn",
"text": "*ethrex L1:* {} {}\n*ethrex L2:* {} {}\n*levm:* {} {}\n*ethrex (total):* {} {}"
}}
}}
]
}}"#,
new_report.ethrex_l1,
match new_report.ethrex_l1.cmp(&old_report.ethrex_l1) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l1_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l1_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex_l2,
match new_report.ethrex_l2.cmp(&old_report.ethrex_l2) {
std::cmp::Ordering::Greater => format!("(+{ethrex_l2_diff})"),
std::cmp::Ordering::Less => format!("(-{ethrex_l2_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.levm,
match new_report.levm.cmp(&old_report.levm) {
std::cmp::Ordering::Greater => format!("(+{levm_diff})"),
std::cmp::Ordering::Less => format!("(-{levm_diff})"),
std::cmp::Ordering::Equal => "".to_string(),
},
new_report.ethrex,
match new_report.ethrex.cmp(&old_report.ethrex) {
std::cmp::Ordering::Greater => format!("(+{ethrex_diff_total})"),
std::cmp::Ordering::Less => format!("(-{ethrex_diff_total})"),
std::cmp::Ordering::Equal => "".to_string(),
},
)
}

pub fn github_step_summary(old_report: LinesOfCodeReport, new_report: LinesOfCodeReport) -> String {
let ethrex_l1_diff = new_report.ethrex_l1.abs_diff(old_report.ethrex_l1);
let ethrex_l2_diff = new_report.ethrex_l2.abs_diff(old_report.ethrex_l2);
let levm_diff = new_report.levm.abs_diff(old_report.levm);
let ethrex_diff_total = ethrex_l1_diff + ethrex_l2_diff + levm_diff;

format!(
r#"```
ethrex loc summary
====================
ethrex L1: {} {}
ethrex L2: {} {}
levm: {} ({})
ethrex (total): {} {}
```"#,
new_report.ethrex_l1,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_l1_diff})")
} else {
format!("(-{ethrex_l1_diff})")
},
new_report.ethrex_l2,
if new_report.ethrex_l2 > old_report.ethrex_l2 {
format!("(+{ethrex_l2_diff})")
} else {
format!("(-{ethrex_l2_diff})")
},
new_report.levm,
if new_report.levm > old_report.levm {
format!("(+{levm_diff})")
} else {
format!("(-{levm_diff})")
},
new_report.ethrex,
if new_report.ethrex > old_report.ethrex {
format!("(+{ethrex_diff_total})")
} else {
format!("(-{ethrex_diff_total})")
},
)
}

pub fn shell_summary(new_report: LinesOfCodeReport) -> String {
format!(
"{}\n{}\n{} {}\n{} {}\n{} {}\n{} {}",
"Lines of Code".bold(),
"=============".bold(),
"ethrex L1:".bold(),
new_report.ethrex_l1,
"ethrex L2:".bold(),
new_report.ethrex_l2,
"levm:".bold(),
new_report.levm,
"ethrex (total):".bold(),
new_report.ethrex,
)
}