-
Notifications
You must be signed in to change notification settings - Fork 13
feat(overlord): add async script to set proposal scores value #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
106 commits
Select commit
Hold shift + click to select a range
84efdb7
feat: set proposal vp value on proposal creation
wa0x6e f7a87bd
Merge branch 'master' into feat-get-proposal-vp-value-from-overlord
wa0x6e ed31f78
feat: set proposal strategies value on proposal creation
wa0x6e 599f9e4
fix: set `cb` column
wa0x6e cb9859b
fix: default last_cb to 1
wa0x6e e589d82
fix: round strategies value up to 9 decimals
wa0x6e 4fb62be
refactor: move precision to a const
wa0x6e 43def63
chore: fix typo
wa0x6e 4510db7
test: fix test
wa0x6e 8a28e02
test: fix tests
wa0x6e 8b8875e
refactor: use entityValue as value logic handler
wa0x6e afed3e3
fix: use randomUUID to generate random number
wa0x6e a2e025c
chore: use consistent logging
wa0x6e ec1028e
fix: handle overlord error
wa0x6e a64a0e6
fix: more precise rounding
wa0x6e adc6257
refactor: DRY json rpc request fetcher
wa0x6e 602555e
refactor: simplify rounding
wa0x6e 3e52e3a
fix: allow customize overlord url via env var
wa0x6e 6589f97
chore: remove white spaces
wa0x6e d834326
Merge branch 'master' into feat-get-proposal-vp-value-from-overlord
wa0x6e 585622a
fix: fix types
wa0x6e 69d4ff8
chore: lint fix
wa0x6e e80d0c4
fix: update overlord url
wa0x6e 83b9d1b
refactor: more consistent function name
wa0x6e c0761e1
fix: fix invalid method name
wa0x6e 5ff71c4
fix: send JSON-RPC id as number
wa0x6e 5b4ffd0
fix: skip vp value fetching for future proposals
wa0x6e 7320439
Merge branch 'master' into feat-get-proposal-vp-value-from-overlord
wa0x6e f124efb
fix: remove the getValue setting on proposal creation
wa0x6e 27d36b5
feat: refresh proposals vp_value_by_strategy async
wa0x6e 933bb27
fix: skip votes vp value computation when proposal score value is not…
wa0x6e 36cd966
fix: use only loop script to handle overlord logic
wa0x6e 5a6534b
fix: process by most recent first
wa0x6e c70da7a
refactor: better function name
wa0x6e 49a9749
fix: fix loop using same data
wa0x6e 5725853
feat: add script to refresh votes' vp_value async
wa0x6e 690c0a5
fix: on new votes using overriding strategies, mark all votes to be r…
wa0x6e cb5b124
Merge branch 'feat-get-proposal-vp-value-from-overlord' into feat-set…
wa0x6e 486655d
fix: add new CB value to trigger other fields computation
wa0x6e 44caefd
Merge branch 'feat-get-proposal-vp-value-from-overlord' into feat-set…
wa0x6e c94e6a8
fix: use dedicated CB when value need refresh
wa0x6e 76ee137
fix: finalize votes CB
wa0x6e c79c4cf
Update src/helpers/proposalStrategiesValue.ts
wa0x6e e5595f3
fix: use static CB value for closed status
wa0x6e 862cddf
refactoring: code improvement
wa0x6e 2be6513
fix: better constant name
wa0x6e a19a334
Merge branch 'master' into feat-get-proposal-vp-value-from-overlord
wa0x6e 3ca345c
fix: process older proposals first
wa0x6e 5e2da2b
fix: send request in batch
wa0x6e b85c1ac
Merge branch 'feat-get-proposal-vp-value-from-overlord' into feat-set…
wa0x6e a23d2ee
fix: update to match proposal script convention
wa0x6e 0004af2
Update src/helpers/votesVpValue.ts
wa0x6e b7f366a
chore: remove unused import
wa0x6e ef9498a
perf: better loop
wa0x6e 7c0cc53
fix: mark votes as errored
wa0x6e 2594734
feat: set proposal vp value on proposal creation
wa0x6e 764e744
feat: set proposal strategies value on proposal creation
wa0x6e a4c07c4
fix: set `cb` column
wa0x6e 18e7e5f
fix: default last_cb to 1
wa0x6e 4ffbd36
fix: round strategies value up to 9 decimals
wa0x6e 132912c
refactor: move precision to a const
wa0x6e 0f0f641
chore: fix typo
wa0x6e a9b066f
test: fix test
wa0x6e bb35683
test: fix tests
wa0x6e 1a63396
refactor: use entityValue as value logic handler
wa0x6e 88a3b8c
fix: use randomUUID to generate random number
wa0x6e 6a89832
chore: use consistent logging
wa0x6e b50edfc
fix: handle overlord error
wa0x6e b9163ab
fix: more precise rounding
wa0x6e 5473075
refactor: DRY json rpc request fetcher
wa0x6e b98aa04
refactor: simplify rounding
wa0x6e 4e55ece
fix: allow customize overlord url via env var
wa0x6e 110893a
chore: remove white spaces
wa0x6e 169e342
fix: fix types
wa0x6e 0c01020
fix: update overlord url
wa0x6e fba0e95
refactor: more consistent function name
wa0x6e ee86a37
fix: fix invalid method name
wa0x6e f46a8a1
fix: send JSON-RPC id as number
wa0x6e 57ef9b1
fix: skip vp value fetching for future proposals
wa0x6e f651c54
fix: remove the getValue setting on proposal creation
wa0x6e 487d90d
feat: refresh proposals vp_value_by_strategy async
wa0x6e 555bb9f
fix: skip votes vp value computation when proposal score value is not…
wa0x6e 3bd4e96
fix: use only loop script to handle overlord logic
wa0x6e 33ffe91
fix: process by most recent first
wa0x6e ce652ab
refactor: better function name
wa0x6e 3f2a49e
feat: add script to refresh votes' vp_value async
wa0x6e f08703e
fix: on new votes using overriding strategies, mark all votes to be r…
wa0x6e d880145
fix: fix loop using same data
wa0x6e 68e6f59
fix: add new CB value to trigger other fields computation
wa0x6e 4f0e151
fix: use dedicated CB when value need refresh
wa0x6e 96aff86
fix: finalize votes CB
wa0x6e 7f8f3b9
Update src/helpers/proposalStrategiesValue.ts
wa0x6e 93f6792
fix: use static CB value for closed status
wa0x6e 7607541
refactoring: code improvement
wa0x6e 610e24e
fix: better constant name
wa0x6e 4059f3b
fix: process older proposals first
wa0x6e db63fcb
fix: send request in batch
wa0x6e 7d9fda2
fix: update CB values
wa0x6e b2707a3
fix: update to match proposal script convention
wa0x6e 53751bc
Update src/helpers/votesVpValue.ts
wa0x6e 0849f02
Update src/helpers/proposalStrategiesValue.ts
wa0x6e 51a3e6b
chore: remove unused import
wa0x6e 81a1c97
feat: compute proposal's scores_total_value
wa0x6e 0d900d3
fix: fix remnant from merge conflict
wa0x6e 8fd5f32
Merge branch 'feat-set-vote-vp-value' into feat-set-proposal-scores-v…
wa0x6e c7b2d03
refactor: use camelCase for variable name
wa0x6e File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // import { capture } from '@snapshot-labs/snapshot-sentry'; | ||
| import snapshot from '@snapshot-labs/snapshot.js'; | ||
| import { getVpValueByStrategy } from './entityValue'; | ||
| import db from './mysql'; | ||
|
|
@@ -57,14 +58,16 @@ async function refreshVpByStrategy(proposals: Proposal[]) { | |
|
|
||
| export default async function run() { | ||
| while (true) { | ||
| const proposals = await getProposals(); | ||
| while (true) { | ||
| const proposals = await getProposals(); | ||
|
|
||
| if (proposals.length === 0) break; | ||
|
|
||
| if (proposals.length) { | ||
| await refreshVpByStrategy(proposals); | ||
| } | ||
|
|
||
| if (proposals.length < BATCH_SIZE) { | ||
| await snapshot.utils.sleep(REFRESH_INTERVAL); | ||
| if (proposals.length < BATCH_SIZE) break; | ||
| } | ||
|
|
||
| await snapshot.utils.sleep(REFRESH_INTERVAL); | ||
|
Comment on lines
+61
to
+71
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { capture } from '@snapshot-labs/snapshot-sentry'; | ||
| import snapshot from '@snapshot-labs/snapshot.js'; | ||
| import { getProposalValue } from './entityValue'; | ||
| import db from './mysql'; | ||
| import { CB } from '../constants'; | ||
|
|
||
| type Proposal = { | ||
| id: string; | ||
| vpValueByStrategy: number[]; | ||
| scoresByStrategy: number[][]; | ||
| }; | ||
|
|
||
| const REFRESH_INTERVAL = 10 * 1000; | ||
| const BATCH_SIZE = 25; | ||
|
|
||
| async function getProposals(): Promise<Proposal[]> { | ||
| const query = ` | ||
| SELECT id, vp_value_by_strategy, scores_by_strategy | ||
| FROM proposals | ||
| WHERE cb = ? AND end < UNIX_TIMESTAMP() AND scores_state = ? | ||
| ORDER BY created ASC | ||
| LIMIT ? | ||
| `; | ||
| const proposals = await db.queryAsync(query, [CB.PENDING_CLOSE, 'final', BATCH_SIZE]); | ||
|
|
||
| return proposals.map((p: any) => { | ||
| p.scoresByStrategy = JSON.parse(p.vp_value_by_strategy); | ||
| p.vpValueByStrategy = JSON.parse(p.scores_by_strategy); | ||
| return p; | ||
| }); | ||
| } | ||
|
|
||
| async function refreshScoresTotal(proposals: Proposal[]) { | ||
| const query: string[] = []; | ||
| const params: any[] = []; | ||
|
|
||
| proposals.map(proposal => { | ||
| query.push('UPDATE proposals SET scores_total_value = ?, cb = ? WHERE id = ? LIMIT 1'); | ||
|
|
||
| try { | ||
| const scoresTotalValue = getProposalValue( | ||
| proposal.scoresByStrategy, | ||
| proposal.vpValueByStrategy | ||
| ); | ||
| params.push(scoresTotalValue, CB.FINAL, proposal.id); | ||
| } catch (e) { | ||
| capture(e); | ||
| params.push(0, CB.INELIGIBLE, proposal.id); | ||
| } | ||
| }); | ||
|
|
||
| if (query.length) { | ||
| await db.queryAsync(query.join(';'), params); | ||
| } | ||
| } | ||
|
|
||
| export default async function run() { | ||
| while (true) { | ||
| const proposals = await getProposals(); | ||
|
|
||
| if (proposals.length) { | ||
| await refreshScoresTotal(proposals); | ||
| } | ||
|
|
||
| if (proposals.length < BATCH_SIZE) { | ||
| await snapshot.utils.sleep(REFRESH_INTERVAL); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import snapshot from '@snapshot-labs/snapshot.js'; | ||
| import { getVoteValue } from './entityValue'; | ||
| import db from './mysql'; | ||
| import { CB } from '../constants'; | ||
|
|
||
| const REFRESH_INTERVAL = 10 * 1000; | ||
| const BATCH_SIZE = 100; | ||
|
|
||
| type Datum = { | ||
| id: string; | ||
| vp_state: string; | ||
| vp_by_strategy: number[]; | ||
| vp_value_by_strategy: number[]; | ||
| }; | ||
|
|
||
| async function getVotes(): Promise<Datum[]> { | ||
| const query = ` | ||
| SELECT votes.id, votes.vp_state, votes.vp_by_strategy, proposals.vp_value_by_strategy | ||
| FROM votes | ||
| JOIN proposals ON votes.proposal = proposals.id | ||
| WHERE proposals.cb IN (?) AND votes.cb IN (?) | ||
| ORDER BY votes.created ASC | ||
| LIMIT ?`; | ||
| const results = await db.queryAsync(query, [ | ||
| [CB.PENDING_CLOSE, CB.PENDING_COMPUTE, CB.FINAL], | ||
| [CB.PENDING_SYNC, CB.PENDING_COMPUTE], | ||
| BATCH_SIZE | ||
| ]); | ||
|
|
||
| return results.map((r: any) => { | ||
| r.vp_value_by_strategy = JSON.parse(r.vp_value_by_strategy); | ||
| r.vp_by_strategy = JSON.parse(r.vp_by_strategy); | ||
| return r; | ||
| }); | ||
| } | ||
|
|
||
| async function refreshVotesVpValues(data: Datum[]) { | ||
| const query: string[] = []; | ||
| const params: any[] = []; | ||
|
|
||
| for (const datum of data) { | ||
| query.push('UPDATE votes SET vp_value = ?, cb = ? WHERE id = ? LIMIT 1'); | ||
|
|
||
| try { | ||
| const value = getVoteValue(datum.vp_value_by_strategy, datum.vp_by_strategy); | ||
|
|
||
| params.push(value, datum.vp_state === 'final' ? CB.FINAL : CB.PENDING_CLOSE, datum.id); | ||
| } catch (e) { | ||
| console.log(e); | ||
| params.push(0, CB.INELIGIBLE, datum.id); | ||
| } | ||
| } | ||
|
|
||
| if (query.length) { | ||
| await db.queryAsync(query.join(';'), params); | ||
| } | ||
| } | ||
|
|
||
| export default async function run() { | ||
| while (true) { | ||
| const votes = await getVotes(); | ||
|
|
||
| if (votes.length) { | ||
| await refreshVotesVpValues(votes); | ||
| } | ||
|
|
||
| if (votes.length < BATCH_SIZE) { | ||
| await snapshot.utils.sleep(REFRESH_INTERVAL); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.