Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add debug_getHistoricalSummaries endpoint #7245

Merged

Conversation

acolytec3
Copy link
Contributor

Motivation

The Portal Network needs a way to access the HistoricalSummaries property on the BeaconState for post Capella beacon state since the HistoricalSummaries are used to anchor EL block header proofs to the beacon state roots in light client updates that the serve as the source of truth for verifying the authenticity of post capella EL block headers. This currently requires downloading the entire Beacon State from a beacon node willing to serve the debug endpoints and then throwing away everything except for the desired data (or else downloading an ERA file from a willing endpoint). It is desirable to be able to access this data more efficiently directly from beacon nodes.

Description

This adds a new getHistoricalSummaries endpoint to the debug namespace on the REST API that serves the HistoricalSummaries field from the current head BeaconState as SSZ bytes. We only need the most current one for use in constructing proofs of recent EL block headers embedded in a beacon block.

This mirrors similar experimental work being done in the nimbus client

Steps to test or reproduce

git checkout historicalSummaries-endpoint
./lodestar beacon \
--rest.namespace='*' \
--checkpointSyncUrl=https://beaconstate.info \

In a separate terminal

curl -X GET --header "Accept: application/octet-stream" "http://127.0.0.1:9596/eth/v1/debug/historical_summaries" > ./hs.ssz

Then, use a script like below to verify that historical summaries are correctly returned

    import { ssz } from '@lodestar/types'

    const summariesBytes = fs.readFileSync('./test/util/hs.ssz')
    const summaries = ssz.capella.BeaconState.fields.historicalSummaries.deserialize(summariesBytes)
    console.log(summaries)

@acolytec3 acolytec3 requested a review from a team as a code owner November 26, 2024 20:50
@CLAassistant
Copy link

CLAassistant commented Nov 26, 2024

CLA assistant check
All committers have signed the CLA.

@acolytec3 acolytec3 marked this pull request as draft November 26, 2024 20:50
@acolytec3 acolytec3 force-pushed the historicalSummaries-endpoint branch from 3c5383c to b45bdd8 Compare November 26, 2024 20:52
packages/api/src/beacon/routes/debug.ts Outdated Show resolved Hide resolved
packages/api/src/beacon/routes/debug.ts Outdated Show resolved Hide resolved
@g11tech g11tech changed the title Add debug_getHistoricalSummaries endpoint feat: Add debug_getHistoricalSummaries endpoint Nov 27, 2024
@nflaig nflaig changed the title feat: Add debug_getHistoricalSummaries endpoint feat: add debug_getHistoricalSummaries endpoint Nov 27, 2024
Copy link
Contributor

@g11tech g11tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, we can always move the endpoint once we have it in beacon apis, CI running

@acolytec3 acolytec3 marked this pull request as ready for review December 2, 2024 20:41
Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good to me, just few remarks regarding loading the state from bytes and need to make CI happy

packages/api/src/beacon/routes/debug.ts Outdated Show resolved Hide resolved
packages/beacon-node/src/api/impl/debug/index.ts Outdated Show resolved Hide resolved
@acolytec3
Copy link
Contributor Author

@nflaig general question, should I go ahead and move over to the lodestar namespace for now, following what nimbus is doing? I don't have an opinion on which namespace (nor do I know if this proposal would ultimately end up under debug or under maybe beacon as a light client API (since presumably this will be used mainly by Portal Network clients).

One further question, does it make sense to add the meta to the response mirroring the getState API? We don't use this directly in Portal Network so I don't have the context to know if this is a useful addition to the overal API.

@nflaig
Copy link
Member

nflaig commented Dec 3, 2024

general question, should I go ahead and move over to the lodestar namespace for now, following what nimbus is doing?

Yeah, might be better to go with lodestar namespace if it's anyhow not standardized between clients.

One further question, does it make sense to add the meta to the response mirroring the getState API? We don't use this directly in Portal Network so I don't have the context to know if this is a useful addition to the overal API.

If it would become standardized as part of beacon-api then it will for sure have the meta as well, if you don't need it we don't have to add it now, we can also always add it later on if there is demand.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.92%. Comparing base (37c4287) to head (a2e9cd7).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #7245      +/-   ##
============================================
+ Coverage     48.51%   48.92%   +0.41%     
============================================
  Files           600      601       +1     
  Lines         40142    40174      +32     
  Branches       2057     2061       +4     
============================================
+ Hits          19474    19655     +181     
+ Misses        20630    20481     -149     
  Partials         38       38              

@acolytec3
Copy link
Contributor Author

general question, should I go ahead and move over to the lodestar namespace for now, following what nimbus is doing?

Yeah, might be better to go with lodestar namespace if it's anyhow not standardized between clients.

One further question, does it make sense to add the meta to the response mirroring the getState API? We don't use this directly in Portal Network so I don't have the context to know if this is a useful addition to the overal API.

If it would become standardized as part of beacon-api then it will for sure have the meta as well, if you don't need it we don't have to add it now, we can also always add it later on if there is demand.

Sounds good. I have moved everything to lodestar and added a new unit test file for lodestar since it doesn't appear there was a unit test at all for that namespace. I opted to just create a specific test for that endpoint since running the GenericServerTest looks like it would require me to add unit testData for all of the lodestar endpoints which feels like it's beyond the scope of this PR.

const fork = config.getForkName(slot) as Exclude<ForkName, "phase0" | "altair" | "bellatrix">;

const stateView =
state instanceof Uint8Array ? loadState(config, chain.getHeadState(), state).state : state.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
state instanceof Uint8Array ? loadState(config, chain.getHeadState(), state).state : state.clone();
(state instanceof Uint8Array ? loadState(config, chain.getHeadState(), state).state : state.clone()) as BeaconStateCapella;

You can avoid the any below by casting this to a BeaconStateCapella here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the proof size for HistoricalSummaries changed in deneb (and will maybe again in Electra). Is it still safe to cast it to BeaconStateCapella here since the shape of the state is changing somewhat?

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -75,6 +79,16 @@ export type LodestarNodePeer = NodePeer & {

export type LodestarThreadType = "main" | "network" | "discv5";

const HistoricalSummariesResponseType = new ContainerType(
{
historicalSummaries: ssz.capella.HistoricalSummaries,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acolytec3 I converted this to lower case to align it with existing json responses

@@ -365,6 +389,21 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions<Endpo
},
resp: JsonOnlyResponseCodec,
},
getHistoricalSummaries: {
url: "/eth/v1/lodestar/historical_summaries/{state_id}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use v1 since it's now part of lodestar namespace

@acolytec3
Copy link
Contributor Author

Thanks for the approval! @nflaig once this gets merged, any idea how long before the public lodestar bootnodes will make it available?

@nflaig
Copy link
Member

nflaig commented Dec 3, 2024

any idea how long before the public lodestar bootnodes will make it available?

We plan to cut a rc at the end of the week, we discussed in the standup today to get your PR in for that as well, so the next release if testing goes well should be some time next week which means the public nodes would be updated next week as well.

@nflaig nflaig added this to the v1.24.0 milestone Dec 5, 2024
@wemeetagain wemeetagain merged commit d55bb2d into ChainSafe:unstable Dec 5, 2024
20 checks passed
wemeetagain added a commit that referenced this pull request Dec 20, 2024
* feat: add keymanager endpoint to retrieve proposer config (#7210)

* feat: add keymanager endpoint to retrieve proposer config

* Do not return empty builder config

* Check all builder proposer config values

* Fix settings builder config if undefined

* Fix builder config parsing

* Use ssz type to handle json serialization

Default parsing can't handle BigInt

* Revert "Use ssz type to handle json serialization"

This reverts commit 01fcea7.

* Fix boost factor json serialization

* Remove unused import

* Update test data

* Update proposer config test

* feat: add mekong network option (#7212)

* chore: fix import order with biome syntax (#7211)

Fix import order

* fix: consistently validate pubkey and throw 404 if not found (#7214)

* Throw error if pubkey is unknown when getting graffiti

* Consistently validate pubkey and throw 404 if not found

* fix: only return local keys from /eth/v1/keystores (#7215)

* fix: only return local keys from /eth/v1/keystores

* Fix fetching remote keys in node assertion

* feat: add and use getBlobsV1 to expedite gossip import (#7134)

* hookup the getblobs api to get bob and proof data from el

remove unused

fix import

metrics overhault, test, debugging testing, some feeback

fix

add nethermind bug dicussion link

fix

resolve conflicts

* deblobs timeout

* fix metric

* chore: revert async aggregate with randomness (#7218)

Revert "feat: asyncAggregateWithRandomness (#7204)"

This reverts commit e31d535.

* fix: update config for relaunched mekong network (#7220)

* fix: light client generating `LightClientUpdate` with wrong length of branches (#7187)

* initial commit

* Rewrite SyncCommitteeWitnessRepository

* Fix finality branch

* Update unit test

* fix e2e

* Review PR

---------

Co-authored-by: Nico Flaig <[email protected]>

* fix: archive finalized state when shutting down beacon node (#7221)

* Fix typo

* feat: remove unfinalized pubkey cache (#7230)

* Remove unfinalized pubkey cache

* lint

* Fix unit test

* chore: skip web3_provider unit tests (#7252)

* fix: prune checkpoint states at syncing time (#7241)

* fix: prune checkpoint states at syncing time

* fix: lint

* fix: check-types in test

* fix: sync cached isCompoundingValidatorArr at epoch transition (#7247)

* fix: handle outOfRangeData when range sync Deneb (#7249)

* fix: handle outOfRangeData for beaconBlocksMaybeBlobsByRange()

* fix: lint

* fix: archiveBlocks - handle deneb outOfRangeData block

* fix: sync cached balance when adding new validator to registry (#7255)

* fix: sync cached balance when adding new validator to registry

* chore: add more comments

* fix: remove persisted checkpoint states from the previous run at startup

* fix: do not throw error when trying to prune missing directory (#7257)

* docs: update documentation Oct 2024 (#7178)

* docs update oct 2024 init

* Reconfig quickstart nav and minor fixes

* fix lint

* spelling fixes

* minor fixes and add to wordlist

* prettier fix

* add to wordlist

* sort wordlist

* modify dominance to include lighthouse

* fix typescript casing and add recommendation

* add selection and boost_factor with keymanager notice

* update wordlist

* remove builder enabled and add keymanager api

* spelling

---------

Co-authored-by: Nico Flaig <[email protected]>

* chore(deps): bump cross-spawn from 7.0.3 to 7.0.6 in /docs (#7268)

Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.6.
- [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md)
- [Commits](moxystudio/node-cross-spawn@v7.0.3...v7.0.6)

---
updated-dependencies:
- dependency-name: cross-spawn
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: add error log to notifier if execution client auth failed (#7239)

* feat: add error log to notifier if execution client auth failed

* Update packages/beacon-node/src/node/notifier.ts

---------

Co-authored-by: NC <[email protected]>

* docs: display rcConfig flag on CLI reference page (#7270)

* docs: display rcConfig flag on CLI reference page

* Update word list

* chore: remove prettier as default formatter for all file types (#7275)

* chore: unhide flags relevant for devnets / testing (#7271)

* feat: debug too many shuffling promises (#7251)

* feat: add asyncShufflingCalculation to StateTransitionOpts

* feat: add asyncShufflingCalculation to all regen / processSlots consumers

* fix: default to false for async shuffling and remove unnecessary props

* fix: remove unnecessary flags from stateTransition

* feat: implement conditional build of shuffling for prepareNextSlot

* fix: spec test bug where shufflingCache is present from BeaconChain constructor

* feat: sync build next shuffling if not queued async

* fix: use getSync to pull next shuffling correctly

* docs: add comment to prepareNextSlot

* refactor: rename StateCloneOpts to StateRegenerationOpts

* feat: pass asyncShufflingCalculation through to afterProcessEpoch and refactor conditional to run purely sync

* docs: add issue number to comment

* chore: lint

* chore: unpin nodejs version from 22.4 (#6982)

* Revert "chore: pin nodejs version to 22.4 (#6964)"

This reverts commit f20484b.

* Don't revert formatting changes

---------

Co-authored-by: Nico Flaig <[email protected]>
Co-authored-by: Cayman <[email protected]>

* chore: update bootnodes file url for holesky and sepolia (#7276)

* feat: add `debug_getHistoricalSummaries` endpoint (#7245)

* feat: add new getHistoricalSummaries endpoint to debug namespace

* Add JSON response

* Restructure to use stateId and add proof to response

* add test scaffolding

* Address feedback

* Move getHistoricalSummaries to lodestar namespace

* add lodestar namespace unit test

* update route name to lodestar namespace

* cast state object as Capella state

* Lint

* json properties need to be lower case

* Make it v1 since it's now part of lodestar namespace

* Group with other /lodestar endpoints

* Simplify beacon node impl

* Rename return type

* Update test description

* Fix variable name

---------

Co-authored-by: Nico Flaig <[email protected]>

* chore: log sync committee signature errors as `error` (#7283)

* fix: update engine_getClientVersionV1 commit encoding (#7282)

* fix: check pubkey or validator index known to a state (#7284)

* fix: check pubkey or validator index known to a state

* chore: add more comments

* feat: lodestar script setup (#7254)

* feat: lodestar_setup

* feat: script_updates + docs

* feat: script_addition_in_docs + command_update

* Remove duplicate script from docs folder

* Minor script updates

* Update script to prepare docs and ignore copied file

* Update installation page

* Wording

---------

Co-authored-by: Nico Flaig <[email protected]>

* feat: add terminal-sized Electra giraffe banner (#7286)

* Create giraffeBanners.ts

* Wire in banner

* Fix file name

* lint

* Address @nflaig's comment

---------

Co-authored-by: NC <[email protected]>

* chore: pin nodejs version to 22.4 (#7291)

Revert "chore: unpin nodejs version from 22.4 (#6982)"

This reverts commit 69ae688.

* feat: expose `DOMAIN_APPLICATION_MASK` in config/spec api (#7296)

* feat: expose DOMAIN_APPLICATION_MASK in config/spec api

* Lint

* feat: make `MAX_REQUEST_BLOB_SIDECARS` and `MAX_BLOBS_PER_BLOCK` configurable (#7294)

* Init commit

* Fix check-types

* Add comment on how MAX_REQUEST_BLOB_SIDECARS is calculated

* Ensure proper config object is passed

* Address comment

---------

Co-authored-by: Nico Flaig <[email protected]>

* feat: use `BLOB_SIDECAR_SUBNET_COUNT` to configure blob subnets (#7297)

feat: use BLOB_SIDECAR_SUBNET_COUNT to configure blob subnets

* chore: log sync aggregate participants when producing beacon block body (#7300)

* chore: log sync aggregate participants when producing beacon block body

* Use isForkLightClient instead of ForkSeq

* Fix produce block unit tests

* chore: print graffiti when producing beacon block body (#7303)

* fix: warn if engine / builder failed to produce block within cutoff time (#7305)

* feat: add kzg commitment length check when validating gossip blocks (#7302)

* feat: add blob sidecar index check (#7313)

Validate blobSidecar index

* fix: fix blob sidecar index check (#7315)

Fix index check

* chore: fix format of printed graffiti from hex to utf-8 (#7306)

* chore: fix format of printed graffiti from hex to utf-8

* Use Buffer.from no copy with offset

* docs: batch commit typos and update contributor readme (#7312)

* batch commit typos and update contributor readme

* update donation text

Co-authored-by: Nico Flaig <[email protected]>

* correct spelling

Co-authored-by: Nico Flaig <[email protected]>

---------

Co-authored-by: Nico Flaig <[email protected]>

* chore: remove trailing null bytes from printed graffiti (#7320)

* chore: remove trailing null bytes from printed graffiti

* Use replaceAll instead of regex

* chore: unpin nodejs version from 22.4 (#7324)

Revert "chore: pin nodejs version to 22.4 (#7291)"

This reverts commit 99794d3.

* chore: bump package versions to 1.24.0

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Nico Flaig <[email protected]>
Co-authored-by: Nazar Hussain <[email protected]>
Co-authored-by: g11tech <[email protected]>
Co-authored-by: Matthew Keil <[email protected]>
Co-authored-by: NC <[email protected]>
Co-authored-by: twoeths <[email protected]>
Co-authored-by: Phil Ngo <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: acolytec3 <[email protected]>
Co-authored-by: Varun Guleria <[email protected]>
Co-authored-by: ClockworkYuzu <[email protected]>
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.24.0 🎉

@acolytec3
Copy link
Contributor Author

Thank you sir 🖖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants