Merge pull request #1699 from ethereum/hwwhww/unpack_compact_validator

Add `unpack_compact_validator` back
This commit is contained in:
Danny Ryan 2020-03-31 10:40:45 -06:00 committed by GitHub
commit 16208790a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 2 deletions

View File

@ -34,6 +34,7 @@
- [Misc](#misc-1) - [Misc](#misc-1)
- [`get_previous_slot`](#get_previous_slot) - [`get_previous_slot`](#get_previous_slot)
- [`pack_compact_validator`](#pack_compact_validator) - [`pack_compact_validator`](#pack_compact_validator)
- [`unpack_compact_validator`](#unpack_compact_validator)
- [`committee_to_compact_committee`](#committee_to_compact_committee) - [`committee_to_compact_committee`](#committee_to_compact_committee)
- [`compute_shard_from_committee_index`](#compute_shard_from_committee_index) - [`compute_shard_from_committee_index`](#compute_shard_from_committee_index)
- [Beacon state accessors](#beacon-state-accessors) - [Beacon state accessors](#beacon-state-accessors)
@ -371,15 +372,29 @@ def get_previous_slot(slot: Slot) -> Slot:
#### `pack_compact_validator` #### `pack_compact_validator`
```python ```python
def pack_compact_validator(index: int, slashed: bool, balance_in_increments: int) -> int: def pack_compact_validator(index: ValidatorIndex, slashed: bool, balance_in_increments: uint64) -> uint64:
""" """
Creates a compact validator object representing index, slashed status, and compressed balance. Create a compact validator object representing index, slashed status, and compressed balance.
Takes as input balance-in-increments (// EFFECTIVE_BALANCE_INCREMENT) to preserve symmetry with Takes as input balance-in-increments (// EFFECTIVE_BALANCE_INCREMENT) to preserve symmetry with
the unpacking function. the unpacking function.
""" """
return (index << 16) + (slashed << 15) + balance_in_increments return (index << 16) + (slashed << 15) + balance_in_increments
``` ```
#### `unpack_compact_validator`
```python
def unpack_compact_validator(compact_validator: uint64) -> Tuple[ValidatorIndex, bool, uint64]:
"""
Return validator index, slashed, balance // EFFECTIVE_BALANCE_INCREMENT
"""
return (
ValidatorIndex(compact_validator >> 16),
bool((compact_validator >> 15) % 2),
compact_validator & (2**15 - 1),
)
```
#### `committee_to_compact_committee` #### `committee_to_compact_committee`
```python ```python