mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf: avoid cloning bytecode when converting revm's &AccountInfo to reth's Account (#13126)
This commit is contained in:
@ -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.
|
||||||
|
|||||||
@ -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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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!(
|
||||||
|
|||||||
@ -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(),
|
||||||
|
|||||||
@ -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(),
|
||||||
|
|||||||
Reference in New Issue
Block a user