virto-network / open-runtime-module-library

Substrate Open Runtime Module Library
Apache License 2.0
0 stars 1 forks source link

Automatically cancel RefundRequested transactions #12

Closed stanly-johnson closed 2 years ago

stanly-johnson commented 2 years ago

ideally the refund is executed automatically... There are several ways to do this but perhaps it will be a good time for off-chain workers to shine? since we might be iterating and filtering the potentially big list of payments I think it's something we can delegate to a worker, we might also want to keep track separately of payments in the RefundRequested state for simpler processing

Originally posted by @olanod in https://github.com/virto-network/virto-node/pull/186#pullrequestreview-874577086

olanod commented 2 years ago

Another approach that is simpler than off-chain workers and elegant enough is to do like the scheduler pallet that has an Agenda which is a storage item that indexes the tasks(e.g. Task::Refund(from, to)) by block number so the on_initialize hook can check for each block if there's anything to be done. Can also be used for virto-network/open-runtime-module-library#8

stanly-johnson commented 2 years ago

How about on_idle hook? The caveat is that we can't guarantee it would execute at block X, it would execute at any non-full block after block X. wdyt?

olanod commented 2 years ago

on_idle sounds reasonable, maybe not for the recurrent payment indexed by block number but here could work, we keep a "queue" of pending refunds and try to refund as many as possible with the remaining weight of the idle block