From 18107425974692612d99434566869683acda1459 Mon Sep 17 00:00:00 2001 From: jankun4 Date: Tue, 20 Feb 2024 14:55:00 +0100 Subject: [PATCH 1/2] [#231] fix broken endpoints fix endpoints broken due to assumption that predefined dreps always exist, even if noone delegated to them --- govtool/backend/sql/get-network-metrics.sql | 12 ++++++------ govtool/backend/sql/get-voting-power.sql | 10 ++++++---- govtool/backend/sql/list-proposals.sql | 12 ++++++------ govtool/backend/src/VVA/DRep.hs | 8 +++----- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/govtool/backend/sql/get-network-metrics.sql b/govtool/backend/sql/get-network-metrics.sql index 25fb12fbd..073312c48 100644 --- a/govtool/backend/sql/get-network-metrics.sql +++ b/govtool/backend/sql/get-network-metrics.sql @@ -21,17 +21,17 @@ with current_epoch as ( select count(*) as count from drep_hash ), always_abstain_voting_power as ( - select amount - from drep_distr - join drep_hash + select coalesce(amount, 0) as amount + from drep_hash + left join drep_distr on drep_hash.id = drep_distr.hash_id where drep_hash.view = 'drep_always_abstain' order by epoch_no desc limit 1 ), always_no_confidence_voting_power as ( - select amount - from drep_distr - join drep_hash + select coalesce(amount, 0) as amount + from drep_hash + left join drep_distr on drep_hash.id = drep_distr.hash_id where drep_hash.view = 'drep_always_no_confidence' order by epoch_no desc diff --git a/govtool/backend/sql/get-voting-power.sql b/govtool/backend/sql/get-voting-power.sql index 33d22d06d..b81b5eb84 100644 --- a/govtool/backend/sql/get-voting-power.sql +++ b/govtool/backend/sql/get-voting-power.sql @@ -1,5 +1,7 @@ -select drep_distr.amount -from drep_distr -join drep_hash +select coalesce(drep_distr.amount, 0) as amount +from drep_hash +left join drep_distr on drep_hash.id = drep_distr.hash_id -where drep_hash.raw = decode(?,'hex') \ No newline at end of file +where drep_hash.raw = decode(?,'hex') +order by epoch_no desc +limit 1 \ No newline at end of file diff --git a/govtool/backend/sql/list-proposals.sql b/govtool/backend/sql/list-proposals.sql index 00ad5ec34..b7bb42a6b 100644 --- a/govtool/backend/sql/list-proposals.sql +++ b/govtool/backend/sql/list-proposals.sql @@ -10,17 +10,17 @@ WITH LatestDrepDistr AS ( Max(end_time) as last_epoch_end_time FROM epoch ), always_no_confidence_voting_power as ( - select amount - from drep_distr - join drep_hash + select coalesce(amount, 0) as amount + from drep_hash + left join drep_distr on drep_hash.id = drep_distr.hash_id where drep_hash.view = 'drep_always_no_confidence' order by epoch_no desc limit 1 ), always_abstain_voting_power as ( - select amount - from drep_distr - join drep_hash + select coalesce(amount, 0) as amount + from drep_hash + left join drep_distr on drep_hash.id = drep_distr.hash_id where drep_hash.view = 'drep_always_abstain' order by epoch_no desc diff --git a/govtool/backend/src/VVA/DRep.hs b/govtool/backend/src/VVA/DRep.hs index cd373cda5..0661f0f82 100644 --- a/govtool/backend/src/VVA/DRep.hs +++ b/govtool/backend/src/VVA/DRep.hs @@ -47,11 +47,9 @@ getVotingPower :: Text -> m Integer getVotingPower drepId = withPool $ \conn -> do - votingPower <- - sum . map (\(SQL.Only x) -> x) <$> - liftIO - (SQL.query @_ @(SQL.Only Scientific) conn getVotingPowerSql $ - SQL.Only drepId) + [SQL.Only votingPower] <- + liftIO + (SQL.query @_ @(SQL.Only Scientific) conn getVotingPowerSql $ SQL.Only drepId) return $ floor votingPower listDRepsSql :: SQL.Query From ec14a1e615031606631b5652c718c24769317a58 Mon Sep 17 00:00:00 2001 From: jankun4 Date: Tue, 20 Feb 2024 15:06:06 +0100 Subject: [PATCH 2/2] [#231] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29f5a4ce..2c7885f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ changes. - i18next library added to FE [Issue 80](https://github.com/IntersectMBO/govtool/issues/80) ### Fixed +- Fix drep voting power calculation [Issue 231](https://github.com/IntersectMBO/govtool/issues/231) +- Fix proposal/list and network/metrics bug that appeared when noone has delegated their funds either to drep_always_abstain or drep_always_no_confidence [Issue 231](https://github.com/IntersectMBO/govtool/issues/231) - Fix copy for maintenance page [Issue 180](https://github.com/IntersectMBO/govtool/issues/180) - Fix misleading metadata hash text [Issue 90](https://github.com/IntersectMBO/govtool/issues/90) - Fixed vote calculation problems related to NoConfidence DRep [Issue 59](https://github.com/IntersectMBO/govtool/issues/59)