Skip to content

Add extra data in /eth/v1/debug/fork_choice #7845

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

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from

Conversation

chong-he
Copy link
Member

@chong-he chong-he commented Aug 8, 2025

Issue Addressed

Additional Info

Querying the endpoint curl -X 'GET' 'http://localhost:5052/eth/v1/debug/fork_choice' | jq yields:

Before:

  {
      "slot": "1033932",
      "block_root": "0xe1b860bbeec083c8edae37025366d3d62ac40bd27e3bd5baf0dfeb3bb74f9d13",
      "parent_root": "0x590d229e47b588449fc68c3f3047ac92e49637b8d2456c5abdaa7a80da2162ec",
      "justified_epoch": "32309",
      "finalized_epoch": "32308",
      "weight": "497146337500000",
      "validity": "valid",
      "execution_block_hash": "0xb7ccfe614cfd3ba54d11a10a5286e2e8365355d7f0bffbc456e5531d93b9b99b"
    }

After:

    {
      "slot": "1056126",
      "block_root": "0x2f4f8155e4c11a621b433570feabb60da6d303ed221e91c41160dde8ef126311",
      "parent_root": "0xde33eb2df97f3e87e1099872cfac19761bbf0379b62ef73afa2688b2fdfcefb5",
      "justified_epoch": "33002",
      "finalized_epoch": "33001",
      "weight": "2252276000000000",
      "validity": "valid",
      "execution_block_hash": "0x3870e095e8a2d9cd7f3e6c1bf26d2e06b071a982d294b774b922b9eea933a54a",
      "extra_data": {
        "target_root": "0x429b73834e076d946645b042cfe218c860c77fa6a0f1a2510a0f3ea5f13c0e83",
        "justified_root": "0xbf4ca2a5062b837822b02c28654535daa31ce465ffa7b7dc3134d68eacacbdff",
        "finalized_root": "0x009ed887bfb16ca18ed24e7463457b3be358b06fd8d8507eb9e46e0121322f09",
        "unrealized_justified_root": "0x429b73834e076d946645b042cfe218c860c77fa6a0f1a2510a0f3ea5f13c0e83",
        "unrealized_finalized_root": "0xbf4ca2a5062b837822b02c28654535daa31ce465ffa7b7dc3134d68eacacbdff",
        "unrealized_justified_epoch": "33003",
        "unrealized_finalized_epoch": "33002",
        "timestamp": "1754886936",
        "execution_status": "valid",
        "best_child": "0x71195e3c4a481d9074fd26ea4833c1a9267d77302690b9f3317b118d65c2c21b",
        "best_descendant": "0x71195e3c4a481d9074fd26ea4833c1a9267d77302690b9f3317b118d65c2c21b"
      }

Copy link
Member Author

@chong-he chong-he left a comment

Choose a reason for hiding this comment

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

I have added most fields mentioned in #7829 , except for balance from the response of Prysm. Initially I thought it is the weight (which is already returned in the main response), but the data shows that weight is not equal to balance most of the time.

This is the field in the source code, which leads to this struct. I only see weight in ProtoNode in Lighthouse code.

Other than that, this PR is ready for review. I am happy to add/remove any fields that are required/not necessary, or rearrange the fields to make it more readable

unrealized_finalized_epoch: node
.unrealized_finalized_checkpoint
.map(|checkpoint| checkpoint.epoch),
timestamp: timestamp_now().as_secs(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This field and best_child and best_descendant are returning numbers without quotes "". I see the response from Prysm is with the quotes, as they convert it to string. So wondering whether I can leave these fields as pure numbers?

Copy link
Member

Choose a reason for hiding this comment

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

Usually quoted numbers are better for compatibility.

For best child and best descendant does Prysm use a numeric index or a block root? To me it seems like a block root would be clearer

Copy link
Member Author

Choose a reason for hiding this comment

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

The code is here (also found the definition for balance): https://github.com/OffchainLabs/prysm/blob/develop/beacon-chain/forkchoice/doubly-linked-tree/types.go#L60-L62

I think the *Node refers to the block root?

In Lighthouse, it is defined as Option<usize> (index):

pub best_descendant: Option<usize>,

Do we have to change this?

Copy link
Member

Choose a reason for hiding this comment

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

You can convert the index into a block root by looking it up in the array of nodes. E.g. if the index for best child is 5, use the block root of the 5th node as best child

For the balance vs weight, I think the difference is the attestation weight for the single block, vs the weight for that block and all its descendants. I think we can leave out the balance for now because it's a bit more involved to calculate it

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed timestamp to String, and best_child and best_descendant to display block_root instead

Thanks!

@chong-he chong-he added ready-for-review The code is ready for review HTTP-API labels Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HTTP-API ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants