Skip to content
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

fix: check for duplicate vote in verify #194

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Oct 6, 2023

If a vote already exist, we check that the new vote is more recent that the existing one before inserting, in the vote's action function.

We should also do the same in the verify function, to avoid a call to get voting power.

This kind of error is currently the slowest one:

Screenshot 2023-10-06 at 06 55 55

@wa0x6e wa0x6e requested a review from ChaituVR October 6, 2023 16:54
Comment on lines +52 to +60
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');
}
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

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Oct 24, 2023

Superseded by #216 , should still move the check from action to verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants