From 8718c00f019d22922527b9139dd46e745db4622b Mon Sep 17 00:00:00 2001 From: Wodann Date: Fri, 17 Feb 2023 17:42:28 -0700 Subject: [PATCH] fix(rethnet): remove second LayeredDatabase::remove_account function --- crates/rethnet_evm/src/state/layered_db.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/crates/rethnet_evm/src/state/layered_db.rs b/crates/rethnet_evm/src/state/layered_db.rs index bc71f4ad62..b7e3fe8640 100644 --- a/crates/rethnet_evm/src/state/layered_db.rs +++ b/crates/rethnet_evm/src/state/layered_db.rs @@ -215,12 +215,14 @@ impl LayeredState { } /// Removes the [`AccountInfo`] corresponding to the specified address. - pub fn remove_account(&mut self, address: &Address) { + fn remove_account(&mut self, address: &Address) -> Option { let account_info = self .iter() - .find_map(|layer| layer.account_infos.get(address)); + .find_map(|layer| layer.account_infos.get(address)) + .cloned() + .flatten(); - if let Some(Some(account_info)) = account_info { + if let Some(account_info) = &account_info { debug_assert!(account_info.code.is_none()); let code_hash = account_info.code_hash; @@ -239,6 +241,8 @@ impl LayeredState { // Write None to signal that the account's storage was deleted self.last_layer_mut().storage.insert(*address, None); } + + account_info } } @@ -399,17 +403,7 @@ impl StateDebug for LayeredState { } fn remove_account(&mut self, address: Address) -> Result, Self::Error> { - // Set None to indicate the account was deleted - if let Some(account_info) = self.last_layer_mut().account_infos.get_mut(&address) { - let old_account_info = account_info.clone(); - - *account_info = None; - - Ok(old_account_info) - } else { - self.last_layer_mut().account_infos.insert(address, None); - Ok(None) - } + Ok(self.remove_account(&address)) } fn remove_snapshot(&mut self, state_root: &B256) -> bool {