|
21 | 21 | ../eth_data_exporter/cl_data_exporter,
|
22 | 22 | ./[portal_bridge_conf, portal_bridge_common]
|
23 | 23 |
|
24 |
| -const |
25 |
| - largeRequestsTimeout = 120.seconds # For downloading large items such as states. |
26 |
| - restRequestsTimeout = 30.seconds |
| 24 | +const restRequestsTimeout = 30.seconds |
27 | 25 |
|
28 | 26 | # TODO: From nimbus_binary_common, but we don't want to import that.
|
29 | 27 | proc sleepAsync(t: TimeDiff): Future[void] =
|
@@ -236,46 +234,44 @@ proc gossipHistoricalSummaries(
|
236 | 234 | portalRpcClient: RpcClient,
|
237 | 235 | cfg: RuntimeConfig,
|
238 | 236 | forkDigests: ref ForkDigests,
|
239 |
| -): Future[Result[void, string]] {.async.} = |
240 |
| - let state = |
| 237 | +): Future[Result[void, string]] {.async: (raises: [CancelledError]).} = |
| 238 | + let summariesOpt = |
241 | 239 | try:
|
242 |
| - notice "Downloading beacon state" |
| 240 | + notice "Downloading beacon historical_summaries" |
243 | 241 | awaitWithTimeout(
|
244 |
| - restClient.getStateV2(StateIdent.init(StateIdentType.Finalized), cfg), |
245 |
| - largeRequestsTimeout, |
| 242 | + restClient.getHistoricalSummariesV1( |
| 243 | + StateIdent.init(StateIdentType.Finalized), cfg |
| 244 | + ), |
| 245 | + restRequestsTimeout, |
246 | 246 | ):
|
247 |
| - return err("Attempt to download beacon state timed out") |
248 |
| - except CatchableError as exc: |
249 |
| - return err("Unable to download beacon state: " & exc.msg) |
| 247 | + return err("Attempt to download historical_summaries timed out") |
| 248 | + except RestError as exc: |
| 249 | + return err("Unable to download historical_summaries: " & exc.msg) |
250 | 250 |
|
251 |
| - if state == nil: |
252 |
| - return err("No beacon state found") |
253 |
| - |
254 |
| - withState(state[]): |
255 |
| - when consensusFork >= ConsensusFork.Capella: |
256 |
| - let |
257 |
| - historical_summaries = forkyState.data.historical_summaries |
258 |
| - proof = ?buildProof(state[]) |
259 |
| - epoch = forkyState.data.slot.epoch() |
260 |
| - forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg) |
261 |
| - summariesWithProof = HistoricalSummariesWithProof( |
262 |
| - epoch: epoch, historical_summaries: historical_summaries, proof: proof |
263 |
| - ) |
| 251 | + if summariesOpt.isNone(): |
| 252 | + return err("No historical_summaries found") |
264 | 253 |
|
265 |
| - contentKey = encode(historicalSummariesContentKey(epoch.uint64)) |
266 |
| - content = encodeSsz(summariesWithProof, forkDigest) |
267 |
| - |
268 |
| - try: |
269 |
| - let peers = await portalRpcClient.portal_beaconRandomGossip( |
270 |
| - contentKey.asSeq().toHex(), content.toHex() |
271 |
| - ) |
272 |
| - info "Beacon historical_summaries gossiped", peers, epoch |
273 |
| - |
274 |
| - return ok() |
275 |
| - except CatchableError as e: |
276 |
| - return err("JSON-RPC error: " & $e.msg) |
277 |
| - else: |
278 |
| - return err("No historical_summaries pre Capella") |
| 254 | + let |
| 255 | + summaries = summariesOpt.get() |
| 256 | + epoch = summaries.slot.epoch() |
| 257 | + forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg) |
| 258 | + summariesWithProof = HistoricalSummariesWithProof( |
| 259 | + epoch: epoch, |
| 260 | + historical_summaries: summaries.historical_summaries, |
| 261 | + proof: summaries.proof, |
| 262 | + ) |
| 263 | + contentKey = encode(historicalSummariesContentKey(epoch.uint64)) |
| 264 | + content = encodeSsz(summariesWithProof, forkDigest) |
| 265 | + |
| 266 | + try: |
| 267 | + let peers = await portalRpcClient.portal_beaconRandomGossip( |
| 268 | + contentKey.asSeq().toHex(), content.toHex() |
| 269 | + ) |
| 270 | + info "Beacon historical_summaries gossiped", peers, epoch |
| 271 | + |
| 272 | + ok() |
| 273 | + except CatchableError as e: |
| 274 | + err("JSON-RPC error: " & $e.msg) |
279 | 275 |
|
280 | 276 | proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
|
281 | 277 | notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams()
|
|
0 commit comments