-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adopt LC REST API with v0 suffix (without proofs) (#3775)
* adopt LC REST API with v0 suffix (without proofs) Adopts the light client data REST API used by Lodestar as defined in ethereum/beacon-APIs#181 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` More work is needed to adopt the proofs endpoint, it is not included. * initialize event queues * register event topics
- Loading branch information
1 parent
5439978
commit 61ee061
Showing
10 changed files
with
194 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
# Copyright (c) 2018-2021 Status Research & Development GmbH | ||
# beacon_chain | ||
# Copyright (c) 2018-2022 Status Research & Development GmbH | ||
# Licensed and distributed under either of | ||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). | ||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). | ||
# at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
|
||
{.push raises: [Defect].} | ||
|
||
## The `rest_api` module is a server implementation for the common REST API for | ||
## Ethereum 2 found at https://ethereum.github.io/eth2.0-APIs/# | ||
## along with several nimbus-specific extensions. It is used by the validator | ||
## client as well as many community utilities. | ||
## A corresponding client can be found in the | ||
## `spec/eth2_apis/rest_beacon_client` module | ||
|
||
import | ||
"."/[ | ||
rest_utils, | ||
rest_beacon_api, rest_config_api, rest_debug_api, rest_event_api, | ||
rest_nimbus_api, rest_node_api, rest_validator_api, rest_key_management_api] | ||
rest_key_management_api, rest_light_client_api, rest_nimbus_api, | ||
rest_node_api, rest_validator_api] | ||
|
||
export | ||
rest_utils, | ||
rest_beacon_api, rest_config_api, rest_debug_api, rest_event_api, | ||
rest_nimbus_api, rest_node_api, rest_validator_api, rest_key_management_api | ||
rest_key_management_api, rest_light_client_api, rest_nimbus_api, | ||
rest_node_api, rest_validator_api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# beacon_chain | ||
# Copyright (c) 2021-2022 Status Research & Development GmbH | ||
# Licensed and distributed under either of | ||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). | ||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). | ||
# at your option. This file may not be copied, modified, or distributed except according to those terms. | ||
|
||
{.push raises: [Defect].} | ||
|
||
import chronicles | ||
import ../beacon_node, | ||
./rest_utils | ||
|
||
logScope: topics = "rest_light_client" | ||
|
||
proc installLightClientApiHandlers*(router: var RestRouter, node: BeaconNode) = | ||
# https://github.com/ethereum/beacon-APIs/pull/181 | ||
router.api(MethodGet, | ||
"/eth/v0/beacon/light_client/bootstrap/{block_root}") do ( | ||
block_root: Eth2Digest) -> RestApiResponse: | ||
doAssert node.dag.lightClientDataServe | ||
let vroot = block: | ||
if block_root.isErr(): | ||
return RestApiResponse.jsonError(Http400, InvalidBlockRootValueError, | ||
$block_root.error()) | ||
block_root.get() | ||
|
||
let bootstrap = node.dag.getLightClientBootstrap(vroot) | ||
if bootstrap.isOk: | ||
return RestApiResponse.jsonResponse(bootstrap) | ||
else: | ||
return RestApiResponse.jsonError(Http404, LCBootstrapUnavailable) | ||
|
||
# https://github.com/ethereum/beacon-APIs/pull/181 | ||
router.api(MethodGet, | ||
"/eth/v0/beacon/light_client/updates") do ( | ||
start_period: Option[SyncCommitteePeriod], count: Option[uint64] | ||
) -> RestApiResponse: | ||
doAssert node.dag.lightClientDataServe | ||
let vstart = block: | ||
if start_period.isNone(): | ||
return RestApiResponse.jsonError(Http400, MissingStartPeriodValueError) | ||
let rstart = start_period.get() | ||
if rstart.isErr(): | ||
return RestApiResponse.jsonError(Http400, InvalidSyncPeriodError, | ||
$rstart.error()) | ||
rstart.get() | ||
let vcount = block: | ||
if count.isNone(): | ||
return RestApiResponse.jsonError(Http400, MissingCountValueError) | ||
let rcount = count.get() | ||
if rcount.isErr(): | ||
return RestApiResponse.jsonError(Http400, InvalidCountError, | ||
$rcount.error()) | ||
rcount.get() | ||
let | ||
headPeriod = node.dag.head.slot.sync_committee_period | ||
# Limit number of updates in response | ||
maxSupportedCount = | ||
if vstart > headPeriod: | ||
0'u64 | ||
else: | ||
min(headPeriod + 1 - vstart, MAX_REQUEST_LIGHT_CLIENT_UPDATES) | ||
numPeriods = min(vcount, maxSupportedCount) | ||
onePastPeriod = vstart + numPeriods | ||
|
||
var updates = newSeqOfCap[LightClientUpdate](numPeriods) | ||
for period in vstart..<onePastPeriod: | ||
let update = node.dag.getLightClientUpdateForPeriod(period) | ||
if update.isSome: | ||
updates.add update.get | ||
return RestApiResponse.jsonResponse(updates) | ||
|
||
# https://github.com/ethereum/beacon-APIs/pull/181 | ||
router.api(MethodGet, | ||
"/eth/v0/beacon/light_client/finality_update") do ( | ||
) -> RestApiResponse: | ||
doAssert node.dag.lightClientDataServe | ||
let finality_update = node.dag.getLightClientFinalityUpdate() | ||
if finality_update.isSome: | ||
return RestApiResponse.jsonResponse(finality_update) | ||
else: | ||
return RestApiResponse.jsonError(Http404, LCFinUpdateUnavailable) | ||
|
||
# https://github.com/ethereum/beacon-APIs/pull/181 | ||
router.api(MethodGet, | ||
"/eth/v0/beacon/light_client/optimistic_update") do ( | ||
) -> RestApiResponse: | ||
doAssert node.dag.lightClientDataServe | ||
let optimistic_update = node.dag.getLightClientOptimisticUpdate() | ||
if optimistic_update.isSome: | ||
return RestApiResponse.jsonResponse(optimistic_update) | ||
else: | ||
return RestApiResponse.jsonError(Http404, LCOptUpdateUnavailable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.