feat: add dependent root to proposer preferences - #9303
Conversation
There was a problem hiding this comment.
Code Review
This pull request integrates the dependentRoot field into ProposerPreferences, updating the SSZ container, error types, and gossip validation logic. The SeenProposerPreferences cache is refactored to include dependentRoot in its indexing. Review feedback identifies a logic error in the epoch calculation and proposer selection during validation and notes that the manual state caching in importBlock.ts is redundant.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 472259da8a
ℹ️ 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".
Performance Report✔️ no performance regression detected Full benchmark results
|
| // [IGNORE] The block with root `dependent_root` has been seen by the node. | ||
| // Sync lookup only to not trigger disk reload from gossip input. | ||
| const cpEpoch = proposalEpoch - 1; | ||
| const checkpointState = chain.regen.getCheckpointStateSync({epoch: cpEpoch, rootHex: dependentRootHex}); |
There was a problem hiding this comment.
there is a tiny chance at the time of preparing for next epoch, head root is not the proposer root
and we don't have this checkpoint state in memory
maybe get head state first, make sure it has the view of this dependent root
then fallback to getting cp state this way
There was a problem hiding this comment.
right, I updated that, noticed we can use head state likely most of the time anyways, so it should cover the edge case you described, we only use getCheckpointStateSync if head state is not viable, the remaining question is if we should load from disk or not, but I think it's safer to not do that, also proposer preferences are only valid for current + next epoch, so we should have it cached
There was a problem hiding this comment.
the proposer look ahead is 2 epochs while we store checkpoint states of the last 3 epochs in memory so should not need that
| for (const slot of this.validatorIndexesBySlot.keys()) { | ||
| if (slot < currentSlot) { | ||
| this.validatorIndexesBySlot.delete(slot); | ||
| for (const [dependentRoot, slotMap] of this.validatorBySlotByDependentRoot.entries()) { |
There was a problem hiding this comment.
why not storing by slot as key of the 1st map? that would help pruning easier
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #9303 +/- ##
=========================================
Coverage 52.59% 52.59%
=========================================
Files 848 848
Lines 61100 61100
Branches 4505 4505
=========================================
Hits 32135 32135
Misses 28901 28901
Partials 64 64 🚀 New features to boost your workflow:
|
**Motivation** As suggested by @twoeths in #9303, the current map nesting in `SeenProposerPreferences` (`Map<dependentRoot, Map<slot, validatorIndex>>`) makes pruning inefficient — it requires iterating through every dependent root and checking each slot individually. **Description** Swaps the map nesting to `Map<slot, Map<dependentRoot, validatorIndex>>` so that pruning can delete entire slot entries directly from the outer map. No changes to the public API; `isKnown`, `add`, and `prune` all retain their existing signatures and behavior. Closes #9309 **AI Assistance Disclosure** - [x] External Contributors: I have read the [contributor guidelines](https://github.com/ChainSafe/lodestar/blob/unstable/CONTRIBUTING.md#ai-assistance-notice) and disclosed my usage of AI below. Used Claude to discuss the approach and review the implementation. --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
🎉 This PR is included in v1.43.0 🎉 |
see ethereum/consensus-specs#5190 and ethereum/consensus-specs#5196