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

head and reorg event not always emitted #5494

Open
dapplion opened this issue May 15, 2023 · 6 comments
Open

head and reorg event not always emitted #5494

dapplion opened this issue May 15, 2023 · 6 comments
Labels
prio-high Resolve issues as soon as possible.

Comments

@dapplion
Copy link
Contributor

this.chain.recomputeForkChoiceHead() is called in multiple places beyond importBlock. The importBlock assumes that recomputeForkChoiceHead is only called there, so the head and reorg events are only emitted for head recomputed there

Also the strong reference to the head state is only set on the importBlock flow, so there's a risk the node gets stuck if the head changes outside of importBlock

@dapplion dapplion added the prio-high Resolve issues as soon as possible. label May 15, 2023
@matthewkeil
Copy link
Member

matthewkeil commented Jun 29, 2023

Sections of code affected by bug

beacon-node/src/api/impl/validator/index.ts

  • Call to recomputeForkChoiceHead in produceBlockV2 before chain.produceBlock.
  • produceBlock calls produceBlockV2
  • Call to forkchoice.updateHead instead of recomputeForkChoiceHead in produceBlindedBlock

beacon-node/src/chain/prepareNextSlot.ts
Call to recomputeForkChoiceHead at the top of prepareForNextSlot

Potential Solution

Will refactoring code in importBlock preceded by notes #5 and #6 to be a function, that can be called in all locations above, resolve the issue?
#5 is Compute head and if new stateCache.setHeadState
#6 Queue notifyForkchoiceUpdate to engine api

The new function could be called maybeUpdateHead and would incorporate the newHead.blockRoot !== oldHead.blockRoot check, with side effects, and return the results from recomputing.

Other notes

Should the call to forkchoice.updateHead be swapped for recomputeForkChoiceHead so the metrics are updated correctly?

@philknows philknows added prio-medium Resolve this some time soon (tm). and removed prio-high Resolve issues as soon as possible. labels Nov 7, 2023
@philknows
Copy link
Member

@matthewkeil will DM @dapplion to discuss :)

@dapplion dapplion added prio-high Resolve issues as soon as possible. and removed prio-medium Resolve this some time soon (tm). labels Nov 10, 2023
@dapplion
Copy link
Contributor Author

https://github.com/ChainSafe/lodestar/blame/fa30bcf10086292883ef086202474ac4df67ffe1/packages/beacon-node/src/api/impl/validator/index.ts#L371-L372

idea

consider creating a type that selected the safe no mutate methods from the forkchoice as ForkChoiceSafe. And expect consumers to cast to ForkChoiceMutate or similar to actually recompute head. At least it's more obvious to devs you are doing something not ok

@wemeetagain
Copy link
Member

unassigning @matthewkeil for now, feel free to reassign if its being worked on

@wemeetagain wemeetagain added the meta-bug Issues that identify a bug and require a fix. label Oct 15, 2024
@philknows philknows added prio-medium Resolve this some time soon (tm). prio-high Resolve issues as soon as possible. and removed prio-high Resolve issues as soon as possible. meta-bug Issues that identify a bug and require a fix. prio-medium Resolve this some time soon (tm). labels Oct 15, 2024
@wemeetagain
Copy link
Member

This is rated as a "high" priority because it affects the events api

@wemeetagain
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
prio-high Resolve issues as soon as possible.
Projects
None yet
Development

No branches or pull requests

4 participants