From d51d99f7c172e790061315d8e1f27ca01773a170 Mon Sep 17 00:00:00 2001 From: kdeme <7857583+kdeme@users.noreply.github.com> Date: Fri, 14 Feb 2025 19:15:21 +0100 Subject: [PATCH] Use new historical_summaries beacon API endpoint in portal_bridge --- .../portal_bridge/portal_bridge_beacon.nim | 52 ++++++++++--------- vendor/nimbus-eth2 | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/fluffy/tools/portal_bridge/portal_bridge_beacon.nim b/fluffy/tools/portal_bridge/portal_bridge_beacon.nim index 6863f17fd..999282feb 100644 --- a/fluffy/tools/portal_bridge/portal_bridge_beacon.nim +++ b/fluffy/tools/portal_bridge/portal_bridge_beacon.nim @@ -21,9 +21,7 @@ import ../eth_data_exporter/cl_data_exporter, ./[portal_bridge_conf, portal_bridge_common] -const - largeRequestsTimeout = 120.seconds # For downloading large items such as states. - restRequestsTimeout = 30.seconds +const restRequestsTimeout = 30.seconds # TODO: From nimbus_binary_common, but we don't want to import that. proc sleepAsync(t: TimeDiff): Future[void] = @@ -236,32 +234,36 @@ proc gossipHistoricalSummaries( portalRpcClient: RpcClient, cfg: RuntimeConfig, forkDigests: ref ForkDigests, -): Future[Result[void, string]] {.async.} = - let state = +): Future[Result[void, string]] {.async: (raises: [CancelledError]).} = + let summariesOpt = try: - notice "Downloading beacon state" + notice "Downloading beacon historical_summaries" awaitWithTimeout( - restClient.getStateV2(StateIdent.init(StateIdentType.Finalized), cfg), - largeRequestsTimeout, + restClient.getHistoricalSummariesV1( + StateIdent.init(StateIdentType.Finalized), cfg + ), + restRequestsTimeout, ): - return err("Attempt to download beacon state timed out") - except CatchableError as exc: - return err("Unable to download beacon state: " & exc.msg) - - if state == nil: - return err("No beacon state found") - - withState(state[]): - when consensusFork >= ConsensusFork.Capella: + return err("Attempt to download historical_summaries timed out") + except RestError as exc: + return err("Unable to download historical_summaries: " & exc.msg) + + if summariesOpt.isNone(): + return err("No historical_summaries found") + + let summariesForked = summariesOpt.get() + withForkyHistoricalSummariesWithProof(summariesForked): + when consensusFork >= ConsensusFork.Electra: + err("Historical summaries not yet supported for Electra and later forks") + elif consensusFork >= ConsensusFork.Capella: let - historical_summaries = forkyState.data.historical_summaries - proof = ?buildProof(state[]) - epoch = forkyState.data.slot.epoch() + epoch = forkySummaries.slot.epoch() forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg) summariesWithProof = HistoricalSummariesWithProof( - epoch: epoch, historical_summaries: historical_summaries, proof: proof + epoch: epoch, + historical_summaries: forkySummaries.historical_summaries, + proof: forkySummaries.proof, ) - contentKey = encode(historicalSummariesContentKey(epoch.uint64)) content = encodeSsz(summariesWithProof, forkDigest) @@ -271,11 +273,11 @@ proc gossipHistoricalSummaries( ) info "Beacon historical_summaries gossiped", peers, epoch - return ok() + ok() except CatchableError as e: - return err("JSON-RPC error: " & $e.msg) + err("JSON-RPC error: " & $e.msg) else: - return err("No historical_summaries pre Capella") + err("No historical summaries pre-Capella") proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} = notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams() diff --git a/vendor/nimbus-eth2 b/vendor/nimbus-eth2 index a629d6bd8..6cebf610d 160000 --- a/vendor/nimbus-eth2 +++ b/vendor/nimbus-eth2 @@ -1 +1 @@ -Subproject commit a629d6bd89eddef49d28f545d5ec7d516afe90b1 +Subproject commit 6cebf610d8ac9047bc8cc44427fb3194581b845f