fix: emit head event whenever fork choice head changes - #9697
Conversation
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 11e1b3a003
鈩癸笍 About Codex in GitHub
Your team has set up Codex to 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 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const head = this.forkChoice.updateAndGetHead({mode: UpdateHeadOpt.GetCanonicalHead}).head; | ||
|
|
||
| if (head.blockRoot !== prevHead.blockRoot) { |
There was a problem hiding this comment.
Emit head events from proposer-head recomputes too
When the first canonical recompute after attestation weight shifts happens through block production, this new emission path is bypassed: BeaconChain.getProposerHead() calls forkChoice.updateAndGetHead({mode: GetProposerHead}), and ForkChoice.updateAndGetHead() runs updateHead() for that mode before returning. In that scenario the cached canonical head changes, but no head SSE event is emitted, so validators watching head events can still miss the duty-dependent-root update until some later recomputeForkChoiceHead() call.
Useful? React with 馃憤聽/ 馃憥.
There was a problem hiding this comment.
this is intentional, we explicitly don't want to emit a head event on the proposer path when we are proposing a block ourselves
that head change is superseded once we import our own block, which emits the head event with the correct dependent roots, so head event consumers aren't affected in practice
Performance Report鉁旓笍 no performance regression detected Full benchmark results
|
| const prevHead = this.forkChoice.getHead(); | ||
| const head = this.forkChoice.updateAndGetHead({mode: UpdateHeadOpt.GetCanonicalHead}).head; | ||
|
|
||
| if (head.blockRoot !== prevHead.blockRoot) { |
There was a problem hiding this comment.
getProposerHead() also changes the head, it's worth to extract this to a separate method to reuse?
There was a problem hiding this comment.
nvm, getProposerHead() is different, could be a proposer boost reorg there
maybe just drop a comment on why we don't need to emit a head event over there
There was a problem hiding this comment.
as noted in the PR description I intentionally don't wanna consider the proposer path, I think it is fine to rely on the block import path in that case, we can add the comment as you suggested
|
馃帀 This PR is included in v1.46.0 馃帀 |
The
headevent is only emitted on block import, but the node's head can change without a new block (e.g. attestation weight shifts duringprepareNextSlot).Emit
headfromrecomputeForkChoiceHeadon any head root change, so it fires on block import and standalone recomputes (e.g.prepareNextSlot) alike, instead of only fromimportBlock.Note we intentionally don't emit on the proposer path (
getProposerHead) when proposing a block ourselves, as that head change is superseded once we import our own block.