-
Notifications
You must be signed in to change notification settings - Fork 147
proxy: rest based light client #3782
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
Open
chirag-parmar
wants to merge
10
commits into
master
Choose a base branch
from
proxy-rest-lc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+758
−417
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba52c51
light client init
chirag-parmar 362b65b
builds
chirag-parmar 10b6757
download per slot
chirag-parmar 2513d9a
format
chirag-parmar ca62170
fix library
chirag-parmar 137804f
nits
chirag-parmar bbf5261
multiple endpoints in config
chirag-parmar 4f17091
fix worker issue
chirag-parmar 9bcebe2
fix
chirag-parmar 08cbdcb
format
chirag-parmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,138 @@ | ||
| # nimbus_verified_proxy | ||
| # Copyright (c) 2025 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: [], gcsafe.} | ||
|
|
||
| import | ||
| stint, | ||
| chronos, | ||
| chronicles, | ||
| presto/client, | ||
| beacon_chain/spec/eth2_apis/rest_light_client_calls, | ||
| beacon_chain/spec/presets, | ||
| beacon_chain/spec/forks, | ||
| ./lc/lc_manager, | ||
| ./nimbus_verified_proxy_conf | ||
|
|
||
| logScope: | ||
| topics = "SSZLCRestClient" | ||
|
|
||
| const | ||
| MaxMessageBodyBytes* = 128 * 1024 * 1024 # 128 MB (JSON encoded) | ||
| BASE_URL = "/eth/v1/beacon/light_client" | ||
|
|
||
| type | ||
| LCRestPeer = ref object | ||
| score: int | ||
| restClient: RestClientRef | ||
|
|
||
| LCRestClient* = ref object | ||
| cfg: RuntimeConfig | ||
| forkDigests: ref ForkDigests | ||
| peers: seq[LCRestPeer] | ||
| urls: seq[string] | ||
|
|
||
| func new*( | ||
| T: type LCRestClient, cfg: RuntimeConfig, forkDigests: ref ForkDigests | ||
| ): LCRestClient = | ||
| LCRestClient(cfg: cfg, forkDigests: forkDigests, peers: @[]) | ||
|
|
||
| proc addEndpoints*(client: LCRestClient, urlList: UrlList) {.raises: [ValueError].} = | ||
| for endpoint in urlList.urls: | ||
| if endpoint in client.urls: | ||
| continue | ||
|
|
||
| let restClient = RestClientRef.new(endpoint).valueOr: | ||
| raise newException(ValueError, $error) | ||
|
|
||
| client.peers.add(LCRestPeer(score: 0, restClient: restClient)) | ||
| client.urls.add(endpoint) | ||
|
|
||
| proc closeAll*(client: LCRestClient) {.async: (raises: []).} = | ||
| for peer in client.peers: | ||
| await peer.restClient.closeWait() | ||
|
|
||
| client.peers.setLen(0) | ||
| client.urls.setLen(0) | ||
|
|
||
| proc getEthLCBackend*(client: LCRestClient): EthLCBackend = | ||
| let | ||
| getLCBootstrapProc = proc( | ||
| reqId: uint64, blockRoot: Eth2Digest | ||
| ): Future[NetRes[ForkedLightClientBootstrap]] {.async: (raises: [CancelledError]).} = | ||
| let | ||
| peer = client.peers[reqId mod uint64(client.peers.len)] | ||
| res = | ||
| try: | ||
| await peer.restClient.getLightClientBootstrap( | ||
| blockRoot, client.cfg, client.forkDigests | ||
| ) | ||
| except CatchableError as e: | ||
| raise newException(CancelledError, e.msg) | ||
|
|
||
| ok(res) | ||
|
|
||
| getLCUpdatesProc = proc( | ||
| reqId: uint64, startPeriod: SyncCommitteePeriod, count: uint64 | ||
| ): Future[LightClientUpdatesByRangeResponse] {.async: (raises: [CancelledError]).} = | ||
| let | ||
| peer = client.peers[reqId mod uint64(client.peers.len)] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
| res = | ||
| try: | ||
| await peer.restClient.getLightClientUpdatesByRange( | ||
| startPeriod, count, client.cfg, client.forkDigests | ||
| ) | ||
| except CatchableError as e: | ||
| raise newException(CancelledError, e.msg) | ||
|
|
||
| ok(res) | ||
|
|
||
| getLCFinalityProc = proc( | ||
| reqId: uint64 | ||
| ): Future[NetRes[ForkedLightClientFinalityUpdate]] {. | ||
| async: (raises: [CancelledError]) | ||
| .} = | ||
| let | ||
| peer = client.peers[reqId mod uint64(client.peers.len)] | ||
| res = | ||
| try: | ||
| await peer.restClient.getLightClientFinalityUpdate( | ||
| client.cfg, client.forkDigests | ||
| ) | ||
| except CatchableError as e: | ||
| raise newException(CancelledError, e.msg) | ||
|
|
||
| ok(res) | ||
|
|
||
| getLCOptimisticProc = proc( | ||
| reqId: uint64 | ||
| ): Future[NetRes[ForkedLightClientOptimisticUpdate]] {. | ||
| async: (raises: [CancelledError]) | ||
| .} = | ||
| let | ||
| peer = client.peers[reqId mod uint64(client.peers.len)] | ||
| res = | ||
| try: | ||
| await peer.restClient.getLightClientOptimisticUpdate( | ||
| client.cfg, client.forkDigests | ||
| ) | ||
| except CatchableError as e: | ||
| raise newException(CancelledError, e.msg) | ||
|
|
||
| ok(res) | ||
|
|
||
| updateScoreProc = proc(reqId: uint64, value: int) = | ||
| let peer = client.peers[reqId mod uint64(client.peers.len)] | ||
| peer.score += value | ||
|
|
||
| EthLCBackend( | ||
| getLightClientBootstrap: getLCBootstrapProc, | ||
| getLightClientUpdatesByRange: getLCUpdatesProc, | ||
| getLightClientFinalityUpdate: getLCFinalityProc, | ||
| getLightClientOptimisticUpdate: getLCOptimisticProc, | ||
| updateScore: updateScoreProc, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CL has a helper,
lenu64, maybe available here