mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-23 07:48:12 +00:00
Merge pull request #2828 from ethereum/is_finality_update
Refactoring: add `is_finality_update` helper
This commit is contained in:
commit
72d4597131
@ -16,6 +16,7 @@
|
|||||||
- [`LightClientUpdate`](#lightclientupdate)
|
- [`LightClientUpdate`](#lightclientupdate)
|
||||||
- [`LightClientStore`](#lightclientstore)
|
- [`LightClientStore`](#lightclientstore)
|
||||||
- [Helper functions](#helper-functions)
|
- [Helper functions](#helper-functions)
|
||||||
|
- [`is_finality_update`](#is_finality_update)
|
||||||
- [`get_subtree_index`](#get_subtree_index)
|
- [`get_subtree_index`](#get_subtree_index)
|
||||||
- [`get_active_header`](#get_active_header)
|
- [`get_active_header`](#get_active_header)
|
||||||
- [`get_safety_threshold`](#get_safety_threshold)
|
- [`get_safety_threshold`](#get_safety_threshold)
|
||||||
@ -95,6 +96,13 @@ class LightClientStore(object):
|
|||||||
|
|
||||||
## Helper functions
|
## Helper functions
|
||||||
|
|
||||||
|
### `is_finality_update`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def is_finality_update(update: LightClientUpdate) -> bool:
|
||||||
|
return update.finalized_header != BeaconBlockHeader()
|
||||||
|
```
|
||||||
|
|
||||||
### `get_subtree_index`
|
### `get_subtree_index`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -109,7 +117,7 @@ def get_active_header(update: LightClientUpdate) -> BeaconBlockHeader:
|
|||||||
# The "active header" is the header that the update is trying to convince us
|
# The "active header" is the header that the update is trying to convince us
|
||||||
# to accept. If a finalized header is present, it's the finalized header,
|
# to accept. If a finalized header is present, it's the finalized header,
|
||||||
# otherwise it's the attested header
|
# otherwise it's the attested header
|
||||||
if update.finalized_header != BeaconBlockHeader():
|
if is_finality_update(update):
|
||||||
return update.finalized_header
|
return update.finalized_header
|
||||||
else:
|
else:
|
||||||
return update.attested_header
|
return update.attested_header
|
||||||
@ -163,7 +171,7 @@ def validate_light_client_update(store: LightClientStore,
|
|||||||
|
|
||||||
# Verify that the `finalized_header`, if present, actually is the finalized header saved in the
|
# Verify that the `finalized_header`, if present, actually is the finalized header saved in the
|
||||||
# state of the `attested header`
|
# state of the `attested header`
|
||||||
if update.finalized_header == BeaconBlockHeader():
|
if not is_finality_update(update):
|
||||||
assert update.finality_branch == [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]
|
assert update.finality_branch == [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]
|
||||||
else:
|
else:
|
||||||
assert is_valid_merkle_branch(
|
assert is_valid_merkle_branch(
|
||||||
@ -252,7 +260,7 @@ def process_light_client_update(store: LightClientStore,
|
|||||||
# Update finalized header
|
# Update finalized header
|
||||||
if (
|
if (
|
||||||
sum(sync_committee_bits) * 3 >= len(sync_committee_bits) * 2
|
sum(sync_committee_bits) * 3 >= len(sync_committee_bits) * 2
|
||||||
and update.finalized_header != BeaconBlockHeader()
|
and is_finality_update(update)
|
||||||
):
|
):
|
||||||
# Normal update through 2/3 threshold
|
# Normal update through 2/3 threshold
|
||||||
apply_light_client_update(store, update)
|
apply_light_client_update(store, update)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user