-
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)
Adopts the light client data REST API used by Lodestar as defined in ethereum/beacon-APIs#181 with a v0 suffix. Requests: - `/eth/v0/light_client/bootstrap/{block_root}` - `/eth/v0/light_client/updates?from={from}&to={to}` - `/eth/v0/light_client/finality_update` - `/eth/v0/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.
- Loading branch information
1 parent
2c623e5
commit 7cf6a37
Showing
10 changed files
with
185 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,93 @@ | ||
# 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/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(block_root) | ||
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/light_client/updates") do ( | ||
`from`, to: Option[SyncCommitteePeriod]) -> RestApiResponse: | ||
doAssert node.dag.lightClientDataServe | ||
let vfrom = block: | ||
if `from`.isNone(): | ||
return RestApiResponse.jsonError(Http400, MissingFromValueError) | ||
let rfrom = `from`.get() | ||
if rfrom.isErr(): | ||
return RestApiResponse.jsonError(Http400, InvalidSyncPeriodError, | ||
$rfrom.error()) | ||
rfrom.get() | ||
let vto = block: | ||
if to.isNone(): | ||
return RestApiResponse.jsonError(Http400, MissingToValueError) | ||
let rto = to.get() | ||
if rto.isErr(): | ||
return RestApiResponse.jsonError(Http400, InvalidSyncPeriodError, | ||
$rto.error()) | ||
rto.get() | ||
let | ||
headPeriod = node.dag.head.slot.sync_committee_period | ||
# Limit number of updates in response | ||
maxSupportedCount = | ||
if startPeriod > headPeriod: | ||
0'u64 | ||
else: | ||
min(headPeriod + 1 - startPeriod, MAX_REQUEST_LIGHT_CLIENT_UPDATES) | ||
count = min(reqCount, maxSupportedCount) | ||
onePastPeriod = startPeriod + count | ||
|
||
var updates = newSeqOfCap[LightClientUpdate](numPeriods) | ||
for period in startPeriod..<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/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/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.