mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-21 06:48:12 +00:00
Merge pull request #2378 from ralexstokes/update-altair-sync-protocol
Updates to Altair light client sync protocol
This commit is contained in:
commit
b979ea144a
@ -43,10 +43,6 @@ ALTAIR_FORK_EPOCH: 18446744073709551615
|
||||
# ---------------------------------------------------------------
|
||||
# 1
|
||||
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
|
||||
# 2**13
|
||||
MAX_VALID_LIGHT_CLIENT_UPDATES: 8192
|
||||
# 2**13 (=8192)
|
||||
LIGHT_CLIENT_UPDATE_TIMEOUT: 8192
|
||||
|
||||
|
||||
# Validator
|
||||
|
@ -43,10 +43,7 @@ ALTAIR_FORK_EPOCH: 18446744073709551615
|
||||
# ---------------------------------------------------------------
|
||||
# 1
|
||||
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
|
||||
# [customized]
|
||||
MAX_VALID_LIGHT_CLIENT_UPDATES: 32
|
||||
# [customized]
|
||||
LIGHT_CLIENT_UPDATE_TIMEOUT: 32
|
||||
|
||||
|
||||
# Validator
|
||||
# ---------------------------------------------------------------
|
||||
|
4
setup.py
4
setup.py
@ -167,7 +167,7 @@ def get_spec(file_name: str) -> SpecObject:
|
||||
comment = _get_eth2_spec_comment(child)
|
||||
if comment == "skip":
|
||||
should_skip = True
|
||||
|
||||
|
||||
return SpecObject(
|
||||
functions=functions,
|
||||
custom_types=custom_types,
|
||||
@ -548,7 +548,7 @@ ignored_dependencies = [
|
||||
'Bytes1', 'Bytes4', 'Bytes20', 'Bytes32', 'Bytes48', 'Bytes96', 'Bitlist', 'Bitvector',
|
||||
'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
||||
'bytes', 'byte', 'ByteList', 'ByteVector',
|
||||
'Dict', 'dict', 'field', 'ceillog2', 'floorlog2',
|
||||
'Dict', 'dict', 'field', 'ceillog2', 'floorlog2', 'Set',
|
||||
]
|
||||
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
- [Constants](#constants)
|
||||
- [Configuration](#configuration)
|
||||
- [Misc](#misc)
|
||||
- [Time parameters](#time-parameters)
|
||||
- [Containers](#containers)
|
||||
- [`LightClientSnapshot`](#lightclientsnapshot)
|
||||
- [`LightClientUpdate`](#lightclientupdate)
|
||||
@ -51,13 +50,6 @@ uses sync committees introduced in [this beacon chain extension](./beacon-chain.
|
||||
| Name | Value |
|
||||
| - | - |
|
||||
| `MIN_SYNC_COMMITTEE_PARTICIPANTS` | `1` |
|
||||
| `MAX_VALID_LIGHT_CLIENT_UPDATES` | `uint64(2**64 - 1)` |
|
||||
|
||||
### Time parameters
|
||||
|
||||
| Name | Value | Unit | Duration |
|
||||
| - | - | :-: | :-: |
|
||||
| `LIGHT_CLIENT_UPDATE_TIMEOUT` | `Slot(2**13)` | slots | ~27 hours |
|
||||
|
||||
## Containers
|
||||
|
||||
@ -94,9 +86,10 @@ class LightClientUpdate(Container):
|
||||
### `LightClientStore`
|
||||
|
||||
```python
|
||||
class LightClientStore(Container):
|
||||
@dataclass
|
||||
class LightClientStore(object):
|
||||
snapshot: LightClientSnapshot
|
||||
valid_updates: List[LightClientUpdate, MAX_VALID_LIGHT_CLIENT_UPDATES]
|
||||
valid_updates: Set[LightClientUpdate]
|
||||
```
|
||||
|
||||
## Helper functions
|
||||
@ -182,20 +175,21 @@ def apply_light_client_update(snapshot: LightClientSnapshot, update: LightClient
|
||||
def process_light_client_update(store: LightClientStore, update: LightClientUpdate, current_slot: Slot,
|
||||
genesis_validators_root: Root) -> None:
|
||||
validate_light_client_update(store.snapshot, update, genesis_validators_root)
|
||||
store.valid_updates.append(update)
|
||||
store.valid_updates.add(update)
|
||||
|
||||
update_timeout = SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||
if (
|
||||
sum(update.sync_committee_bits) * 3 > len(update.sync_committee_bits) * 2
|
||||
sum(update.sync_committee_bits) * 3 >= len(update.sync_committee_bits) * 2
|
||||
and update.finality_header != BeaconBlockHeader()
|
||||
):
|
||||
# Apply update if (1) 2/3 quorum is reached and (2) we have a finality proof.
|
||||
# Note that (2) means that the current light client design needs finality.
|
||||
# It may be changed to re-organizable light client design. See the on-going issue eth2.0-specs#2182.
|
||||
apply_light_client_update(store.snapshot, update)
|
||||
store.valid_updates = []
|
||||
elif current_slot > store.snapshot.header.slot + LIGHT_CLIENT_UPDATE_TIMEOUT:
|
||||
store.valid_updates = set()
|
||||
elif current_slot > store.snapshot.header.slot + update_timeout:
|
||||
# Forced best update when the update timeout has elapsed
|
||||
apply_light_client_update(store.snapshot,
|
||||
max(store.valid_updates, key=lambda update: sum(update.sync_committee_bits)))
|
||||
store.valid_updates = []
|
||||
store.valid_updates = set()
|
||||
```
|
||||
|
@ -32,7 +32,7 @@ def test_process_light_client_update_not_updated(spec, state):
|
||||
)
|
||||
store = spec.LightClientStore(
|
||||
snapshot=pre_snapshot,
|
||||
valid_updates=[]
|
||||
valid_updates=set(),
|
||||
)
|
||||
|
||||
# Block at slot 1 doesn't increase sync committee period, so it won't update snapshot
|
||||
@ -76,7 +76,7 @@ def test_process_light_client_update_not_updated(spec, state):
|
||||
spec.process_light_client_update(store, update, state.slot, state.genesis_validators_root)
|
||||
|
||||
assert len(store.valid_updates) == 1
|
||||
assert store.valid_updates[0] == update
|
||||
assert store.valid_updates.pop() == update
|
||||
assert store.snapshot == pre_snapshot
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ def test_process_light_client_update_timeout(spec, state):
|
||||
)
|
||||
store = spec.LightClientStore(
|
||||
snapshot=pre_snapshot,
|
||||
valid_updates=[]
|
||||
valid_updates=set(),
|
||||
)
|
||||
|
||||
# Forward to next sync committee period
|
||||
@ -156,7 +156,7 @@ def test_process_light_client_update_finality_updated(spec, state):
|
||||
)
|
||||
store = spec.LightClientStore(
|
||||
snapshot=pre_snapshot,
|
||||
valid_updates=[]
|
||||
valid_updates=set(),
|
||||
)
|
||||
|
||||
# Change finality
|
||||
|
Loading…
x
Reference in New Issue
Block a user