Compute epoch only once for better readability

This commit is contained in:
Etan Kissling 2022-12-12 13:09:18 +01:00
parent 4df86632b6
commit e67ca3d309
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
2 changed files with 9 additions and 3 deletions

View File

@ -34,7 +34,9 @@ def compute_merkle_proof_for_block_body(body: BeaconBlockBody,
```python
def block_to_light_client_header(block: SignedBeaconBlock) -> LightClientHeader:
if compute_epoch_at_slot(block.message.slot) >= CAPELLA_FORK_EPOCH:
epoch = compute_epoch_at_slot(block.message.slot)
if epoch >= CAPELLA_FORK_EPOCH:
payload = block.message.body.execution_payload
execution_header = ExecutionPayloadHeader(
parent_hash=payload.parent_hash,

View File

@ -152,7 +152,9 @@ def get_lc_beacon_root(header: LightClientHeader) -> Root:
```python
def get_lc_execution_root(header: LightClientHeader) -> Root:
if compute_epoch_at_slot(get_lc_beacon_slot(header)) >= CAPELLA_FORK_EPOCH:
epoch = compute_epoch_at_slot(get_lc_beacon_slot(header))
if epoch >= CAPELLA_FORK_EPOCH:
return hash_tree_root(header.execution)
return Root()
@ -162,7 +164,9 @@ def get_lc_execution_root(header: LightClientHeader) -> Root:
```python
def is_valid_light_client_header(header: LightClientHeader) -> bool:
if compute_epoch_at_slot(get_lc_beacon_slot(header)) < CAPELLA_FORK_EPOCH:
epoch = compute_epoch_at_slot(get_lc_beacon_slot(header))
if epoch < CAPELLA_FORK_EPOCH:
if header.execution != ExecutionPayloadHeader():
return False