Skip to content

Commit 33e64b4

Browse files
committed
Use new historical_summaries beacon API endpoint in portal_bridge
1 parent 0d4de33 commit 33e64b4

File tree

2 files changed

+35
-39
lines changed

2 files changed

+35
-39
lines changed

fluffy/tools/portal_bridge/portal_bridge_beacon.nim

Lines changed: 34 additions & 38 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,46 +234,44 @@ 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)
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)
250250

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")
264253

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)
279275

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

0 commit comments

Comments
 (0)