2023-01-23 14:08:34 +00:00
# Deneb Light Client -- Fork Logic
2022-12-12 12:11:49 +00:00
## Table of contents
<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
- [Introduction ](#introduction )
2024-06-21 08:59:13 +00:00
- [Upgrading light client data ](#upgrading-light-client-data )
- [Upgrading the store ](#upgrading-the-store )
2022-12-12 12:11:49 +00:00
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
## Introduction
2023-01-23 14:08:34 +00:00
This document describes how to upgrade existing light client objects based on the [Capella specification ](../../capella/light-client/sync-protocol.md ) to Deneb. This is necessary when processing pre-Deneb data with a post-Deneb `LightClientStore` . Note that the data being exchanged over the network protocols uses the original format.
2022-12-12 12:11:49 +00:00
2024-06-21 08:59:13 +00:00
## Upgrading light client data
2022-12-12 12:11:49 +00:00
2023-01-23 14:08:34 +00:00
A Deneb `LightClientStore` can still process earlier light client data. In order to do so, that pre-Deneb data needs to be locally upgraded to Deneb before processing.
2022-12-12 12:11:49 +00:00
```python
2023-01-23 14:08:34 +00:00
def upgrade_lc_header_to_deneb(pre: capella.LightClientHeader) -> LightClientHeader:
2022-12-12 12:11:49 +00:00
return LightClientHeader(
beacon=pre.beacon,
execution=ExecutionPayloadHeader(
parent_hash=pre.execution.parent_hash,
fee_recipient=pre.execution.fee_recipient,
state_root=pre.execution.state_root,
receipts_root=pre.execution.receipts_root,
logs_bloom=pre.execution.logs_bloom,
prev_randao=pre.execution.prev_randao,
block_number=pre.execution.block_number,
gas_limit=pre.execution.gas_limit,
gas_used=pre.execution.gas_used,
timestamp=pre.execution.timestamp,
extra_data=pre.execution.extra_data,
base_fee_per_gas=pre.execution.base_fee_per_gas,
block_hash=pre.execution.block_hash,
transactions_root=pre.execution.transactions_root,
withdrawals_root=pre.execution.withdrawals_root,
2023-07-25 05:28:34 +00:00
blob_gas_used=uint64(0), # [New in Deneb:EIP4844]
excess_blob_gas=uint64(0), # [New in Deneb:EIP4844]
2022-12-12 12:11:49 +00:00
),
execution_branch=pre.execution_branch,
)
```
```python
2023-01-23 14:08:34 +00:00
def upgrade_lc_bootstrap_to_deneb(pre: capella.LightClientBootstrap) -> LightClientBootstrap:
2022-12-12 12:11:49 +00:00
return LightClientBootstrap(
2023-01-23 14:08:34 +00:00
header=upgrade_lc_header_to_deneb(pre.header),
2022-12-12 12:11:49 +00:00
current_sync_committee=pre.current_sync_committee,
current_sync_committee_branch=pre.current_sync_committee_branch,
)
```
```python
2023-01-23 14:08:34 +00:00
def upgrade_lc_update_to_deneb(pre: capella.LightClientUpdate) -> LightClientUpdate:
2022-12-12 12:11:49 +00:00
return LightClientUpdate(
2023-01-23 14:08:34 +00:00
attested_header=upgrade_lc_header_to_deneb(pre.attested_header),
2022-12-12 12:11:49 +00:00
next_sync_committee=pre.next_sync_committee,
next_sync_committee_branch=pre.next_sync_committee_branch,
2023-01-23 14:08:34 +00:00
finalized_header=upgrade_lc_header_to_deneb(pre.finalized_header),
2022-12-12 12:11:49 +00:00
finality_branch=pre.finality_branch,
sync_aggregate=pre.sync_aggregate,
signature_slot=pre.signature_slot,
)
```
```python
2023-01-23 14:08:34 +00:00
def upgrade_lc_finality_update_to_deneb(pre: capella.LightClientFinalityUpdate) -> LightClientFinalityUpdate:
2022-12-12 12:11:49 +00:00
return LightClientFinalityUpdate(
2023-01-23 14:08:34 +00:00
attested_header=upgrade_lc_header_to_deneb(pre.attested_header),
finalized_header=upgrade_lc_header_to_deneb(pre.finalized_header),
2022-12-12 12:11:49 +00:00
finality_branch=pre.finality_branch,
sync_aggregate=pre.sync_aggregate,
signature_slot=pre.signature_slot,
)
```
```python
2023-01-23 14:08:34 +00:00
def upgrade_lc_optimistic_update_to_deneb(pre: capella.LightClientOptimisticUpdate) -> LightClientOptimisticUpdate:
2022-12-12 12:11:49 +00:00
return LightClientOptimisticUpdate(
2023-01-23 14:08:34 +00:00
attested_header=upgrade_lc_header_to_deneb(pre.attested_header),
2022-12-12 12:11:49 +00:00
sync_aggregate=pre.sync_aggregate,
signature_slot=pre.signature_slot,
)
```
2024-06-21 08:59:13 +00:00
## Upgrading the store
2022-12-12 12:11:49 +00:00
2023-01-23 14:08:34 +00:00
Existing `LightClientStore` objects based on Capella MUST be upgraded to Deneb before Deneb based light client data can be processed. The `LightClientStore` upgrade MAY be performed before `DENEB_FORK_EPOCH` .
2022-12-12 12:11:49 +00:00
```python
2023-01-23 14:08:34 +00:00
def upgrade_lc_store_to_deneb(pre: capella.LightClientStore) -> LightClientStore:
2022-12-12 12:11:49 +00:00
if pre.best_valid_update is None:
best_valid_update = None
else:
2023-01-23 14:08:34 +00:00
best_valid_update = upgrade_lc_update_to_deneb(pre.best_valid_update)
2022-12-12 12:11:49 +00:00
return LightClientStore(
2023-01-23 14:08:34 +00:00
finalized_header=upgrade_lc_header_to_deneb(pre.finalized_header),
2022-12-12 12:11:49 +00:00
current_sync_committee=pre.current_sync_committee,
next_sync_committee=pre.next_sync_committee,
best_valid_update=best_valid_update,
2023-01-23 14:08:34 +00:00
optimistic_header=upgrade_lc_header_to_deneb(pre.optimistic_header),
2022-12-12 12:11:49 +00:00
previous_max_active_participants=pre.previous_max_active_participants,
current_max_active_participants=pre.current_max_active_participants,
)
```