convert `LightClientStore` to python object instead of SSZ object
this avoids the type overhead of having to define a max size for the object's data and skips the overhead of serialization/consensus for a type that does not need it
This commit is contained in:
parent
165c960cf1
commit
4c73fec88e
|
@ -45,8 +45,6 @@ ALTAIR_FORK_EPOCH: 18446744073709551615
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# 1
|
# 1
|
||||||
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
|
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
|
||||||
# 2**64 - 1
|
|
||||||
MAX_VALID_LIGHT_CLIENT_UPDATES: 18446744073709551615
|
|
||||||
|
|
||||||
|
|
||||||
# Validator
|
# Validator
|
||||||
|
|
|
@ -45,8 +45,7 @@ ALTAIR_FORK_EPOCH: 18446744073709551615
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# 1
|
# 1
|
||||||
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
|
MIN_SYNC_COMMITTEE_PARTICIPANTS: 1
|
||||||
# 2**64 - 1
|
|
||||||
MAX_VALID_LIGHT_CLIENT_UPDATES: 18446744073709551615
|
|
||||||
|
|
||||||
# Validator
|
# Validator
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -548,7 +548,7 @@ ignored_dependencies = [
|
||||||
'Bytes1', 'Bytes4', 'Bytes20', 'Bytes32', 'Bytes48', 'Bytes96', 'Bitlist', 'Bitvector',
|
'Bytes1', 'Bytes4', 'Bytes20', 'Bytes32', 'Bytes48', 'Bytes96', 'Bitlist', 'Bitvector',
|
||||||
'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
|
||||||
'bytes', 'byte', 'ByteList', 'ByteVector',
|
'bytes', 'byte', 'ByteList', 'ByteVector',
|
||||||
'Dict', 'dict', 'field', 'ceillog2', 'floorlog2',
|
'Dict', 'dict', 'field', 'ceillog2', 'floorlog2', 'Set'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ uses sync committees introduced in [this beacon chain extension](./beacon-chain.
|
||||||
| Name | Value |
|
| Name | Value |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `MIN_SYNC_COMMITTEE_PARTICIPANTS` | `1` |
|
| `MIN_SYNC_COMMITTEE_PARTICIPANTS` | `1` |
|
||||||
| `MAX_VALID_LIGHT_CLIENT_UPDATES` | `uint64(2**64 - 1)` |
|
|
||||||
|
|
||||||
## Containers
|
## Containers
|
||||||
|
|
||||||
|
@ -87,9 +86,10 @@ class LightClientUpdate(Container):
|
||||||
### `LightClientStore`
|
### `LightClientStore`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class LightClientStore(Container):
|
@dataclass
|
||||||
|
class LightClientStore(object):
|
||||||
snapshot: LightClientSnapshot
|
snapshot: LightClientSnapshot
|
||||||
valid_updates: List[LightClientUpdate, MAX_VALID_LIGHT_CLIENT_UPDATES]
|
valid_updates: Set[LightClientUpdate]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Helper functions
|
## Helper functions
|
||||||
|
@ -175,7 +175,7 @@ def apply_light_client_update(snapshot: LightClientSnapshot, update: LightClient
|
||||||
def process_light_client_update(store: LightClientStore, update: LightClientUpdate, current_slot: Slot,
|
def process_light_client_update(store: LightClientStore, update: LightClientUpdate, current_slot: Slot,
|
||||||
genesis_validators_root: Root) -> None:
|
genesis_validators_root: Root) -> None:
|
||||||
validate_light_client_update(store.snapshot, update, genesis_validators_root)
|
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
|
update_timeout = SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||||
if (
|
if (
|
||||||
|
@ -186,10 +186,10 @@ def process_light_client_update(store: LightClientStore, update: LightClientUpda
|
||||||
# Note that (2) means that the current light client design needs finality.
|
# 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.
|
# 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)
|
apply_light_client_update(store.snapshot, update)
|
||||||
store.valid_updates = []
|
store.valid_updates = set()
|
||||||
elif current_slot > store.snapshot.header.slot + update_timeout:
|
elif current_slot > store.snapshot.header.slot + update_timeout:
|
||||||
# Forced best update when the update timeout has elapsed
|
# Forced best update when the update timeout has elapsed
|
||||||
apply_light_client_update(store.snapshot,
|
apply_light_client_update(store.snapshot,
|
||||||
max(store.valid_updates, key=lambda update: sum(update.sync_committee_bits)))
|
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(
|
store = spec.LightClientStore(
|
||||||
snapshot=pre_snapshot,
|
snapshot=pre_snapshot,
|
||||||
valid_updates=[]
|
valid_updates=set(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Block at slot 1 doesn't increase sync committee period, so it won't update snapshot
|
# 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)
|
spec.process_light_client_update(store, update, state.slot, state.genesis_validators_root)
|
||||||
|
|
||||||
assert len(store.valid_updates) == 1
|
assert len(store.valid_updates) == 1
|
||||||
assert store.valid_updates[0] == update
|
assert store.valid_updates.pop() == update
|
||||||
assert store.snapshot == pre_snapshot
|
assert store.snapshot == pre_snapshot
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ def test_process_light_client_update_timeout(spec, state):
|
||||||
)
|
)
|
||||||
store = spec.LightClientStore(
|
store = spec.LightClientStore(
|
||||||
snapshot=pre_snapshot,
|
snapshot=pre_snapshot,
|
||||||
valid_updates=[]
|
valid_updates=set(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Forward to next sync committee period
|
# Forward to next sync committee period
|
||||||
|
@ -156,7 +156,7 @@ def test_process_light_client_update_finality_updated(spec, state):
|
||||||
)
|
)
|
||||||
store = spec.LightClientStore(
|
store = spec.LightClientStore(
|
||||||
snapshot=pre_snapshot,
|
snapshot=pre_snapshot,
|
||||||
valid_updates=[]
|
valid_updates=set(),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Change finality
|
# Change finality
|
||||||
|
|
Loading…
Reference in New Issue