|
1 | 1 | # Nimbus - Portal Network |
2 | | -# Copyright (c) 2022-2024 Status Research & Development GmbH |
| 2 | +# Copyright (c) 2022-2025 Status Research & Development GmbH |
3 | 3 | # Licensed and distributed under either of |
4 | 4 | # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). |
5 | 5 | # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). |
@@ -193,6 +193,29 @@ proc stop*(lightClient: LightClient) {.async: (raises: []).} = |
193 | 193 | proc resetToFinalizedHeader*( |
194 | 194 | lightClient: LightClient, |
195 | 195 | header: ForkedLightClientHeader, |
196 | | - current_sync_committee: altair.SyncCommittee, |
| 196 | + current_sync_committee: SyncCommittee, |
197 | 197 | ) = |
198 | 198 | lightClient.processor[].resetToFinalizedHeader(header, current_sync_committee) |
| 199 | + |
| 200 | +proc resetToTrustedBlockRoot*( |
| 201 | + lightClient: LightClient, trustedBlockRoot: Digest |
| 202 | +) {.async: (raises: [CancelledError]).} = |
| 203 | + lightClient.network.trustedBlockRoot = Opt.some(trustedBlockRoot) |
| 204 | + |
| 205 | + let bootstrap = (await lightClient.network.getLightClientBootstrap(trustedBlockRoot)).valueOr: |
| 206 | + warn "Could not get bootstrap, wait for offer" |
| 207 | + # Empty, this will reset the LC store. |
| 208 | + # Then it will continue requesting or can receive through an offer |
| 209 | + lightClient.processor[].resetToFinalizedHeader( |
| 210 | + ForkedLightClientHeader(), SyncCommittee() |
| 211 | + ) |
| 212 | + return |
| 213 | + |
| 214 | + withForkyBootstrap(bootstrap): |
| 215 | + when lcDataFork > LightClientDataFork.None: |
| 216 | + let forkedHeader = ForkedLightClientHeader.init(forkyBootstrap.header) |
| 217 | + lightClient.resetToFinalizedHeader( |
| 218 | + forkedHeader, forkyBootstrap.current_sync_committee |
| 219 | + ) |
| 220 | + else: |
| 221 | + warn "Could not reset to trusted block root: no light client header pre Altair" |
0 commit comments