Open davecreaser opened 1 day ago
Just writing out my thoughts on this issue:
There is no "Motion is ready to be finalized" event emitted by the contracts which is what makes this difficult.
A motion becomes finalizable when either:
A motion fails to get enough stakes and the Staking Phase Duration passes (Failed)
A fully staked motion is unopposed and the Staking Phase Duration passes (Passed)
A fully opposed motion motion is unsupported and the Staking Phase Duration passes (Failed)
A motion goes to a vote, the Voting Phase Duration passes without any members voting (Failed)
A motion goes to a vote, members vote, but not all members reveal their votes within the Reveal Phase Duration and the motion outcome is revealed as the reveal phase ends (Passed / Failed)
A motion goes to a vote, all voters reveal their votes within the Reveal Phase Duration and the motion outcome is revealed when the last vote is revealed (Passed / Failed)
The last situation is the only one that is tied to a user action, for that one we could add a check on the block-ingestor motion vote revealed handler, if this is the last vote to be revealed, send the finalizable notification.
All the others rely on a timer elapsing. The phase durations are determined by the extension settings, presumably we are tracking the timestamps for each stage starting somewhere as we are showing the timers in motion UI, activity feed, etc. We could possibly try to line up the timestamps and the durations and assume if it has passed then the motion is finalizable.
We can also fetch the motion state from the VotingReputationClient compare it against the state we have stored in the database. The contracts have a Finalizable
state, so presumably the VotingReputationClient would return that state once all the timers have elapsed.
One possible solution would be to run a CRON lambda each hour( / each day?), fetch all the motions in the staking / voting / reveal state from the database, then fetch the state for each of these motions from the VotingReputationClient for each colony to check which have changed to the Finalizable
state and generate notifications from there. (Are there any issues with generating notifications from a lambda?) Would need some logic in the lambda to determine if the motion had passed or failed.
Obviously triggering it via a CRON job would mean that the notification wouldn't get sent as soon as the motion is finalizable, if we ran it once an hour then it could be up to an hour delayed, but I think this is an okay trade off. If a motion had been finalized before the CRON job runs, then it wouldn't get picked up as we would only query motions in the staking / voting / reveal state from the database, so no risk of finalizable notifications being sent for motions which have already been finalized.
I think that the CRON approach is pretty much the only way of doing this.
The only other option I can think of is to run a lambda every time a user is logged in (similar to how we fetch the latest reputation amounts when a colony is loaded). And fetch the staking / voting / reveal state motions for each colony that the user is in, then as you suggest load the state from the VotingReputationClient to figure out if it's finalizable or not. What we may need to do then though is either update the state in the database to 'Finalizable' so that notifications aren't triggered multiple times for each motion, or perhaps add a flag to each motion to keep track of whether or not a finalizable notification has been fired.
Either way this isn't gonna be super pretty 🥴
I don't think either solution is good here, although the cron job might be more "agreeable", however it's still too "heavy"
Problem with the CRON job is that people will have different reveal times, even going down to the minute, meaning notifications will always be late.
The other option, is going to basically kill loading of the app, so it's not in any way viable.
I think we might need to escalate this and either find a different solution, or just remove this notification
Specification
Story
Example: As a user using motions within a colony, I want to see a notification when a motion in the colony is ready to be finalized, so that I am kept informed
Description
Finalizable
notification for reputation motions.Implementation
This issue is complete when...