Reuse indexes with full sweep
This commit is contained in:
parent
c46c3945fd
commit
f9b359be09
|
@ -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)
|
||||||
|
```
|
|
@ -511,16 +511,28 @@ def apply_deposit(state: BeaconState,
|
||||||
signing_root = compute_signing_root(deposit_message, domain)
|
signing_root = compute_signing_root(deposit_message, domain)
|
||||||
# Initialize validator if the deposit signature is valid
|
# Initialize validator if the deposit signature is valid
|
||||||
if bls.Verify(pubkey, signing_root, signature):
|
if bls.Verify(pubkey, signing_root, signature):
|
||||||
state.validators.append(get_validator_from_deposit(pubkey, withdrawal_credentials, amount))
|
index = assign_index_to_deposit(state)
|
||||||
state.balances.append(amount)
|
update_list(state.validators, index, get_validator_from_deposit(pubkey, withdrawal_credentials, amount))
|
||||||
|
update_list(state.balances, index, amount)
|
||||||
# [New in Altair]
|
# [New in Altair]
|
||||||
state.previous_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
update_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000))
|
||||||
state.current_epoch_participation.append(ParticipationFlags(0b0000_0000))
|
update_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000))
|
||||||
state.inactivity_scores.append(uint64(0))
|
update_list(state.inactivity_scores, index, uint64(0))
|
||||||
else:
|
else:
|
||||||
# Increase balance by deposit amount
|
# Increase balance by deposit amount
|
||||||
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
index = ValidatorIndex(validator_pubkeys.index(pubkey))
|
||||||
increase_balance(state, index, amount)
|
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
|
#### Sync aggregate processing
|
||||||
|
|
Loading…
Reference in New Issue