Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_previous_epoch as a helper #565

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- [`hash`](#hash)
- [`hash_tree_root`](#hash_tree_root)
- [`slot_to_epoch`](#slot_to_epoch)
- [`get_previous_epoch`](#get_previous_epoch)
- [`get_current_epoch`](#get_current_epoch)
- [`get_epoch_start_slot`](#get_epoch_start_slot)
- [`is_active_validator`](#is_active_validator)
Expand Down Expand Up @@ -639,6 +640,19 @@ def slot_to_epoch(slot: SlotNumber) -> EpochNumber:
return slot // EPOCH_LENGTH
```

### `get_previous_epoch`

```python
def get_previous_epoch(state: BeaconState) -> EpochNumber:
"""`
Return the previous epoch of the given ``state``.
terencechain marked this conversation as resolved.
Show resolved Hide resolved
If the current epoch is ``GENESIS_EPOCH``, return ``GENESIS_EPOCH``.
"""
if slot_to_epoch(state.slot) > GENESIS_EPOCH:
return slot_to_epoch(state.slot) - 1
return slot_to_epoch(state.slot)
```

### `get_current_epoch`

```python
Expand Down Expand Up @@ -844,7 +858,7 @@ def get_crosslink_committees_at_slot(state: BeaconState,
"""
epoch = slot_to_epoch(slot)
current_epoch = get_current_epoch(state)
previous_epoch = current_epoch - 1 if current_epoch > GENESIS_EPOCH else current_epoch
previous_epoch = get_previous_epoch(state)
next_epoch = current_epoch + 1

assert previous_epoch <= epoch <= next_epoch
Expand Down Expand Up @@ -1827,7 +1841,7 @@ The steps below happen when `(state.slot + 1) % EPOCH_LENGTH == 0`.
#### Helpers

* Let `current_epoch = get_current_epoch(state)`.
* Let `previous_epoch = current_epoch - 1 if current_epoch > GENESIS_EPOCH else current_epoch`.
* Let `previous_epoch = get_previous_epoch(state)`.
* Let `next_epoch = current_epoch + 1`.

[Validators](#dfn-Validator) attesting during the current epoch:
Expand Down