Skip to content

Commit 7f76690

Browse files
committed
Use new historical_summaries beacon API endpoint in portal_bridge
1 parent b658415 commit 7f76690

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

fluffy/tools/portal_bridge/portal_bridge_beacon.nim

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import
2121
../eth_data_exporter/cl_data_exporter,
2222
./[portal_bridge_conf, portal_bridge_common]
2323

24-
const
25-
largeRequestsTimeout = 120.seconds # For downloading large items such as states.
26-
restRequestsTimeout = 30.seconds
24+
const restRequestsTimeout = 30.seconds
2725

2826
# TODO: From nimbus_binary_common, but we don't want to import that.
2927
proc sleepAsync(t: TimeDiff): Future[void] =
@@ -236,32 +234,36 @@ proc gossipHistoricalSummaries(
236234
portalRpcClient: RpcClient,
237235
cfg: RuntimeConfig,
238236
forkDigests: ref ForkDigests,
239-
): Future[Result[void, string]] {.async.} =
240-
let state =
237+
): Future[Result[void, string]] {.async: (raises: [CancelledError]).} =
238+
let summariesOpt =
241239
try:
242-
notice "Downloading beacon state"
240+
notice "Downloading beacon historical_summaries"
243241
awaitWithTimeout(
244-
restClient.getStateV2(StateIdent.init(StateIdentType.Finalized), cfg),
245-
largeRequestsTimeout,
242+
restClient.getHistoricalSummariesV1(
243+
StateIdent.init(StateIdentType.Finalized), cfg
244+
),
245+
restRequestsTimeout,
246246
):
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)
250-
251-
if state == nil:
252-
return err("No beacon state found")
253-
254-
withState(state[]):
255-
when consensusFork >= ConsensusFork.Capella:
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+
251+
if summariesOpt.isNone():
252+
return err("No historical_summaries found")
253+
254+
let summariesForked = summariesOpt.get()
255+
withForkyHistoricalSummariesWithProof(summariesForked):
256+
when consensusFork >= ConsensusFork.Electra:
257+
err("Historical summaries not yet supported for Electra and later forks")
258+
elif consensusFork >= ConsensusFork.Capella:
256259
let
257-
historical_summaries = forkyState.data.historical_summaries
258-
proof = ?buildProof(state[])
259-
epoch = forkyState.data.slot.epoch()
260+
epoch = forkySummaries.slot.epoch()
260261
forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg)
261262
summariesWithProof = HistoricalSummariesWithProof(
262-
epoch: epoch, historical_summaries: historical_summaries, proof: proof
263+
epoch: epoch,
264+
historical_summaries: forkySummaries.historical_summaries,
265+
proof: forkySummaries.proof,
263266
)
264-
265267
contentKey = encode(historicalSummariesContentKey(epoch.uint64))
266268
content = encodeSsz(summariesWithProof, forkDigest)
267269

@@ -271,11 +273,11 @@ proc gossipHistoricalSummaries(
271273
)
272274
info "Beacon historical_summaries gossiped", peers, epoch
273275

274-
return ok()
276+
ok()
275277
except CatchableError as e:
276-
return err("JSON-RPC error: " & $e.msg)
278+
err("JSON-RPC error: " & $e.msg)
277279
else:
278-
return err("No historical_summaries pre Capella")
280+
err("No historical summaries pre-Capella")
279281

280282
proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
281283
notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams()

vendor/nimbus-eth2

Submodule nimbus-eth2 updated 198 files

0 commit comments

Comments
 (0)