|
| 1 | +Limit churn -- The Beacon Chain |
| 2 | + |
| 3 | +## Table of contents |
| 4 | + |
| 5 | +<!-- TOC --> |
| 6 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 7 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 8 | + |
| 9 | +- [Introduction](#introduction) |
| 10 | +- [Configuration](#configuration) |
| 11 | + - [Validator cycle](#validator-cycle) |
| 12 | +- [Helper functions](#helper-functions) |
| 13 | + - [Beacon state accessors](#beacon-state-accessors) |
| 14 | + - [New `get_validator_inbound_churn_limit`](#new-get_validator_inbound_churn_limit) |
| 15 | +- [Beacon chain state transition function](#beacon-chain-state-transition-function) |
| 16 | + - [Epoch processing](#epoch-processing) |
| 17 | + - [Registry updates](#registry-updates) |
| 18 | + |
| 19 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 20 | +<!-- /TOC --> |
| 21 | + |
| 22 | +## Introduction |
| 23 | + |
| 24 | +This is the beacon chain specification to limit the max inbound churn value, motivated to limit the validator active set growth rate. |
| 25 | + |
| 26 | +*Note:* This specification is built upon [Capella](../../capella/beacon_chain.md) and is under active development. |
| 27 | + |
| 28 | +## Configuration |
| 29 | + |
| 30 | +### Validator cycle |
| 31 | + |
| 32 | +| Name | Value | |
| 33 | +| - | - | |
| 34 | +| `MAX_PER_EPOCH_INBOUND_CHURN_LIMIT` | `uint64(12)` (= 12) | |
| 35 | + |
| 36 | +## Helper functions |
| 37 | + |
| 38 | +### Beacon state accessors |
| 39 | + |
| 40 | +#### New `get_validator_inbound_churn_limit` |
| 41 | + |
| 42 | +```python |
| 43 | +def get_validator_inbound_churn_limit(state: BeaconState) -> uint64: |
| 44 | + """ |
| 45 | + Return the validator inbound churn limit for the current epoch. |
| 46 | + """ |
| 47 | + active_validator_indices = get_active_validator_indices(state, get_current_epoch(state)) |
| 48 | + return min( |
| 49 | + MAX_PER_EPOCH_INBOUND_CHURN_LIMIT, |
| 50 | + max( |
| 51 | + MIN_PER_EPOCH_CHURN_LIMIT, |
| 52 | + uint64(len(active_validator_indices)) // CHURN_LIMIT_QUOTIENT |
| 53 | + ) |
| 54 | + ) |
| 55 | +``` |
| 56 | + |
| 57 | +## Beacon chain state transition function |
| 58 | + |
| 59 | +### Epoch processing |
| 60 | + |
| 61 | +#### Registry updates |
| 62 | + |
| 63 | +```python |
| 64 | +def process_registry_updates(state: BeaconState) -> None: |
| 65 | + # Process activation eligibility and ejections |
| 66 | + for index, validator in enumerate(state.validators): |
| 67 | + if is_eligible_for_activation_queue(validator): |
| 68 | + validator.activation_eligibility_epoch = get_current_epoch(state) + 1 |
| 69 | + |
| 70 | + if ( |
| 71 | + is_active_validator(validator, get_current_epoch(state)) |
| 72 | + and validator.effective_balance <= EJECTION_BALANCE |
| 73 | + ): |
| 74 | + initiate_validator_exit(state, ValidatorIndex(index)) |
| 75 | + |
| 76 | + # Queue validators eligible for activation and not yet dequeued for activation |
| 77 | + activation_queue = sorted([ |
| 78 | + index for index, validator in enumerate(state.validators) |
| 79 | + if is_eligible_for_activation(state, validator) |
| 80 | + # Order by the sequence of activation_eligibility_epoch setting and then index |
| 81 | + ], key=lambda index: (state.validators[index].activation_eligibility_epoch, index)) |
| 82 | + # Dequeued validators for activation up to churn limit |
| 83 | + # [Modified in limit churn] |
| 84 | + for index in activation_queue[:get_validator_inbound_churn_limit(state)]: |
| 85 | + validator = state.validators[index] |
| 86 | + validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state)) |
| 87 | +``` |
| 88 | + |
0 commit comments