perf: avoid cloning bytecode when converting revm's &AccountInfo to reth's Account (#13126)

This commit is contained in:
Hai | RISE
2024-12-04 20:13:35 +07:00
committed by GitHub
parent 8d1a332119
commit 53243a29f3
7 changed files with 18 additions and 9 deletions

View File

@ -147,7 +147,7 @@ impl<T> ExecutionOutcome<T> {
/// 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::into)) self.bundle.account(address).map(|a| a.info.as_ref().map(Into::into))
} }
/// Get storage if value is known. /// Get storage if value is known.

View File

@ -178,11 +178,20 @@ impl From<&GenesisAccount> for Account {
impl From<AccountInfo> for Account { impl From<AccountInfo> for Account {
fn from(revm_acc: AccountInfo) -> Self { fn from(revm_acc: AccountInfo) -> Self {
let code_hash = revm_acc.code_hash;
Self { Self {
balance: revm_acc.balance, balance: revm_acc.balance,
nonce: revm_acc.nonce, nonce: revm_acc.nonce,
bytecode_hash: (code_hash != KECCAK_EMPTY).then_some(code_hash), bytecode_hash: (!revm_acc.is_empty_code_hash()).then_some(revm_acc.code_hash),
}
}
}
impl From<&AccountInfo> for Account {
fn from(revm_acc: &AccountInfo) -> Self {
Self {
balance: revm_acc.balance,
nonce: revm_acc.nonce,
bytecode_hash: (!revm_acc.is_empty_code_hash()).then_some(revm_acc.code_hash),
} }
} }
} }

View File

@ -45,7 +45,7 @@ impl ExecutionWitnessRecord {
let hashed_address = keccak256(address); let hashed_address = keccak256(address);
self.hashed_state self.hashed_state
.accounts .accounts
.insert(hashed_address, account.account.as_ref().map(|a| a.info.clone().into())); .insert(hashed_address, account.account.as_ref().map(|a| (&a.info).into()));
let storage = self let storage = self
.hashed_state .hashed_state

View File

@ -171,7 +171,7 @@ fn bundle_state_root(execution_outcome: &ExecutionOutcome) -> B256 {
( (
address, address,
( (
Into::<Account>::into(info.clone()), Into::<Account>::into(info),
storage_root_unhashed( storage_root_unhashed(
account account
.storage .storage

View File

@ -357,7 +357,7 @@ mod tests {
let reth_account_a = account_a.into(); let reth_account_a = account_a.into();
let reth_account_b = account_b.into(); let reth_account_b = account_b.into();
let reth_account_b_changed = account_b_changed.clone().into(); let reth_account_b_changed = (&account_b_changed).into();
// Check plain state // Check plain state
assert_eq!( assert_eq!(

View File

@ -29,7 +29,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::into)); this.accounts.insert(hashed_address, account.info.as_ref().map(Into::into));
let hashed_storage = HashedStorage::from_iter( let hashed_storage = HashedStorage::from_iter(
account.status.was_destroyed(), account.status.was_destroyed(),

View File

@ -34,7 +34,7 @@ impl HashedPostState {
.into_par_iter() .into_par_iter()
.map(|(address, account)| { .map(|(address, account)| {
let hashed_address = KH::hash_key(address); let hashed_address = KH::hash_key(address);
let hashed_account = account.info.clone().map(Into::into); let hashed_account = account.info.as_ref().map(Into::into);
let hashed_storage = HashedStorage::from_plain_storage( let hashed_storage = HashedStorage::from_plain_storage(
account.status, account.status,
account.storage.iter().map(|(slot, value)| (slot, &value.present_value)), account.storage.iter().map(|(slot, value)| (slot, &value.present_value)),
@ -61,7 +61,7 @@ impl HashedPostState {
.into_par_iter() .into_par_iter()
.map(|(address, account)| { .map(|(address, account)| {
let hashed_address = KH::hash_key(address); let hashed_address = KH::hash_key(address);
let hashed_account = account.account.as_ref().map(|a| a.info.clone().into()); let hashed_account = account.account.as_ref().map(|a| (&a.info).into());
let hashed_storage = HashedStorage::from_plain_storage( let hashed_storage = HashedStorage::from_plain_storage(
account.status, account.status,
account.account.as_ref().map(|a| a.storage.iter()).into_iter().flatten(), account.account.as_ref().map(|a| a.storage.iter()).into_iter().flatten(),