Skip to content

Commit ff3a7d1

Browse files
committed
(fix) Hotfix for duplicated entries for pools for epoch 568 on mainnet in pool_stat table
1 parent f91a04e commit ff3a7d1

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

govtool/backend/sql/list-proposals.sql

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,28 @@ RankedPoolVotes AS (
113113
vp.vote
114114
FROM
115115
voting_procedure vp
116-
WHERE
116+
WHERE
117117
vp.pool_voter IS NOT NULL
118118
AND vp.gov_action_proposal_id IN (SELECT id FROM ActiveProposals)
119-
ORDER BY
120-
vp.pool_voter,
121-
vp.gov_action_proposal_id,
119+
ORDER BY
120+
vp.pool_voter,
121+
vp.gov_action_proposal_id,
122122
vp.tx_id DESC,
123123
vp.id DESC
124124
),
125+
-- This CTE retrieves the latest pool statistics for each pool in the current epoch.
126+
-- It ensures that we only consider the most recent data for each pool.
127+
-- it's a hotfix for duplication issue https://github.com/IntersectMBO/cardano-db-sync/issues/1986
128+
LatestPoolStat AS (
129+
SELECT DISTINCT ON (pool_hash_id, epoch_no, number_of_blocks, number_of_delegators, stake, voting_power)
130+
*
131+
FROM
132+
pool_stat
133+
WHERE
134+
epoch_no = (SELECT MAX(no) FROM epoch)
135+
ORDER BY
136+
pool_hash_id, epoch_no, number_of_blocks, number_of_delegators, stake, voting_power, id DESC
137+
),
125138
PoolVotes AS (
126139
SELECT
127140
rpv.gov_action_proposal_id,
@@ -132,10 +145,10 @@ PoolVotes AS (
132145
SUM(CASE WHEN rpv.vote = 'Yes' THEN ps.voting_power ELSE 0 END) AS poolYesVotes,
133146
SUM(CASE WHEN rpv.vote = 'No' THEN ps.voting_power ELSE 0 END) AS poolNoVotes,
134147
SUM(CASE WHEN rpv.vote = 'Abstain' THEN ps.voting_power ELSE 0 END) AS poolAbstainVotes
135-
FROM
148+
FROM
136149
RankedPoolVotes rpv
137-
JOIN
138-
pool_stat ps
150+
JOIN
151+
LatestPoolStat ps
139152
ON rpv.pool_voter = ps.pool_hash_id
140153
WHERE
141154
ps.epoch_no = (SELECT MAX(no) FROM epoch)

0 commit comments

Comments
 (0)