Revert "Flags to BitVector"

This reverts commit 786e611c71.

# Conflicts:
#	specs/altair/beacon-chain.md
This commit is contained in:
Dankrad Feist 2021-05-05 22:02:37 +01:00
parent 55471bc5d4
commit 77524036f5
1 changed files with 29 additions and 3 deletions

View File

@ -27,6 +27,9 @@
- [Helper functions](#helper-functions)
- [`Predicates`](#predicates)
- [`eth2_fast_aggregate_verify`](#eth2_fast_aggregate_verify)
- [Misc](#misc-2)
- [`add_flag`](#add_flag)
- [`has_flag`](#has_flag)
- [Beacon state accessors](#beacon-state-accessors)
- [`get_sync_committee_indices`](#get_sync_committee_indices)
- [`get_sync_committee`](#get_sync_committee)
@ -65,7 +68,7 @@ Altair is the first beacon chain hard fork. Its main features are:
| Name | SSZ equivalent | Description |
| - | - | - |
| `ParticipationFlags` | `BitVector[PARTICIPATION_FLAGS_LENGTH]` | a succinct representation of up to 8 boolean participation flags |
| `ParticipationFlags` | `uint8` | a succinct representation of 8 boolean participation flags |
## Constants
@ -95,7 +98,6 @@ Altair is the first beacon chain hard fork. Its main features are:
| Name | Value |
| - | - |
| `G2_POINT_AT_INFINITY` | `BLSSignature(b'\xc0' + b'\x00' * 95)` |
| `PARTICIPATION_FLAGS_LENGTH` | `8` |
| `PARTICIPATION_FLAGS` | `3` |
| `PARTICIPATION_FLAG_WEIGHTS` | `[TIMELY_HEAD_WEIGHT, TIMELY_SOURCE_WEIGHT, TIMELY_TARGET_WEIGHT]` |
@ -231,6 +233,30 @@ def eth2_fast_aggregate_verify(pubkeys: Sequence[BLSPubkey], message: Bytes32, s
return bls.FastAggregateVerify(pubkeys, message, signature)
```
### Misc
#### `add_flag`
```python
def add_flag(flags: ParticipationFlags, flag_index: int) -> ParticipationFlags:
"""
Return a new ``ParticipationFlags`` adding ``flag_index`` to ``flags``.
"""
flag = ParticipationFlags(2**flag_index)
return flags | flag
```
#### `has_flag`
```python
def has_flag(flags: ParticipationFlags, flag_index: int) -> bool:
"""
Return whether ``flags`` has ``flag_index`` set.
"""
flag = ParticipationFlags(2**flag_index)
return flags & flag == flag
```
### Beacon state accessors
#### `get_sync_committee_indices`
@ -311,7 +337,7 @@ def get_unslashed_participating_indices(state: BeaconState, flag_index: int, epo
else:
epoch_participation = state.previous_epoch_participation
active_validator_indices = get_active_validator_indices(state, epoch)
participating_indices = [i for i in active_validator_indices if epoch_participation[i][flag_index]]
participating_indices = [i for i in active_validator_indices if has_flag(epoch_participation[i], flag_index)]
return set(filter(lambda index: not state.validators[index].slashed, participating_indices))
```