Skip to content

refactor: optimize head event emission logic - #9720

Merged
nflaig merged 3 commits into
ChainSafe:unstablefrom
markolazic01:chore/head-v2-condition-optimization
Jul 28, 2026
Merged

refactor: optimize head event emission logic#9720
nflaig merged 3 commits into
ChainSafe:unstablefrom
markolazic01:chore/head-v2-condition-optimization

Conversation

@markolazic01

Copy link
Copy Markdown
Contributor

Description

Simplifies conditioning of head event emissions.
Inspired by #9486 (comment).

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃挕 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e03d4e1ca

鈩癸笍 About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 馃憤.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/beacon-node/src/chain/chain.ts Outdated
Comment thread packages/beacon-node/src/chain/chain.ts Outdated

@lodekeeper lodekeeper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed commit: 7e03d4e1ca

Behavior looks good to me. I rechecked the Codex PENDING concern: Gloas import creates PENDING -> EMPTY, payload import adds FULL as the sibling, and findHead() returns the best descendant, so this path should expose EMPTY/FULL, not PENDING. Over that domain this preserves the old event behavior: head only on root change, head_v2 on root or payload-status change.

Verification: pnpm exec biome check packages/beacon-node/src/chain/chain.ts; pnpm vitest run --project unit packages/fork-choice/test/unit/protoArray/getViableHeads.test.ts; pnpm --filter @lodestar/beacon-node... build.

Holding approval for Nico's naming nit: headChanged should be something like headRootChanged since same-root EMPTY/FULL flips are still head changes for head_v2.

@nflaig

nflaig commented Jul 28, 2026

Copy link
Copy Markdown
Member

@lodekeeper can you give this another review, this should be a pure refactor with now behavioral changes

@nflaig nflaig changed the title chore: optimize head event emission logic refactor: optimize head event emission logic Jul 28, 2026

@lodekeeper lodekeeper left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed commit: 970ccd70ca7e251c07c7c497c619e4ca122a4f89

Re-reviewed after the headRootChanged rename. This is now a pure refactor / no behavior change: head still emits only when the head root changes, and head_v2 still emits when the root changes or the exposed payload status changes. The earlier PENDING concern does not apply because this path gets the canonical getHead() / findHead() result, where Gloas PENDING is internal and exposed heads are EMPTY/FULL.

Local verification:

  • pnpm exec biome check packages/beacon-node/src/chain/chain.ts
  • pnpm --filter @lodestar/beacon-node... build
  • pnpm vitest run --project unit packages/fork-choice/test/unit/protoArray/getViableHeads.test.ts

CI: build/lint/type/unit checks are green; broader E2E/spec jobs are still pending.

@nflaig nflaig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the follow-up @markolazic01 馃檹

@nflaig
nflaig enabled auto-merge (squash) July 28, 2026 12:04
@nflaig
nflaig merged commit 82546f1 into ChainSafe:unstable Jul 28, 2026
19 checks passed
@wemeetagain

Copy link
Copy Markdown
Member

馃帀 This PR is included in v1.46.0 馃帀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants