substrate icon indicating copy to clipboard operation
substrate copied to clipboard

[pallet_assets] How to destroy an asset with potentially `u32::MAX` accounts?

Open Chralt98 opened this issue 3 years ago • 8 comments

Hey valuable Substrate maintainers,

I found out, that the witness limits the number of deletions here, but when there are too many accounts for one asset, then a sufficiently high number for the accounts in the witness param would lead to a weight which exceeds the maximum block limit. What could be done, if there are u32::MAX accounts with non-zero balances? Then, we couldn't destroy the asset right? Or is the consumed weight with u32::MAX below the maximum block limit? I don't think so.

What can I do to destroy a portion of all accounts? For example one could call an extrinsic multiple times with a small witness to destroy all u32::MAX accounts.

u32::MAX should only be an example to get a better understanding of this problem

Chralt98 avatar Sep 15 '22 10:09 Chralt98

cc @jsidorenko

kianenigma avatar Sep 15 '22 11:09 kianenigma

cc @tonyalaribe

jsidorenko avatar Sep 16 '22 07:09 jsidorenko

What if we change the assets deletion process a bit:

  1. we mark an asset as soft-deleted and thus prevent any transfers
  2. we create a method to wipe user balances for such a token by passing either the addresses or the number of accounts to wipe. This would allow calling the same method multiple times
  3. and finally, completely delete the token

jsidorenko avatar Sep 16 '22 10:09 jsidorenko

  1. we mark an asset as soft-deleted and thus prevent any transfers

freeze_asset could be enough for that.

ggwpez avatar Sep 16 '22 11:09 ggwpez

It's a bit of an edge case, but freeze_asset should really be used in advance of deleting an asset anyway in order to provide the correct witness data. Otherwise, a simple transfer getting between your transaction construction and inclusion will invalidate the destroy call.

joepetrowski avatar Sep 16 '22 11:09 joepetrowski

So an alternate solution would be to destroy the maximum number of accounts, and then emit a PartiallyDestroyed event to encourage reexecuting the action to complete destroying the asset. Like the refund and dissolve pattern in crowdloans

[Joe edit: changed master to commit to save in the future]

tonyalaribe avatar Sep 16 '22 11:09 tonyalaribe

yeah, that could work as well

jsidorenko avatar Sep 16 '22 12:09 jsidorenko

I'll create a PR for this.

tonyalaribe avatar Sep 16 '22 16:09 tonyalaribe