2023-03-30 00:11:36 +00:00
|
|
|
# Reuse indices -- The Beacon Chain
|
2023-03-28 03:03:14 +00:00
|
|
|
|
|
|
|
## 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-04-04 03:00:09 +00:00
|
|
|
- [Helper functions](#helper-functions)
|
2023-03-28 06:34:07 +00:00
|
|
|
- [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 |
|
2023-04-04 02:45:08 +00:00
|
|
|
| - | - | - | - |
|
2023-03-30 00:11:36 +00:00
|
|
|
| `REUSE_VALIDATOR_INDEX_DELAY` | `uint64(2**16)` (= 65,536) | epochs | ~0.8 year |
|
2023-03-28 03:03:14 +00:00
|
|
|
|
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 (
|
2023-03-30 00:11:36 +00:00
|
|
|
epoch > validator.withdrawable_epoch + REUSE_VALIDATOR_INDEX_DELAY
|
2023-03-28 06:46:01 +00:00
|
|
|
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-30 00:11:36 +00:00
|
|
|
def get_index_for_new_validator(state: BeaconState) -> ValidatorIndex:
|
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-30 00:11:36 +00:00
|
|
|
return ValidatorIndex(index)
|
|
|
|
return ValidatorIndex(len(state.validators))
|
2023-03-28 03:03:14 +00:00
|
|
|
```
|