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

fix(l1): use levm flag for apply transaction function #1755

Merged
merged 16 commits into from
Jan 21, 2025
Merged
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
84 changes: 64 additions & 20 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ use ethrex_core::{
};
use ethrex_rlp::encode::RLPEncode;
use ethrex_storage::{error::StoreError, Store};
#[cfg(feature = "levm")]
use ethrex_vm::{db::StoreWrapper, execute_tx_levm};

#[cfg(feature = "levm")]
use std::sync::Arc;

#[cfg(not(feature = "levm"))]
use ethrex_vm::execute_tx;

use ethrex_vm::{
beacon_root_contract_call, evm_state, execute_tx, get_state_transitions, process_withdrawals,
spec_id, EvmError, EvmState, SpecId,
beacon_root_contract_call, evm_state, get_state_transitions, process_withdrawals, spec_id,
EvmError, EvmState, SpecId,
};

use sha3::{Digest, Keccak256};

use ethrex_metrics::metrics;
Expand Down Expand Up @@ -422,24 +432,58 @@ fn apply_plain_transaction(
head: &HeadTransaction,
context: &mut PayloadBuildContext,
) -> Result<Receipt, ChainError> {
let result = execute_tx(
&head.tx,
&context.payload.header,
context.evm_state,
spec_id(
&context.chain_config().map_err(ChainError::from)?,
context.payload.header.timestamp,
),
)?;
context.remaining_gas = context.remaining_gas.saturating_sub(result.gas_used());
context.block_value += U256::from(result.gas_used()) * head.tip;
let receipt = Receipt::new(
head.tx.tx_type(),
result.is_success(),
context.payload.header.gas_limit - context.remaining_gas,
result.logs(),
);
Ok(receipt)
#[cfg(feature = "levm")]
{
let block_cache = HashMap::new();

let store_wrapper = Arc::new(StoreWrapper {
store: context.evm_state.database().unwrap().clone(),
block_hash: context.payload.header.parent_hash,
});

let result = execute_tx_levm(
&head.tx,
&context.payload.header,
store_wrapper.clone(),
block_cache,
spec_id(
&context.chain_config().map_err(ChainError::from)?,
context.payload.header.timestamp,
),
)
.map_err(EvmError::from)?;

let receipt = Receipt::new(
head.tx.tx_type(),
result.is_success(),
context.payload.header.gas_limit - context.remaining_gas,
result.logs,
);
Ok(receipt)
}

// REVM Implementation
#[cfg(not(feature = "levm"))]
{
let result = execute_tx(
&head.tx,
&context.payload.header,
context.evm_state,
spec_id(
&context.chain_config().map_err(ChainError::from)?,
context.payload.header.timestamp,
),
)?;
context.remaining_gas = context.remaining_gas.saturating_sub(result.gas_used());
context.block_value += U256::from(result.gas_used()) * head.tip;
let receipt = Receipt::new(
head.tx.tx_type(),
result.is_success(),
context.payload.header.gas_limit - context.remaining_gas,
result.logs(),
);
Ok(receipt)
}
}

fn finalize_payload(context: &mut PayloadBuildContext) -> Result<(), StoreError> {
Expand Down
Loading