Skip to content

Commit 1b551ea

Browse files
committed
feat(#3189): exclude network information from network metrics endpoint
1 parent 405bf3e commit 1b551ea

File tree

24 files changed

+389
-168
lines changed

24 files changed

+389
-168
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ changes.
1212

1313
### Added
1414

15-
### Fixed
15+
- Add support for preprod in matomo analytics [Issue 3173](https://github.com/IntersectMBO/govtool/issues/3173)
1616

17-
- hotfix for ada handle and payment address validation order [Issue 3155](https://github.com/IntersectMBO/govtool/issues/3155)
17+
### Fixed
1818

1919
### Changed
2020

21+
- Exclude network total stake and info from network metrics [Issue 3189](https://github.com/IntersectMBO/govtool/issues/3189)
22+
2123
### Removed
2224

2325
## [v2.0.15](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.15) 2025-03-11

govtool/backend/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This is a backend application of GovTool project.
66

77
In order to run `backend` your host machine will need access to the `cardano-db-sync` postgres database. To have this database running locally you'll need:
88

9-
- `cardano-node`
10-
- `cardano-db-sync`
11-
- PostgreSQL database
9+
- [cardano-node](https://github.com/IntersectMBO/cardano-node)
10+
- [cardano-db-sync](https://github.com/IntersectMBO/cardano-db-sync)
11+
- [PostgreSQL database](https://www.postgresql.org/download/) (psql needs to be installed on your machine in order to compile the project)
1212

1313
You will need your `cardano-node` and `cardano-db-sync` to be compatible with Sancho testnet. Until these features will be merged to the master branch the new Sancho compatible versions are available as releases on [github](https://github.com/IntersectMBO/cardano-db-sync/releases). You will also need a correct `cardano-node` version. The release notes for `cardano-db-sync` usualy specify that.
1414

@@ -30,44 +30,44 @@ Due to problems with openapi3 package it's hard to build this project with plain
3030

3131
2. Get [direnv](https://direnv.net/).
3232

33-
3. Set GHC version to 9.10.1:
33+
3. Set GHC version to 9.2.8:
3434

3535
```sh
36-
ghcup install ghc 9.10.1
36+
ghcup install ghc 9.2.8
3737

38-
ghcup set ghc 9.10.1
38+
ghcup set ghc 9.2.8
3939
```
4040

4141
4. Install cabal
4242

43-
```sh
44-
ghcup install cabal
45-
ghcup set cabal
46-
```
43+
```sh
44+
ghcup install cabal
45+
ghcup set cabal
46+
```
4747

4848
5. Enter `govtool/backend` directory:
4949

5050
```sh
51-
cd govtool/backend
51+
cd govtool/backend
5252
```
5353

5454
6. Allow direnv to setup your environment:
5555

5656
```sh
57-
direnv allow
57+
direnv allow
5858
```
5959

6060
7. Update cabal & build project
6161
```sh
62-
cabal update
63-
cabal build all
62+
cabal update
63+
cabal build all
6464
```
6565
8. Create a config file. You can use `example-config.json` as a template.
6666

6767
9. Run project
68-
`sh
69-
cabal run vva-be -- --config <YOUR CONFIG FILE> start-app
70-
`
68+
```sh
69+
cabal run vva-be -- --config <YOUR CONFIG FILE> start-app
70+
```
7171
> [!WARNING]
7272
> In the context of our ongoing project enhancements, it is assumed that the executable previously known as 'vva-be' should be now officially renamed to 'govtool-backend'. This change is necessary for aligning with the updated branding and functional scope of the application and it has to be implemented in the near future as a chore and refactoring ticket. Make sure that the documentation matches the actual name of the executable.
7373

govtool/backend/app/Main.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ startApp vvaConfig sentryService = do
122122
dRepVotingPowerCache <- newCache
123123
dRepListCache <- newCache
124124
networkMetricsCache <- newCache
125+
networkInfoCache <- newCache
126+
networkTotalStakeCache <- newCache
125127
return $ CacheEnv
126128
{ proposalListCache
127129
, getProposalCache
@@ -133,6 +135,8 @@ startApp vvaConfig sentryService = do
133135
, dRepVotingPowerCache
134136
, dRepListCache
135137
, networkMetricsCache
138+
, networkInfoCache
139+
, networkTotalStakeCache
136140
}
137141

138142
let connectionString = encodeUtf8 (dbSyncConnectionString $ getter vvaConfig)
@@ -144,6 +148,7 @@ startApp vvaConfig sentryService = do
144148

145149
exceptionHandler :: VVAConfig -> SentryService -> Maybe Request -> SomeException -> IO ()
146150
exceptionHandler vvaConfig sentryService mRequest exception = do
151+
print exception
147152
let isNotTimeoutThread x = case fromException x of
148153
Just TimeoutThread -> False
149154
_ -> True
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SELECT
2+
(SELECT MAX(no) FROM epoch) AS current_epoch,
3+
(SELECT MAX(block_no) FROM block) AS current_block,
4+
network_name
5+
FROM
6+
meta;

govtool/backend/sql/get-network-metrics.sql

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,6 @@ TotalActiveCIP119CompliantDReps AS (
110110
AND lve.epoch_no >= (SELECT epoch_no FROM ActiveDRepBoundaryEpoch)
111111
)))
112112
),
113-
TotalStakeControlledByActiveDReps AS (
114-
SELECT
115-
COALESCE(SUM(dd.amount), 0)::bigint AS total
116-
FROM
117-
drep_hash dh
118-
LEFT JOIN DRepDistr dd ON dd.hash_id = dh.id AND dd.rn = 1
119-
LEFT JOIN RankedDRepRegistration rd ON dd.hash_id = rd.drep_hash_id AND rd.rn = 1
120-
LEFT JOIN LatestVoteEpoch lve ON lve.drep_id = dh.id
121-
CROSS JOIN DRepActivity
122-
WHERE
123-
dd.epoch_no = (SELECT no FROM CurrentEpoch)
124-
AND COALESCE(rd.deposit, 0) >= 0
125-
AND ((DRepActivity.epoch_no - GREATEST(COALESCE(lve.epoch_no, 0), COALESCE(rd.epoch_no, 0))) <= DRepActivity.drep_activity)
126-
),
127-
CurrentBlock AS (
128-
SELECT MAX(block_no) AS block_no FROM block
129-
),
130113
UniqueDelegators AS (
131114
SELECT COUNT(DISTINCT addr_id) AS count FROM delegation_vote
132115
),
@@ -139,9 +122,6 @@ TotalGovActionProposals AS (
139122
TotalDRepVotes AS (
140123
SELECT COUNT(*) AS count FROM voting_procedure WHERE voter_role = 'DRep'
141124
),
142-
TotalStakeControlledBySPOs AS (
143-
SELECT SUM(ps.stake)::bigint AS total FROM pool_stat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch)
144-
),
145125
LatestExistingVotingAnchor AS (
146126
SELECT
147127
subquery.drep_registration_id,
@@ -192,18 +172,6 @@ TotalRegisteredDirectVoters AS (
192172
LEFT JOIN HasNonDeregisterVotingAnchor hndva ON hndva.drep_hash_id = rdr.drep_hash_id
193173
WHERE rdr.rn = 1 AND COALESCE(rdr.deposit, 0) >= 0 AND (leva.url IS NULL OR hndva.value = true)
194174
),
195-
AlwaysAbstainVotingPower AS (
196-
SELECT COALESCE((SELECT amount FROM drep_hash
197-
LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id
198-
WHERE drep_hash.view = 'drep_always_abstain'
199-
ORDER BY epoch_no DESC LIMIT 1), 0) AS amount
200-
),
201-
AlwaysNoConfidenceVotingPower AS (
202-
SELECT COALESCE((SELECT amount FROM drep_hash
203-
LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id
204-
WHERE drep_hash.view = 'drep_always_no_confidence'
205-
ORDER BY epoch_no DESC LIMIT 1), 0) AS amount
206-
),
207175
TotalDRepDistr AS (
208176
SELECT SUM(COALESCE(amount, 0))::bigint total_drep_distr FROM drep_distr where epoch_no = (SELECT no from CurrentEpoch)
209177
),
@@ -223,42 +191,28 @@ CommitteeThreshold AS (
223191
OR (c.gov_action_proposal_id IS NULL)
224192
)
225193
SELECT
226-
CurrentEpoch.no AS epoch_no,
227-
CurrentBlock.block_no,
228194
UniqueDelegators.count AS unique_delegators,
229195
TotalDelegations.count AS total_delegations,
230196
TotalGovActionProposals.count AS total_gov_action_proposals,
231197
TotalDRepVotes.count AS total_drep_votes,
232198
TotalRegisteredDReps.unique_registrations AS total_registered_dreps,
233199
TotalDRepDistr.total_drep_distr,
234-
COALESCE(TotalStakeControlledByActiveDReps.total, 0) + COALESCE(AlwaysNoConfidenceVotingPower.amount, 0) AS total_stake_controlled_by_active_dreps,
235-
COALESCE(TotalStakeControlledBySPOs.total, 0) AS total_stake_controlled_by_spos,
236200
TotalActiveDReps.unique_active_drep_registrations AS total_active_dreps,
237201
TotalInactiveDReps.total_inactive_dreps AS total_inactive_dreps,
238202
TotalActiveCIP119CompliantDReps.unique_active_cip119_compliant_drep_registrations AS total_active_cip119_compliant_dreps,
239203
TotalRegisteredDirectVoters.unique_direct_voters AS total_registered_direct_voters,
240-
AlwaysAbstainVotingPower.amount AS always_abstain_voting_power,
241-
AlwaysNoConfidenceVotingPower.amount AS always_no_confidence_voting_power,
242-
meta.network_name,
243204
NoOfCommitteeMembers.total no_of_committee_members,
244205
CommitteeThreshold.quorum_numerator,
245206
CommitteeThreshold.quorum_denominator
246-
FROM CurrentEpoch
247-
CROSS JOIN CurrentBlock
248-
CROSS JOIN UniqueDelegators
207+
FROM UniqueDelegators
249208
CROSS JOIN TotalDRepDistr
250209
CROSS JOIN TotalDelegations
251210
CROSS JOIN TotalGovActionProposals
252211
CROSS JOIN TotalDRepVotes
253212
CROSS JOIN TotalRegisteredDReps
254-
CROSS JOIN TotalStakeControlledByActiveDReps
255-
CROSS JOIN TotalStakeControlledBySPOs
256213
CROSS JOIN TotalActiveDReps
257214
CROSS JOIN TotalInactiveDReps
258215
CROSS JOIN TotalActiveCIP119CompliantDReps
259216
CROSS JOIN TotalRegisteredDirectVoters
260-
CROSS JOIN AlwaysAbstainVotingPower
261-
CROSS JOIN AlwaysNoConfidenceVotingPower
262217
CROSS JOIN NoOfCommitteeMembers
263218
CROSS JOIN CommitteeThreshold
264-
CROSS JOIN meta;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
WITH DRepActivity AS (
2+
SELECT
3+
drep_activity AS drep_activity,
4+
epoch_no AS epoch_no
5+
FROM
6+
epoch_param
7+
WHERE
8+
epoch_no IS NOT NULL
9+
ORDER BY
10+
epoch_no DESC
11+
LIMIT 1
12+
),
13+
LatestVotingProcedure AS (
14+
SELECT
15+
vp.*,
16+
ROW_NUMBER() OVER (PARTITION BY drep_voter ORDER BY tx_id DESC) AS rn
17+
FROM
18+
voting_procedure vp
19+
),
20+
DRepDistr AS (
21+
SELECT
22+
drep_distr.*,
23+
ROW_NUMBER() OVER (PARTITION BY drep_hash.id ORDER BY drep_distr.epoch_no DESC) AS rn
24+
FROM
25+
drep_distr
26+
JOIN drep_hash ON drep_hash.id = drep_distr.hash_id
27+
),
28+
CurrentEpoch AS (
29+
SELECT MAX(no) AS no FROM epoch
30+
),
31+
LatestVoteEpoch AS (
32+
SELECT
33+
block.epoch_no,
34+
lvp.drep_voter AS drep_id
35+
FROM
36+
LatestVotingProcedure lvp
37+
JOIN tx ON tx.id = lvp.tx_id
38+
JOIN block ON block.id = tx.block_id
39+
WHERE
40+
lvp.rn = 1
41+
),
42+
RankedDRepRegistration AS (
43+
SELECT
44+
dr.id,
45+
dr.drep_hash_id,
46+
dr.deposit,
47+
dr.voting_anchor_id,
48+
ROW_NUMBER() OVER (PARTITION BY dr.drep_hash_id ORDER BY dr.tx_id DESC) AS rn,
49+
encode(tx.hash, 'hex') AS tx_hash,
50+
block.epoch_no
51+
FROM
52+
drep_registration dr
53+
JOIN tx ON tx.id = dr.tx_id
54+
JOIN block ON block.id = tx.block_id
55+
),
56+
TotalStakeControlledByActiveDReps AS (
57+
SELECT
58+
COALESCE(SUM(dd.amount), 0)::bigint AS total
59+
FROM
60+
drep_hash dh
61+
LEFT JOIN DRepDistr dd ON dd.hash_id = dh.id AND dd.rn = 1
62+
LEFT JOIN RankedDRepRegistration rd ON dd.hash_id = rd.drep_hash_id AND rd.rn = 1
63+
LEFT JOIN LatestVoteEpoch lve ON lve.drep_id = dh.id
64+
CROSS JOIN DRepActivity
65+
WHERE
66+
dd.epoch_no = (SELECT no FROM CurrentEpoch)
67+
AND COALESCE(rd.deposit, 0) >= 0
68+
AND ((DRepActivity.epoch_no - GREATEST(COALESCE(lve.epoch_no, 0), COALESCE(rd.epoch_no, 0))) <= DRepActivity.drep_activity)
69+
),
70+
TotalStakeControlledBySPOs AS (
71+
SELECT SUM(ps.stake)::bigint AS total FROM pool_stat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch)
72+
),
73+
AlwaysAbstainVotingPower AS (
74+
SELECT COALESCE((SELECT amount FROM drep_hash
75+
LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id
76+
WHERE drep_hash.view = 'drep_always_abstain'
77+
ORDER BY epoch_no DESC LIMIT 1), 0) AS amount
78+
),
79+
AlwaysNoConfidenceVotingPower AS (
80+
SELECT COALESCE((SELECT amount FROM drep_hash
81+
LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id
82+
WHERE drep_hash.view = 'drep_always_no_confidence'
83+
ORDER BY epoch_no DESC LIMIT 1), 0) AS amount
84+
)
85+
SELECT
86+
COALESCE(TotalStakeControlledByActiveDReps.total, 0) + COALESCE(AlwaysNoConfidenceVotingPower.amount, 0) AS total_stake_controlled_by_active_dreps,
87+
COALESCE(TotalStakeControlledBySPOs.total, 0) AS total_stake_controlled_by_spos,
88+
AlwaysAbstainVotingPower.amount AS always_abstain_voting_power,
89+
AlwaysNoConfidenceVotingPower.amount AS always_no_confidence_voting_power
90+
FROM TotalStakeControlledByActiveDReps
91+
LEFT JOIN TotalStakeControlledBySPOs ON TRUE
92+
LEFT JOIN AlwaysAbstainVotingPower ON TRUE
93+
LEFT JOIN AlwaysNoConfidenceVotingPower ON TRUE

govtool/backend/src/VVA/API.hs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type VVAApi =
7979
:<|> "transaction" :> "status" :> Capture "transactionId" HexText :> Get '[JSON] GetTransactionStatusResponse
8080
:<|> "throw500" :> Get '[JSON] ()
8181
:<|> "network" :> "metrics" :> Get '[JSON] GetNetworkMetricsResponse
82+
:<|> "network" :> "info" :> Get '[JSON] GetNetworkInfoResponse
83+
:<|> "network" :> "total-stake" :> Get '[JSON] GetNetworkTotalStakeResponse
84+
8285
server :: App m => ServerT VVAApi m
8386
server = drepList
8487
:<|> getVotingPower
@@ -92,7 +95,8 @@ server = drepList
9295
:<|> getTransactionStatus
9396
:<|> throw500
9497
:<|> getNetworkMetrics
95-
98+
:<|> getNetworkInfo
99+
:<|> getNetworkTotalStake
96100

97101
mapDRepType :: Types.DRepType -> DRepType
98102
mapDRepType Types.DRep = NormalDRep
@@ -428,29 +432,43 @@ getTransactionStatus (unHexText -> transactionId) = do
428432
throw500 :: App m => m ()
429433
throw500 = throwError $ CriticalError "intentional system break for testing purposes"
430434

435+
getNetworkInfo :: App m => m GetNetworkInfoResponse
436+
getNetworkInfo = do
437+
CacheEnv {networkInfoCache} <- asks vvaCache
438+
Types.NetworkInfo {..} <- Network.networkInfo
439+
return $ GetNetworkInfoResponse
440+
{ getNetworkInfoResponseCurrentTime = networkInfoCurrentTime
441+
, getNetworkInfoResponseEpochNo = networkInfoEpochNo
442+
, getNetworkInfoResponseBlockNo = networkInfoBlockNo
443+
, getNetworkInfoResponseNetworkName = networkInfoNetworkName
444+
}
445+
446+
getNetworkTotalStake :: App m => m GetNetworkTotalStakeResponse
447+
getNetworkTotalStake = do
448+
CacheEnv {networkTotalStakeCache} <- asks vvaCache
449+
Types.NetworkTotalStake {..} <- Network.networkTotalStake
450+
return $ GetNetworkTotalStakeResponse
451+
{ getNetworkTotalStakeResponseTotalStakeControlledByDReps = networkTotalStakeControlledByDReps
452+
, getNetworkTotalStakeResponseTotalStakeControlledBySPOs = networkTotalStakeControlledBySPOs
453+
, getNetworkTotalStakeResponseAlwaysAbstainVotingPower = networkTotalAlwaysAbstainVotingPower
454+
, getNetworkTotalStakeResponseAlwaysNoConfidenceVotingPower = networkTotalAlwaysNoConfidenceVotingPower
455+
}
456+
431457
getNetworkMetrics :: App m => m GetNetworkMetricsResponse
432458
getNetworkMetrics = do
433459
CacheEnv {networkMetricsCache} <- asks vvaCache
434460
Types.NetworkMetrics {..} <- Network.networkMetrics
435461
return $ GetNetworkMetricsResponse
436-
{ getNetworkMetricsResponseCurrentTime = networkMetricsCurrentTime
437-
, getNetworkMetricsResponseCurrentEpoch = networkMetricsCurrentEpoch
438-
, getNetworkMetricsResponseCurrentBlock = networkMetricsCurrentBlock
439-
, getNetworkMetricsResponseUniqueDelegators = networkMetricsUniqueDelegators
462+
{ getNetworkMetricsResponseUniqueDelegators = networkMetricsUniqueDelegators
440463
, getNetworkMetricsResponseTotalDelegations = networkMetricsTotalDelegations
441464
, getNetworkMetricsResponseTotalGovernanceActions = networkMetricsTotalGovernanceActions
442465
, getNetworkMetricsResponseTotalDRepVotes = networkMetricsTotalDRepVotes
443466
, getNetworkMetricsResponseTotalRegisteredDReps = networkMetricsTotalRegisteredDReps
444467
, getNetworkMetricsResponseTotalDRepDistr = networkMetricsTotalDRepDistr
445-
, getNetworkMetricsResponseTotalStakeControlledByDReps = networkMetricsTotalStakeControlledByDReps
446-
, getNetworkMetricsResponseTotalStakeControlledBySPOs = networkMetricsTotalStakeControlledBySPOs
447468
, getNetworkMetricsResponseTotalActiveDReps = networkMetricsTotalActiveDReps
448469
, getNetworkMetricsResponseTotalInactiveDReps = networkMetricsTotalInactiveDReps
449470
, getNetworkMetricsResponseTotalActiveCIP119CompliantDReps = networkMetricsTotalActiveCIP119CompliantDReps
450471
, getNetworkMetricsResponseTotalRegisteredDirectVoters = networkMetricsTotalRegisteredDirectVoters
451-
, getNetworkMetricsResponseAlwaysAbstainVotingPower = networkMetricsAlwaysAbstainVotingPower
452-
, getNetworkMetricsResponseAlwaysNoConfidenceVotingPower = networkMetricsAlwaysNoConfidenceVotingPower
453-
, getNetworkMetricsResponseNetworkName = networkMetricsNetworkName
454472
, getNetworkMetricsResponseNoOfCommitteeMembers = networkMetricsNoOfCommitteeMembers
455473
, getNetworkMetricsResponseQuorumNumerator = networkMetricsQuorumNumerator
456474
, getNetworkMetricsResponseQuorumDenominator = networkMetricsQuorumDenominator

0 commit comments

Comments
 (0)