Reuse indexes with full sweep

This commit is contained in:
dapplion 2023-03-28 12:03:14 +09:00
parent c46c3945fd
commit f9b359be09
2 changed files with 62 additions and 5 deletions

View File

@ -0,0 +1,45 @@
# 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)
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
- [Block processing](#block-processing)
- [Modified `assign_index_to_deposit`](#modified-assign_index_to_deposit)
<!-- 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 |
## 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)
```

View File

@ -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