Skip to content

Commit

Permalink
feat: implement eip7514 to limit the validatior activation limit dene…
Browse files Browse the repository at this point in the history
…b onwards
  • Loading branch information
g11tech committed Sep 18, 2023
1 parent 8794025 commit 7903820
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/config/src/chainConfig/presets/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const chainConfig: ChainConfig = {
MIN_PER_EPOCH_CHURN_LIMIT: 4,
// 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536,
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8,
PROPOSER_SCORE_BOOST: 40,

// Deposit contract
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/chainConfig/presets/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const chainConfig: ChainConfig = {
MIN_PER_EPOCH_CHURN_LIMIT: 4,
// [customized] scale queue churn at much lower validator counts for testing
CHURN_LIMIT_QUOTIENT: 32,
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: 8,
PROPOSER_SCORE_BOOST: 40,

// Deposit contract
Expand Down
2 changes: 2 additions & 0 deletions packages/config/src/chainConfig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type ChainConfig = {
EJECTION_BALANCE: number;
MIN_PER_EPOCH_CHURN_LIMIT: number;
CHURN_LIMIT_QUOTIENT: number;
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: number;

// Proposer boost
PROPOSER_SCORE_BOOST: number;
Expand Down Expand Up @@ -106,6 +107,7 @@ export const chainConfigTypes: SpecTypes<ChainConfig> = {
EJECTION_BALANCE: "number",
MIN_PER_EPOCH_CHURN_LIMIT: "number",
CHURN_LIMIT_QUOTIENT: "number",
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: "number",

// Proposer boost
PROPOSER_SCORE_BOOST: "number",
Expand Down
16 changes: 15 additions & 1 deletion packages/state-transition/src/cache/epochCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export class EpochCache {
* change through the epoch. It's used in initiateValidatorExit(). Must be update after changing active indexes.
*/
churnLimit: number;
/**
* Modified ("limited") churn limit as per the fork dependent activation of EIP-7514
*/
activationChurnLimit: number;
/**
* Closest epoch with available churn for validators to exit at. May be updated every block as validators are
* initiateValidatorExit(). This value may vary on each fork of the state.
Expand Down Expand Up @@ -213,6 +217,7 @@ export class EpochCache {
epoch: Epoch;
syncPeriod: SyncPeriod;
}) {
this.epoch = data.epoch;
this.config = data.config;
this.pubkey2index = data.pubkey2index;
this.index2pubkey = data.index2pubkey;
Expand All @@ -227,14 +232,19 @@ export class EpochCache {
this.syncProposerReward = data.syncProposerReward;
this.baseRewardPerIncrement = data.baseRewardPerIncrement;
this.totalActiveBalanceIncrements = data.totalActiveBalanceIncrements;

this.churnLimit = data.churnLimit;
this.activationChurnLimit =
this.epoch >= this.config.DENEB_FORK_EPOCH
? Math.min(this.config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT, this.churnLimit)
: this.churnLimit;

this.exitQueueEpoch = data.exitQueueEpoch;
this.exitQueueChurn = data.exitQueueChurn;
this.currentTargetUnslashedBalanceIncrements = data.currentTargetUnslashedBalanceIncrements;
this.previousTargetUnslashedBalanceIncrements = data.previousTargetUnslashedBalanceIncrements;
this.currentSyncCommitteeIndexed = data.currentSyncCommitteeIndexed;
this.nextSyncCommitteeIndexed = data.nextSyncCommitteeIndexed;
this.epoch = data.epoch;
this.syncPeriod = data.syncPeriod;
}

Expand Down Expand Up @@ -503,6 +513,10 @@ export class EpochCache {
// the first block of the epoch process_block() call. So churnLimit must be computed at the end of the before epoch
// transition and the result is valid until the end of the next epoch transition
this.churnLimit = getChurnLimit(this.config, this.currentShuffling.activeIndices.length);
this.activationChurnLimit =
this.config.DENEB_FORK_EPOCH >= this.epoch
? Math.min(this.config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT, this.churnLimit)
: this.churnLimit;

// Maybe advance exitQueueEpoch at the end of the epoch if there haven't been any exists for a while
const exitQueueEpoch = computeActivationExitEpoch(currEpoch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function processRegistryUpdates(state: CachedBeaconStateAllForks, cache:

const finalityEpoch = state.finalizedCheckpoint.epoch;
// dequeue validators for activation up to churn limit
for (const index of cache.indicesEligibleForActivation.slice(0, epochCtx.churnLimit)) {
// - use fork dependent churn limit for activation (EIP-7514)
for (const index of cache.indicesEligibleForActivation.slice(0, epochCtx.activationChurnLimit)) {
const validator = validators.get(index);
// placement in queue is finalized
if (validator.activationEligibilityEpoch > finalityEpoch) {
Expand Down
5 changes: 5 additions & 0 deletions packages/state-transition/src/util/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ export function getActiveValidatorIndices(state: BeaconStateAllForks, epoch: Epo
export function getChurnLimit(config: ChainForkConfig, activeValidatorCount: number): number {
return Math.max(config.MIN_PER_EPOCH_CHURN_LIMIT, intDiv(activeValidatorCount, config.CHURN_LIMIT_QUOTIENT));
}

// Just for completeness sake, epochCtx directly uses churnLimit to get the final churn limit
export function getctivationChurnLimit(config: ChainForkConfig, activeValidatorCount: number): number {
return Math.min(config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT, getChurnLimit(config, activeValidatorCount));
}
1 change: 1 addition & 0 deletions packages/validator/src/util/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function getSpecCriticalParams(localConfig: ChainConfig): Record<keyof ConfigWit
EJECTION_BALANCE: true,
MIN_PER_EPOCH_CHURN_LIMIT: true,
CHURN_LIMIT_QUOTIENT: true,
MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: denebForkRelevant,

// Proposer boost
PROPOSER_SCORE_BOOST: false, // Ignored as it's changing https://github.com/ethereum/consensus-specs/pull/2895
Expand Down

0 comments on commit 7903820

Please sign in to comment.