Skip to content

Commit d014164

Browse files
committed
fix: wrong drep activity conditions
1 parent fef8b9f commit d014164

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ changes.
1818

1919
- Fix CIP-129 DRep view identifier for script based DReps [Issue 2583](https://github.com/IntersectMBO/govtool/issues/2583)
2020
- Fix bad request on passing the random sorting to GA list request [Issue 2535](https://github.com/IntersectMBO/govtool/issues/2535)
21+
- Fix wrong drep activity conditions
2122

2223
### Changed
2324

govtool/backend/sql/list-dreps.sql

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ DRepActivity AS (
1717
ORDER BY
1818
epoch_no DESC
1919
LIMIT 1
20+
),
21+
LatestVotingProcedure AS (
22+
SELECT
23+
vp.*,
24+
ROW_NUMBER() OVER (PARTITION BY drep_voter ORDER BY tx_id DESC) AS rn
25+
FROM
26+
voting_procedure vp
27+
),
28+
LatestVoteEpoch AS (
29+
SELECT
30+
block.epoch_no,
31+
lvp.drep_voter as drep_id
32+
FROM
33+
LatestVotingProcedure lvp
34+
JOIN tx ON tx.id = lvp.tx_id
35+
JOIN block ON block.id = tx.block_id
36+
WHERE
37+
lvp.rn = 1
2038
)
2139
SELECT DISTINCT ON (dh.raw)
2240
encode(dh.raw, 'hex'),
@@ -26,7 +44,7 @@ SELECT DISTINCT ON (dh.raw)
2644
encode(va.data_hash, 'hex'),
2745
dr_deposit.deposit,
2846
DRepDistr.amount,
29-
(DRepActivity.epoch_no - newestRegister.epoch_no) <= DRepActivity.drep_activity AS active,
47+
(DRepActivity.epoch_no - GREATEST(MAX(COALESCE(block.epoch_no, block_first_register.epoch_no)), lve.epoch_no)) <= DRepActivity.drep_activity AS active,
3048
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
3149
newestRegister.time AS last_register_time,
3250
COALESCE(latestDeposit.deposit, 0),
@@ -143,6 +161,7 @@ FROM
143161
) AS dr_first_register ON dr_first_register.drep_hash_id = dh.id AND dr_first_register.rn = 1
144162
LEFT JOIN tx AS tx_first_register ON tx_first_register.id = dr_first_register.tx_id
145163
LEFT JOIN block AS block_first_register ON block_first_register.id = tx_first_register.block_id
164+
LEFT JOIN LatestVoteEpoch lve ON lve.drep_id = dh.id
146165
WHERE
147166
(
148167
COALESCE(?, '') = '' OR
@@ -163,6 +182,7 @@ GROUP BY
163182
DRepDistr.amount,
164183
DRepActivity.epoch_no,
165184
DRepActivity.drep_activity,
185+
lve.epoch_no,
166186
dr_voting_anchor.tx_hash,
167187
newestRegister.time,
168188
newestRegister.epoch_no,

0 commit comments

Comments
 (0)