ValidatorFlags -> ValidatorFlag

This commit is contained in:
Danny Ryan 2021-02-04 08:45:25 -07:00
parent 1c1ba5cba2
commit 34cea67b91
No known key found for this signature in database
GPG Key ID: 2765A792E42CE07A
3 changed files with 20 additions and 20 deletions

View File

@ -60,23 +60,23 @@ This is a patch implementing the first hard fork to the beacon chain, tentativel
| Name | SSZ equivalent | Description |
| - | - | - |
| `ValidatorFlags` | `uint8` | Bitflags to track validator actions with |
| `ValidatorFlag` | `uint8` | Bitflags to track validator actions with |
## Constants
### Validator action flags
This is formatted as an enum, with values `2**i` that can be combined as bit-flags.
The `0` value is reserved as default. Remaining bits in `ValidatorFlags` may be used in future hardforks.
The `0` value is reserved as default. Remaining bits in `ValidatorFlag` may be used in future hardforks.
**Note**: Unlike Phase0, a `TIMELY_TARGET_FLAG` does not necessarily imply a `TIMELY_SOURCE_FLAG`
due to the varying slot delay requirements of each.
| Name | Value |
| - | - |
| `TIMELY_HEAD_FLAG` | `ValidatorFlags(2**0)` (= 1) |
| `TIMELY_SOURCE_FLAG` | `ValidatorFlags(2**1)` (= 2) |
| `TIMELY_TARGET_FLAG` | `ValidatorFlags(2**2)` (= 4) |
| `TIMELY_HEAD_FLAG` | `ValidatorFlag(2**0)` (= 1) |
| `TIMELY_SOURCE_FLAG` | `ValidatorFlag(2**1)` (= 2) |
| `TIMELY_TARGET_FLAG` | `ValidatorFlag(2**2)` (= 4) |
### Participation rewards
@ -158,8 +158,8 @@ class BeaconState(Container):
# Slashings
slashings: Vector[Gwei, EPOCHS_PER_SLASHINGS_VECTOR] # Per-epoch sums of slashed effective balances
# Participation
previous_epoch_participation: List[ValidatorFlags, VALIDATOR_REGISTRY_LIMIT]
current_epoch_participation: List[ValidatorFlags, VALIDATOR_REGISTRY_LIMIT]
previous_epoch_participation: List[ValidatorFlag, VALIDATOR_REGISTRY_LIMIT]
current_epoch_participation: List[ValidatorFlag, VALIDATOR_REGISTRY_LIMIT]
# Finality
justification_bits: Bitvector[JUSTIFICATION_BITS_LENGTH] # Bit set for every recent justified epoch
previous_justified_checkpoint: Checkpoint
@ -201,7 +201,7 @@ def eth2_fast_aggregate_verify(pubkeys: Sequence[BLSPubkey], message: Bytes32, s
#### `flags_and_numerators`
```python
def get_flags_and_numerators() -> Sequence[Tuple[ValidatorFlags, int]]:
def get_flags_and_numerators() -> Sequence[Tuple[ValidatorFlag, int]]:
return (
(TIMELY_HEAD_FLAG, TIMELY_HEAD_NUMERATOR),
(TIMELY_SOURCE_FLAG, TIMELY_SOURCE_NUMERATOR),
@ -210,12 +210,12 @@ def get_flags_and_numerators() -> Sequence[Tuple[ValidatorFlags, int]]:
```
```python
def add_flags(flags: ValidatorFlags, add: ValidatorFlags) -> ValidatorFlags:
def add_flags(flags: ValidatorFlag, add: ValidatorFlag) -> ValidatorFlag:
return flags | add
```
```python
def has_flags(flags: ValidatorFlags, has: ValidatorFlags) -> bool:
def has_flags(flags: ValidatorFlag, has: ValidatorFlag) -> bool:
return flags & has == has
```
@ -277,7 +277,7 @@ def get_base_reward(state: BeaconState, index: ValidatorIndex) -> Gwei:
#### `get_unslashed_participating_indices`
```python
def get_unslashed_participating_indices(state: BeaconState, flags: ValidatorFlags, epoch: Epoch) -> Set[ValidatorIndex]:
def get_unslashed_participating_indices(state: BeaconState, flags: ValidatorFlag, epoch: Epoch) -> Set[ValidatorIndex]:
"""
Retrieve the active validator indices of the given epoch, which are not slashed, and have all of the given flags.
"""
@ -297,7 +297,7 @@ def get_unslashed_participating_indices(state: BeaconState, flags: ValidatorFlag
```python
def get_flag_deltas(state: BeaconState,
flag: ValidatorFlags,
flag: ValidatorFlag,
numerator: uint64) -> Tuple[Sequence[Gwei], Sequence[Gwei]]:
"""
Compute the rewards and penalties associated with a particular duty, by scanning through the participation
@ -457,8 +457,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
state.validators.append(get_validator_from_deposit(state, deposit))
state.balances.append(amount)
# [Added in hf-1] Initialize empty participation flags for new validator
state.previous_epoch_participation.append(ValidatorFlags(0))
state.current_epoch_participation.append(ValidatorFlags(0))
state.previous_epoch_participation.append(ValidatorFlag(0))
state.current_epoch_participation.append(ValidatorFlag(0))
else:
# Increase balance by deposit amount
index = ValidatorIndex(validator_pubkeys.index(pubkey))
@ -597,5 +597,5 @@ def process_participation_flag_updates(state: BeaconState) -> None:
Call to ``process_participation_flag_updates`` added to ``process_epoch`` in HF1
"""
state.previous_epoch_participation = state.current_epoch_participation
state.current_epoch_participation = [ValidatorFlags(0) for _ in range(len(state.validators))]
state.current_epoch_participation = [ValidatorFlag(0) for _ in range(len(state.validators))]
```

View File

@ -67,8 +67,8 @@ def upgrade_to_lightclient_patch(pre: phase0.BeaconState) -> BeaconState:
# Slashings
slashings=pre.slashings,
# Attestations
previous_epoch_participation=[ValidatorFlags(0) for _ in range(len(pre.validators))],
current_epoch_participation=[ValidatorFlags(0) for _ in range(len(pre.validators))],
previous_epoch_participation=[ValidatorFlag(0) for _ in range(len(pre.validators))],
current_epoch_participation=[ValidatorFlag(0) for _ in range(len(pre.validators))],
# Finality
justification_bits=pre.justification_bits,
previous_justified_checkpoint=pre.previous_justified_checkpoint,

View File

@ -314,7 +314,7 @@ def run_test_full_but_partial_participation(spec, state, rng=Random(5522)):
else:
for index in range(len(state.validators)):
if rng.choice([True, False]):
state.previous_epoch_participation[index] = spec.ValidatorFlags(0)
state.previous_epoch_participation[index] = spec.ValidatorFlag(0)
yield from run_deltas(spec, state)
@ -328,7 +328,7 @@ def run_test_partial(spec, state, fraction_filled):
state.previous_epoch_attestations = state.previous_epoch_attestations[:num_attestations]
else:
for index in range(int(len(state.validators) * fraction_filled)):
state.previous_epoch_participation[index] = spec.ValidatorFlags(0)
state.previous_epoch_participation[index] = spec.ValidatorFlag(0)
yield from run_deltas(spec, state)
@ -394,7 +394,7 @@ def run_test_some_very_low_effective_balances_that_did_not_attest(spec, state):
else:
index = 0
state.validators[index].effective_balance = 1
state.previous_epoch_participation[index] = spec.ValidatorFlags(0)
state.previous_epoch_participation[index] = spec.ValidatorFlag(0)
yield from run_deltas(spec, state)