This document focuses on specifying a group expiration mechanism. The proposed functionality enables a group to expire after a particular condition is met. An expired group can not be chosen to perform new actions, but any ongoing group actions will continue until finished.
The goal is to provide a minimal set of functions necessary for implementing the group expiration mechanism into the Keep network. The group expires when group expiration timeout passes.
Group selection contract should include the following information:
-
active groups list (with group formation agreements),
-
active groups counter,
-
active groups threshold (which protects the network from expiring all groups),
-
expired groups list,
and (per group formation agreement):
-
group formation agreement identifier,
-
group members identifiers,
-
registration time when the group was created,
-
timeout, after which the group expires,
-
current state indicating if the group is active or expired.
The contract should also have the following discrete pieces of functionality: group registration, and group selection.
When a group is formed, the group formation agreement is added to the active groups list, the active groups counter is incremented, and the agreement is filled with:
-
unique group formation agreement identifier,
-
group members identifiers,
-
registration time set to current block time,
-
timeout evaluated as the time required to mark a group as expired, counted in blocks, (it might be explicit or implicit),
-
current agreement state set to active.
When a group selection is invoked, the work contract (the one that is starting the group selection) needs to call the group selection contract. When called, the group selection contract selects at random potential group from the active groups list and performs the group status verification. And then the group selection contract responds with group information.
The group selection contract presents the selected group to the work contract.
The work contract is obligated to forbid non-members from group work.
If the number of active groups is below the active groups threshold all remaining groups on the active groups list are treated as active.
Otherwise, the following is performed.
If the current block time is larger than the group registration time plus the timeout then set the group agreement status to expired. Move the expired group agreement from the active groups list to the expired groups list and decrease the active group counter by one. Then the next group is selected and its status is verified until an active group is found or the number of active groups falls below the active groups threshold.
Expired groups need not be tracked for an unlimited time. They might be removed when deemed unnecessary for current network operations.