Skip to content

Commit

Permalink
fix: withdrawal status (#147)
Browse files Browse the repository at this point in the history
* fix: withdrawal status

* fix: group by
  • Loading branch information
vgorkavenko committed Apr 5, 2023
1 parent 7a53c8c commit f6806db
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions src/storage/clickhouse/clickhouse.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,26 @@ export const userNodeOperatorsStatsQuery = (epoch: Epoch): string => `
IF(val_status = '${ValStatus.ActiveOngoing}', count(val_status), 0) as a,
IF(val_status = '${ValStatus.PendingQueued}' OR val_status = '${ValStatus.PendingInitialized}', count(val_status), 0) as p,
IF(val_status = '${ValStatus.ActiveSlashed}' OR val_status = '${ValStatus.ExitedSlashed}' OR val_slashed = 1, count(val_status), 0) as s,
IF(val_status in ['${ValStatus.ActiveExiting}','${ValStatus.ExitedUnslashed}', '${ValStatus.ExitedSlashed}'], count(val_status), 0) as wp,
IF(val_status in ['${ValStatus.WithdrawalPossible}', '${ValStatus.WithdrawalDone}'], count(val_status), 0) as w
IF(
(val_status in ['${ValStatus.ActiveExiting}','${ValStatus.ExitedUnslashed}', '${ValStatus.ExitedSlashed}'])
OR
(val_status == '${ValStatus.WithdrawalPossible}' AND val_balance != 0),
count(val_status), 0
) as wp,
IF(
(val_status == '${ValStatus.WithdrawalDone}')
OR
(val_status == '${ValStatus.WithdrawalPossible}' AND val_balance == 0),
count(val_status), 0
) as w
FROM (
SELECT val_nos_id, val_status, val_slashed
SELECT val_nos_id, val_status, val_slashed, val_balance
FROM validators_summary
WHERE
val_nos_id IS NOT NULL and epoch = ${epoch}
LIMIT 1 BY val_id
)
GROUP BY val_nos_id, val_status, val_slashed
GROUP BY val_nos_id, val_status, val_slashed, val_balance
)
GROUP by val_nos_id
`;
Expand All @@ -419,16 +429,26 @@ export const userValidatorsSummaryStatsQuery = (epoch: Epoch): string => `
IF(val_status = '${ValStatus.ActiveOngoing}', count(val_status), 0) as a,
IF(val_status = '${ValStatus.PendingQueued}' OR val_status = '${ValStatus.PendingInitialized}', count(val_status), 0) as p,
IF(val_status = '${ValStatus.ActiveSlashed}' OR val_status = '${ValStatus.ExitedSlashed}' OR val_slashed = 1, count(val_status), 0) as s,
IF(val_status in ['${ValStatus.ActiveExiting}', '${ValStatus.ExitedUnslashed}', '${ValStatus.ExitedSlashed}'], count(val_status), 0) as wp,
IF(val_status in ['${ValStatus.WithdrawalPossible}', '${ValStatus.WithdrawalDone}'], count(val_status), 0) as w
IF(
(val_status in ['${ValStatus.ActiveExiting}','${ValStatus.ExitedUnslashed}', '${ValStatus.ExitedSlashed}'])
OR
(val_status == '${ValStatus.WithdrawalPossible}' AND val_balance != 0),
count(val_status), 0
) as wp,
IF(
(val_status == '${ValStatus.WithdrawalDone}')
OR
(val_status == '${ValStatus.WithdrawalPossible}' AND val_balance == 0),
count(val_status), 0
) as w
FROM (
SELECT val_status, val_slashed
SELECT val_status, val_slashed, val_balance
FROM validators_summary
WHERE
val_nos_id IS NOT NULL and epoch = ${epoch}
LIMIT 1 BY val_id
)
GROUP BY val_status, val_slashed
GROUP BY val_status, val_slashed, val_balance
)
`;

Expand All @@ -444,16 +464,26 @@ export const otherValidatorsSummaryStatsQuery = (epoch: Epoch): string => `
IF(val_status = '${ValStatus.ActiveOngoing}', count(val_status), 0) as a,
IF(val_status = '${ValStatus.PendingQueued}' OR val_status = '${ValStatus.PendingInitialized}', count(val_status), 0) as p,
IF(val_status = '${ValStatus.ActiveSlashed}' OR val_status = '${ValStatus.ExitedSlashed}' OR val_slashed = 1, count(val_status), 0) as s,
IF(val_status in ['${ValStatus.ActiveExiting}', '${ValStatus.ExitedUnslashed}', '${ValStatus.ExitedSlashed}'], count(val_status), 0) as wp,
IF(val_status in ['${ValStatus.WithdrawalPossible}', '${ValStatus.WithdrawalDone}'], count(val_status), 0) as w
IF(
(val_status in ['${ValStatus.ActiveExiting}','${ValStatus.ExitedUnslashed}', '${ValStatus.ExitedSlashed}'])
OR
(val_status == '${ValStatus.WithdrawalPossible}' AND val_balance != 0),
count(val_status), 0
) as wp,
IF(
(val_status == '${ValStatus.WithdrawalDone}')
OR
(val_status == '${ValStatus.WithdrawalPossible}' AND val_balance == 0),
count(val_status), 0
) as w
FROM (
SELECT val_status, val_slashed
SELECT val_status, val_slashed, val_balance
FROM validators_summary
WHERE
val_nos_id IS NULL and epoch = ${epoch}
LIMIT 1 BY val_id
)
GROUP BY val_status, val_slashed
GROUP BY val_status, val_slashed, val_balance
)
`;

Expand Down Expand Up @@ -647,33 +677,33 @@ export const userNodeOperatorsWithdrawalsStats = (epoch: Epoch): string => `
ifNull(
sumIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance = 0
val_balance_withdrawn > 0 AND val_balance == 0
),
0
) as full_withdrawn_sum,
ifNull(
sumIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance >= 32000000000 AND val_effective_balance = 32000000000
val_balance_withdrawn > 0 AND val_balance != 0
),
0
) as partial_withdrawn_sum,
ifNull(
countIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance = 0
val_balance_withdrawn > 0 AND val_balance == 0
),
0
) as full_withdrawn_count,
ifNull(
countIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance >= 32000000000 AND val_effective_balance = 32000000000
val_balance_withdrawn > 0 AND val_balance != 0
),
0
) as partial_withdrawn_count
FROM (
SELECT val_balance_withdrawn, val_effective_balance, val_balance, val_id, val_nos_id
SELECT val_balance_withdrawn, val_balance, val_id, val_nos_id
FROM validators_summary
WHERE
val_nos_id IS NOT NULL AND
Expand All @@ -688,33 +718,33 @@ export const otherChainWithdrawalsStats = (epoch: Epoch): string => `
ifNull(
sumIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance = 0
val_balance_withdrawn > 0 AND val_balance == 0
),
0
) as full_withdrawn_sum,
ifNull(
sumIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance >= 32000000000 AND val_effective_balance = 32000000000
val_balance_withdrawn > 0 AND val_balance != 0
),
0
) as partial_withdrawn_sum,
ifNull(
countIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance = 0
val_balance_withdrawn > 0 AND val_balance == 0
),
0
) as full_withdrawn_count,
ifNull(
countIf(
val_balance_withdrawn,
val_balance_withdrawn > 0 AND val_balance >= 32000000000 AND val_effective_balance = 32000000000
val_balance_withdrawn > 0 AND val_balance != 0
),
0
) as partial_withdrawn_count
FROM (
SELECT val_balance_withdrawn, val_effective_balance, val_balance, val_id, val_nos_id
SELECT val_balance_withdrawn, val_balance, val_id, val_nos_id
FROM validators_summary
WHERE
val_nos_id IS NULL AND
Expand Down

0 comments on commit f6806db

Please sign in to comment.