Skip to content

Commit 2e40c39

Browse files
authored
Merge pull request #2717 from IntersectMBO/test
hotfix: handle type mismatch between haskell and sql result
2 parents d4d370b + 2234144 commit 2e40c39

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ changes.
3838

3939
- Fix usage of trim on missing label
4040
- Fix blank screen when registering as a DRep [Issue 2408](https://github.com/IntersectMBO/govtool/issues/2408)
41+
- Fix type mismatch between sql and haskell code for stake key address
4142

4243
### Changed
4344

govtool/backend/app/Main.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ startApp vvaConfig sentryService = do
144144

145145
exceptionHandler :: VVAConfig -> SentryService -> Maybe Request -> SomeException -> IO ()
146146
exceptionHandler vvaConfig sentryService mRequest exception = do
147-
print exception
148-
-- These are not considered application errors
149-
-- They represent the client closing the connection prematurely
150-
-- or the timeout thread being killed by WARP
151147
let isNotTimeoutThread x = case fromException x of
152148
Just TimeoutThread -> False
153149
_ -> True
@@ -160,13 +156,18 @@ exceptionHandler vvaConfig sentryService mRequest exception = do
160156
Nothing -> True
161157
isNotThreadKilledByTimeoutManager x =
162158
"Thread killed by timeout manager" `notElem` lines (show x)
163-
shouldSkipError =
159+
isNotUserErrorMzero x = case fromException x of
160+
Just ioe -> not ("user error (mzero)" `isInfixOf` show (ioe :: IOException))
161+
_ -> True
162+
163+
isGuardException =
164164
isNotTimeoutThread exception &&
165165
isNotConnectionClosedByPeer exception &&
166166
isNotClientClosedConnection exception &&
167-
isNotThreadKilledByTimeoutManager exception
167+
isNotThreadKilledByTimeoutManager exception &&
168+
isNotUserErrorMzero exception
168169

169-
guard shouldSkipError
170+
guard isGuardException
170171

171172
let env = sentryEnv vvaConfig
172173
case mRequest of
Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
1+
WITH RewardRest AS (
2+
SELECT
3+
SUM(amount) AS amount,
4+
addr_id
5+
FROM
6+
reward_rest
7+
GROUP BY
8+
addr_id
9+
),
10+
Reward AS (
11+
SELECT
12+
SUM(amount) AS amount,
13+
addr_id
14+
FROM
15+
reward
16+
GROUP BY
17+
addr_id
18+
),
19+
Balance AS (
20+
SELECT
21+
COALESCE(SUM(uv.value), 0) AS amount,
22+
sa.id AS addr_id,
23+
encode(sa.hash_raw, 'hex') AS addr_raw
24+
FROM
25+
stake_address sa
26+
JOIN utxo_view uv ON uv.stake_address_id = sa.id
27+
GROUP BY
28+
addr_id,
29+
addr_raw
30+
)
131
SELECT
2-
COALESCE(SUM(tx_out.value), 0) AS voting_power,
3-
stake_address.id as addr_id
32+
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
33+
b.addr_raw::text AS stake_address
434
FROM
5-
stake_address
6-
JOIN
7-
tx_out on tx_out.stake_address_id = stake_address.id
35+
Balance b
836
LEFT JOIN
9-
tx_in ON tx_in.tx_out_id = tx_out.id AND tx_in.tx_out_index = tx_out.index
37+
RewardRest rr ON rr.addr_id = b.addr_id
38+
LEFT JOIN
39+
Reward r ON r.addr_id = rr.addr_id
1040
WHERE
11-
stake_address.hash_raw = decode(?, 'hex') AND tx_in.id IS NULL
41+
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
1242
GROUP BY
13-
stake_address.id;
43+
b.addr_raw,
44+
rr.amount,
45+
r.amount,
46+
b.amount

govtool/backend/src/VVA/AdaHolder.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ getStakeKeyVotingPower ::
5151
Text ->
5252
m Integer
5353
getStakeKeyVotingPower stakeKey = withPool $ \conn -> do
54-
result <- liftIO $ SQL.query @_ @(Scientific, Text) conn getVotingPowerSql (SQL.Only stakeKey)
54+
result <- liftIO $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey)
5555
case result of
5656
[(votingPower,_)] -> return $ floor votingPower
5757
_ -> do

0 commit comments

Comments
 (0)