Commit Graph

127 Commits

Author SHA1 Message Date
dapplion
5353710e0a Fix compilation, clear best_child/best_descendant in migration
- Fix leaf detection in heads_descended_from_finalization (parent()
  method call, map away enumerate index)
- Clear best_child and best_descendant in v28->v29 migration (no
  longer used, replaced by virtual tree walk)
- Migration now rewrites fork choice data instead of being a no-op
2026-03-31 00:51:19 -05:00
Michael Sproul
b6728c2030 Start removing more best_child/best_descend 2026-03-31 16:02:19 +11:00
Michael Sproul
517d16f2fd Revert parent->child optimisation 2026-03-31 15:47:50 +11:00
Michael Sproul
4c3fd70dbf Merge remote-tracking branch 'origin/unstable' into gloas-walk-always 2026-03-30 16:10:35 +11:00
Mac L
a5e748f808 Use yaml_serde in place of deprecated serde_yaml (#9040)
`serde_yaml` is now deprecated. The API-compatible `yaml_serde` should be used instead.


  Replace `serde_yaml` with `yaml_serde`. This is purely mechanical as the API is 1-to-1.


Co-Authored-By: Mac L <mjladson@pm.me>
2026-03-29 18:39:20 +00:00
Michael Sproul
12f5ab04f3 Load the state corresponding to head payload status yay 2026-03-26 16:03:55 +11:00
dapplion
c7670ede02 Cleanup and spec parity fixes
- Add missing payload attestation slot check: spec returns early when
  data.slot != block.slot (PTC votes only for assigned block)
- Remove dead ignored tests (need mock EL Gloas support to run)
- Remove unused new_with_gloas and inspect_queued_payload_attestations
- Remove gloas entries from bin.rs (not part of this PR)
- Collapse nested if in payload attestation error handling (clippy)
- Rename env -> envelope in load_parent
- Add TODO(gloas) for parent_head_hash in re-org path
- Remove head_payload_status from ForkchoiceUpdateParameters (lives on
  CachedHead, sourced from get_head return)
2026-03-25 23:07:45 -05:00
dapplion
e676c33c92 Merge sigp/unstable into gloas-walk-always 2026-03-25 22:02:08 -05:00
Michael Sproul
bd34bb1430 Remove schema migrations for v28 and earlier (#9031)
With LH v8.1.3 supporting Fulu-on-Gnosis, we no longer need these DB migrations. All Lighthouse nodes running in prod will soon be updated to LH v8.0.0+ and schema v28+.

This PR helps with Gloas fork choice changes, by allowing us to avoid updating old schema migrations when adding V29 for Gloas:

- https://github.com/sigp/lighthouse/pull/9025


  


Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
2026-03-26 02:10:34 +00:00
dapplion
a34b7c99dc Fix CI: collapse nested if, ignore payload attestation test
- Collapse nested if in build_children_index (clippy::collapsible_if)
- Ignore payload_attestation_for_previous_slot_is_accepted_at_next_slot
  — test uses pre-Gloas blocks (V17) but on_payload_attestation requires
  V29 nodes. Needs mock EL Gloas block support.
2026-03-25 20:33:17 -05:00
dapplion
e7f027badd O(n) children index, fix load_parent for gloas blocks
- Build parent->children index once per find_head call, replacing O(n)
  scans in filter_block_tree and get_node_children with O(1) lookups.
- Skip zero block_hash in is_parent_block_full check — default/zero
  hashes don't indicate a real payload relationship.
- Fall back to block state_root for genesis when envelope not stored.
- Store execution payload envelope in EF test harness during
  on_execution_payload step.
2026-03-25 19:38:54 -05:00
Michael Sproul
d58df3a656 Make proposer_index mandatory in on_block 2026-03-26 11:07:38 +11:00
Michael Sproul
a69a848590 Remove expect 2026-03-26 10:48:18 +11:00
Michael Sproul
9f1f68c3ee Add back AttestationFromBlock 2026-03-26 10:39:57 +11:00
dapplion
84679b1c07 Remove redundant invalid-node check from filter_block_tree
The children filter already skips invalid nodes, so a valid parent
whose only children are invalid becomes a leaf and gets rejected by
node_is_viable_for_head. The top-level check was redundant.
2026-03-25 18:22:51 -05:00
Michael Sproul
66f71b3f22 Remove unused params 2026-03-26 10:01:33 +11:00
dapplion
324c61d2e2 Implement get_filtered_block_tree and fix remaining test failures
- Add get_filtered_block_tree/filter_block_tree matching the spec's
  recursive viability pre-filter for get_head
- Skip invalid execution status nodes in the filter (they aren't in
  store.blocks in the spec)
- Fix attestation_score for V17 nodes: fall back to weight() for
  Empty/Full since pre-Gloas has no payload separation
- Include head_payload_status in ForkChoiceView so CachedHead updates
  when payload status changes
- Update votes test: branch with incompatible finalized leaf is now
  correctly excluded by the recursive filter
- Update execution_status test_03: stored weights no longer include
  proposer boost

All 30 proto_array/fork_choice tests pass.
All 9 EF fork_choice test suites pass.
2026-03-25 17:47:49 -05:00
dapplion
93ef1e395c Include head_payload_status in ForkChoiceView comparison
The early exit check in recompute_head_at_slot compared only
head_block_root and checkpoints. When on_execution_payload changed
the payload status from Empty to Full without changing the head root,
the CachedHead was not updated. Add head_payload_status to
ForkChoiceView so the change is detected.
2026-03-25 17:47:49 -05:00
dapplion
e943888ee7 Fix test_03: update weight assertions for spec-parity boost
Proposer boost is no longer baked into node.weight() — it is applied
on-the-fly in the walk's get_weight via is_supporting_vote. Update
the expected weights in test_03 to reflect pure attestation scores.
2026-03-25 17:47:49 -05:00
dapplion
9f56fd0751 Review fixes: cache should_apply_proposer_boost, improve error context
- Compute should_apply_proposer_boost once before the walk instead of
  per-child per-level
- Clear previous_proposer_boost in apply_score_changes
- Use correct node root in get_ancestor_node error messages
- Add comment explaining is_supporting_vote slot comparison behavior
2026-03-25 17:47:49 -05:00
dapplion
845831ce56 Align GLOAS fork choice with spec
- Move proposer boost from apply_score_changes to get_weight, matching
  the spec's structure where get_weight adds boost via is_supporting_vote
- Implement is_supporting_vote and get_ancestor_node spec functions
- Fix should_extend_payload: return true when proposer_boost_root is zero
- Compute record_block_timeliness from time_into_slot instead of hardcoding false
- Fix anchor block_timeliness to [true, true] per get_forkchoice_store spec
- Add equivocating_attestation_score for is_head_weak monotonicity
- Use payload-aware weight in is_parent_strong
- Add with_status helper on IndexedForkChoiceNode
- Simplify find_head_walk to return IndexedForkChoiceNode directly
2026-03-25 17:47:49 -05:00
Michael Sproul
cec5ce179d Undo botched optimisation 2026-03-25 14:12:46 +11:00
Michael Sproul
8b448864f0 Re-do head_payload_status 2026-03-25 14:05:11 +11:00
Michael Sproul
c841603003 Fix compilation issues 2026-03-25 13:43:30 +11:00
Michael Sproul
81b96a59d2 More spec compliance 2026-03-25 13:03:34 +11:00
Michael Sproul
52e397f8c1 Refactoring fork choice to look more like the spec 2026-03-24 15:58:54 +11:00
hopinheimer
ce714710e9 passing ef tests ft. @dapplion 2026-03-23 14:40:41 -04:00
hopinheimer
cc8466dfa5 fixing recursive calls with caching 2026-03-20 16:10:43 -04:00
Michael Sproul
ab1305d490 Propagate weight to parent's full/empty variants 2026-03-19 11:38:05 +11:00
hopinheimer
5aa11925ac unstable merge 2026-03-17 02:44:31 -04:00
hopinheimer
ffec1a1f1e enable ef tests @brech1 commit 2026-03-17 01:59:53 -04:00
hopinheimer
9ce88ea3c1 addressing comments: 2026-03-16 19:36:48 -04:00
hopinheimer
916d9fb018 changes 2026-03-16 07:00:51 -04:00
hopinheimer
0df749f0a2 completing should_extend_payload implementation 2026-03-16 05:53:47 -04:00
hopinheimer
f747696113 bitfield for PTC votes 2026-03-16 02:30:35 -04:00
hopinheimer
5679994285 addressing comments 2026-03-13 10:55:16 -04:00
hopinheimer
9c6f25cf36 fix migration SszContainer scripts 2026-03-09 19:06:50 -04:00
hopinheimer
275ac11200 test fixes 2026-03-02 15:33:53 -05:00
hopinheimer
e68cc03114 vote sanity and genesis epoch fix 2026-03-02 13:25:03 -05:00
hopinheimer
eb1b81063d fixing test 2026-02-26 04:38:45 -05:00
hopinheimer
e04a8c31ea adding tests and payload changes 2026-02-26 03:14:57 -05:00
hopinheimer
d5c5077a31 implement scoring mechanisms and plumbing 2026-02-24 17:40:11 -05:00
Michael Sproul
3e3ccba1a6 adding michael commits 2026-02-19 23:13:19 -05:00
hopinheimer
491b69f364 proto node versioning 2026-02-19 23:07:31 -05:00
Mac L
f3fd1f210b Remove consensus/types re-exports (#8540)
There are certain crates which we re-export within `types` which creates a fragmented DevEx, where there are various ways to import the same crates.

```rust
// consensus/types/src/lib.rs
pub use bls::{
AggregatePublicKey, AggregateSignature, Error as BlsError, Keypair, PUBLIC_KEY_BYTES_LEN,
PublicKey, PublicKeyBytes, SIGNATURE_BYTES_LEN, SecretKey, Signature, SignatureBytes,
get_withdrawal_credentials,
};
pub use context_deserialize::{ContextDeserialize, context_deserialize};
pub use fixed_bytes::FixedBytesExtended;
pub use milhouse::{self, List, Vector};
pub use ssz_types::{BitList, BitVector, FixedVector, VariableList, typenum, typenum::Unsigned};
pub use superstruct::superstruct;
```

This PR removes these re-exports and makes it explicit that these types are imported from a non-`consensus/types` crate.


Co-Authored-By: Mac L <mjladson@pm.me>
2025-12-09 07:13:41 +00:00
Lion - dapplion
53e73fa376 Remove duplicate state in ProtoArray (#8324)
Part of a fork-choice tech debt clean-up https://github.com/sigp/lighthouse/issues/8325

https://github.com/sigp/lighthouse/issues/7089 (non-finalized checkpoint sync) changes the meaning of the checkpoints inside fork-choice. It turns out that we persist the justified and finalized checkpoints **twice** in fork-choice
1. Inside the fork-choice store
2. Inside the proto-array

There's no reason for 2. except for making the function signature of some methods smallers. It's not consistent with the rest of the crate, because in some functions we pass the external variable of time (current_slot) via args, but then read the finalized checkpoint from the internal state. Passing both variables as args makes fork-choice easier to reason about at the cost of a few extra lines.


  Remove the unnecessary state (`justified_checkpoint`, `finalized_checkpoint`) inside `ProtoArray`, to make it easier to reason about.


Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>

Co-Authored-By: Michael Sproul <michaelsproul@users.noreply.github.com>
2025-11-12 03:42:17 +00:00
Michael Sproul
38fdaf791c Fix proposer shuffling decision slot at boundary (#8128)
Follow-up to the bug fixed in:

- https://github.com/sigp/lighthouse/pull/8121

This fixes the root cause of that bug, which was introduced by me in:

- https://github.com/sigp/lighthouse/pull/8101

Lion identified the issue here:

- https://github.com/sigp/lighthouse/pull/8101#discussion_r2382710356


  In the methods that compute the proposer shuffling decision root, ensure we don't use lookahead for the Fulu fork epoch itself. This is accomplished by checking if Fulu is enabled at `epoch - 1`, i.e. if `epoch > fulu_fork_epoch`.

I haven't updated the methods that _compute_ shufflings to use these new corrected bounds (e.g. `BeaconState::compute_proposer_indices`), although we could make this change in future. The `get_beacon_proposer_indices` method already gracefully handles the Fulu boundary case by using the `proposer_lookahead` field (if initialised).


Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
2025-09-29 01:13:33 +00:00
Michael Sproul
c754234b2c Fix bugs in proposer calculation post-Fulu (#8101)
As identified by a researcher during the Fusaka security competition, we were computing the proposer index incorrectly in some places by computing without lookahead.


  - [x] Add "low level" checks to computation functions in `consensus/types` to ensure they error cleanly
- [x] Re-work the determination of proposer shuffling decision roots, which are now fork aware.
- [x] Re-work and simplify the beacon proposer cache to be fork-aware.
- [x] Optimise `with_proposer_cache` to use `OnceCell`.
- [x] All tests passing.
- [x] Resolve all remaining `FIXME(sproul)`s.
- [x] Unit tests for `ProtoBlock::proposer_shuffling_root_for_child_block`.
- [x] End-to-end regression test.
- [x] Test on pre-Fulu network.
- [x] Test on post-Fulu network.


Co-Authored-By: Michael Sproul <michael@sigmaprime.io>
2025-09-26 14:44:50 +00:00
Michael Sproul
836c39efaa Shrink persisted fork choice data (#7805)
Closes:

- https://github.com/sigp/lighthouse/issues/7760


  - [x] Remove `balances_cache` from `PersistedForkChoiceStore` (~65 MB saving on mainnet)
- [x] Remove `justified_balances` from `PersistedForkChoiceStore` (~16 MB saving on mainnet)
- [x] Remove `balances` from `ProtoArray`/`SszContainer`.
- [x] Implement zstd compression for votes
- [x] Fix bug in justified state usage
- [x] Bump schema version to V28 and implement migration.
2025-08-18 06:03:28 +00:00
chonghe
522bd9e9c6 Update Rust Edition to 2024 (#7766)
* #7749

Thanks @dknopik and @michaelsproul for your help!
2025-08-13 03:04:31 +00:00