Closed EGreg closed 4 months ago
This task is about delays, not about the order of executions with delays.
I suggest adding a new method, invoke, with a parameter uint64 delay (defaulting to 0).
function invoke(
address contractAddress,
string memory method,
string memory params,
uint64 delay
)
The behavior will remain the same. The invoked operation will execute after exceeding the necessary enforced operations. However, if delay != 0, the operation can execute only after the specified delay.
There are no schedules. We cannot wait for a previous operation that might get stuck.
[upd]
it would be method addMethod
, not invoke
seems workflow are:
addMethod
!AND after that we cannot change minimums/fraction and delay for this methods. So set should be immutable
BUT we can call addMethod
with the same params to add next pair or roles : invoke/endorseWould be great if invoke can be called with different /minimums/fraction/delay for the same contract/method/params
In
params
, adduint32 delay
which is the number of seconds to delay since executing "this line":https://github.com/Intercoin/ControlContract/blob/a800a4c8f56b321d5e90407a69035981de1b62d5/contracts/ControlContract.sol#L568Please emit
OperationScheduled
right beforeOperationExecuted
, ifdelay = 0
.Otherwise if
delay > 0
then push this operation to theoperations
array, and emitOperationScheduled
only.I didn't find anything in OpenZeppelin to have an array with "from" and "to" indexes. You can make a class
struct Array
struct ArrayWindowwhich can have uint32 startIndex, uint32 endIndex, and
window.push()and
window.unshift(). Arrays are really stored as mapping. The
window.push(value)will simply store
window[++endIndex] = valuewhile
unshift()will
delete window[startIndex++]` (notice that startIndex is incremented after being evaluated, for clarity you can break it out into two different statements). Anyway, so Operation Scheduled will push the operation.Meanwhile, anyone can call
executeNextOperation()
which willvar operationId = operations.unshift()
and then execute this operation, and emitOperationExecuted
. Thedelete
will even save some gas.So basically, refactor into
_executeOperation()
which may be called immediately ifdelay = 0
otherwise fromexecuteNextOperation()
.Since
delay
is the same for the whole contract, the operations would always be executed in order! But with a delay.