1

Would it be possible to clear a pallet storage with a call on a live chain ?

Precisely I would like to remove all contracts and code hash existing on my chain (as sudo).

1 Answer 1

1

It may be challenging to achieve that with a call.

You will need to send numerous extrinsics to accomplish it.


I suggest performing a runtime upgrade.

Refer to this link for more information: https://paritytech.github.io/substrate/master/frame_support/storage/migration/fn.clear_storage_prefix.html

use frame_support::migration;

migration::clear_storage_prefix(b"module name", &[], &[], None, None);

If your pallet storage is extensive, it is advisable to review the documentation mentioned above and adjust the values of None according to your specific situation.

2
  • Okay thanks ! What about weights on that function ? I need to return the used weights when doing a runtime upgrade and clear_storage_prefix() doesn’t calculate any weights used so do I need to check how many iterations was done and calculate weights from it ?
    – SailorSnoW
    Commented Aug 20, 2023 at 13:53
  • You could count the delections and return the weight T::DbWeights::writes(x).
    – aurexav
    Commented Aug 20, 2023 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.