Merge pull request #3337 from benjaminion/move-is-prev-epoch-just

Move is_previous_epoch_justified
This commit is contained in:
Hsiao-Wei Wang 2023-04-21 16:43:30 +08:00 committed by GitHub
commit 1a38b83e5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,8 +11,8 @@
- [Configuration](#configuration)
- [Helpers](#helpers)
- [`LatestMessage`](#latestmessage)
- [`is_previous_epoch_justified`](#is_previous_epoch_justified)
- [`Store`](#store)
- [`is_previous_epoch_justified`](#is_previous_epoch_justified)
- [`get_forkchoice_store`](#get_forkchoice_store)
- [`get_slots_since_genesis`](#get_slots_since_genesis)
- [`get_current_slot`](#get_current_slot)
@ -92,17 +92,6 @@ class LatestMessage(object):
root: Root
```
### `is_previous_epoch_justified`
```python
def is_previous_epoch_justified(store: Store) -> bool:
current_slot = get_current_slot(store)
current_epoch = compute_epoch_at_slot(current_slot)
return store.justified_checkpoint.epoch + 1 == current_epoch
```
#### `Store`
The `Store` is responsible for tracking information required for the fork choice algorithm. The important fields being tracked are described below:
@ -130,6 +119,15 @@ class Store(object):
unrealized_justifications: Dict[Root, Checkpoint] = field(default_factory=dict)
```
#### `is_previous_epoch_justified`
```python
def is_previous_epoch_justified(store: Store) -> bool:
current_slot = get_current_slot(store)
current_epoch = compute_epoch_at_slot(current_slot)
return store.justified_checkpoint.epoch + 1 == current_epoch
```
#### `get_forkchoice_store`
The provided anchor-state will be regarded as a trusted state, to not roll back beyond.