Skip to content

Commit

Permalink
Merge pull request #2588 from IntersectMBO/staging
Browse files Browse the repository at this point in the history
GovTool - v2.0.3
  • Loading branch information
MSzalowski authored Dec 30, 2024
2 parents fce4728 + 6e9a766 commit 409e4a8
Show file tree
Hide file tree
Showing 68 changed files with 760 additions and 471 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/test_integration_playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- "staging.govtool.byron.network"
- "govtool.cardanoapi.io"
- "preview.gov.tools"
- "gov.tools"

workflow_run:
workflows: ["Build and deploy GovTool to TEST server"]
Expand Down Expand Up @@ -54,18 +55,27 @@ jobs:
mkdir -p ./lib/_mock
chmod +w ./lib/_mock
npm run generate-wallets
if [[ "${{ env.NETWORK }}" == "preprod" ]]; then
# Set network variables based on deployment input and environment
if [[ "${{inputs.deployment}}" == "gov.tools" ]]; then
export NETWORK='mainnet'
else
export NETWORK="${{ vars.NETWORK }}"
fi
# Set API keys based on the network
if [[ "${{ vars.NETWORK }}" == "preprod" ]]; then
export FAUCET_API_KEY="${{ secrets.FAUCET_API_KEY_PREPROD }}"
export BLOCKFROST_API_KEY="${{ secrets.BLOCKFROST_API_KEY_PREPROD }}"
elif [[ "${{ env.NETWORK }}" == "sanchonet" ]]; then
elif [[ "${{ vars.NETWORK }}" == "sanchonet" ]]; then
export FAUCET_API_KEY="${{ secrets.FAUCET_API_KEY_SANCHONET }}"
export BLOCKFROST_API_KEY="${{ secrets.BLOCKFROST_API_KEY_SANCHONET }}"
else
export FAUCET_API_KEY="${{ secrets.FAUCET_API_KEY_PREVIEW }}"
export BLOCKFROST_API_KEY="${{ secrets.BLOCKFROST_API_KEY_PREVIEW }}"
fi
npm test
- name: Upload report
uses: actions/upload-artifact@v3
Expand All @@ -88,7 +98,6 @@ jobs:
KUBER_API_KEY: ${{secrets.KUBER_API_KEY}}
TEST_WORKERS: ${{vars.TEST_WORKERS}}
CI: ${{vars.CI}}
NETWORK: ${{vars.NETWORK}}
FAUCET_ADDRESS: ${{vars.FAUCET_ADDRESS}}
CARDANOAPI_METADATA_URL: ${{vars.CARDANOAPI_METADATA_URL}}
PROPOSAL_FAUCET_PAYMENT_PRIVATE: ${{secrets.PROPOSAL_FAUCET_PAYMENT_PRIVATE}}
Expand Down
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,29 @@ changes.

-

## [v2.0.2](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.2) 2024-12-20
## [v2.0.3](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.3) 2024-12-30

### Added

-

### Fixed

- Fix calculating DRep live voting power [Issue 2460](https://github.com/IntersectMBO/govtool/issues/2460)
- Fix link and description validation [Issue 2403](https://github.com/IntersectMBO/govtool/issues/2403)
- Revert to drep_distr for providing active voting power
- Add rewards amount in the ada holder voting power
- Fix nested @value in jsonld metadatas [Issue 2509](https://github.com/IntersectMBO/govtool/issues/2509)

### Changed

- Split New constitution on-chain details into tabs

### Removed

-

## [v2.0.2](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.2) 2024-12-23

### Added

Expand All @@ -37,6 +59,7 @@ changes.
- Move matomo initalization out of the react code
- Fix some non-ipfs related errors while fetching the DRep images [Issue 2546](https://github.com/IntersectMBO/govtool/issues/2546)
- Remaining mobile responsiveness issue [Issue 2493](https://github.com/IntersectMBO/govtool/issues/2493)
- Fix searching by CIP-129 identifiers [Issue 2571](https://github.com/IntersectMBO/govtool/issues/2571)

### Changed

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-2.0.2/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-2.0.3/x/vva-be/build/vva-be/vva-be /usr/local/bin
2 changes: 1 addition & 1 deletion govtool/backend/Dockerfile.qovery
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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-2.0.2/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-2.0.3/x/vva-be/build/vva-be/vva-be /usr/local/bin

# Expose the necessary port
EXPOSE 9876
Expand Down
18 changes: 15 additions & 3 deletions govtool/backend/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Data.Monoid (mempty)
import Data.OpenApi (OpenApi, Server (Server), _openApiServers,
_serverDescription, _serverUrl, _serverVariables,
servers)
import Data.Pool (createPool)
import Data.Pool (createPool, Pool)
import Data.Proxy
import Data.String (fromString)
import Data.String.Conversions (cs)
Expand All @@ -36,7 +36,7 @@ import qualified Data.Text.IO as Text
import qualified Data.Text.Lazy as LazyText
import qualified Data.Text.Lazy.Encoding as LazyText

import Database.PostgreSQL.Simple (close, connectPostgreSQL)
import Database.PostgreSQL.Simple (close, connectPostgreSQL, Connection)

import Network.Wai
import Network.Wai.Handler.Warp
Expand Down Expand Up @@ -65,6 +65,15 @@ import VVA.Types (AppEnv (..),
AppError (CriticalError, InternalError, NotFoundError, ValidationError),
CacheEnv (..))

-- Function to create a connection pool with optimized settings
createOptimizedConnectionPool :: BS.ByteString -> IO (Pool Connection)
createOptimizedConnectionPool connectionString = createPool
(connectPostgreSQL connectionString) -- Connection creation function
close -- Connection destruction function
1 -- Number of stripes (sub-pools)
60 -- Idle timeout (seconds)
50 -- Maximum number of connections per stripe

proxyAPI :: Proxy (VVAApi :<|> SwaggerAPI)
proxyAPI = Proxy

Expand Down Expand Up @@ -125,7 +134,10 @@ startApp vvaConfig sentryService = do
, dRepListCache
, networkMetricsCache
}
connectionPool <- createPool (connectPostgreSQL (encodeUtf8 (dbSyncConnectionString $ getter vvaConfig))) close 1 10 60

let connectionString = encodeUtf8 (dbSyncConnectionString $ getter vvaConfig)
connectionPool <- createOptimizedConnectionPool connectionString

let appEnv = AppEnv {vvaConfig=vvaConfig, vvaCache=cacheEnv, vvaConnectionPool=connectionPool }
server' <- mkVVAServer appEnv
runSettings settings server'
Expand Down
52 changes: 46 additions & 6 deletions govtool/backend/sql/get-stake-key-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
SELECT COALESCE(SUM(utxo_view.value::numeric), 0),
encode(stake_address.hash_raw, 'hex')
FROM stake_address
JOIN utxo_view ON utxo_view.stake_address_id = stake_address.id
WHERE stake_address.hash_raw = decode(?, 'hex')
GROUP BY stake_address.hash_raw;
WITH RewardRest AS (
SELECT
SUM(amount) AS amount,
addr_id
FROM
reward_rest
GROUP BY
addr_id
),
Reward AS (
SELECT
SUM(amount) AS amount,
addr_id
FROM
reward
GROUP BY
addr_id
),
Balance AS (
SELECT
COALESCE(SUM(uv.value), 0) AS amount,
sa.id AS addr_id,
encode(sa.hash_raw, 'hex') AS addr_raw
FROM
stake_address sa
JOIN utxo_view uv ON uv.stake_address_id = sa.id
GROUP BY
addr_id,
addr_raw
)
SELECT
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
b.addr_raw
FROM
Balance b
LEFT JOIN
RewardRest rr ON rr.addr_id = b.addr_id
LEFT JOIN
Reward r ON r.addr_id = rr.addr_id
WHERE
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
GROUP BY
b.addr_raw,
rr.amount,
r.amount,
b.amount
13 changes: 7 additions & 6 deletions govtool/backend/sql/get-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
select coalesce(sum(uv.value), 0) as amount
from utxo_view uv
join delegation_vote dv on uv.stake_address_id = dv.addr_id
join drep_hash dh on dv.drep_hash_id = dh.id
where dh.raw = decode(?,'hex')
and dv.cert_index != 0
SELECT
amount
FROM
drep_distr
WHERE
hash_id = (SELECT id FROM drep_hash WHERE raw = decode(?,'hex'))
ORDER BY epoch_no DESC LIMIT 1
78 changes: 44 additions & 34 deletions govtool/backend/sql/list-dreps.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
WITH DRepDistr AS (
SELECT
*,
drep_distr.*,
ROW_NUMBER() OVER (PARTITION BY drep_hash.id ORDER BY drep_distr.epoch_no DESC) AS rn
FROM
drep_distr
JOIN drep_hash ON drep_hash.id = drep_distr.hash_id
),
DRepActivity AS (
SELECT
drep_activity AS drep_activity,
epoch_no AS epoch_no
drep_activity,
epoch_no
FROM
epoch_param
WHERE
Expand All @@ -26,7 +26,7 @@ SELECT
encode(va.data_hash, 'hex'),
dr_deposit.deposit,
DRepDistr.amount,
(DRepActivity.epoch_no - Max(coalesce(block.epoch_no, block_first_register.epoch_no))) <= DRepActivity.drep_activity AS active,
(DRepActivity.epoch_no - COALESCE(block.epoch_no, block_first_register.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 All @@ -50,17 +50,17 @@ FROM
FROM
drep_registration dr
WHERE
dr.deposit IS NOT NULL) AS dr_deposit ON dr_deposit.drep_hash_id = dh.id
AND dr_deposit.rn = 1
JOIN (
dr.deposit IS NOT NULL
) AS dr_deposit ON dr_deposit.drep_hash_id = dh.id AND dr_deposit.rn = 1
JOIN (
SELECT
dr.id,
dr.drep_hash_id,
dr.deposit,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
FROM
drep_registration dr) AS latestDeposit ON latestDeposit.drep_hash_id = dh.id
AND latestDeposit.rn = 1
drep_registration dr
) AS latestDeposit ON latestDeposit.drep_hash_id = dh.id AND latestDeposit.rn = 1
LEFT JOIN (
SELECT
dr.id,
Expand All @@ -70,9 +70,11 @@ FROM
tx.hash AS tx_hash
FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id) AS dr_voting_anchor ON dr_voting_anchor.drep_hash_id = dh.id
AND dr_voting_anchor.rn = 1
LEFT JOIN (
JOIN tx ON tx.id = dr.tx_id
WHERE
dr.deposit IS NOT NULL AND dr.deposit >= 0
) AS dr_voting_anchor ON dr_voting_anchor.drep_hash_id = dh.id AND dr_voting_anchor.rn = 1
LEFT JOIN (
SELECT
dr.id,
dr.drep_hash_id,
Expand All @@ -82,36 +84,42 @@ FROM
FROM
drep_registration dr
JOIN tx ON tx.id = dr.tx_id
WHERE dr.deposit is not null
AND dr.deposit >= 0) AS dr_non_deregister_voting_anchor ON dr_non_deregister_voting_anchor.drep_hash_id = dh.id
AND dr_non_deregister_voting_anchor.rn = 1
) AS dr_non_deregister_voting_anchor ON dr_non_deregister_voting_anchor.drep_hash_id = dh.id AND dr_non_deregister_voting_anchor.rn = 1
LEFT JOIN (
SELECT
dr.id,
dr.drep_hash_id,
dr.voting_anchor_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn
FROM
drep_registration dr) AS second_to_newest_drep_registration ON second_to_newest_drep_registration.drep_hash_id = dh.id
AND second_to_newest_drep_registration.rn = 2
LEFT JOIN DRepDistr ON DRepDistr.hash_id = dh.id
AND DRepDistr.rn = 1
drep_registration dr
) AS second_to_newest_drep_registration ON second_to_newest_drep_registration.drep_hash_id = dh.id AND second_to_newest_drep_registration.rn = 2
LEFT JOIN DRepDistr ON DRepDistr.hash_id = dh.id AND DRepDistr.rn = 1
LEFT JOIN voting_anchor va ON va.id = dr_voting_anchor.voting_anchor_id
LEFT JOIN voting_anchor non_deregister_voting_anchor ON non_deregister_voting_anchor.id = dr_non_deregister_voting_anchor.voting_anchor_id
LEFT JOIN (
SELECT fetch_error as message, voting_anchor_id
FROM off_chain_vote_fetch_error
WHERE fetch_time = (
SELECT max(fetch_time)
FROM off_chain_vote_fetch_error)
GROUP BY fetch_error, voting_anchor_id
SELECT
fetch_error as message,
voting_anchor_id
FROM
off_chain_vote_fetch_error
WHERE
fetch_time = (
SELECT
max(fetch_time)
FROM
off_chain_vote_fetch_error
)
GROUP BY
fetch_error,
voting_anchor_id
) AS fetch_error ON fetch_error.voting_anchor_id = va.id
LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = va.id
LEFT JOIN off_chain_vote_drep_data on off_chain_vote_drep_data.off_chain_vote_data_id = off_chain_vote_data.id
LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data.off_chain_vote_data_id = off_chain_vote_data.id
CROSS JOIN DRepActivity
LEFT JOIN voting_procedure AS voting_procedure ON voting_procedure.drep_voter = dh.id
LEFT JOIN tx AS tx ON tx.id = voting_procedure.tx_id
LEFT JOIN block AS block ON block.id = tx.block_id
LEFT JOIN voting_procedure ON voting_procedure.drep_voter = dh.id
LEFT JOIN tx ON tx.id = voting_procedure.tx_id
LEFT JOIN block ON block.id = tx.block_id
LEFT JOIN (
SELECT
block.time,
Expand All @@ -122,16 +130,16 @@ FROM
JOIN tx ON tx.id = dr.tx_id
JOIN block ON block.id = tx.block_id
WHERE
NOT (dr.deposit < 0)) AS newestRegister ON newestRegister.drep_hash_id = dh.id
AND newestRegister.rn = 1
NOT (dr.deposit < 0)
) AS newestRegister ON newestRegister.drep_hash_id = dh.id AND newestRegister.rn = 1
LEFT JOIN (
SELECT
dr.tx_id,
dr.drep_hash_id,
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id ASC) AS rn
FROM
drep_registration dr) AS dr_first_register ON dr_first_register.drep_hash_id = dh.id
AND dr_first_register.rn = 1
drep_registration dr
) 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
WHERE
Expand All @@ -142,6 +150,8 @@ WHERE
off_chain_vote_drep_data.given_name ILIKE ?
)
GROUP BY
block_first_register.epoch_no,
block.epoch_no,
dh.raw,
second_to_newest_drep_registration.voting_anchor_id,
dh.view,
Expand All @@ -163,4 +173,4 @@ GROUP BY
off_chain_vote_drep_data.motivations,
off_chain_vote_drep_data.qualifications,
off_chain_vote_drep_data.image_url,
off_chain_vote_drep_data.image_hash
off_chain_vote_drep_data.image_hash;
2 changes: 1 addition & 1 deletion govtool/backend/vva-be.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.6
name: vva-be
version: 2.0.2
version: 2.0.3

-- A short (one-line) description of the package.
-- synopsis:
Expand Down
2 changes: 2 additions & 0 deletions govtool/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ARG VITE_PDF_API_URL
ARG VITE_IPFS_GATEWAY
ARG VITE_IPFS_PROJECT_ID

ENV NODE_OPTIONS="--max-old-space-size=4096"

# Ensure all required build arguments are set
RUN \
: "${VITE_APP_ENV:?Build argument VITE_APP_ENV is not set}" && \
Expand Down
Loading

0 comments on commit 409e4a8

Please sign in to comment.