Skip to content

Commit e7be184

Browse files
ensi321philknows
authored andcommitted
feat: update correlation penalty computation (#7071)
* Update slashing calculation to be more aligned with spec style * Update calculation * Lint * Fix rounding issue * Update calculation * Enable slashing spec test * lint
1 parent 21a7d3b commit e7be184

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/beacon-node/test/spec/utils/specTestIterator.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ export const defaultSkipOpts: SkipOpts = {
6666
/^capella\/light_client\/single_merkle_proof\/BeaconBlockBody.*/,
6767
/^deneb\/light_client\/single_merkle_proof\/BeaconBlockBody.*/,
6868
/^electra\/light_client\/single_merkle_proof\/BeaconBlockBody.*/,
69-
// TODO Electra: slashings tests to be enabled in PR#7071
70-
/^electra\/epoch_processing\/slashings.*/,
7169
],
7270
skippedTests: [],
7371
skippedRunners: ["merkle_proof", "networking"],

packages/state-transition/src/epoch/processSlashings.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ export function processSlashings(
5050
totalBalanceByIncrement
5151
);
5252
const increment = EFFECTIVE_BALANCE_INCREMENT;
53+
54+
const penaltyPerEffectiveBalanceIncrement = Math.floor(
55+
(adjustedTotalSlashingBalanceByIncrement * increment) / totalBalanceByIncrement
56+
);
5357
const penalties: number[] = [];
5458

5559
const penaltiesByEffectiveBalanceIncrement = new Map<number, number>();
5660
for (const index of cache.indicesToSlash) {
5761
const effectiveBalanceIncrement = effectiveBalanceIncrements[index];
5862
let penalty = penaltiesByEffectiveBalanceIncrement.get(effectiveBalanceIncrement);
5963
if (penalty === undefined) {
60-
const penaltyNumeratorByIncrement = effectiveBalanceIncrement * adjustedTotalSlashingBalanceByIncrement;
61-
penalty = Math.floor(penaltyNumeratorByIncrement / totalBalanceByIncrement) * increment;
64+
if (fork < ForkSeq.electra) {
65+
const penaltyNumeratorByIncrement = effectiveBalanceIncrement * adjustedTotalSlashingBalanceByIncrement;
66+
penalty = Math.floor(penaltyNumeratorByIncrement / totalBalanceByIncrement) * increment;
67+
} else {
68+
penalty = penaltyPerEffectiveBalanceIncrement * effectiveBalanceIncrement;
69+
}
6270
penaltiesByEffectiveBalanceIncrement.set(effectiveBalanceIncrement, penalty);
6371
}
6472

0 commit comments

Comments
 (0)