From d8e89ee6214ff0dba720df5e5064a8849d970fd9 Mon Sep 17 00:00:00 2001 From: Ahmad Kaouk Date: Wed, 15 Nov 2023 13:44:44 +0100 Subject: [PATCH] fix limit --- frame/evm/precompile/clear-storage/src/lib.rs | 13 ++++++++++--- frame/evm/precompile/clear-storage/src/tests.rs | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/frame/evm/precompile/clear-storage/src/lib.rs b/frame/evm/precompile/clear-storage/src/lib.rs index 371cf9f487..35e6267911 100644 --- a/frame/evm/precompile/clear-storage/src/lib.rs +++ b/frame/evm/precompile/clear-storage/src/lib.rs @@ -60,19 +60,26 @@ where return Err(revert(format!("NotSuicided: {}", address.0))); } - let mut iter = pallet_evm::AccountStorages::::drain_prefix(&address.0); + let mut iter = pallet_evm::AccountStorages::::iter_key_prefix(address.0); loop { handle.record_db_read::(116)?; // Record the gas cost of deleting the storage item handle.record_cost(RuntimeHelper::::db_write_gas_cost())?; - - if iter.next().is_none() { + // Delete the storage item + if let Some(key) = iter.next() { + pallet_evm::AccountStorages::::remove(address.0, &key); + } else { handle.refund_external_cost(None, Some(116)); Self::clear_suicided_contract(address); break; } deleted_entries += 1; if deleted_entries >= limit { + handle.record_db_read::(116)?; + if iter.next().is_none() { + handle.refund_external_cost(None, Some(116)); + Self::clear_suicided_contract(address); + } return Ok(()); } } diff --git a/frame/evm/precompile/clear-storage/src/tests.rs b/frame/evm/precompile/clear-storage/src/tests.rs index 9f23aab4cd..a3c8924237 100644 --- a/frame/evm/precompile/clear-storage/src/tests.rs +++ b/frame/evm/precompile/clear-storage/src/tests.rs @@ -352,7 +352,7 @@ fn test_clear_suicided_entry_limit() { Precompile1, PCall::clear_suicided_storage { addresses: vec![contract_address1.into(), contract_address2.into()].into(), - limit: 5, + limit: 4, }, ) .execute_returns(()); @@ -368,7 +368,7 @@ fn test_clear_suicided_entry_limit() { assert_eq!( pallet_evm::AccountStorages::::iter_prefix(contract_address2).count(), - 2 + 3 ); assert_eq!(