Skip to content

Commit

Permalink
Merge pull request #2716 from IntersectMBO/staging
Browse files Browse the repository at this point in the history
hotfix: handle type mismatch between haskell and sql result
  • Loading branch information
MSzalowski authored Jan 24, 2025
2 parents 4f91b0b + 37d5e68 commit 2234144
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ changes.

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

### Changed

Expand Down
15 changes: 8 additions & 7 deletions govtool/backend/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ startApp vvaConfig sentryService = do

exceptionHandler :: VVAConfig -> SentryService -> Maybe Request -> SomeException -> IO ()
exceptionHandler vvaConfig sentryService mRequest exception = do
print exception
-- These are not considered application errors
-- They represent the client closing the connection prematurely
-- or the timeout thread being killed by WARP
let isNotTimeoutThread x = case fromException x of
Just TimeoutThread -> False
_ -> True
Expand All @@ -160,13 +156,18 @@ exceptionHandler vvaConfig sentryService mRequest exception = do
Nothing -> True
isNotThreadKilledByTimeoutManager x =
"Thread killed by timeout manager" `notElem` lines (show x)
shouldSkipError =
isNotUserErrorMzero x = case fromException x of
Just ioe -> not ("user error (mzero)" `isInfixOf` show (ioe :: IOException))
_ -> True

isGuardException =
isNotTimeoutThread exception &&
isNotConnectionClosedByPeer exception &&
isNotClientClosedConnection exception &&
isNotThreadKilledByTimeoutManager exception
isNotThreadKilledByTimeoutManager exception &&
isNotUserErrorMzero exception

guard shouldSkipError
guard isGuardException

let env = sentryEnv vvaConfig
case mRequest of
Expand Down
49 changes: 41 additions & 8 deletions govtool/backend/sql/get-stake-key-voting-power.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
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(SUM(tx_out.value), 0) AS voting_power,
stake_address.id as addr_id
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
b.addr_raw::text AS stake_address
FROM
stake_address
JOIN
tx_out on tx_out.stake_address_id = stake_address.id
Balance b
LEFT JOIN
tx_in ON tx_in.tx_out_id = tx_out.id AND tx_in.tx_out_index = tx_out.index
RewardRest rr ON rr.addr_id = b.addr_id
LEFT JOIN
Reward r ON r.addr_id = rr.addr_id
WHERE
stake_address.hash_raw = decode(?, 'hex') AND tx_in.id IS NULL
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
GROUP BY
stake_address.id;
b.addr_raw,
rr.amount,
r.amount,
b.amount
2 changes: 1 addition & 1 deletion govtool/backend/src/VVA/AdaHolder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ getStakeKeyVotingPower ::
Text ->
m Integer
getStakeKeyVotingPower stakeKey = withPool $ \conn -> do
result <- liftIO $ SQL.query @_ @(Scientific, Text) conn getVotingPowerSql (SQL.Only stakeKey)
result <- liftIO $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey)
case result of
[(votingPower,_)] -> return $ floor votingPower
_ -> do
Expand Down

0 comments on commit 2234144

Please sign in to comment.