Skip to content

Commit

Permalink
Use new historical_summaries beacon API endpoint in portal_bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeme committed Nov 8, 2024
1 parent 9e98c93 commit 6a93877
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
72 changes: 34 additions & 38 deletions fluffy/tools/portal_bridge/portal_bridge_beacon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -236,46 +234,44 @@ 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")

withState(state[]):
when consensusFork >= ConsensusFork.Capella:
let
historical_summaries = forkyState.data.historical_summaries
proof = ?buildProof(state[])
epoch = forkyState.data.slot.epoch()
forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg)
summariesWithProof = HistoricalSummariesWithProof(
epoch: epoch, historical_summaries: historical_summaries, proof: proof
)
if summariesOpt.isNone():
return err("No historical_summaries found")

contentKey = encode(historicalSummariesContentKey(epoch.uint64))
content = encodeSsz(summariesWithProof, forkDigest)

try:
let peers = await portalRpcClient.portal_beaconRandomGossip(
contentKey.asSeq().toHex(), content.toHex()
)
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")
let
summaries = summariesOpt.get()
epoch = summaries.slot.epoch()
forkDigest = forkDigestAtEpoch(forkDigests[], epoch, cfg)
summariesWithProof = HistoricalSummariesWithProof(
epoch: epoch,
historical_summaries: summaries.historical_summaries,
proof: summaries.proof,
)
contentKey = encode(historicalSummariesContentKey(epoch.uint64))
content = encodeSsz(summariesWithProof, forkDigest)

try:
let peers = await portalRpcClient.portal_beaconRandomGossip(
contentKey.asSeq().toHex(), content.toHex()
)
info "Beacon historical_summaries gossiped", peers, epoch

ok()
except CatchableError as e:
err("JSON-RPC error: " & $e.msg)

proc runBeacon*(config: PortalBridgeConf) {.raises: [CatchableError].} =
notice "Launching Fluffy beacon chain bridge", cmdParams = commandLineParams()
Expand Down
2 changes: 1 addition & 1 deletion vendor/nimbus-eth2
Submodule nimbus-eth2 updated 95 files
+1 −1 .github/workflows/ci.yml
+1 −1 .github/workflows/nightly_build.yml
+10 −1 AllTests-mainnet.md
+24 −0 CHANGELOG.md
+2 −2 Makefile
+950 −0 beacon_chain/beacon_chain_file.nim
+11 −4 beacon_chain/beacon_node.nim
+12 −3 beacon_chain/beacon_node_light_client.nim
+123 −10 beacon_chain/consensus_object_pools/block_clearance.nim
+12 −1 beacon_chain/consensus_object_pools/block_pools_types.nim
+25 −19 beacon_chain/consensus_object_pools/blockchain_dag.nim
+1 −1 beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim
+247 −0 beacon_chain/consensus_object_pools/blockchain_list.nim
+82 −29 beacon_chain/el/el_manager.nim
+3 −3 beacon_chain/el/engine_api_conversions.nim
+15 −3 beacon_chain/el/eth1_chain.nim
+74 −18 beacon_chain/gossip_processing/block_processor.nim
+4 −4 beacon_chain/libnimbus_lc/libnimbus_lc.nim
+6 −6 beacon_chain/libnimbus_lc/test_files/transactions.json
+4 −6 beacon_chain/networking/eth2_network.nim
+1 −60 beacon_chain/networking/eth2_protocol_dsl.nim
+116 −49 beacon_chain/nimbus_beacon_node.nim
+2 −0 beacon_chain/rpc/rest_constants.nim
+49 −0 beacon_chain/rpc/rest_nimbus_api.nim
+2 −2 beacon_chain/rpc/rest_rewards_api.nim
+2 −1 beacon_chain/rpc/rest_utils.nim
+8 −1 beacon_chain/spec/digest.nim
+3 −47 beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
+19 −8 beacon_chain/spec/eth2_apis/rest_fork_config.nim
+60 −0 beacon_chain/spec/eth2_apis/rest_nimbus_calls.nim
+10 −1 beacon_chain/spec/eth2_apis/rest_types.nim
+0 −9 beacon_chain/spec/eth2_apis/rest_validator_calls.nim
+1 −1 beacon_chain/spec/presets.nim
+32 −0 beacon_chain/spec/signatures_batch.nim
+1 −1 beacon_chain/spec/state_transition.nim
+10 −3 beacon_chain/spec/state_transition_block.nim
+25 −11 beacon_chain/spec/validator.nim
+177 −53 beacon_chain/sync/sync_manager.nim
+501 −0 beacon_chain/sync/sync_overseer.nim
+85 −0 beacon_chain/sync/sync_types.nim
+0 −97 beacon_chain/validator_client/api.nim
+40 −8 beacon_chain/validator_client/common.nim
+1 −0 beacon_chain/validator_client/fork_service.nim
+1 −0 beacon_chain/validators/validator_monitor.nim
+1 −1 beacon_chain/version.nim
+4 −4 config.nims
+3 −4 docker/dist/entry_point.sh
+2 −2 docs/README.md
+1 −0 docs/requirements.in
+53 −31 docs/requirements.txt
+0 −3 docs/the_auditors_handbook/src/SUMMARY.md
+2 −0 docs/the_nimbus_book/mkdocs.yml
+0 −7 docs/the_nimbus_book/src/developers.md
+5 −48 docs/the_nimbus_book/src/el-light-client.md
+3 −4 docs/the_nimbus_book/src/eth1.md
+131 −0 docs/the_nimbus_book/src/execution-client.md
+0 −3 docs/the_nimbus_book/src/faq.md
+6 −7 docs/the_nimbus_book/src/index.md
+1 −1 docs/the_nimbus_book/src/log-rotate.md
+2 −2 docs/the_nimbus_book/src/networking.md
+1 −0 docs/the_nimbus_book/src/optimistic-sync.md
+6 −2 docs/the_nimbus_book/src/pi-guide.md
+2 −1 docs/the_nimbus_book/src/quick-start.md
+10 −4 docs/the_nimbus_book/src/rest-api.md
+1 −1 docs/the_nimbus_book/src/troubleshooting.md
+9 −6 ncli/ncli_db.nim
+2 −3 ncli/ncli_testnet.nim
+2 −2 research/block_sim.nim
+2 −1 scripts/run_ssz_fuzzing_test.nims
+3 −2 tests/all_tests.nim
+2 −5 tests/consensus_spec/test_fixture_fork_choice.nim
+ tests/fixtures/bfdata-test.bin
+6 −0 tests/test_attestation_pool.nim
+342 −0 tests/test_beacon_chain_file.nim
+2 −1 tests/test_block_processor.nim
+11 −8 tests/test_blockchain_dag.nim
+1 −1 tests/test_discovery.nim
+39 −9 tests/test_sync_manager.nim
+3 −3 tests/test_validator_client.nim
+1 −1 vendor/holesky
+1 −1 vendor/nim-confutils
+1 −1 vendor/nim-eth
+1 −1 vendor/nim-faststreams
+1 −1 vendor/nim-json-rpc
+1 −1 vendor/nim-json-serialization
+1 −1 vendor/nim-libbacktrace
+1 −1 vendor/nim-libp2p
+1 −1 vendor/nim-presto
+1 −1 vendor/nim-secp256k1
+1 −1 vendor/nim-serialization
+1 −1 vendor/nim-snappy
+1 −1 vendor/nim-web3
+1 −1 vendor/nim-websock
+1 −1 vendor/nimbus-build-system
+1 −1 wasm/index_ncli.html

0 comments on commit 6a93877

Please sign in to comment.