Skip to content

Commit 6c6fa4f

Browse files
wa0x6eChaituVR
andauthored
feat: add delay before finalizing proposal scores (#541)
* feat: add delay before finalising proposal scores * Revert "feat: add delay before finalising proposal scores" This reverts commit f174357. * fix: add delay up to 1min after proposal close * Update src/scores.ts Co-authored-by: Chaitanya <[email protected]> * Update src/scores.ts * Update src/scores.ts Co-authored-by: Chaitanya <[email protected]> --------- Co-authored-by: Chaitanya <[email protected]>
1 parent 44765f1 commit 6c6fa4f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/scores.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getDecryptionKey } from './helpers/shutter';
55
import { hasStrategyOverride, sha256 } from './helpers/utils';
66

77
const scoreAPIUrl = process.env.SCORE_API_URL || 'https://score.snapshot.org';
8+
const FINALIZE_SCORE_SECONDS_DELAY = 60;
89

910
async function getProposal(id: string): Promise<any | undefined> {
1011
const query = 'SELECT * FROM proposals WHERE id = ? LIMIT 1';
@@ -108,8 +109,16 @@ export async function updateProposalAndVotes(proposalId: string, force = false)
108109
return true;
109110
}
110111

111-
// Ignore score calculation if proposal have more than 100k votes and scores_updated greater than 5 minute
112112
const ts = Number((Date.now() / 1e3).toFixed());
113+
114+
// Delay computation of final scores, to allow time for last minute votes to finish
115+
// up to 1 minute after the end of the proposal
116+
if (proposal.end <= ts) {
117+
const secondsSinceEnd = ts - proposal.end;
118+
await snapshot.utils.sleep(Math.max(FINALIZE_SCORE_SECONDS_DELAY - secondsSinceEnd, 0) * 1000);
119+
}
120+
121+
// Ignore score calculation if proposal have more than 100k votes and scores_updated greater than 5 minute
113122
if (
114123
(proposal.votes > 20000 && proposal.scores_updated > ts - 300) ||
115124
pendingRequests[proposalId]

0 commit comments

Comments
 (0)