1

I understand that off-chain workers are spawned during block import, quote:

Offchain workers are spawned during each block import. However, they aren't executed during initial blockchain synchronization.

I was wondering if there is any way to configure OCWs to be spawned either:

  • in specific intervals, e.g. every 10 blocks, or
  • on demand (e.g. during block import on a specific height)

?

1 Answer 1

1

You can access the block number inside the offchain worker so you can also encapsulate the whole logic inside the if clause.

Example:

fn offchain_worker() {
    let current_block_num = <frame_system::Pallet<T>>::block_number();
    
    if current_block_number % 10 == 0 {
        logic_to_run_every_10_block();
    } else if currenct_block_number == x {
        logic_to_run_on_block_x();
    }

}

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.