Skip to content

Commit

Permalink
fix: wrong drep activity conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Jan 7, 2025
1 parent fef8b9f commit d014164
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ changes.

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

### Changed

Expand Down
22 changes: 21 additions & 1 deletion govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ DRepActivity AS (
ORDER BY
epoch_no DESC
LIMIT 1
),
LatestVotingProcedure AS (
SELECT
vp.*,
ROW_NUMBER() OVER (PARTITION BY drep_voter ORDER BY tx_id DESC) AS rn
FROM
voting_procedure vp
),
LatestVoteEpoch AS (
SELECT
block.epoch_no,
lvp.drep_voter as drep_id
FROM
LatestVotingProcedure lvp
JOIN tx ON tx.id = lvp.tx_id
JOIN block ON block.id = tx.block_id
WHERE
lvp.rn = 1
)
SELECT DISTINCT ON (dh.raw)
encode(dh.raw, 'hex'),
Expand All @@ -26,7 +44,7 @@ SELECT DISTINCT ON (dh.raw)
encode(va.data_hash, 'hex'),
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - newestRegister.epoch_no) <= DRepActivity.drep_activity AS active,
(DRepActivity.epoch_no - GREATEST(MAX(COALESCE(block.epoch_no, block_first_register.epoch_no)), lve.epoch_no)) <= DRepActivity.drep_activity AS active,
encode(dr_voting_anchor.tx_hash, 'hex') AS tx_hash,
newestRegister.time AS last_register_time,
COALESCE(latestDeposit.deposit, 0),
Expand Down Expand Up @@ -143,6 +161,7 @@ FROM
) AS dr_first_register ON dr_first_register.drep_hash_id = dh.id AND dr_first_register.rn = 1
LEFT JOIN tx AS tx_first_register ON tx_first_register.id = dr_first_register.tx_id
LEFT JOIN block AS block_first_register ON block_first_register.id = tx_first_register.block_id
LEFT JOIN LatestVoteEpoch lve ON lve.drep_id = dh.id
WHERE
(
COALESCE(?, '') = '' OR
Expand All @@ -163,6 +182,7 @@ GROUP BY
DRepDistr.amount,
DRepActivity.epoch_no,
DRepActivity.drep_activity,
lve.epoch_no,
dr_voting_anchor.tx_hash,
newestRegister.time,
newestRegister.epoch_no,
Expand Down

0 comments on commit d014164

Please sign in to comment.