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

refactor(l1,l2,levm): add evm cli arg instead of flag #1861

Merged
merged 38 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ae40c8c
feat: add evm cli arg
fborello-lambda Jan 31, 2025
c236a95
refactor: separate vm.rs into 2 different modules
fborello-lambda Jan 31, 2025
e1a9cba
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 3, 2025
d9f34d5
fix: imports
fborello-lambda Feb 3, 2025
422beb1
fix: gated import
fborello-lambda Feb 3, 2025
5145656
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 3, 2025
6363492
fix
fborello-lambda Feb 3, 2025
4305a5d
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 3, 2025
7a3d897
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 3, 2025
142fb06
fix: >=
fborello-lambda Feb 3, 2025
5395748
fix: lint
fborello-lambda Feb 3, 2025
5b2f70a
feat: EVM_BACKEND OnceCell
fborello-lambda Feb 4, 2025
924f180
rm levm feature
fborello-lambda Feb 4, 2025
a120d11
feat: integrate root's Makefile
fborello-lambda Feb 5, 2025
783a948
feat: integrate CI
fborello-lambda Feb 5, 2025
5bee771
feat: info msg
fborello-lambda Feb 5, 2025
80e35e9
more integrations
fborello-lambda Feb 5, 2025
4a5d742
fix: linter and use REVM for tests
fborello-lambda Feb 5, 2025
28bf933
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 5, 2025
0d88e94
fix: typo
fborello-lambda Feb 5, 2025
3d7bb05
Merge branch 'levm/cli_arg_not_flag' of github.com:lambdaclass/ethrex…
fborello-lambda Feb 5, 2025
acb845b
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 5, 2025
4dd518c
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 5, 2025
e43f8b9
pr_comments: rename evm_backends -> backends
fborello-lambda Feb 6, 2025
0fa4412
chore: fmt
fborello-lambda Feb 6, 2025
b803738
momentary fix
fborello-lambda Feb 6, 2025
b25a6e2
test ci
fborello-lambda Feb 6, 2025
2f757da
chore(hive): fix Makefile and CI
fborello-lambda Feb 6, 2025
9b966da
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 6, 2025
00d9344
pr_comments: consistent behavior
fborello-lambda Feb 6, 2025
e21ddab
chore: improve makefile
fborello-lambda Feb 6, 2025
6caa248
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 7, 2025
e88c406
Merge branch 'main' into levm/cli_arg_not_flag
fborello-lambda Feb 7, 2025
d813b15
Update crates/vm/backends/levm.rs
fborello-lambda Feb 7, 2025
bfa2414
chore: update readme
fborello-lambda Feb 7, 2025
2086222
Merge branch 'levm/cli_arg_not_flag' of github.com:lambdaclass/ethrex…
fborello-lambda Feb 7, 2025
c0efe4e
chore: fix linter
fborello-lambda Feb 7, 2025
84d95fa
chore: fix tests
fborello-lambda Feb 7, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/ci_l1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ jobs:
run: |
docker load --input /tmp/ethrex_image.tar

# By default ethrex uses revm as evm backend.
- name: Run Hive Simulation
run: chmod +x hive && ./hive --client ethrex --sim ${{ matrix.simulation }} --sim.limit "${{ matrix.test_pattern }}" --sim.parallelism 4

Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/ci_levm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ jobs:
name: results_levm_trigger.md

- name: Rename result (1)
run: cp results.md results_levm.md
run: |
cp results.md results_levm.md
echo "RESULTS:"
cat results_levm.md
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved

- name: Download results (main)
uses: actions/download-artifact@v4
Expand All @@ -97,12 +100,17 @@ jobs:
continue-on-error: true

- name: Rename result (2)
run: cp results.md results_levm_main.md
run: |
cp results.md results_levm_main.md
echo "RESULTS:"
cat results_levm_main.md
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved

- name: Create diff message
run: |
bash .github/scripts/hive_levm_revm_diff.sh results_levm_main.md results_levm.md >> diff.md
cat diff.md >> $GITHUB_STEP_SUMMARY
echo "SUMMARY:"
cat diff.md

- name: Check Regression
run: |
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/common_hive_reports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:

steps:
- name: Pull image
if: ${{ inputs.evm == 'revm' }}
run: |
docker pull ghcr.io/lambdaclass/ethrex:latest
docker tag ghcr.io/lambdaclass/ethrex:latest ethrex:latest
Expand All @@ -53,18 +52,14 @@ jobs:
with:
ref: main

- name: Build Image with LEVM
if: ${{ inputs.evm == 'levm' }}
run: cd crates/vm/levm && make build-image-levm

- name: Setup Go
uses: actions/setup-go@v5

- name: Setup Hive
run: make setup-hive

- name: Run Hive Simulation
run: cd hive && ./hive --client ethrex --sim ${{ matrix.test.simulation }} --sim.parallelism 16
run: cd hive && ./hive --client ethrex --sim ${{ matrix.test.simulation }} --ethrex.flags "--evm ${{ inputs.evm }}" --sim.parallelism 16
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
continue-on-error: true

- name: Upload results
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/flamegraph_reporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ jobs:
ethrex_l2 config create default --default
ethrex_l2 config set default

# By default ethrex uses revm as evm backend.
- id: generate-flamegraph-ethrex
name: Generate Flamegraph data for Ethrex
shell: bash
Expand Down
37 changes: 24 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,19 @@ stop-localnet-silent:
@kurtosis enclave stop $(ENCLAVE) >/dev/null 2>&1 || true
@kurtosis enclave rm $(ENCLAVE) --force >/dev/null 2>&1 || true

HIVE_REVISION := b0b0f98bd24676239722e3aa7885e29ef856d804
HIVE_REVISION := feb4333db7fe9f6dc161326ebb11957d4306d2f9
# Shallow clones can't specify a single revision, but at least we avoid working
# the whole history by making it shallow since a given date (one day before our
# target revision).
HIVE_SHALLOW_SINCE := 2024-09-02
QUIET ?= false

hive:
if [ "$(QUIET)" = "true" ]; then \
git clone --quiet --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive && \
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
git clone --quiet --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive ; \
cd hive && git checkout --quiet --detach $(HIVE_REVISION) && go build .; \
else \
git clone --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive && \
git clone --single-branch --branch master --shallow-since=$(HIVE_SHALLOW_SINCE) https://github.com/lambdaclass/hive ; \
cd hive && git checkout --detach $(HIVE_REVISION) && go build .; \
fi

Expand Down Expand Up @@ -106,6 +107,9 @@ SIM_LOG_LEVEL ?= 4
run-hive: build-image setup-hive ## 🧪 Run Hive testing suite
cd hive && ./hive --client ethrex --sim $(SIMULATION) --sim.limit "$(TEST_PATTERN)"

run-hive-levm: build-image setup-hive ## 🧪 Run Hive testing suite with LEVM
cd hive && ./hive --client ethrex --ethrex.flags "--evm levm" --sim $(SIMULATION) --sim.limit "$(TEST_PATTERN)"

run-hive-all: build-image setup-hive ## 🧪 Run all Hive testing suites
cd hive && ./hive --client ethrex --sim ".*" --sim.parallelism 4

Expand All @@ -115,6 +119,16 @@ run-hive-debug: build-image setup-hive ## 🐞 Run Hive testing suite in debug m
clean-hive-logs: ## 🧹 Clean Hive logs
rm -rf ./hive/workspace/logs

SIM_PARALLELISM := 48
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
EVM_BACKEND := revm
# `make run-hive-report SIM_PARALLELISM=24 EVM_BACKEND="levm"`
run-hive-report: build-image setup-hive clean-hive-logs ## 🐝 Run Hive and Build report
cd hive && ./hive --ethrex.flags "--evm $(EVM_BACKEND)" --sim ethereum/rpc-compat --client ethrex --sim.limit "$(TEST_PATTERN)" --sim.parallelism $(SIM_PARALLELISM) || exit 0
cd hive && ./hive --ethrex.flags "--evm $(EVM_BACKEND)" --sim devp2p --client ethrex --sim.limit "$(TEST_PATTERN)" --sim.parallelism $(SIM_PARALLELISM) || exit 0
cd hive && ./hive --ethrex.flags "--evm $(EVM_BACKEND)" --sim ethereum/engine --client ethrex --sim.limit "$(TEST_PATTERN)" --sim.parallelism $(SIM_PARALLELISM) || exit 0
cd hive && ./hive --ethrex.flags "--evm $(EVM_BACKEND)" --sim ethereum/sync --client ethrex --sim.limit "$(TEST_PATTERN)" --sim.parallelism $(SIM_PARALLELISM) || exit 0
cargo run --release -p hive_report

loc:
cargo run -p loc

Expand Down Expand Up @@ -152,17 +166,18 @@ install-cli: ## 🛠️ Installs the ethrex-l2 cli

start-node-with-flamegraph: rm-test-db ## 🚀🔥 Starts an ethrex client used for testing
@if [ -z "$$L" ]; then \
LEVM=""; \
LEVM="revm"; \
echo "Running the test-node without the LEVM feature"; \
echo "If you want to use levm, run the target with an L at the end: make <target> L=1"; \
else \
LEVM=",levm"; \
LEVM="levm"; \
echo "Running the test-node with the LEVM feature"; \
fi; \
sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph \
sudo -E CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph \
--bin ethrex \
--features "dev$$LEVM" \
--features "dev" \
-- \
--evm $$LEVM \
--network test_data/genesis-l2.json \
--http.port 1729 \
--datadir test_ethrex
Expand All @@ -176,14 +191,10 @@ load-node: install-cli ## 🚧 Runs a load-test. Run make start-node-with-flameg
CONTRACT_INTERACTION="-c"; \
echo "Running the load-test with contract interaction"; \
fi; \
ethrex_l2 test load --path test_data/private_keys.txt -i 100 -v --value 1 $$CONTRACT_INTERACTION
ethrex_l2 test load --path test_data/private_keys.txt -i 1000 -v --value 100000 $$CONTRACT_INTERACTION

rm-test-db: ## 🛑 Removes the DB used by the ethrex client used for testing
sudo cargo run --release --bin ethrex -- removedb --datadir test_ethrex

flamegraph:
sudo -E CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin ethrex --features dev -- --network test_data/genesis-l2.json --http.port 1729 >/dev/null &
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
flamegraph: ## 🚧 Runs a load-test. Run make start-node-with-flamegraph and in a new terminal make flamegraph
bash scripts/flamegraph.sh

test-load:
ethrex_l2 test load --path ./test_data/private_keys.txt -i 1000 -v --value 10000000 --to 0xFCbaC0713ACf16708aB6BC977227041FA1BC618D
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions cmd/ef_tests/levm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ version.workspace = true
edition.workspace = true

[dependencies]
ethrex-blockchain = { workspace = true, features = ["levm"] }
ethrex-blockchain = { workspace = true }
ethrex-core.workspace = true
ethrex-storage.workspace = true
ethrex-rlp.workspace = true
ethrex-vm = { workspace = true, features = ["levm"] }
ethrex-vm = { workspace = true }
ethrex-levm = { path = "../../../crates/vm/levm" }
serde.workspace = true
serde_json.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion cmd/ef_tests/levm/runner/levm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ethrex_levm::{
Environment,
};
use ethrex_storage::AccountUpdate;
use ethrex_vm::{db::StoreWrapper, EvmState};
use ethrex_vm::db::{EvmState, StoreWrapper};
use keccak_hash::keccak;
use std::{collections::HashMap, sync::Arc};

Expand Down
5 changes: 4 additions & 1 deletion cmd/ef_tests/levm/runner/revm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use ethrex_levm::{
Account, StorageSlot,
};
use ethrex_storage::{error::StoreError, AccountUpdate};
use ethrex_vm::{db::StoreWrapper, fork_to_spec_id, EvmState, RevmAddress, RevmU256};
use ethrex_vm::{
db::{EvmState, StoreWrapper},
fork_to_spec_id, RevmAddress, RevmU256,
};
use revm::{
db::State,
inspectors::TracerEip3155 as RevmTracerEip3155,
Expand Down
2 changes: 1 addition & 1 deletion cmd/ef_tests/levm/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use ethrex_core::{types::Genesis, H256, U256};
use ethrex_storage::{EngineType, Store};
use ethrex_vm::{evm_state, EvmState};
use ethrex_vm::db::{evm_state, EvmState};
use spinoff::Spinner;

pub fn load_initial_state(test: &EFTest) -> (EvmState, H256) {
Expand Down
1 change: 0 additions & 1 deletion cmd/ethrex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ metrics = ["ethrex-blockchain/metrics", "ethrex-l2/metrics"]
libmdbx = ["dep:libmdbx", "ethrex-storage/libmdbx"]
redb = ["dep:redb", "ethrex-storage/redb"]
l2 = ["dep:ethrex-l2", "ethrex-vm/l2"]
levm = ["default", "ethrex-vm/levm", "ethrex-blockchain/levm"]
2 changes: 2 additions & 0 deletions cmd/ethrex/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{Arg, ArgAction, Command};
use ethrex_p2p::types::Node;
use ethrex_vm::backends::EVM;
use tracing::Level;

pub fn cli() -> Command {
Expand Down Expand Up @@ -128,6 +129,7 @@ pub fn cli() -> Command {
.required(false)
.default_value("revm")
.value_name("EVM_BACKEND")
.value_parser(clap::value_parser!(EVM))
.help("Has to be `levm` or `revm`"),
)
.subcommand(
Expand Down
21 changes: 17 additions & 4 deletions cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ethrex_p2p::{
};
use ethrex_rlp::decode::RLPDecode;
use ethrex_storage::{EngineType, Store};
use ethrex_vm::{backends::EVM, EVM_BACKEND};
use k256::ecdsa::SigningKey;
use local_ip_address::local_ip;
use rand::rngs::OsRng;
Expand Down Expand Up @@ -150,6 +151,10 @@ async fn main() {

let sync_mode = sync_mode(&matches);

let evm = matches.get_one::<EVM>("evm").unwrap_or(&EVM::REVM);
let evm = EVM_BACKEND.get_or_init(|| evm.clone());
info!("EVM_BACKEND set to: {:?}", evm);

cfg_if::cfg_if! {
if #[cfg(feature = "redb")] {
let store = Store::new(&data_dir, EngineType::RedB).expect("Failed to create Store");
Expand Down Expand Up @@ -284,7 +289,14 @@ async fn main() {
};
let max_tries = 3;
let url = format!("http://{authrpc_socket_addr}");
let block_producer_engine = ethrex_dev::block_producer::start_block_producer(url, authrpc_jwtsecret.into(), head_block_hash, max_tries, 1000, ethrex_core::Address::default());
let block_producer_engine = ethrex_dev::block_producer::start_block_producer(
url,
authrpc_jwtsecret.into(),
head_block_hash,
max_tries,
1000,
ethrex_core::Address::default(),
);
tracker.spawn(block_producer_engine);
} else {
ethrex_p2p::start_network(
Expand Down Expand Up @@ -419,12 +431,13 @@ fn import_blocks(store: &Store, blocks: &Vec<Block>) {
}
if let Some(last_block) = blocks.last() {
let hash = last_block.hash();
cfg_if::cfg_if! {
if #[cfg(feature = "levm")] {
match EVM_BACKEND.get() {
Some(EVM::LEVM) => {
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
// We are allowing this not to unwrap so that tests can run even if block execution results in the wrong root hash with LEVM.
let _ = apply_fork_choice(store, hash, hash, hash);
}
else {
// This means we are using REVM as default
Some(EVM::REVM) | None => {
apply_fork_choice(store, hash, hash, hash).unwrap();
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ethrex-levm = { path = "../vm/levm", optional = true }
ethrex-levm = { path = "../vm/levm" }
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
thiserror.workspace = true
sha3.workspace = true
tracing.workspace = true
Expand All @@ -31,7 +31,6 @@ path = "./blockchain.rs"

[features]
default = ["c-kzg"]
levm = ["default", "ethrex-vm/levm", "ethrex-levm"]
libmdbx = ["ethrex-core/libmdbx", "ethrex-storage/default", "ethrex-vm/libmdbx"]
c-kzg = ["ethrex-core/c-kzg"]
metrics = ["ethrex-metrics/transactions"]
23 changes: 12 additions & 11 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use ethrex_core::H256;

use ethrex_storage::error::StoreError;
use ethrex_storage::{AccountUpdate, Store};
use ethrex_vm::{evm_state, execute_block, EvmState};
use ethrex_vm::db::{evm_state, EvmState};

use ethrex_vm::EVM_BACKEND;
use ethrex_vm::{backends, backends::EVM};

//TODO: Implement a struct Chain or BlockChain to encapsulate
//functionality and canonical chain state and config
Expand All @@ -40,16 +43,14 @@ pub fn add_block(block: &Block, storage: &Store) -> Result<(), ChainError> {
// Validate the block pre-execution
validate_block(block, &parent_header, &state)?;
let (receipts, account_updates): (Vec<Receipt>, Vec<AccountUpdate>) = {
// TODO: Consider refactoring both implementations so that they have the same signature
#[cfg(feature = "levm")]
{
execute_block(block, &mut state)?
}
#[cfg(not(feature = "levm"))]
{
let receipts = execute_block(block, &mut state)?;
let account_updates = ethrex_vm::get_state_transitions(&mut state);
(receipts, account_updates)
match EVM_BACKEND.get() {
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
Some(EVM::LEVM) => backends::levm::execute_block(block, &mut state)?,
// This means we are using REVM as default for tests
Some(EVM::REVM) | None => {
fborello-lambda marked this conversation as resolved.
Show resolved Hide resolved
let receipts = backends::revm::execute_block(block, &mut state)?;
let account_updates = ethrex_vm::get_state_transitions(&mut state);
(receipts, account_updates)
}
}
};

Expand Down
Loading
Loading