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

chore: remove revm/compat from reth-primitives #8960

Merged
merged 1 commit into from
Jun 19, 2024
Merged
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
14 changes: 6 additions & 8 deletions crates/evm/execution-types/src/execution_outcome.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use reth_primitives::{
logs_bloom,
revm::compat::{into_reth_acc, into_revm_acc},
Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests, StorageEntry,
B256, U256,
logs_bloom, Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests,
StorageEntry, B256, U256,
};
use reth_trie::HashedPostState;
use revm::{
Expand Down Expand Up @@ -81,8 +79,8 @@ impl ExecutionOutcome {
state_init.into_iter().map(|(address, (original, present, storage))| {
(
address,
original.map(into_revm_acc),
present.map(into_revm_acc),
original.map(Into::into),
present.map(Into::into),
storage.into_iter().map(|(k, s)| (k.into(), s)).collect(),
)
}),
Expand All @@ -91,7 +89,7 @@ impl ExecutionOutcome {
reverts.into_iter().map(|(address, (original, storage))| {
(
address,
original.map(|i| i.map(into_revm_acc)),
original.map(|i| i.map(Into::into)),
storage.into_iter().map(|entry| (entry.key.into(), entry.value)),
)
})
Expand Down Expand Up @@ -129,7 +127,7 @@ impl ExecutionOutcome {

/// Get account if account is known.
pub fn account(&self, address: &Address) -> Option<Option<Account>> {
self.bundle.account(address).map(|a| a.info.clone().map(into_reth_acc))
self.bundle.account(address).map(|a| a.info.clone().map(Into::into))
}

/// Get storage if value is known.
Expand Down
24 changes: 23 additions & 1 deletion crates/primitives-traits/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use byteorder::{BigEndian, ReadBytesExt};
use bytes::Buf;
use derive_more::Deref;
use reth_codecs::{main_codec, Compact};
use revm_primitives::{Bytecode as RevmBytecode, JumpTable};
use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, JumpTable};
use serde::{Deserialize, Serialize};

/// An Ethereum account.
Expand Down Expand Up @@ -122,6 +122,28 @@ impl Compact for Bytecode {
}
}

impl From<AccountInfo> for Account {
fn from(revm_acc: AccountInfo) -> Self {
let code_hash = revm_acc.code_hash;
Self {
balance: revm_acc.balance,
nonce: revm_acc.nonce,
bytecode_hash: (code_hash != KECCAK_EMPTY).then_some(code_hash),
}
}
}

impl From<Account> for AccountInfo {
fn from(reth_acc: Account) -> Self {
Self {
balance: reth_acc.balance,
nonce: reth_acc.nonce,
code_hash: reth_acc.bytecode_hash.unwrap_or(KECCAK_EMPTY),
code: None,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
28 changes: 0 additions & 28 deletions crates/primitives/src/revm/compat.rs

This file was deleted.

9 changes: 0 additions & 9 deletions crates/primitives/src/revm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
//! Helpers for working with revm.

/// The `compat` module contains utility functions that perform conversions between reth and revm,
/// compare analogous types from the two implementations, and calculate intrinsic gas usage.
///
/// The included conversion methods can be used to convert between:
/// * reth's [Log](crate::Log) type and revm's [Log](revm_primitives::Log) type.
/// * reth's [Account](crate::Account) type and revm's [`AccountInfo`](revm_primitives::AccountInfo)
/// type.
pub mod compat;

/// Reth block execution/validation configuration and constants
pub mod config;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ mod tests {
models::{AccountBeforeTx, BlockNumberAddress},
};
use reth_primitives::{
keccak256,
revm::compat::{into_reth_acc, into_revm_acc},
Account, Address, Receipt, Receipts, StorageEntry, B256, U256,
keccak256, Account, Address, Receipt, Receipts, StorageEntry, B256, U256,
};
use reth_trie::{test_utils::state_root, StateRoot};
use revm::{
Expand Down Expand Up @@ -149,9 +147,9 @@ mod tests {
.write_to_db(provider.tx_ref(), 1)
.expect("Could not write reverts to DB");

let reth_account_a = into_reth_acc(account_a);
let reth_account_b = into_reth_acc(account_b);
let reth_account_b_changed = into_reth_acc(account_b_changed.clone());
let reth_account_a = account_a.into();
let reth_account_b = account_b.into();
let reth_account_b_changed = account_b_changed.clone().into();

// Check plain state
assert_eq!(
Expand Down Expand Up @@ -926,7 +924,7 @@ mod tests {
// destroy account 1
let address1 = Address::with_last_byte(1);
let account1_old = prestate.remove(&address1).unwrap();
state.insert_account(address1, into_revm_acc(account1_old.0));
state.insert_account(address1, account1_old.0.into());
state.commit(HashMap::from([(
address1,
RevmAccount {
Expand All @@ -946,7 +944,7 @@ mod tests {
let account2_slot2_old_value = *account2.1.get(&slot2_key).unwrap();
state.insert_account_with_storage(
address2,
into_revm_acc(account2.0),
account2.0.into(),
HashMap::from([(slot2, account2_slot2_old_value)]),
);

Expand All @@ -956,7 +954,7 @@ mod tests {
address2,
RevmAccount {
status: AccountStatus::Touched,
info: into_revm_acc(account2.0),
info: account2.0.into(),
storage: HashMap::from_iter([(
slot2,
EvmStorageSlot::new_changed(account2_slot2_old_value, account2_slot2_new_value),
Expand All @@ -969,14 +967,14 @@ mod tests {
// change balance of account 3
let address3 = Address::with_last_byte(3);
let account3 = prestate.get_mut(&address3).unwrap();
state.insert_account(address3, into_revm_acc(account3.0));
state.insert_account(address3, account3.0.into());

account3.0.balance = U256::from(24);
state.commit(HashMap::from([(
address3,
RevmAccount {
status: AccountStatus::Touched,
info: into_revm_acc(account3.0),
info: account3.0.into(),
storage: HashMap::default(),
},
)]));
Expand All @@ -986,14 +984,14 @@ mod tests {
// change nonce of account 4
let address4 = Address::with_last_byte(4);
let account4 = prestate.get_mut(&address4).unwrap();
state.insert_account(address4, into_revm_acc(account4.0));
state.insert_account(address4, account4.0.into());

account4.0.nonce = 128;
state.commit(HashMap::from([(
address4,
RevmAccount {
status: AccountStatus::Touched,
info: into_revm_acc(account4.0),
info: account4.0.into(),
storage: HashMap::default(),
},
)]));
Expand All @@ -1008,7 +1006,7 @@ mod tests {
address1,
RevmAccount {
status: AccountStatus::Touched | AccountStatus::Created,
info: into_revm_acc(account1_new),
info: account1_new.into(),
storage: HashMap::default(),
},
)]));
Expand All @@ -1024,7 +1022,7 @@ mod tests {
address1,
RevmAccount {
status: AccountStatus::Touched | AccountStatus::Created,
info: into_revm_acc(account1_new),
info: account1_new.into(),
storage: HashMap::from_iter([(
slot20,
EvmStorageSlot::new_changed(U256::ZERO, account1_slot20_value),
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/provider/src/bundle_state/state_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use reth_db_api::{
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
transaction::{DbTx, DbTxMut},
};
use reth_primitives::{revm::compat::into_reth_acc, Bytecode, StorageEntry, U256};
use reth_primitives::{Bytecode, StorageEntry, U256};
use reth_storage_errors::db::DatabaseError;
use revm::db::states::{PlainStorageChangeset, StateChangeset};

Expand Down Expand Up @@ -34,7 +34,7 @@ impl StateChanges {
for (address, account) in self.0.accounts {
if let Some(account) = account {
tracing::trace!(target: "provider::bundle_state", ?address, "Updating plain state account");
accounts_cursor.upsert(address, into_reth_acc(account))?;
accounts_cursor.upsert(address, account.into())?;
} else if accounts_cursor.seek_exact(address)?.is_some() {
tracing::trace!(target: "provider::bundle_state", ?address, "Deleting plain state account");
accounts_cursor.delete_current()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/provider/src/bundle_state/state_reverts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reth_db_api::{
models::{AccountBeforeTx, BlockNumberAddress},
transaction::{DbTx, DbTxMut},
};
use reth_primitives::{revm::compat::into_reth_acc, BlockNumber, StorageEntry, B256, U256};
use reth_primitives::{BlockNumber, StorageEntry, B256, U256};
use reth_storage_errors::db::DatabaseError;
use revm::db::states::{PlainStateReverts, PlainStorageRevert, RevertToSlot};
use std::iter::Peekable;
Expand Down Expand Up @@ -82,7 +82,7 @@ impl StateReverts {
for (address, info) in account_block_reverts {
account_changeset_cursor.append_dup(
block_number,
AccountBeforeTx { address, info: info.map(into_reth_acc) },
AccountBeforeTx { address, info: info.map(Into::into) },
)?;
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/storage/provider/src/test_utils/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use alloy_rlp::Decodable;
use reth_db::tables;
use reth_db_api::{database::Database, models::StoredBlockBodyIndices};
use reth_primitives::{
alloy_primitives, b256, hex_literal::hex, revm::compat::into_reth_acc, Address, BlockNumber,
Bytes, Header, Receipt, Requests, SealedBlock, SealedBlockWithSenders, TxType, Withdrawal,
Withdrawals, B256, U256,
alloy_primitives, b256, hex_literal::hex, Account, Address, BlockNumber, Bytes, Header,
Receipt, Requests, SealedBlock, SealedBlockWithSenders, TxType, Withdrawal, Withdrawals, B256,
U256,
};
use reth_trie::root::{state_root_unhashed, storage_root_unhashed};
use revm::{
Expand Down Expand Up @@ -119,7 +119,7 @@ fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 {
(
address,
(
into_reth_acc(info.clone()),
Into::<Account>::into(info.clone()),
storage_root_unhashed(
account
.storage
Expand Down
4 changes: 2 additions & 2 deletions crates/trie/trie/benches/hash_post_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(missing_docs, unreachable_pub)]
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner};
use reth_primitives::{keccak256, revm::compat::into_reth_acc, Address, B256, U256};
use reth_primitives::{keccak256, Address, B256, U256};
use reth_trie::{HashedPostState, HashedStorage};
use revm::db::{states::BundleBuilder, BundleAccount};
use std::collections::HashMap;
Expand Down Expand Up @@ -30,7 +30,7 @@ fn from_bundle_state_seq(state: &HashMap<Address, BundleAccount>) -> HashedPostS

for (address, account) in state {
let hashed_address = keccak256(address);
this.accounts.insert(hashed_address, account.info.clone().map(into_reth_acc));
this.accounts.insert(hashed_address, account.info.clone().map(Into::into));

let hashed_storage = HashedStorage::from_iter(
account.status.was_destroyed(),
Expand Down
6 changes: 2 additions & 4 deletions crates/trie/trie/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use reth_db_api::{
transaction::DbTx,
};
use reth_execution_errors::StateRootError;
use reth_primitives::{
keccak256, revm::compat::into_reth_acc, Account, Address, BlockNumber, B256, U256,
};
use reth_primitives::{keccak256, Account, Address, BlockNumber, B256, U256};
use revm::db::BundleAccount;
use std::{
collections::{hash_map, HashMap, HashSet},
Expand All @@ -41,7 +39,7 @@ impl HashedPostState {
.into_par_iter()
.map(|(address, account)| {
let hashed_address = keccak256(address);
let hashed_account = account.info.clone().map(into_reth_acc);
let hashed_account = account.info.clone().map(Into::into);
let hashed_storage = HashedStorage::from_iter(
account.status.was_destroyed(),
account.storage.iter().map(|(key, value)| {
Expand Down
Loading