Remove DISTINCT ON from delegation_events join to fix VP#124
Closed
Remove DISTINCT ON from delegation_events join to fix VP#124
Conversation
…regression The DISTINCT ON (delegator_id) was picking ft_burn events over ft_mint, causing the delegate_event = 'ft_mint' filter to fail and making delegating voters show their full principal balance instead of 0. Restores the direct LEFT JOIN while keeping registered_voter_id instead of signer_account_id for the join key.
Collaborator
|
Commit was cherry picked and included in #123 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix: Remove DISTINCT ON from delegation_events join
Problem
PR #122 introduced a
DISTINCT ON (delegator_id)subquery wrapper around thedelegation_eventsLEFT JOIN in theregistered_votersview. This caused a regression where delegating voters showed their full principal balance instead of 0.Root Cause
Each delegation action produces multiple log entries (
ft_mint+ft_burn). TheDISTINCT ON (delegator_id)picks only one row per delegator (latest byblock_timestamp). When that row is theft_burnevent, the filter conditions in theONclause (delegate_event = 'ft_mint') fail, causing the LEFT JOIN to return NULL — making the voter appear as **not delegating** and showing their full VP.Fix
DISTINCT ONsubquery wrapper (the cause of the regression)registered_voter_idinstead ofsigner_account_idas the join key (the original deduplication fix from Deduplicate Registered Voters View #122)account_idfrom logs instead ofsigner_account_id)Impact