5

Is it possible to schedule a call using timestamp from timestamp pallet instead of blocknumber?

The docs of scheduler pallet states the following:

"This Pallet exposes capabilities for scheduling dispatches to occur at a specified block number or at a specified period."

And timestamp pallet states:

"NOTE: The Timestamp pallet is the recommended way to query the on-chain time instead of using an approach based on block numbers. The block number based time measurement can cause issues because of cumulative calculation errors and hence should be avoided."

So, it sounds like there should be compatible, but scheduler struct has the following form with only blocknumber as type of time:

pub enum Call<T: Config> { schedule { when: T::BlockNumber, maybe_periodic: Option<Period<T::BlockNumber>>, priority: Priority, call: Box<::RuntimeCall>, },

1 Answer 1

3

The scheduler pallet only knows block numbers. It is not at all aware of the concept of "Time". So it is not possible to simply switch it over to timestamps. The block-number is basically the "Time" of the blockchain. I think this is reasonable limitation for current blockchains.

It may be a less precise approach when seen from the off-chain world, but when seen on-chain, this is the most precise approach. So far it has still provided reasonable precision even from the off-chain view, since its mostly used for non time-critical governance tasks.

This is used in most pallets that need to set deadlines or measure progress since a past point. The advantage of the block-number is that it increases each block by exactly one. This gives nice guarantees and simplifies the code a lot, as compared to when chrono libraries would have to be used to calculate time differences (Not to mention all the special cases about leap seconds/years and other oddities).

I guess it would still be possible to change the scheduler to poll the timestamp once before dispatching a task, just to ensure that it wont fire too early - but i dont think its worth the hazzle. For best precision i would rather use an OCW that submits the extrinsic at an exact time. But not even that would give any real guarantees.

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.