Use new historical_summaries beacon API endpoint in portal_bridge
This commit is contained in:
parent
9e98c934b7
commit
6a938774d0
|
@ -21,9 +21,7 @@ import
|
||||||
../eth_data_exporter/cl_data_exporter,
|
../eth_data_exporter/cl_data_exporter,
|
||||||
./[portal_bridge_conf, portal_bridge_common]
|
./[portal_bridge_conf, portal_bridge_common]
|
||||||
|
|
||||||
const
|
const restRequestsTimeout = 30.seconds
|
||||||
largeRequestsTimeout = 120.seconds # For downloading large items such as states.
|
|
||||||
restRequestsTimeout = 30.seconds
|
|
||||||
|
|
||||||
# TODO: From nimbus_binary_common, but we don't want to import that.
|
# TODO: From nimbus_binary_common, but we don't want to import that.
|
||||||
proc sleepAsync(t: TimeDiff): Future[void] =
|
proc sleepAsync(t: TimeDiff): Future[void] =
|
||||||
|
@ -236,46 +234,44 @@ proc gossipHistoricalSummaries(
|
||||||
portalRpcClient: RpcClient,
|
portalRpcClient: RpcClient,
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
forkDigests: ref ForkDigests,
|
forkDigests: ref ForkDigests,
|
||||||
): Future[Result[void, string]] {.async.} =
|
): Future[Result[void, string]] {.async: (raises: [CancelledError]).} =
|
||||||
let state =
|
let summariesOpt =
|
||||||
try:
|
try:
|
||||||
notice "Downloading beacon state"
|
notice "Downloading beacon historical_summaries"
|
||||||
awaitWithTimeout(
|
awaitWithTimeout(
|
||||||
restClient.getStateV2(StateIdent.init(StateIdentType.Finalized), cfg),
|
restClient.getHistoricalSummariesV1(
|
||||||
largeRequestsTimeout,
|
StateIdent.init(StateIdentType.Finalized), cfg
|
||||||
|
),
|
||||||
|
restRequestsTimeout,
|
||||||
):
|
):
|
||||||
return err("Attempt to download beacon state timed out")
|
return err("Attempt to download historical_summaries timed out")
|
||||||
except CatchableError as exc:
|
except RestError as exc:
|
||||||
return err("Unable to download beacon state: " & exc.msg)
|
return err("Unable to download historical_summaries: " & exc.msg)
|
||||||
|
|
||||||
if state == nil:
|
if summariesOpt.isNone():
|
||||||
return err("No beacon state found")
|
return err("No historical_summaries found")
|
||||||
|
|
||||||
withState(state[]):
|
let
|
||||||
when consensusFork >= ConsensusFork.Capella:
|
summaries = summariesOpt.get()
|
||||||
let
|
epoch = summaries.slot.epoch()
|
||||||
historical_summaries = forkyState.data.historical_summaries
|
forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg)
|
||||||
proof = ?buildProof(state[])
|
summariesWithProof = HistoricalSummariesWithProof(
|
||||||
epoch = forkyState.data.slot.epoch()
|
epoch: epoch,
|
||||||
forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg)
|
historical_summaries: summaries.historical_summaries,
|
||||||
summariesWithProof = HistoricalSummariesWithProof(
|
proof: summaries.proof,
|
||||||
epoch: epoch, historical_summaries: historical_summaries, proof: proof
|
)
|
||||||
)
|
contentKey = encode(historicalSummariesContentKey(epoch.uint64))
|
||||||
|
content = encodeSsz(summariesWithProof, forkDigest)
|
||||||
|
|
||||||
contentKey = encode(historicalSummariesContentKey(epoch.uint64))
|
try:
|
||||||
content = encodeSsz(summariesWithProof, forkDigest)
|
let peers = await portalRpcClient.portal_beaconRandomGossip(
|
||||||
|
contentKey.asSeq().toHex(), content.toHex()
|
||||||
|
)
|
||||||
|
info "Beacon historical_summaries gossiped", peers, epoch
|
||||||
|
|
||||||
try:
|
ok()
|
||||||
let peers = await portalRpcClient.portal_beaconRandomGossip(
|
except CatchableError as e:
|
||||||
contentKey.asSeq().toHex(), content.toHex()
|
err("JSON-RPC error: " & $e.msg)
|
||||||
)
|
|
||||||
info "Beacon historical_summaries gossiped", peers, epoch
|
|
||||||
|
|
||||||
return ok()
|
|
||||||
except CatchableError as e:
|
|
||||||
return err("JSON-RPC error: " & $e.msg)
|
|
||||||
else:
|
|
||||||
return err("No historical_summaries pre Capella")
|
|
||||||
|
|
||||||
proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
|
proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
|
||||||
notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams()
|
notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams()
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5d940b4c1eaf65475f8cea54d396ebbec35deec2
|
Subproject commit 566e69b1c44e4f271af75f6a7a7df6c0498890da
|
Loading…
Reference in New Issue