-
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
21
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.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f28469d
light client init
chirag-parmar ce5b639
builds
chirag-parmar a1a593f
download per slot
chirag-parmar a13c7cf
format
chirag-parmar a5a6b2b
fix library
chirag-parmar b27b18a
nits
chirag-parmar ce6bf3d
multiple endpoints in config
chirag-parmar b0d5536
fix worker issue
chirag-parmar dc15f57
fix
chirag-parmar 5596f23
format
chirag-parmar 4e19ffe
reviews
chirag-parmar aa1897e
change casing and fix lib
chirag-parmar 054dcfc
formatting
chirag-parmar 731adf1
reviews
chirag-parmar 3bc98c0
fix
chirag-parmar 74b38ad
reraise cancelled
chirag-parmar 26f179b
fix
chirag-parmar 4ef01d8
fix naming and scoring
chirag-parmar 253d878
remove unused variables
chirag-parmar 7bc48e3
fix cancellation
chirag-parmar a91631d
need not be comma separated
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # 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: [].} | ||
|
|
||
| import | ||
| chronicles, | ||
| chronos, | ||
| beacon_chain/gossip_processing/light_client_processor, | ||
| beacon_chain/beacon_clock, | ||
| ./lc_manager # use the modified light client manager | ||
|
|
||
| type | ||
| LightClientHeaderCallback* = proc( | ||
| lightClient: LightClient, header: ForkedLightClientHeader | ||
| ) {.gcsafe, raises: [].} | ||
|
|
||
| LightClient* = ref object | ||
| cfg: RuntimeConfig | ||
| forkDigests: ref ForkDigests | ||
| getBeaconTime*: GetBeaconTimeFn | ||
| store*: ref ForkedLightClientStore | ||
| processor*: ref LightClientProcessor | ||
| manager: LightClientManager | ||
| onFinalizedHeader*, onOptimisticHeader*: LightClientHeaderCallback | ||
| trustedBlockRoot*: Option[Eth2Digest] | ||
|
|
||
| func getFinalizedHeader*(lightClient: LightClient): ForkedLightClientHeader = | ||
| withForkyStore(lightClient.store[]): | ||
| when lcDataFork > LightClientDataFork.None: | ||
| var header = ForkedLightClientHeader(kind: lcDataFork) | ||
| header.forky(lcDataFork) = forkyStore.finalized_header | ||
| header | ||
| else: | ||
| default(ForkedLightClientHeader) | ||
|
|
||
| func getOptimisticHeader*(lightClient: LightClient): ForkedLightClientHeader = | ||
| withForkyStore(lightClient.store[]): | ||
| when lcDataFork > LightClientDataFork.None: | ||
| var header = ForkedLightClientHeader(kind: lcDataFork) | ||
| header.forky(lcDataFork) = forkyStore.optimistic_header | ||
| header | ||
| else: | ||
| default(ForkedLightClientHeader) | ||
|
|
||
| proc new*( | ||
| T: type LightClient, | ||
| rng: ref HmacDrbgContext, | ||
| cfg: RuntimeConfig, | ||
| forkDigests: ref ForkDigests, | ||
| getBeaconTime: GetBeaconTimeFn, | ||
| genesis_validators_root: Eth2Digest, | ||
| finalizationMode: LightClientFinalizationMode, | ||
| ): T = | ||
| let lightClient = LightClient( | ||
| cfg: cfg, | ||
| forkDigests: forkDigests, | ||
| getBeaconTime: getBeaconTime, | ||
| store: (ref ForkedLightClientStore)(), | ||
| ) | ||
|
|
||
| func getTrustedBlockRoot(): Option[Eth2Digest] = | ||
| lightClient.trustedBlockRoot | ||
|
|
||
| proc onStoreInitialized() = | ||
| discard | ||
|
|
||
| proc onFinalizedHeader() = | ||
| if lightClient.onFinalizedHeader != nil: | ||
| lightClient.onFinalizedHeader(lightClient, lightClient.getFinalizedHeader) | ||
|
|
||
| proc onOptimisticHeader() = | ||
| if lightClient.onOptimisticHeader != nil: | ||
| lightClient.onOptimisticHeader(lightClient, lightClient.getOptimisticHeader) | ||
|
|
||
| const | ||
| dumpEnabled = false | ||
| dumpDirInvalid = "." | ||
| dumpDirIncoming = "." | ||
|
|
||
| # initialize without dumping | ||
| lightClient.processor = LightClientProcessor.new( | ||
| dumpEnabled, dumpDirInvalid, dumpDirIncoming, cfg, genesis_validators_root, | ||
| finalizationMode, lightClient.store, getBeaconTime, getTrustedBlockRoot, | ||
| onStoreInitialized, onFinalizedHeader, onOptimisticHeader, | ||
| ) | ||
|
|
||
| proc lightClientVerifier( | ||
| obj: SomeForkedLightClientObject | ||
| ): Future[Result[void, LightClientVerifierError]] {. | ||
| async: (raises: [CancelledError], raw: true) | ||
| .} = | ||
| let resfut = Future[Result[void, LightClientVerifierError]] | ||
| .Raising([CancelledError]) | ||
| .init("lightClientVerifier") | ||
| lightClient.processor[].addObject(MsgSource.gossip, obj, resfut) | ||
| resfut | ||
|
|
||
| proc bootstrapVerifier(obj: ForkedLightClientBootstrap): auto = | ||
| lightClientVerifier(obj) | ||
|
|
||
| proc updateVerifier(obj: ForkedLightClientUpdate): auto = | ||
| lightClientVerifier(obj) | ||
|
|
||
| proc finalityVerifier(obj: ForkedLightClientFinalityUpdate): auto = | ||
| lightClientVerifier(obj) | ||
|
|
||
| proc optimisticVerifier(obj: ForkedLightClientOptimisticUpdate): auto = | ||
| lightClientVerifier(obj) | ||
|
|
||
| func isLightClientStoreInitialized(): bool = | ||
| lightClient.store[].kind > LightClientDataFork.None | ||
|
|
||
| func isNextSyncCommitteeKnown(): bool = | ||
| withForkyStore(lightClient.store[]): | ||
| when lcDataFork > LightClientDataFork.None: | ||
| forkyStore.is_next_sync_committee_known | ||
| else: | ||
| false | ||
|
|
||
| func getFinalizedSlot(): Slot = | ||
| withForkyStore(lightClient.store[]): | ||
| when lcDataFork > LightClientDataFork.None: | ||
| forkyStore.finalized_header.beacon.slot | ||
| else: | ||
| GENESIS_SLOT | ||
|
|
||
| func getOptimisticSlot(): Slot = | ||
| withForkyStore(lightClient.store[]): | ||
| when lcDataFork > LightClientDataFork.None: | ||
| forkyStore.optimistic_header.beacon.slot | ||
| else: | ||
| GENESIS_SLOT | ||
|
|
||
| lightClient.manager = LightClientManager.init( | ||
| rng, cfg.timeParams, getTrustedBlockRoot, bootstrapVerifier, updateVerifier, | ||
| finalityVerifier, optimisticVerifier, isLightClientStoreInitialized, | ||
| isNextSyncCommitteeKnown, getFinalizedSlot, getOptimisticSlot, getBeaconTime, | ||
| ) | ||
|
|
||
| lightClient | ||
|
|
||
| proc setBackend*(lightClient: LightClient, backend: EthLCBackend) = | ||
| lightClient.manager.backend = backend | ||
chirag-parmar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| proc start*(lightClient: LightClient) = | ||
| info "Starting beacon light client", trusted_block_root = lightClient.trustedBlockRoot | ||
| lightClient.manager.start() | ||
|
|
||
| proc stop*(lightClient: LightClient) {.async: (raises: []).} = | ||
| info "Stopping beacon light client" | ||
| await lightClient.manager.stop() | ||
|
|
||
| proc resetToFinalizedHeader*( | ||
| lightClient: LightClient, | ||
| header: ForkedLightClientHeader, | ||
| current_sync_committee: SyncCommittee, | ||
| ) = | ||
| lightClient.processor[].resetToFinalizedHeader(header, current_sync_committee) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.