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

Define endpoints for light client sync #247

Merged
merged 6 commits into from
Oct 10, 2022

Conversation

etan-status
Copy link
Contributor

@etan-status etan-status commented Sep 22, 2022

Introduces additional REST endpoints for light client sync, compatible with the libp2p specification defined in ethereum/consensus-specs: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/specs/altair/light-client/p2p-interface.md

Endpoints are defined to be fork-aware to allow potential optimizations such as including EL block hash into BeaconBlockHeader in the future.

The getLightClientUpdatesByRange endpoint is a new kind of endpoint, as it introduces the concept of list responses. Each list item could potentially be of a different fork. Likewise, for the events stream, the fork may update between events. Both the list response and the event are additionall wrapped with a per-item version indicator in JSON. For SSZ, the list items are encoded as length/version/payload triples. Note that the events endpoint does not support the SSZ format.

This builds on prior work from:

The proof endpoint in that PR is out-of-scope here, but could be useful as part of the debug API as an eth_getProof equivalent for CL data.

Introduces additional REST endpoints for light client sync, compatible
with the libp2p specification defined in `ethereum/consensus-specs`:
https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.3/specs/altair/light-client/p2p-interface.md

Endpoints are defined to be fork-aware to allow potential optimizations
such as including EL block hash into `BeaconBlockHeader` in the future.

The `getLightClientUpdatesByRange` endpoint is a new kind of endpoint,
as it introduces the concept of list responses. Each list item could
potentially be of a different fork. Likewise, for the events stream,
the fork may update between events. Both the list response and the event
are additionall wrapped with a per-item `version` indicator in JSON.
For SSZ, the list items are encoded as length/version/payload triples.
Note that the events endpoint does not support the SSZ format.

This builds on prior work from:
- @dapplion at ethereum#181

The proof endpoint in that PR is out-of-scope here, but could be useful
as part of the debug API as an `eth_getProof` equivalent for CL data.
@hujw77
Copy link

hujw77 commented Sep 28, 2022

If beacon light client provide single_proof API would be great for solidity smart contract to verify beacon state easily.
https://github.com/ethereum/consensus-specs/blob/dev/ssz/merkle-proofs.md

def calculate_merkle_root(leaf: Bytes32, proof: Sequence[Bytes32], index: GeneralizedIndex) -> Root:
    assert len(proof) == get_generalized_index_length(index)
    for i, h in enumerate(proof):
        if get_generalized_index_bit(index, i):
            leaf = hash(h + leaf)
        else:
            leaf = hash(leaf + h)
    return leaf

@etan-status
Copy link
Contributor Author

If beacon light client provide single_proof API would be great for solidity smart contract to verify beacon state easily.

Proofs are not specific to light clients, and should be introduced separately, e.g., as part of the /debug namespace that already provides a way to query state. #181 (comment)

They need a separate discussion as there are different possible designs regarding supported complexity and serialization formats. e.g., should it support querying "the last validator's balance" without knowing the number of validators / should it support querying multiple items at a time / should it support proofs for historic states.

For the popular use case of EL block hash to have end-to-end proof of eth_getProof, the EL block hash could simply be moved into BeaconBlockHeader from capella onwards. The libp2p, REST and portal specs are fork-aware for potential changes like that.

Copy link
Collaborator

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

Looks great!

etan-status added a commit to status-im/nimbus-eth2 that referenced this pull request Oct 3, 2022
Implements the latest proposal for providing LC data via REST, as of
ethereum/beacon-APIs#247 with a v0 suffix.

Requests:
- `/eth/v0/beacon/light_client/bootstrap/{block_root}`
- `/eth/v0/beacon/light_client/updates?start_period={start_period}&count={count}`
- `/eth/v0/beacon/light_client/finality_update`
- `/eth/v0/beacon/light_client/optimistic_update`

HTTP Server-Sent Events (SSE):
- `light_client_finality_update_v0`
- `light_client_optimistic_update_v0`
@etan-status
Copy link
Contributor Author

etan-status commented Oct 3, 2022

Implemented in Nimbus at status-im/nimbus-eth2#4213 with a v0 suffix

Sample endpoint:

etan-status added a commit to status-im/nimbus-eth2 that referenced this pull request Oct 4, 2022
Implements the latest proposal for providing LC data via REST, as of
ethereum/beacon-APIs#247 with a v0 suffix.

Requests:
- `/eth/v0/beacon/light_client/bootstrap/{block_root}`
- `/eth/v0/beacon/light_client/updates?start_period={start_period}&count={count}`
- `/eth/v0/beacon/light_client/finality_update`
- `/eth/v0/beacon/light_client/optimistic_update`

HTTP Server-Sent Events (SSE):
- `light_client_finality_update_v0`
- `light_client_optimistic_update_v0`
@dadepo
Copy link

dadepo commented Oct 4, 2022

Proofs are not specific to light clients, and should be introduced separately, e.g., as part of the /debug namespace that already provides a way to query state. #181 (comment)

Only thought on this is that to be useful for light client purposes, it should not be put under the /debug namespace (as this shouldn't be exposed publicly).

@rolfyone
Copy link
Collaborator

rolfyone commented Oct 5, 2022

LGTM. Raised teku ticket for prioritisation.

Copy link
Collaborator

@rolfyone rolfyone left a comment

Choose a reason for hiding this comment

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

Looks like plenty of approval to merge this...

@rolfyone rolfyone merged commit 4dbc9d3 into ethereum:master Oct 10, 2022
etan-status added a commit to status-im/nimbus-eth2 that referenced this pull request Oct 12, 2022
The LC REST API has been merged into the ethereum/beacon-APIs specs:
- ethereum/beacon-APIs#247

Update URLs to v1 and update REST tests. Note that REST tests do not
start with Altair, so the tested BN will return empty / error responses.
etan-status added a commit to status-im/nimbus-eth2 that referenced this pull request Oct 13, 2022
The LC REST API has been merged into the ethereum/beacon-APIs specs:
- ethereum/beacon-APIs#247

Update URLs to v1 and update REST tests. Note that REST tests do not
start with Altair, so the tested BN will return empty / error responses.
zah pushed a commit to status-im/nimbus-eth2 that referenced this pull request Oct 13, 2022
Implements the latest proposal for providing LC data via REST, as of
ethereum/beacon-APIs#247 with a v0 suffix.

Requests:
- `/eth/v0/beacon/light_client/bootstrap/{block_root}`
- `/eth/v0/beacon/light_client/updates?start_period={start_period}&count={count}`
- `/eth/v0/beacon/light_client/finality_update`
- `/eth/v0/beacon/light_client/optimistic_update`

HTTP Server-Sent Events (SSE):
- `light_client_finality_update_v0`
- `light_client_optimistic_update_v0`
zah pushed a commit to status-im/nimbus-eth2 that referenced this pull request Oct 13, 2022
The LC REST API has been merged into the ethereum/beacon-APIs specs:
- ethereum/beacon-APIs#247

Update URLs to v1 and update REST tests. Note that REST tests do not
start with Altair, so the tested BN will return empty / error responses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants