eth2.0-specs/specs/_features/reuse_indexes/beacon-chain.md

67 lines
1.9 KiB
Markdown
Raw Normal View History

2023-03-28 03:03:14 +00:00
# Reuse indexes -- The Beacon Chain
## Table of contents
<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
- [Introduction](#introduction)
- [Preset](#preset)
- [Time parameters](#time-parameters)
2023-03-28 06:34:07 +00:00
- [Helpers](#helpers)
- [Predicates](#predicates)
- [`is_reusable_validator`](#is_reusable_validator)
2023-03-28 03:03:14 +00:00
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
- [Block processing](#block-processing)
2023-03-28 06:34:07 +00:00
- [Modified `get_index_for_new_validator`](#modified-get_index_for_new_validator)
2023-03-28 03:03:14 +00:00
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
## 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 |
2023-03-28 06:34:07 +00:00
## Helper functions
### Predicates
#### `is_reusable_validator`
```python
def is_reusable_validator(validator: Validator, balance: Gwei, epoch: Epoch) -> bool:
"""
Check if ``validator`` index can be re-assigned to a new deposit.
"""
return (
epoch > REUSE_VALIDATOR_INDEX_DELAY
and validator.withdrawable_epoch < epoch - REUSE_VALIDATOR_INDEX_DELAY
and balance == 0
2023-03-28 06:34:07 +00:00
)
```
2023-03-28 03:03:14 +00:00
## Beacon chain state transition function
### Block processing
2023-03-28 06:34:07 +00:00
#### Modified `get_index_for_new_validator`
2023-03-28 03:03:14 +00:00
```python
2023-03-28 06:34:07 +00:00
def get_index_for_new_validator(state: BeaconState) -> int:
2023-03-28 03:03:14 +00:00
for index, validator in enumerate(state.validators):
2023-03-28 06:34:07 +00:00
if is_reusable_validator(validator, state.balances[index], get_current_epoch(state)):
2023-03-28 03:03:14 +00:00
return index
return len(state.validators)
```