diff --git a/.github/workflows/pr_perf_build_block_bench.yml b/.github/workflows/pr_perf_build_block_bench.yml index c723592a6aa..ca650bc582e 100644 --- a/.github/workflows/pr_perf_build_block_bench.yml +++ b/.github/workflows/pr_perf_build_block_bench.yml @@ -5,7 +5,7 @@ name: Benchmark Block building on: workflow_dispatch: #pull_request: - #branches: ["**"] + #branches: ["**"] permissions: pull-requests: write @@ -23,7 +23,7 @@ jobs: - name: Benchmarks uses: boa-dev/criterion-compare-action@v3 with: - cwd: "cmd/ethrex/bench" + cwd: "benches/benches" benchName: "build_block_benchmark" branchName: ${{ github.base_ref }} token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 935c002714f..b0f5d59e5ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3513,7 +3513,6 @@ dependencies = [ "bytes", "clap 4.5.48", "clap_complete", - "criterion", "directories 5.0.1", "ethrex-blockchain", "ethrex-common 3.0.0", @@ -3543,7 +3542,6 @@ dependencies = [ "secp256k1", "serde", "serde_json", - "tempfile", "thiserror 2.0.17", "tikv-jemallocator", "tokio", @@ -3555,6 +3553,24 @@ dependencies = [ "vergen-git2", ] +[[package]] +name = "ethrex-benches" +version = "3.0.0" +dependencies = [ + "bytes", + "criterion", + "ethrex", + "ethrex-blockchain", + "ethrex-common 3.0.0", + "ethrex-config", + "ethrex-l2-rpc", + "ethrex-storage 3.0.0", + "secp256k1", + "serde_json", + "tempfile", + "tokio", +] + [[package]] name = "ethrex-blockchain" version = "3.0.0" diff --git a/Cargo.toml b/Cargo.toml index 83eb3d9556c..65c7600b9af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "benches", "cmd/ethrex", "crates/blockchain", "crates/blockchain/dev", diff --git a/Dockerfile b/Dockerfile index 38eb96e1798..9cba772e025 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,7 @@ WORKDIR /ethrex # This layer is fast and will be invalidated on any source change. FROM chef AS planner +COPY benches ./benches COPY crates ./crates COPY tooling ./tooling COPY metrics ./metrics @@ -39,6 +40,7 @@ RUN cargo chef cook --release --recipe-path recipe.json RUN curl -L -o /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.29/solc-static-linux \ && chmod +x /usr/bin/solc +COPY benches ./benches COPY crates ./crates COPY cmd ./cmd COPY metrics ./metrics diff --git a/benches/Cargo.toml b/benches/Cargo.toml new file mode 100644 index 00000000000..fcf3e38e5ee --- /dev/null +++ b/benches/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "ethrex-benches" +version.workspace = true +edition.workspace = true +authors.workspace = true +documentation.workspace = true + +[dependencies] +ethrex.workspace = true +ethrex-blockchain.workspace = true +ethrex-common.workspace = true +ethrex-config.workspace = true +ethrex-storage.workspace = true + +bytes.workspace = true +tokio.workspace = true +serde_json.workspace = true + +[dev-dependencies] +criterion = { version = "0.5.1", features = [ + "html_reports", + "async_futures", + "async_tokio", +] } +secp256k1.workspace = true +tempfile.workspace = true +ethrex-l2-rpc.workspace = true + +[[bench]] +name = "build_block_benchmark" +harness = false diff --git a/cmd/ethrex/bench/build_block_benchmark.rs b/benches/benches/build_block_benchmark.rs similarity index 98% rename from cmd/ethrex/bench/build_block_benchmark.rs rename to benches/benches/build_block_benchmark.rs index 63897dc2f7c..e79733430a2 100644 --- a/cmd/ethrex/bench/build_block_benchmark.rs +++ b/benches/benches/build_block_benchmark.rs @@ -103,7 +103,7 @@ impl ValueFormatter for GasMeasurementFormatter { } fn read_private_keys() -> Vec { - let file = include_str!("../../../fixtures/keys/private_keys_l1.txt"); + let file = include_str!("../../fixtures/keys/private_keys_l1.txt"); file.lines() .map(|line| { let line = line.trim().strip_prefix("0x").unwrap(); @@ -122,7 +122,7 @@ async fn setup_genesis(accounts: &Vec
) -> (Store, Genesis) { if std::fs::exists(&storage_path).unwrap_or(false) { std::fs::remove_dir_all(&storage_path).unwrap(); } - let genesis_file = include_bytes!("../../../fixtures/genesis/l1-dev.json"); + let genesis_file = include_bytes!("../../fixtures/genesis/l1-dev.json"); let mut genesis: Genesis = serde_json::from_slice(genesis_file).unwrap(); let store = Store::new(storage_path, EngineType::RocksDB).unwrap(); for address in accounts { diff --git a/cmd/ethrex/Cargo.toml b/cmd/ethrex/Cargo.toml index af671945306..3eed0f46318 100644 --- a/cmd/ethrex/Cargo.toml +++ b/cmd/ethrex/Cargo.toml @@ -27,7 +27,10 @@ ethrex-storage.workspace = true ethrex-storage-rollup = { workspace = true, optional = true } ethrex-vm.workspace = true -tikv-jemallocator = { version = "0.6.0", optional = true, features = ["stats", "unprefixed_malloc_on_supported_platforms"] } +tikv-jemallocator = { version = "0.6.0", optional = true, features = [ + "stats", + "unprefixed_malloc_on_supported_platforms", +] } bytes.workspace = true hex.workspace = true tracing.workspace = true @@ -55,7 +58,11 @@ url.workspace = true tui-logger = { workspace = true, optional = true } [target.'cfg(linux)'.dependencies] -tikv-jemallocator = { version = "0.6.0", optional = true, features = ["stats", "unprefixed_malloc_on_supported_platforms", "background_threads"] } +tikv-jemallocator = { version = "0.6.0", optional = true, features = [ + "stats", + "unprefixed_malloc_on_supported_platforms", + "background_threads", +] } [[bin]] name = "ethrex" @@ -102,33 +109,11 @@ l2 = [ "dep:serde_json", "dep:hex", ] -l2-sql = [ - "ethrex-storage-rollup/sql", -] +l2-sql = ["ethrex-storage-rollup/sql"] sp1 = ["ethrex-prover/sp1"] gpu = ["ethrex-prover/gpu"] risc0 = ["ethrex-prover/risc0"] -[dev-dependencies] -criterion = { version = "0.5.1", features = [ - "html_reports", - "async_futures", - "async_tokio", -] } -secp256k1.workspace = true -tempfile.workspace = true -ethrex-l2-rpc.workspace = true - -[[bench]] -path = "./bench/import_blocks_benchmark.rs" -name = "import_blocks_benchmark" -harness = false - -[[bench]] -path = "./bench/build_block_benchmark.rs" -name = "build_block_benchmark" -harness = false - [build-dependencies] vergen-git2 = { version = "1.0.7", features = ["rustc"] } ethrex-sdk = { workspace = true, optional = true } diff --git a/cmd/ethrex/bench/import_blocks_benchmark.rs b/cmd/ethrex/bench/import_blocks_benchmark.rs deleted file mode 100644 index 22451ae5f94..00000000000 --- a/cmd/ethrex/bench/import_blocks_benchmark.rs +++ /dev/null @@ -1,42 +0,0 @@ -use criterion::{Criterion, criterion_group, criterion_main}; -use ethrex::{ - cli::{import_blocks, remove_db}, - utils::{default_datadir, init_datadir}, -}; -use ethrex_blockchain::{BlockchainOptions, BlockchainType}; -use ethrex_config::networks::Network; - -#[inline] -fn block_import() { - let datadir = default_datadir(); - init_datadir(&datadir); - remove_db(&datadir, true); - - let blockchain_type = BlockchainType::default(); // TODO: Should we support L2? - - let network = Network::from("../../fixtures/genesis/perf-ci.json"); - let genesis = network - .get_genesis() - .expect("Failed to generate genesis from file"); - let rt = tokio::runtime::Runtime::new().unwrap(); - rt.block_on(import_blocks( - "../../fixtures/blockchain/l2-1k-erc20.rlp", - &datadir, - genesis, - BlockchainOptions { - r#type: blockchain_type, - ..Default::default() - }, - )) - .expect("Failed to import blocks on the Tokio runtime"); -} - -pub fn import_blocks_benchmark(c: &mut Criterion) { - let mut group = c.benchmark_group("Block import"); - group.sample_size(10); - group.bench_function("Block import ERC20 transfers", |b| b.iter(block_import)); - group.finish(); -} - -criterion_group!(runner, import_blocks_benchmark); -criterion_main!(runner);