diff --git a/specs/_features/reuse_indexes/beacon-chain.md b/specs/_features/reuse_indexes/beacon-chain.md new file mode 100644 index 000000000..fcf1de896 --- /dev/null +++ b/specs/_features/reuse_indexes/beacon-chain.md @@ -0,0 +1,45 @@ +# Reuse indexes -- The Beacon Chain + +## Table of contents + + + + + +- [Introduction](#introduction) +- [Preset](#preset) + - [Time parameters](#time-parameters) +- [Beacon chain state transition function](#beacon-chain-state-transition-function) + - [Block processing](#block-processing) + - [Modified `assign_index_to_deposit`](#modified-assign_index_to_deposit) + + + + +## Introduction + +This is the beacon chain specification to assign new deposits to existing validator records that have withdrawn long ago. + +*Note:* This specification is built upon [Capella](../../capella/beacon_chain.md) and is under active development. + +## Preset + +### Time parameters + +| Name | Value | Unit | Duration | +| - | - | - | +| `REUSE_VALIDATOR_INDEX_DELAY` | `uint64(2**16)` (= 65,536) | epochs | ~1 year | + +## Beacon chain state transition function + +### Block processing + +#### Modified `assign_index_to_deposit` + +```python +def assign_index_to_deposit(state: BeaconState) -> int: + for index, validator in enumerate(state.validators): + if validator.withdrawable_epoch < get_current_epoch(state) - REUSE_VALIDATOR_INDEX_DELAY: + return index + return len(state.validators) +``` diff --git a/specs/altair/beacon-chain.md b/specs/altair/beacon-chain.md index 58dfad608..d5b89a387 100644 --- a/specs/altair/beacon-chain.md +++ b/specs/altair/beacon-chain.md @@ -511,16 +511,28 @@ def apply_deposit(state: BeaconState, signing_root = compute_signing_root(deposit_message, domain) # Initialize validator if the deposit signature is valid if bls.Verify(pubkey, signing_root, signature): - state.validators.append(get_validator_from_deposit(pubkey, withdrawal_credentials, amount)) - state.balances.append(amount) + index = assign_index_to_deposit(state) + update_list(state.validators, index, get_validator_from_deposit(pubkey, withdrawal_credentials, amount)) + update_list(state.balances, index, amount) # [New in Altair] - state.previous_epoch_participation.append(ParticipationFlags(0b0000_0000)) - state.current_epoch_participation.append(ParticipationFlags(0b0000_0000)) - state.inactivity_scores.append(uint64(0)) + update_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000)) + update_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000)) + update_list(state.inactivity_scores, index, uint64(0)) else: # Increase balance by deposit amount index = ValidatorIndex(validator_pubkeys.index(pubkey)) increase_balance(state, index, amount) + + +def assign_index_to_deposit(state: BeaconState) -> int: + return len(state.validators) + + +def update_list(list: List, index: int, value: Any) -> None: + if index == len(list): + list.append(value) + else: + list[index] = value ``` #### Sync aggregate processing