Use new historical_summaries beacon API endpoint in portal_bridge

This commit is contained in:
kdeme 2024-10-24 15:30:33 +02:00
parent 9e98c934b7
commit 6a938774d0
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
2 changed files with 33 additions and 37 deletions

View File

@ -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,32 @@ 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)
return err("Attempt to download historical_summaries timed out")
except RestError as exc:
return err("Unable to download historical_summaries: " & exc.msg)
if state == nil:
return err("No beacon state found")
if summariesOpt.isNone():
return err("No historical_summaries found")
withState(state[]):
when consensusFork >= ConsensusFork.Capella:
let
historical_summaries = forkyState.data.historical_summaries
proof = ?buildProof(state[])
epoch = forkyState.data.slot.epoch()
summaries = summariesOpt.get()
epoch = summaries.slot.epoch()
forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg)
summariesWithProof = HistoricalSummariesWithProof(
epoch: epoch, historical_summaries: historical_summaries, proof: proof
epoch: epoch,
historical_summaries: summaries.historical_summaries,
proof: summaries.proof,
)
contentKey = encode(historicalSummariesContentKey(epoch.uint64))
content = encodeSsz(summariesWithProof, forkDigest)
@ -271,11 +269,9 @@ proc gossipHistoricalSummaries(
)
info "Beacon historical_summaries gossiped", peers, epoch
return ok()
ok()
except CatchableError as e:
return err("JSON-RPC error: " & $e.msg)
else:
return err("No historical_summaries pre Capella")
err("JSON-RPC error: " & $e.msg)
proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams()

2
vendor/nimbus-eth2 vendored

@ -1 +1 @@
Subproject commit 5d940b4c1eaf65475f8cea54d396ebbec35deec2
Subproject commit 566e69b1c44e4f271af75f6a7a7df6c0498890da