Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Light client p2p interface #2786

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions specs/altair/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@
- [Modified `process_attestation`](#modified-process_attestation)
- [Modified `process_deposit`](#modified-process_deposit)
- [Sync aggregate processing](#sync-aggregate-processing)
- [Light Client Update Processing](#light-client-update-processing)
- [Epoch processing](#epoch-processing)
- [Justification and finalization](#justification-and-finalization)
- [Inactivity scores](#inactivity-scores)
- [Rewards and penalties](#rewards-and-penalties)
- [Slashings](#slashings)
- [Participation flags updates](#participation-flags-updates)
- [Sync committee updates](#sync-committee-updates)
- [Skip sync update](#skip-sync-update)
- [Initialize state for pure Altair testnets and test vectors](#initialize-state-for-pure-altair-testnets-and-test-vectors)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -447,6 +449,7 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
process_eth1_data(state, block.body)
process_operations(state, block.body) # [Modified in Altair]
process_sync_aggregate(state, block.body.sync_aggregate) # [New in Altair]
process_light_update(state, block.body) # [light-client]
```

#### Modified `process_attestation`
Expand Down Expand Up @@ -564,6 +567,16 @@ def process_sync_aggregate(state: BeaconState, sync_aggregate: SyncAggregate) ->
decrease_balance(state, participant_index, participant_reward)
```

#### Light Client Update Processing

*Note*: The function `process_light_update` is new.

```python
def process_light_update(state: BeaconState, block: BeaconBlock) -> None:
# TODO: Create a LightClientUpdate and save it to a queue
```


### Epoch processing

```python
Expand All @@ -580,6 +593,7 @@ def process_epoch(state: BeaconState) -> None:
process_historical_roots_update(state)
process_participation_flag_updates(state) # [New in Altair]
process_sync_committee_updates(state) # [New in Altair]
process_skip_sync_update(state) # [light-client]
```

#### Justification and finalization
Expand Down Expand Up @@ -678,6 +692,15 @@ def process_sync_committee_updates(state: BeaconState) -> None:
state.next_sync_committee = get_next_sync_committee(state)
```

#### Skip sync update

*Note*: The function `process_skip_sync_update` is new.

```python
def process_skip_sync_update(state: BeaconState) -> None:
# TODO: Create SkipSyncUpdate and save it to a db keyed by hash_tree_root(state.current_sync_committee)
```

## Initialize state for pure Altair testnets and test vectors

This helper function is only for initializing the state for pure Altair testnets and tests.
Expand Down
69 changes: 69 additions & 0 deletions specs/altair/light-client-p2p-interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Ethereum Altair Light Client P2P Interface

**Notice**: This document is a work-in-progress for researchers and implementers.

This document contains the networking specification for [minimal light client](./sync-protocol.md).
This document should be viewed as a patch to the [Altair networking specification](./p2p-interface.md).

## 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 -->

- [The gossip domain: gossipsub](#the-gossip-domain-gossipsub)
- [Topics and messages](#topics-and-messages)
- [The Req/Resp domain](#the-reqresp-domain)
- [Messages](#messages)
- [LightClientUpdate](#lightclientupdate)
- [Server discovery](#server-discovery)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->

## The gossip domain: gossipsub

The `light_client_update` gossip topic is added to support a light client searching for latest block header information.

### Topics and messages

The new topics along with the type of the `data` field of a gossipsub message are given in this table:

| Name | Message Type |
| - | - |
| `light_client_update` | `LightClientUpdate` |

Definitions of these new types can be found in the [sync-protocol](./sync-protocol.md#LightClientUpdate).


## The Req/Resp domain

### Messages

#### LightClientUpdate

**Protocol ID:** `/eth2/beacon_chain/req/skip-sync/1/`

Request Content:
```
(
key: bytes32
)
```

Response Content:
```
(
LightClientUpdate
)
```

The request key is the hash root of a SyncCommittee. This allows a light client to start with any trusted sync-committee root to skip sync to the latest sync-committee.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not bullet proof, as the same SyncCommittee may be selected for multiple sync committee periods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great observation. In that case, the key must include information about sync period as well.



## Server discovery

[TODO]
- Note that if we simply use the same set of bootnodes as the set configured in BeaconChain, the majority of the discovered peers are not likely to support the gossip topic of the req/resp protocol defined in this document.
- If disv5 supports [topic advertisement](https://github.com/ethereum/devp2p/blob/master/discv5/discv5-theory.md#topic-advertisement), this could be used to discover a subnet of nodes that supports the light client protocol.