Skip to content

Commit

Permalink
fix limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadkaouk committed Nov 15, 2023
1 parent 76921f1 commit d8e89ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions frame/evm/precompile/clear-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,26 @@ where
return Err(revert(format!("NotSuicided: {}", address.0)));
}

let mut iter = pallet_evm::AccountStorages::<Runtime>::drain_prefix(&address.0);
let mut iter = pallet_evm::AccountStorages::<Runtime>::iter_key_prefix(address.0);
loop {
handle.record_db_read::<Runtime>(116)?;
// Record the gas cost of deleting the storage item
handle.record_cost(RuntimeHelper::<Runtime>::db_write_gas_cost())?;

if iter.next().is_none() {
// Delete the storage item
if let Some(key) = iter.next() {
pallet_evm::AccountStorages::<Runtime>::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::<Runtime>(116)?;
if iter.next().is_none() {
handle.refund_external_cost(None, Some(116));
Self::clear_suicided_contract(address);
}
return Ok(());
}
}
Expand Down
4 changes: 2 additions & 2 deletions frame/evm/precompile/clear-storage/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand All @@ -368,7 +368,7 @@ fn test_clear_suicided_entry_limit() {

assert_eq!(
pallet_evm::AccountStorages::<Runtime>::iter_prefix(contract_address2).count(),
2
3
);

assert_eq!(
Expand Down

0 comments on commit d8e89ee

Please sign in to comment.