Skip to content

Commit

Permalink
Reuse indexes with full sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Mar 28, 2023
1 parent c46c394 commit f9b359b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
45 changes: 45 additions & 0 deletions specs/_features/reuse_indexes/beacon-chain.md
Original file line number Diff line number Diff line change
@@ -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)
```
22 changes: 17 additions & 5 deletions specs/altair/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f9b359b

Please sign in to comment.