Skip to content

fix: check for duplicate vote in verify #194

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/writer/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ export async function verify(body): Promise<any> {
return Promise.reject('invalid choice');
}

// Check if voter already voted
const votes = await db.queryAsync(
'SELECT created FROM votes WHERE voter = ? AND proposal = ? AND space = ? ORDER BY created DESC LIMIT 1',
[body.address, msg.payload.proposal, msg.space]
);

// Reject vote with later timestamp
if (votes[0]?.created > msgTs) {
return Promise.reject('already voted at later time');
}
Comment on lines +51 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already checked in action right https://github.com/snapshot-labs/snapshot-sequencer/blob/use-alias-schema/src/writer/vote.ts#L148 ? maybe we should remove that if we already check it in verify

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check inside action is to there in case some other threads/container are processing the same exact request, and is still needed, since we can't guarantee that the check inside verify is valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm better to handle parallel requests in requestDeduplicator, because this can cause duplicate query and code, meaning additional time to vote for users 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move all inside verify, after implementing requestDeduplicator #202

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm better to install deduplication first


if (proposal.validation?.name && proposal.validation.name !== 'any') {
try {
const {
Expand Down