1

Is it possible to split the execution of an extrinsic into several continuous blocks? Looking at this post, it is possible to create migrations, but I was wondering if the same can be applied to an extrinsic.

So for example, let's say I have the following enum (keep in mind this is a dummy example):

pub enum ItemType {
    A(u32),
    B(u32),
    C(u32),
}

Now, let's imagine that there's a list (with millions of entries) declared as:

#[pallet::storage]
#[pallet::getter(fn items)]
pub(super) type AllItems<T: Config> = StorageValue<_, Vec<ItemType>, ValueQuery>;

I want to create an extrinsic that changes all the elements stored within the AllItems structure from ItemType::A to ItemType::B, but a single run will certainly require a lot of time to modify the whole vector, so I want to split the execution into multiple blocks, so the execution does not exceed the maximum block weight and also allow the chain to process other transactions and not only this.

This is just a simple example to get the idea, but imagine that is not a simple modification and it has to perform updates on different structures at the same time.

1 Answer 1

2

An example of splitting large transactions between several blocks can be found in crowdloan.refund. The basic idea is that you define a limit L of items that can be processed at once based on the weights of a single operation. Then you only allow to process up to L items in a single transaction. Above mentioned pallet also emits events for partial/full refunds to allow clients to see whether the process is finished completely or not

2
  • Interesting, but it seems like the extrinsic needs to be called manually until there's no more people to refund right? Although I would like to execute the migration automatically, this is useful to model a first approach, thx!
    – andresvsm
    Commented Nov 3, 2022 at 9:50
  • 1
    Yes, you are right, this approach will require manual execution until whole storage will be updated
    – Valentun
    Commented Nov 3, 2022 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.