Skip to content

Commit 03ab43f

Browse files
committed
(fix): duplications in pool_stat table in db-sync
1 parent e9ebbde commit 03ab43f

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

govtool/backend/sql/get-network-total-stake.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ TotalStakeControlledByActiveDReps AS (
6767
AND COALESCE(rd.deposit, 0) >= 0
6868
AND ((DRepActivity.epoch_no - GREATEST(COALESCE(lve.epoch_no, 0), COALESCE(rd.epoch_no, 0))) <= DRepActivity.drep_activity)
6969
),
70+
-- it's a fix for duplication issue https://github.com/IntersectMBO/cardano-db-sync/issues/1986
71+
LatestPoolStat AS (
72+
SELECT DISTINCT ON (pool_hash_id) *
73+
FROM
74+
pool_stat
75+
WHERE
76+
epoch_no = (SELECT MAX(no) FROM epoch)
77+
),
7078
TotalStakeControlledBySPOs AS (
71-
SELECT SUM(ps.stake)::bigint AS total FROM pool_stat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch)
79+
SELECT SUM(ps.stake)::bigint AS total FROM LatestPoolStat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch)
7280
),
7381
AlwaysAbstainVotingPower AS (
7482
SELECT COALESCE((SELECT amount FROM drep_hash

govtool/backend/sql/list-proposals.sql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ RankedPoolVotes AS (
122122
vp.tx_id DESC,
123123
vp.id DESC
124124
),
125+
-- it's a fix for duplication issue https://github.com/IntersectMBO/cardano-db-sync/issues/1986
126+
LatestPoolStat AS (
127+
SELECT DISTINCT ON (pool_hash_id) *
128+
FROM
129+
pool_stat
130+
WHERE
131+
epoch_no = (SELECT MAX(no) FROM epoch)
132+
),
125133
PoolVotes AS (
126134
SELECT
127135
rpv.gov_action_proposal_id,
@@ -132,10 +140,10 @@ PoolVotes AS (
132140
SUM(CASE WHEN rpv.vote = 'Yes' THEN ps.voting_power ELSE 0 END) AS poolYesVotes,
133141
SUM(CASE WHEN rpv.vote = 'No' THEN ps.voting_power ELSE 0 END) AS poolNoVotes,
134142
SUM(CASE WHEN rpv.vote = 'Abstain' THEN ps.voting_power ELSE 0 END) AS poolAbstainVotes
135-
FROM
143+
FROM
136144
RankedPoolVotes rpv
137-
JOIN
138-
pool_stat ps
145+
JOIN
146+
LatestPoolStat ps
139147
ON rpv.pool_voter = ps.pool_hash_id
140148
WHERE
141149
ps.epoch_no = (SELECT MAX(no) FROM epoch)

0 commit comments

Comments
 (0)