substrate
substrate copied to clipboard
[pallet_assets] How to destroy an asset with potentially `u32::MAX` accounts?
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
cc @jsidorenko
cc @tonyalaribe
What if we change the assets deletion process a bit:
- we mark an asset as soft-deleted and thus prevent any transfers
- 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
- and finally, completely delete the token
- we mark an asset as soft-deleted and thus prevent any transfers
freeze_asset could be enough for that.
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.
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]
yeah, that could work as well
I'll create a PR for this.