Skip to content

Commit

Permalink
cleanup as per specs feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed May 7, 2024
1 parent a5b5fe0 commit 93fabdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/state-transition/src/block/processConsolidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function assertValidConsolidation(
}

// Verify the same withdrawal address
const sourceWithdrawalAddress = toHexString(sourceValidator.withdrawalCredentials.slice(12));
const targetWithdrawalAddress = toHexString(targetValidator.withdrawalCredentials.slice(12));
const sourceWithdrawalAddress = toHexString(sourceValidator.withdrawalCredentials.subarray(12));
const targetWithdrawalAddress = toHexString(targetValidator.withdrawalCredentials.subarray(12));

if (sourceWithdrawalAddress !== targetWithdrawalAddress) {
throw new Error(
Expand Down
21 changes: 9 additions & 12 deletions packages/state-transition/src/util/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,14 @@ export function getActivationChurnLimit(config: ChainForkConfig, fork: ForkSeq,
}
}

export function getActivationExitChurnLimit(state: CachedBeaconStateElectra): number {
return Math.min(
state.config.MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT,
getActivationExitConsolidationChurnLimit(state)
);
}

export function getConsolidationChurnLimit(state: CachedBeaconStateElectra): number {
return getActivationExitConsolidationChurnLimit(state) - getActivationExitChurnLimit(state);
export function getChurnLimit(config: ChainForkConfig, activeValidatorCount: number): number {
return Math.max(config.MIN_PER_EPOCH_CHURN_LIMIT, intDiv(activeValidatorCount, config.CHURN_LIMIT_QUOTIENT));
}

/**
* Get combined churn limit of activation-exit and consolidation
*/
export function getActivationExitConsolidationChurnLimit(state: CachedBeaconStateElectra): number {
export function getBalanceChurnLimit(state: CachedBeaconStateElectra): number {
const churnLimitByTotalActiveBalance = Math.floor(
(state.epochCtx.totalActiveBalanceIncrements / state.config.CHURN_LIMIT_QUOTIENT) * EFFECTIVE_BALANCE_INCREMENT
); // TODO Electra: verify calculation
Expand All @@ -74,8 +67,12 @@ export function getActivationExitConsolidationChurnLimit(state: CachedBeaconStat
return churn - (churn % EFFECTIVE_BALANCE_INCREMENT);
}

export function getChurnLimit(config: ChainForkConfig, activeValidatorCount: number): number {
return Math.max(config.MIN_PER_EPOCH_CHURN_LIMIT, intDiv(activeValidatorCount, config.CHURN_LIMIT_QUOTIENT));
export function getActivationExitChurnLimit(state: CachedBeaconStateElectra): number {
return Math.min(state.config.MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT, getBalanceChurnLimit(state));
}

export function getConsolidationChurnLimit(state: CachedBeaconStateElectra): number {
return getBalanceChurnLimit(state) - getActivationExitChurnLimit(state);
}

export function getValidatorMaxEffectiveBalance(withdrawalCredentials: Uint8Array): number {
Expand Down

0 comments on commit 93fabdc

Please sign in to comment.