mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: remove revm/compat from reth-primitives (#8960)
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
logs_bloom,
|
logs_bloom, Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests,
|
||||||
revm::compat::{into_reth_acc, into_revm_acc},
|
StorageEntry, B256, U256,
|
||||||
Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests, StorageEntry,
|
|
||||||
B256, U256,
|
|
||||||
};
|
};
|
||||||
use reth_trie::HashedPostState;
|
use reth_trie::HashedPostState;
|
||||||
use revm::{
|
use revm::{
|
||||||
@ -81,8 +79,8 @@ impl ExecutionOutcome {
|
|||||||
state_init.into_iter().map(|(address, (original, present, storage))| {
|
state_init.into_iter().map(|(address, (original, present, storage))| {
|
||||||
(
|
(
|
||||||
address,
|
address,
|
||||||
original.map(into_revm_acc),
|
original.map(Into::into),
|
||||||
present.map(into_revm_acc),
|
present.map(Into::into),
|
||||||
storage.into_iter().map(|(k, s)| (k.into(), s)).collect(),
|
storage.into_iter().map(|(k, s)| (k.into(), s)).collect(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@ -91,7 +89,7 @@ impl ExecutionOutcome {
|
|||||||
reverts.into_iter().map(|(address, (original, storage))| {
|
reverts.into_iter().map(|(address, (original, storage))| {
|
||||||
(
|
(
|
||||||
address,
|
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)),
|
storage.into_iter().map(|entry| (entry.key.into(), entry.value)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -129,7 +127,7 @@ impl ExecutionOutcome {
|
|||||||
|
|
||||||
/// Get account if account is known.
|
/// Get account if account is known.
|
||||||
pub fn account(&self, address: &Address) -> Option<Option<Account>> {
|
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.
|
/// Get storage if value is known.
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use byteorder::{BigEndian, ReadBytesExt};
|
|||||||
use bytes::Buf;
|
use bytes::Buf;
|
||||||
use derive_more::Deref;
|
use derive_more::Deref;
|
||||||
use reth_codecs::{main_codec, Compact};
|
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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// An Ethereum account.
|
/// An Ethereum account.
|
||||||
@ -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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
use crate::{revm_primitives::AccountInfo, Account, KECCAK_EMPTY};
|
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
|
||||||
use alloc::vec::Vec;
|
|
||||||
|
|
||||||
/// Converts a Revm [`AccountInfo`] into a Reth [`Account`].
|
|
||||||
///
|
|
||||||
/// Sets `bytecode_hash` to `None` if `code_hash` is [`KECCAK_EMPTY`].
|
|
||||||
pub fn into_reth_acc(revm_acc: AccountInfo) -> Account {
|
|
||||||
let code_hash = revm_acc.code_hash;
|
|
||||||
Account {
|
|
||||||
balance: revm_acc.balance,
|
|
||||||
nonce: revm_acc.nonce,
|
|
||||||
bytecode_hash: (code_hash != KECCAK_EMPTY).then_some(code_hash),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts a Revm [`AccountInfo`] into a Reth [`Account`].
|
|
||||||
///
|
|
||||||
/// Sets `code_hash` to [`KECCAK_EMPTY`] if `bytecode_hash` is `None`.
|
|
||||||
pub fn into_revm_acc(reth_acc: Account) -> AccountInfo {
|
|
||||||
AccountInfo {
|
|
||||||
balance: reth_acc.balance,
|
|
||||||
nonce: reth_acc.nonce,
|
|
||||||
code_hash: reth_acc.bytecode_hash.unwrap_or(KECCAK_EMPTY),
|
|
||||||
code: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,14 +1,5 @@
|
|||||||
//! Helpers for working with revm.
|
//! 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
|
/// Reth block execution/validation configuration and constants
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
|
|||||||
@ -76,9 +76,7 @@ mod tests {
|
|||||||
models::{AccountBeforeTx, BlockNumberAddress},
|
models::{AccountBeforeTx, BlockNumberAddress},
|
||||||
};
|
};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
keccak256,
|
keccak256, Account, Address, Receipt, Receipts, StorageEntry, B256, U256,
|
||||||
revm::compat::{into_reth_acc, into_revm_acc},
|
|
||||||
Account, Address, Receipt, Receipts, StorageEntry, B256, U256,
|
|
||||||
};
|
};
|
||||||
use reth_trie::{test_utils::state_root, StateRoot};
|
use reth_trie::{test_utils::state_root, StateRoot};
|
||||||
use revm::{
|
use revm::{
|
||||||
@ -149,9 +147,9 @@ mod tests {
|
|||||||
.write_to_db(provider.tx_ref(), 1)
|
.write_to_db(provider.tx_ref(), 1)
|
||||||
.expect("Could not write reverts to DB");
|
.expect("Could not write reverts to DB");
|
||||||
|
|
||||||
let reth_account_a = into_reth_acc(account_a);
|
let reth_account_a = account_a.into();
|
||||||
let reth_account_b = into_reth_acc(account_b);
|
let reth_account_b = account_b.into();
|
||||||
let reth_account_b_changed = into_reth_acc(account_b_changed.clone());
|
let reth_account_b_changed = account_b_changed.clone().into();
|
||||||
|
|
||||||
// Check plain state
|
// Check plain state
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -926,7 +924,7 @@ mod tests {
|
|||||||
// destroy account 1
|
// destroy account 1
|
||||||
let address1 = Address::with_last_byte(1);
|
let address1 = Address::with_last_byte(1);
|
||||||
let account1_old = prestate.remove(&address1).unwrap();
|
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([(
|
state.commit(HashMap::from([(
|
||||||
address1,
|
address1,
|
||||||
RevmAccount {
|
RevmAccount {
|
||||||
@ -946,7 +944,7 @@ mod tests {
|
|||||||
let account2_slot2_old_value = *account2.1.get(&slot2_key).unwrap();
|
let account2_slot2_old_value = *account2.1.get(&slot2_key).unwrap();
|
||||||
state.insert_account_with_storage(
|
state.insert_account_with_storage(
|
||||||
address2,
|
address2,
|
||||||
into_revm_acc(account2.0),
|
account2.0.into(),
|
||||||
HashMap::from([(slot2, account2_slot2_old_value)]),
|
HashMap::from([(slot2, account2_slot2_old_value)]),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -956,7 +954,7 @@ mod tests {
|
|||||||
address2,
|
address2,
|
||||||
RevmAccount {
|
RevmAccount {
|
||||||
status: AccountStatus::Touched,
|
status: AccountStatus::Touched,
|
||||||
info: into_revm_acc(account2.0),
|
info: account2.0.into(),
|
||||||
storage: HashMap::from_iter([(
|
storage: HashMap::from_iter([(
|
||||||
slot2,
|
slot2,
|
||||||
EvmStorageSlot::new_changed(account2_slot2_old_value, account2_slot2_new_value),
|
EvmStorageSlot::new_changed(account2_slot2_old_value, account2_slot2_new_value),
|
||||||
@ -969,14 +967,14 @@ mod tests {
|
|||||||
// change balance of account 3
|
// change balance of account 3
|
||||||
let address3 = Address::with_last_byte(3);
|
let address3 = Address::with_last_byte(3);
|
||||||
let account3 = prestate.get_mut(&address3).unwrap();
|
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);
|
account3.0.balance = U256::from(24);
|
||||||
state.commit(HashMap::from([(
|
state.commit(HashMap::from([(
|
||||||
address3,
|
address3,
|
||||||
RevmAccount {
|
RevmAccount {
|
||||||
status: AccountStatus::Touched,
|
status: AccountStatus::Touched,
|
||||||
info: into_revm_acc(account3.0),
|
info: account3.0.into(),
|
||||||
storage: HashMap::default(),
|
storage: HashMap::default(),
|
||||||
},
|
},
|
||||||
)]));
|
)]));
|
||||||
@ -986,14 +984,14 @@ mod tests {
|
|||||||
// change nonce of account 4
|
// change nonce of account 4
|
||||||
let address4 = Address::with_last_byte(4);
|
let address4 = Address::with_last_byte(4);
|
||||||
let account4 = prestate.get_mut(&address4).unwrap();
|
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;
|
account4.0.nonce = 128;
|
||||||
state.commit(HashMap::from([(
|
state.commit(HashMap::from([(
|
||||||
address4,
|
address4,
|
||||||
RevmAccount {
|
RevmAccount {
|
||||||
status: AccountStatus::Touched,
|
status: AccountStatus::Touched,
|
||||||
info: into_revm_acc(account4.0),
|
info: account4.0.into(),
|
||||||
storage: HashMap::default(),
|
storage: HashMap::default(),
|
||||||
},
|
},
|
||||||
)]));
|
)]));
|
||||||
@ -1008,7 +1006,7 @@ mod tests {
|
|||||||
address1,
|
address1,
|
||||||
RevmAccount {
|
RevmAccount {
|
||||||
status: AccountStatus::Touched | AccountStatus::Created,
|
status: AccountStatus::Touched | AccountStatus::Created,
|
||||||
info: into_revm_acc(account1_new),
|
info: account1_new.into(),
|
||||||
storage: HashMap::default(),
|
storage: HashMap::default(),
|
||||||
},
|
},
|
||||||
)]));
|
)]));
|
||||||
@ -1024,7 +1022,7 @@ mod tests {
|
|||||||
address1,
|
address1,
|
||||||
RevmAccount {
|
RevmAccount {
|
||||||
status: AccountStatus::Touched | AccountStatus::Created,
|
status: AccountStatus::Touched | AccountStatus::Created,
|
||||||
info: into_revm_acc(account1_new),
|
info: account1_new.into(),
|
||||||
storage: HashMap::from_iter([(
|
storage: HashMap::from_iter([(
|
||||||
slot20,
|
slot20,
|
||||||
EvmStorageSlot::new_changed(U256::ZERO, account1_slot20_value),
|
EvmStorageSlot::new_changed(U256::ZERO, account1_slot20_value),
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use reth_db_api::{
|
|||||||
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
|
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
|
||||||
transaction::{DbTx, DbTxMut},
|
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 reth_storage_errors::db::DatabaseError;
|
||||||
use revm::db::states::{PlainStorageChangeset, StateChangeset};
|
use revm::db::states::{PlainStorageChangeset, StateChangeset};
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ impl StateChanges {
|
|||||||
for (address, account) in self.0.accounts {
|
for (address, account) in self.0.accounts {
|
||||||
if let Some(account) = account {
|
if let Some(account) = account {
|
||||||
tracing::trace!(target: "provider::bundle_state", ?address, "Updating plain state 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() {
|
} else if accounts_cursor.seek_exact(address)?.is_some() {
|
||||||
tracing::trace!(target: "provider::bundle_state", ?address, "Deleting plain state account");
|
tracing::trace!(target: "provider::bundle_state", ?address, "Deleting plain state account");
|
||||||
accounts_cursor.delete_current()?;
|
accounts_cursor.delete_current()?;
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use reth_db_api::{
|
|||||||
models::{AccountBeforeTx, BlockNumberAddress},
|
models::{AccountBeforeTx, BlockNumberAddress},
|
||||||
transaction::{DbTx, DbTxMut},
|
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 reth_storage_errors::db::DatabaseError;
|
||||||
use revm::db::states::{PlainStateReverts, PlainStorageRevert, RevertToSlot};
|
use revm::db::states::{PlainStateReverts, PlainStorageRevert, RevertToSlot};
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
@ -82,7 +82,7 @@ impl StateReverts {
|
|||||||
for (address, info) in account_block_reverts {
|
for (address, info) in account_block_reverts {
|
||||||
account_changeset_cursor.append_dup(
|
account_changeset_cursor.append_dup(
|
||||||
block_number,
|
block_number,
|
||||||
AccountBeforeTx { address, info: info.map(into_reth_acc) },
|
AccountBeforeTx { address, info: info.map(Into::into) },
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,9 @@ use alloy_rlp::Decodable;
|
|||||||
use reth_db::tables;
|
use reth_db::tables;
|
||||||
use reth_db_api::{database::Database, models::StoredBlockBodyIndices};
|
use reth_db_api::{database::Database, models::StoredBlockBodyIndices};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
alloy_primitives, b256, hex_literal::hex, revm::compat::into_reth_acc, Address, BlockNumber,
|
alloy_primitives, b256, hex_literal::hex, Account, Address, BlockNumber, Bytes, Header,
|
||||||
Bytes, Header, Receipt, Requests, SealedBlock, SealedBlockWithSenders, TxType, Withdrawal,
|
Receipt, Requests, SealedBlock, SealedBlockWithSenders, TxType, Withdrawal, Withdrawals, B256,
|
||||||
Withdrawals, B256, U256,
|
U256,
|
||||||
};
|
};
|
||||||
use reth_trie::root::{state_root_unhashed, storage_root_unhashed};
|
use reth_trie::root::{state_root_unhashed, storage_root_unhashed};
|
||||||
use revm::{
|
use revm::{
|
||||||
@ -119,7 +119,7 @@ fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 {
|
|||||||
(
|
(
|
||||||
address,
|
address,
|
||||||
(
|
(
|
||||||
into_reth_acc(info.clone()),
|
Into::<Account>::into(info.clone()),
|
||||||
storage_root_unhashed(
|
storage_root_unhashed(
|
||||||
account
|
account
|
||||||
.storage
|
.storage
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![allow(missing_docs, unreachable_pub)]
|
#![allow(missing_docs, unreachable_pub)]
|
||||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||||
use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner};
|
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 reth_trie::{HashedPostState, HashedStorage};
|
||||||
use revm::db::{states::BundleBuilder, BundleAccount};
|
use revm::db::{states::BundleBuilder, BundleAccount};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -30,7 +30,7 @@ fn from_bundle_state_seq(state: &HashMap<Address, BundleAccount>) -> HashedPostS
|
|||||||
|
|
||||||
for (address, account) in state {
|
for (address, account) in state {
|
||||||
let hashed_address = keccak256(address);
|
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(
|
let hashed_storage = HashedStorage::from_iter(
|
||||||
account.status.was_destroyed(),
|
account.status.was_destroyed(),
|
||||||
|
|||||||
@ -12,9 +12,7 @@ use reth_db_api::{
|
|||||||
transaction::DbTx,
|
transaction::DbTx,
|
||||||
};
|
};
|
||||||
use reth_execution_errors::StateRootError;
|
use reth_execution_errors::StateRootError;
|
||||||
use reth_primitives::{
|
use reth_primitives::{keccak256, Account, Address, BlockNumber, B256, U256};
|
||||||
keccak256, revm::compat::into_reth_acc, Account, Address, BlockNumber, B256, U256,
|
|
||||||
};
|
|
||||||
use revm::db::BundleAccount;
|
use revm::db::BundleAccount;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{hash_map, HashMap, HashSet},
|
collections::{hash_map, HashMap, HashSet},
|
||||||
@ -41,7 +39,7 @@ impl HashedPostState {
|
|||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|(address, account)| {
|
.map(|(address, account)| {
|
||||||
let hashed_address = keccak256(address);
|
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(
|
let hashed_storage = HashedStorage::from_iter(
|
||||||
account.status.was_destroyed(),
|
account.status.was_destroyed(),
|
||||||
account.storage.iter().map(|(key, value)| {
|
account.storage.iter().map(|(key, value)| {
|
||||||
|
|||||||
Reference in New Issue
Block a user