Skip to content

Commit

Permalink
Merge pull request #1660 from IntersectMBO/develop
Browse files Browse the repository at this point in the history
Sancho-v1.0.12
  • Loading branch information
MSzalowski authored Aug 1, 2024
2 parents b85441e + 24e1ec2 commit 285e31c
Show file tree
Hide file tree
Showing 47 changed files with 420 additions and 469 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ changes.

-

## [sancho-v1.0.12](https://github.com/IntersectMBO/govtool/releases/tag/sancho-v1.0.12) 2024-08-01

### Added

- Add network name to GET /network/metrics [Issue 1644](https://github.com/IntersectMBO/govtool/issues/1644)

### Fixed

- Fix displaying Governance Action & DRep metadatas

### Changed

- Change link to propose a governace action docs [Issue 1132](https://github.com/IntersectMBO/govtool/issues/1132)
- Change link to docs regarding DReps [Issue 1130](https://github.com/IntersectMBO/govtool/issues/1130)
- Change link to view governance actions docs [Issue 1131](https://github.com/IntersectMBO/govtool/issues/1131)
- Make all the frontend build arguments mandatory [Issue 1642](https://github.com/IntersectMBO/govtool/issues/1642), [Issue 1643](https://github.com/IntersectMBO/govtool/issues/1643)
- Breaking! Remove usage of metadata validation service in Haskell Backend

## [sancho-v1.0.11](https://github.com/IntersectMBO/govtool/releases/tag/sancho-v1.0.11) 2024-07-30

### Added
Expand Down
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ FROM $BASE_IMAGE_REPO:$BASE_IMAGE_TAG
WORKDIR /src
COPY . .
RUN cabal build
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.11/x/vva-be/build/vva-be/vva-be /usr/local/bin
RUN cp dist-newstyle/build/x86_64-linux/ghc-9.2.7/vva-be-1.0.12/x/vva-be/build/vva-be/vva-be /usr/local/bin
12 changes: 2 additions & 10 deletions govtool/backend/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

module Main where

import Control.Concurrent.QSem (newQSem)
import Control.Exception (Exception, SomeException, fromException, throw)
import Control.Lens.Operators ((.~))
import Control.Monad
Expand Down Expand Up @@ -38,8 +37,6 @@ import qualified Data.Text.Lazy.Encoding as LazyText

import Database.PostgreSQL.Simple (close, connectPostgreSQL)

import Network.HTTP.Client hiding (Proxy, Request)
import Network.HTTP.Client.TLS
import Network.Wai
import Network.Wai.Handler.Warp
import Network.Wai.Middleware.Cors
Expand Down Expand Up @@ -85,6 +82,7 @@ startApp vvaConfig = do
settings =
setPort vvaPort
$ setHost vvaHost
$ setTimeout 60 -- 60 seconds timeout
$ setBeforeMainLoop
( Text.hPutStrLn stderr $
Text.pack
Expand All @@ -107,8 +105,6 @@ startApp vvaConfig = do
dRepVotingPowerCache <- newCache
dRepListCache <- newCache
networkMetricsCache <- newCache
proposalMetadataValidationCache <- newCache
dRepMetadataValidationCache <- newCache
return $ CacheEnv
{ proposalListCache
, getProposalCache
Expand All @@ -120,13 +116,9 @@ startApp vvaConfig = do
, dRepVotingPowerCache
, dRepListCache
, networkMetricsCache
, proposalMetadataValidationCache
, dRepMetadataValidationCache
}
connectionPool <- createPool (connectPostgreSQL (encodeUtf8 (dbSyncConnectionString $ getter vvaConfig))) close 1 1 60
vvaTlsManager <- newManager tlsManagerSettings
qsem <- newQSem (metadataValidationMaxConcurrentRequests vvaConfig)
let appEnv = AppEnv {vvaConfig=vvaConfig, vvaCache=cacheEnv, vvaConnectionPool=connectionPool, vvaTlsManager, vvaMetadataQSem=qsem}
let appEnv = AppEnv {vvaConfig=vvaConfig, vvaCache=cacheEnv, vvaConnectionPool=connectionPool }
server' <- mkVVAServer appEnv
runSettings settings server'

Expand Down
8 changes: 2 additions & 6 deletions govtool/backend/example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
"host" : "localhost",
"dbname" : "cexplorer",
"user" : "postgres",
"password" : "v8hlDV0yMAHHlIurYupj",
"password" : "postgres",
"port" : 5432
},
"port" : 9999,
"host" : "localhost",
"cachedurationseconds": 20,
"sentrydsn": "https://username:[email protected]/id",
"sentryenv": "dev",
"metadatavalidationenabled": true,
"metadatavalidationhost": "localhost",
"metadatavalidationport": 3001,
"metadatavalidationmaxconcurrentrequests": 10
"sentryenv": "dev"
}
4 changes: 3 additions & 1 deletion govtool/backend/sql/get-network-metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ SELECT
total_drep_votes.count,
total_registered_dreps.count,
always_abstain_voting_power.amount,
always_no_confidence_voting_power.amount
always_no_confidence_voting_power.amount,
network_name
FROM
current_epoch
CROSS JOIN current_block
Expand All @@ -82,3 +83,4 @@ FROM
CROSS JOIN total_registered_dreps
CROSS JOIN always_abstain_voting_power
CROSS JOIN always_no_confidence_voting_power
CROSS JOIN meta;
113 changes: 113 additions & 0 deletions govtool/backend/sql/list-proposals-my.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
WITH LatestDrepDistr AS (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY hash_id ORDER BY epoch_no DESC) AS rn
FROM
drep_distr
),
EpochUtils AS (
SELECT
(Max(end_time) - Min(end_time)) / (Max(NO) - Min(NO)) AS epoch_duration,
Max(NO) AS last_epoch_no,
Max(end_time) AS last_epoch_end_time
FROM
epoch
),
always_no_confidence_voting_power AS (
SELECT
coalesce((
SELECT
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), 0) AS amount
),
always_abstain_voting_power AS (
SELECT
coalesce((
SELECT
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), 0) AS amount
)
SELECT
gov_action_proposal.id AS proposal_id,
encode(creator_tx.hash, 'hex') AS tx_hash,
gov_action_proposal.index,
gov_action_proposal.type::text,
CASE
WHEN gov_action_proposal.type = 'TreasuryWithdrawals' THEN
json_build_object('Reward Address', stake_address.view, 'Amount', treasury_withdrawal.amount)
WHEN gov_action_proposal.type::text = 'InfoAction' THEN
json_build_object()
ELSE
NULL
END AS description,
epoch_utils.last_epoch_end_time + epoch_utils.epoch_duration * (gov_action_proposal.expiration - epoch_utils.last_epoch_no) AS expiry_date,
gov_action_proposal.expiration AS expiry_epoch_no,
creator_block.time AS created_date,
creator_block.epoch_no AS created_epoch_no,
voting_anchor.url,
encode(voting_anchor.data_hash, 'hex') AS metadata_hash,
off_chain_vote_gov_action_data.title,
off_chain_vote_gov_action_data.abstract,
off_chain_vote_gov_action_data.motivation,
off_chain_vote_gov_action_data.rationale,
coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0) +
CASE
WHEN gov_action_proposal.type = 'NoConfidence' THEN always_no_confidence_voting_power.amount
ELSE 0
END AS yes_votes,
coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'No'), 0) +
CASE
WHEN gov_action_proposal.type = 'NoConfidence' THEN 0
ELSE always_no_confidence_voting_power.amount
END AS no_votes,
coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0) + always_abstain_voting_power.amount AS abstain_votes
FROM
gov_action_proposal
LEFT JOIN treasury_withdrawal ON gov_action_proposal.id = treasury_withdrawal.gov_action_proposal_id
LEFT JOIN stake_address ON stake_address.id = treasury_withdrawal.stake_address_id
CROSS JOIN EpochUtils AS epoch_utils
CROSS JOIN always_no_confidence_voting_power
CROSS JOIN always_abstain_voting_power
CROSS JOIN off_chain_vote_gov_action_data ON off_chain_vote_gov_action_data.off_chain_vote_data_id = off_chain_vote_data.id
JOIN tx AS creator_tx ON creator_tx.id = gov_action_proposal.tx_id
JOIN block AS creator_block ON creator_block.id = creator_tx.block_id
LEFT JOIN voting_anchor ON voting_anchor.id = gov_action_proposal.voting_anchor_id
LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = voting_anchor.id
LEFT JOIN voting_procedure ON voting_procedure.gov_action_proposal_id = gov_action_proposal.id
LEFT JOIN LatestDrepDistr ldd ON ldd.hash_id = voting_procedure.drep_voter AND ldd.rn = 1
WHERE (NOT ?
OR (concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) IN ?))
AND gov_action_proposal.expiration > (
SELECT
Max(NO)
FROM
epoch)
AND gov_action_proposal.ratified_epoch IS NULL
AND gov_action_proposal.enacted_epoch IS NULL
AND gov_action_proposal.expired_epoch IS NULL
AND gov_action_proposal.dropped_epoch IS NULL
GROUP BY
(gov_action_proposal.id,
stake_address.view,
treasury_withdrawal.amount,
creator_block.epoch_no,
off_chain_vote_gov_action_data.title,
off_chain_vote_gov_action_data.abstract,
off_chain_vote_gov_action_data.motivation,
off_chain_vote_gov_action_data.rationale,
gov_action_proposal.index,
creator_tx.hash,
creator_block.time,
epoch_utils.epoch_duration,
epoch_utils.last_epoch_no,
epoch_utils.last_epoch_end_time,
voting_anchor.url,
voting_anchor.data_hash,
always_no_confidence_voting_power.amount,
always_abstain_voting_power.amount)
9 changes: 2 additions & 7 deletions govtool/backend/sql/list-proposals.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,16 @@ SELECT
null
end
) as description,
epoch_utils.last_epoch_end_time + epoch_utils.epoch_duration *(gov_action_proposal.expiration - epoch_utils.last_epoch_no),
epoch_utils.last_epoch_end_time + epoch_utils.epoch_duration * (gov_action_proposal.expiration - epoch_utils.last_epoch_no),
gov_action_proposal.expiration,
creator_block.time,
creator_block.epoch_no,
/* created date */
voting_anchor.url,
encode(voting_anchor.data_hash, 'hex'),
off_chain_vote_gov_action_data.title,
off_chain_vote_gov_action_data.abstract,
off_chain_vote_gov_action_data.motivation,
off_chain_vote_gov_action_data.rationale,
off_chain_vote_data.json,
off_chain_vote_data.json#>'{body, references}' as references,
coalesce(Sum(ldd.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0) +(
CASE WHEN gov_action_proposal.type = 'NoConfidence' THEN
always_no_confidence_voting_power.amount
Expand All @@ -80,7 +77,6 @@ FROM
on gov_action_proposal.id = treasury_withdrawal.gov_action_proposal_id
LEFT JOIN stake_address
on stake_address.id = treasury_withdrawal.stake_address_id

CROSS JOIN EpochUtils AS epoch_utils
CROSS JOIN always_no_confidence_voting_power
CROSS JOIN always_abstain_voting_power
Expand Down Expand Up @@ -112,7 +108,6 @@ GROUP BY
off_chain_vote_gov_action_data.abstract,
off_chain_vote_gov_action_data.motivation,
off_chain_vote_gov_action_data.rationale,
off_chain_vote_data.json,
gov_action_proposal.index,
creator_tx.hash,
creator_block.time,
Expand All @@ -122,4 +117,4 @@ GROUP BY
voting_anchor.url,
voting_anchor.data_hash,
always_no_confidence_voting_power.amount,
always_abstain_voting_power.amount)
always_abstain_voting_power.amount)
Loading

0 comments on commit 285e31c

Please sign in to comment.