Skip to content

Remove DISTINCT ON from delegation_events join to fix VP#124

Closed
atomauro wants to merge 1 commit intomainfrom
fix/delegation-regression
Closed

Remove DISTINCT ON from delegation_events join to fix VP#124
atomauro wants to merge 1 commit intomainfrom
fix/delegation-regression

Conversation

@atomauro
Copy link
Copy Markdown
Contributor

@atomauro atomauro commented Feb 18, 2026

Fix: Remove DISTINCT ON from delegation_events join

Problem

PR #122 introduced a DISTINCT ON (delegator_id) subquery wrapper around the delegation_events LEFT JOIN in the registered_voters view. 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). The DISTINCT ON (delegator_id) picks only one row per delegator (latest by block_timestamp). When that row is the ft_burn event, the filter conditions in the ON clause (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

Impact

Before (regression) After (this fix)
Delegating voters show full VP (e.g. 479K) Delegating voters show 0 VP ✅
Duplicates fixed ✅ Duplicates fixed ✅

…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.
@atomauro atomauro requested a review from pedrohasf February 18, 2026 22:07
@atomauro atomauro self-assigned this Feb 18, 2026
@atomauro atomauro added the bug Something isn't working label Feb 18, 2026
@atomauro atomauro marked this pull request as ready for review February 18, 2026 22:08
@pedrohasf
Copy link
Copy Markdown
Collaborator

Commit was cherry picked and included in #123

@pedrohasf pedrohasf closed this Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants