Skip to content

Commit

Permalink
feat: update correlation penalty computation (#7071)
Browse files Browse the repository at this point in the history
* Update slashing calculation to be more aligned with spec style

* Update calculation

* Lint

* Fix rounding issue

* Update calculation

* Enable slashing spec test

* lint
  • Loading branch information
ensi321 committed Sep 30, 2024
1 parent 13d1a37 commit d69d809
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions packages/beacon-node/test/spec/utils/specTestIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export const defaultSkipOpts: SkipOpts = {
/^capella\/light_client\/single_merkle_proof\/BeaconBlockBody.*/,
/^deneb\/light_client\/single_merkle_proof\/BeaconBlockBody.*/,
/^electra\/light_client\/single_merkle_proof\/BeaconBlockBody.*/,
// TODO Electra: slashings tests to be enabled in PR#7071
/^electra\/epoch_processing\/slashings.*/,
],
skippedTests: [],
skippedRunners: ["merkle_proof", "networking"],
Expand Down
12 changes: 10 additions & 2 deletions packages/state-transition/src/epoch/processSlashings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,23 @@ export function processSlashings(
totalBalanceByIncrement
);
const increment = EFFECTIVE_BALANCE_INCREMENT;

const penaltyPerEffectiveBalanceIncrement = Math.floor(
(adjustedTotalSlashingBalanceByIncrement * increment) / totalBalanceByIncrement
);
const penalties: number[] = [];

const penaltiesByEffectiveBalanceIncrement = new Map<number, number>();
for (const index of cache.indicesToSlash) {
const effectiveBalanceIncrement = effectiveBalanceIncrements[index];
let penalty = penaltiesByEffectiveBalanceIncrement.get(effectiveBalanceIncrement);
if (penalty === undefined) {
const penaltyNumeratorByIncrement = effectiveBalanceIncrement * adjustedTotalSlashingBalanceByIncrement;
penalty = Math.floor(penaltyNumeratorByIncrement / totalBalanceByIncrement) * increment;
if (fork < ForkSeq.electra) {
const penaltyNumeratorByIncrement = effectiveBalanceIncrement * adjustedTotalSlashingBalanceByIncrement;
penalty = Math.floor(penaltyNumeratorByIncrement / totalBalanceByIncrement) * increment;
} else {
penalty = penaltyPerEffectiveBalanceIncrement * effectiveBalanceIncrement;
}
penaltiesByEffectiveBalanceIncrement.set(effectiveBalanceIncrement, penalty);
}

Expand Down

0 comments on commit d69d809

Please sign in to comment.