Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

on_idle hook #4064

@xlc

Description

@xlc

Depends on the type of the chain, it usually have peak and off-peak hours. It will be good if there is a way to run some maintenance task on off-peak hours, for example, claim contract states, actively and progressively migrate storage format, doing expensive but not urgent calculation like calculate the winners of an election.

When block producer finished packing all the transactions and still have lots free remaining block weights (with #4058, it is possible to have a good estimation of the free amount before execute on_finalize hooks), it can call the on_idle(block_number: BlockNumber, free_weight: Weight) -> Weight to perform additional non-urgent work. This hook can return a number to indicate how much weight it used, and allow other modules to consume the unused part.

Chain operator can always dispatch an operational transaction to force perform the maintenance task if the the chain is too busy and never calls on_idle hook. Or on_initalize can do the maintenance task if it notices on_idle was never called in last N blocks.

Metadata

Metadata

Assignees

Labels

J0-enhancementAn additional feature request.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions