Skip to content

Commit

Permalink
fix: penalty calculation for active_slashed (#160)
Browse files Browse the repository at this point in the history
* fix: penalty calculation for `active_slashed`

* fix: att_inc_delay
  • Loading branch information
vgorkavenko committed Apr 14, 2023
1 parent 006ec38 commit 46be064
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/duty/attestation/attestation.rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ export class AttestationRewards {
let att_earned_reward = 0;
let att_missed_reward = 0;
let att_penalty = 0;
if (v.val_slashed) {
// If validator is slashed, we calculate it as if it missed attestation
// And set their attestation data to undefined, because there is no sense to consider attestation from slashed validator
pv.att_happened = undefined;
pv.att_inc_delay = undefined;
pv.att_valid_source = undefined;
pv.att_valid_target = undefined;
pv.att_valid_head = undefined;
}
const rewards = getRewards({ source: pv.att_valid_source, target: pv.att_valid_target, head: pv.att_valid_head });
const penalties = getPenalties({ source: pv.att_valid_source, target: pv.att_valid_target, head: pv.att_valid_head });
const rewardSource = Math.trunc(rewards.source * epochMeta.state.base_reward * increments * sourceParticipation);
Expand Down
4 changes: 2 additions & 2 deletions src/storage/clickhouse/clickhouse.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const validatorsCountWithNegativeDeltaQuery = (epoch: Epoch): string => `
current.val_nos_id as val_nos_id,
count(current.val_id) AS amount
FROM (
SELECT val_balance, val_id, val_nos_id
SELECT val_balance, val_id, val_nos_id, val_slashed
FROM validators_summary
WHERE
val_status != '${ValStatus.PendingQueued}' AND
Expand Down Expand Up @@ -128,7 +128,7 @@ export const validatorsCountWithNegativeDeltaQuery = (epoch: Epoch): string => `
ON
withdrawals.val_id = current.val_id
GROUP BY current.val_nos_id
HAVING (current.val_balance - previous.val_balance + ifNull(withdrawals.withdrawn, 0)) < 0
HAVING (current.val_balance - previous.val_balance + ifNull(withdrawals.withdrawn, 0)) < 0 AND current.val_slashed = 0
`;

export const validatorsCountWithSyncParticipationByConditionLastNEpochQuery = (
Expand Down

0 comments on commit 46be064

Please sign in to comment.