313 Commits

Author SHA1 Message Date
Nico Flaig
84b481ddb5 chore: restore code required to perform sync through bellatrix (#8700)
**Motivation**

As noted in
https://github.com/ChainSafe/lodestar/pull/8680#discussion_r2624026653
we cannot sync through bellatrix anymore. While I don't think it's a big
deal it's simple enough to keep that functionality as that code is
pretty isolated and won't get in our way during refactors and with gloas
won't be part of the block processing pipeline anymore due to
block/payload separation.


**Description**

Restore code required to perform sync through bellatrix
- re-added `isExecutionEnabled()` and `isMergeTransitionComplete()`
checks during block processing
- enabled some spec tests again that were previously skipped
- mostly copied original code removed in
[#8680](https://github.com/ChainSafe/lodestar/pull/8680) but cleaned up
some comments and simplified a bit
2025-12-18 18:00:34 -05:00
Phil Ngo
3bf4734ba9 chore: merge v1.38.0 stable back to unstable (#8694) 2025-12-15 11:08:40 -05:00
Nico Flaig
889b1c4475 chore: remove merge transition code (#8680)
**Motiviation**

All networks have completed the merge transition and most execution
clients no longer support pre-merge so it's not even possible anymore to
run a network from a genesis before bellatrix, unless you keep it to
phase0/altair only, which still works after this PR is merged.

This code is effectively tech debt, no longer exercised and just gets in
the way when doing refactors.

**Description**

Removes all code related to performing the merge transition. Running the
node pre-merge (CL only mode) is still possible and syncing still works.
Also removed a few CLI flags we added for the merge specifically, those
shouldn't be used anymore. Spec constants like
`TERMINAL_TOTAL_DIFFICULTY` are kept for spec compliance and ssz types
(like `PowBlock`) as well. I had to disable a few spec tests related to
handling the merge block since those code paths are removed.

Closes https://github.com/ChainSafe/lodestar/issues/8661
2025-12-12 10:18:23 +07:00
philknows
62d3e49f28 chore: bump package versions to 1.38.0 2025-12-10 11:44:00 -05:00
twoeths
1ad9c40143 chore: improve benchmark (#8664)
**Motivation**

- it takes so much time to run benchmark, a lot of them does not make
sense
- seeing OOM with NodeJS 24, see
https://github.com/ChainSafe/lodestar/pull/8645#issuecomment-3601327203

**Description**

- remove benchmarks for flow that's not used in prod
- remove some "minMs" option for some tests that causes a lot of time
- remote test that does not reflect the bottle neck of lodestar's
performance as of Dec 2025
- remote tests that's not part of lodestar code. It's only meaningful in
the scope of that PR only

this is based on the long running test I found in
https://github.com/ChainSafe/lodestar/actions/runs/19874295397/job/56957698411

```
packages/beacon-node/test/perf/chain/validation/attestation.test.ts
  validate gossip attestation
    ✔ batch validate gossip attestation - vc 640000 - chunk 32            8931.657 ops/s    111.9613 us/op   x0.918       7814 runs   30.0 s
    ✔ batch validate gossip attestation - vc 640000 - chunk 64            9972.473 ops/s    100.2760 us/op   x0.926       4321 runs   30.1 s
    ✔ batch validate gossip attestation - vc 640000 - chunk 128           10569.62 ops/s    94.61075 us/op   x0.921       2268 runs   30.0 s
    ✔ batch validate gossip attestation - vc 640000 - chunk 256           10069.74 ops/s    99.30746 us/op   x0.901       1154 runs   30.1 s

packages/fork-choice/test/perf/protoArray/computeDeltas.test.ts
  computeDeltas
    ✔ computeDeltas 1400000 validators 0% inactive                        73.51301 ops/s    13.60303 ms/op   x0.986        539 runs   10.0 s
    ✔ computeDeltas 1400000 validators 10% inactive                       78.91095 ops/s    12.67251 ms/op   x0.989        556 runs   10.0 s
    ✔ computeDeltas 1400000 validators 20% inactive                       86.73608 ops/s    11.52923 ms/op   x1.001        598 runs   10.0 s
    ✔ computeDeltas 1400000 validators 50% inactive                       114.8443 ops/s    8.707439 ms/op   x0.990        799 runs   10.0 s
    ✔ computeDeltas 2100000 validators 0% inactive                        48.69939 ops/s    20.53414 ms/op   x0.996        371 runs   10.0 s
    ✔ computeDeltas 2100000 validators 10% inactive                       53.13929 ops/s    18.81847 ms/op   x1.000        371 runs   10.0 s
    ✔ computeDeltas 2100000 validators 20% inactive                       60.11017 ops/s    16.63612 ms/op   x0.978        418 runs   10.0 s
    ✔ computeDeltas 2100000 validators 50% inactive                       79.46802 ops/s    12.58368 ms/op   x0.967        552 runs   10.0 s

packages/state-transition/test/perf/util/loadState/findModifiedValidators.test.ts
  find modified validators by different ways
    serialize validators then findModifiedValidators
      ✔ findModifiedValidators - 10000 modified validators                  1.382729 ops/s    723.2076 ms/op   x0.993         10 runs   9.21 s
      ✔ findModifiedValidators - 1000 modified validators                   1.298120 ops/s    770.3450 ms/op   x1.152         10 runs   8.68 s
      ✔ findModifiedValidators - 100 modified validators                    3.535168 ops/s    282.8720 ms/op   x1.329         10 runs   3.85 s
      ✔ findModifiedValidators - 10 modified validators                     4.648368 ops/s    215.1293 ms/op   x1.548         10 runs   3.13 s
      ✔ findModifiedValidators - 1 modified validators                      5.296754 ops/s    188.7949 ms/op   x1.187         10 runs   3.10 s
      ✔ findModifiedValidators - no difference                              3.873496 ops/s    258.1647 ms/op   x1.236         12 runs   3.88 s
    deserialize validators then compare validator ViewDUs
      ✔ compare ViewDUs                                                    0.1524038 ops/s    6.561514  s/op   x1.077          9 runs   65.7 s
    serialize each validator then compare Uin8Array
      ✔ compare each validator Uint8Array                                  0.8007866 ops/s    1.248772  s/op   x0.830         10 runs   13.7 s
    compare validator ViewDU to Uint8Array
      ✔ compare ViewDU to Uint8Array                                       0.9549799 ops/s    1.047143  s/op   x0.999         10 runs   11.5 s

packages/state-transition/test/perf/util/loadState/loadState.test.ts
  loadState
    ✔ migrate state 1000000 validators, 24 modified, 0 new               0.9790753 ops/s    1.021372  s/op   x1.147         57 runs   60.1 s
    ✔ migrate state 1000000 validators, 1700 modified, 1000 new          0.7290797 ops/s    1.371592  s/op   x0.942         43 runs   61.1 s
    ✔ migrate state 1000000 validators, 3400 modified, 2000 new          0.6307866 ops/s    1.585322  s/op   x0.883         37 runs   60.9 s
    ✔ migrate state 1500000 validators, 24 modified, 0 new               0.9393088 ops/s    1.064613  s/op   x0.911         55 runs   60.5 s
    ✔ migrate state 1500000 validators, 1700 modified, 1000 new          0.8235204 ops/s    1.214299  s/op   x0.785         48 runs   60.2 s
    ✔ migrate state 1500000 validators, 3400 modified, 2000 new          0.6997867 ops/s    1.429007  s/op   x0.720         41 runs   60.7 s


  ✔ naive computeProposerIndex 100000 validators                        21.29210 ops/s    46.96578 ms/op   x0.591         10 runs   51.8 s

  getNextSyncCommitteeIndices electra
    ✔ naiveGetNextSyncCommitteeIndices 1000 validators                   0.1319639 ops/s    7.577831  s/op   x0.675          8 runs   66.8 s
    ✔ getNextSyncCommitteeIndices 1000 validators                         9.444554 ops/s    105.8811 ms/op   x0.753         10 runs   1.60 s
    ✔ naiveGetNextSyncCommitteeIndices 10000 validators                  0.1280431 ops/s    7.809868  s/op   x0.766          7 runs   61.8 s
    ✔ getNextSyncCommitteeIndices 10000 validators                        9.244910 ops/s    108.1676 ms/op   x0.880         10 runs   1.62 s
    ✔ naiveGetNextSyncCommitteeIndices 100000 validators                 0.1295493 ops/s    7.719071  s/op   x0.814          7 runs   61.9 s
    ✔ getNextSyncCommitteeIndices 100000 validators                       9.279165 ops/s    107.7683 ms/op   x0.751         10 runs   1.62 s

  computeShuffledIndex
    ✔ naive computeShuffledIndex 100000 validators                      0.04376956 ops/s    22.84693  s/op   x0.719          2 runs   67.8 s
    ✔ cached computeShuffledIndex 100000 validators                       1.790556 ops/s    558.4858 ms/op   x0.973         10 runs   6.16 s
    ✔ naive computeShuffledIndex 2000000 validators                    0.002243157 ops/s    445.8003  s/op   x0.922          1 runs    931 s
    ✔ cached computeShuffledIndex 2000000 validators                    0.02947726 ops/s    33.92445  s/op   x0.810          1 runs   71.3 s

packages/state-transition/test/perf/util/signingRoot.test.ts
  computeSigningRoot
    ✔ computeSigningRoot for AttestationData                              51551.61 ops/s    19.39804 us/op   x0.905        491 runs   10.0 s
    ✔ hash AttestationData serialized data then Buffer.toString(base64    639269.7 ops/s    1.564285 us/op   x0.977       5818 runs   10.0 s
    ✔ toHexString serialized data                                         886487.9 ops/s    1.128047 us/op   x0.926       8417 runs   10.0 s
    ✔ Buffer.toString(base64)                                              6071166 ops/s    164.7130 ns/op   x0.974      50685 runs   10.1 s
```

---------

Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
2025-12-03 09:57:51 -05:00
philknows
2303b06a91 chore: bump package versions to 1.37.0 2025-11-28 10:17:20 -05:00
Nazar Hussain
c68bfb2ae3 refactor: introduce safe-block to fork-choice (#8618)
**Motivation**

There is a concept documented in the specs called
[safe-block](https://github.com/ethereum/consensus-specs/blob/master/fork_choice/safe-block.md).
Wanted to introduce that concept in our codebase so upcoming feature of
`fcr` have less invasive changes.

**Description**

- Expose functions `getSafeBeaconBlockRoot` and
`getSafeExecutionBlockHash` from `fork-choice` package.
- Update the usage of `safeBlock` to use those functions

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-11-28 15:48:06 +01:00
philknows
6eb05a083a chore: bump package versions to 1.36.0 2025-11-04 12:28:29 -05:00
Nico Flaig
7e3c18443f feat: sync from unfinalized checkpoint state (#8527)
**Motivation**

This was a feature we developed for [rescuing
Holesky](https://blog.chainsafe.io/lodestar-holesky-rescue-retrospective/)
as part of https://github.com/ChainSafe/lodestar/pull/7501 to quickly
sync nodes to head during a period of long non-finality (~3 weeks).
While it's unlikely we will have such a long period of non-finality on
mainnet, this feature is still useful to have for much shorter periods
and testing purposes on devnets.

It is now part of [Ethereum protocol
hardening](https://github.com/eth-clients/diamond) mitigations described
[here](https://github.com/eth-clients/diamond/blob/main/mitigations/nfin-checkpoint-001.md)
> Ordinary checkpoint sync begins from the latest finalized checkpoint
(block and/or state). As an escape hatch during non-finality, it is
useful to have the ability to checkpoint sync from an unfinalized
checkpoint. A client implementing this mitigation MUST support
checkpoint sync from an arbitrary non-finalized checkpoint state.

We will support this with the exception that our checkpoint state needs
to be an epoch boundary checkpoint.

**Description**

The main feature of this PR is to allow initializing a node from an
unfinalized checkpoint state either retrieved locally or from a remote
source.

This behavior is disabled by default but can be enabled by either adding
- the `--lastPersistedCheckpointState` flag to load from the last safe
persisted checkpoint state stored locally
- or `--unsafeCheckpointState` to provide a file path or url to an
unfinalized checkpoint state to start syncing from which can be used
with new endpoint `GET /eth/v1/lodestar/persisted_checkpoint_state` to
sync from a remote node or by sharing states from `checkpoint_states`
folder

Both of these options are not safe to use on a network that recently
finalized an epoch and must only be considered if syncing from last
finalized checkpoint state is unfeasible.

An unfinalized checkpoint state persisted locally is only considered to
be safe to boot if
- it's the only checkpoint in it's epoch to avoid ambiguity from forks
- its last processed block slot is at an epoch boundary or last slot of
previous epoch
- state slot is at an epoch boundary
- state slot is equal to `epoch * SLOTS_PER_EPOCH`

But even if these criteria are met, there is chance that the node will
end up on a minority chain as it will not be able to pivot to another
chain that conflicts with the checkpoint state it was initialized from.

Other existing flags (like `--checkpointState`) are unchanged by this PR
and will continue to expect a finalized checkpoint state.

Previous PRs https://github.com/ChainSafe/lodestar/pull/7509,
https://github.com/ChainSafe/lodestar/pull/7541,
https://github.com/ChainSafe/lodestar/pull/7542 not merged to unstable
are included.

Closes https://github.com/ChainSafe/lodestar/issues/7963

cc @twoeths

---------

Co-authored-by: twoeths <10568965+twoeths@users.noreply.github.com>
Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
2025-10-22 15:22:05 -04:00
twoeths
8ac1ed5b17 chore: decompose VoteTracker (#8549)
**Motivation**

- fix performance issue of Bun due to sparse array, see
https://github.com/ChainSafe/lodestar/issues/8519#issuecomment-3420322338
- decompose VoteTracker, same to #6945

**Description**
- decompose VoteTracker to `voteCurrentIndices` `voteNextIndices`
`voteNextEpochs`, data is populated on initialization, hence avoid the
sparse issue in
https://github.com/ChainSafe/lodestar/issues/8519#issuecomment-3420322338
- the old `null` index means not to point to any nodes of ProtoArray, we
represent it as 0xffffffff (max u32) instead of null
- update `computeDeltas()` benchmark to reproduce the issue and fix it
in this PR. It shows bun loops is 2x faster than NodeJS for now

part of #8519

**Hoodi result**

- 4x-5x faster on NodeJS

<img width="967" height="300" alt="Screenshot 2025-10-20 at 14 35 01"
src="https://github.com/user-attachments/assets/80998967-f6d6-4179-8976-699750a1e6fe"
/>

- almost 30x faster on Bun
<img width="1301" height="377" alt="Screenshot 2025-10-20 at 14 35 32"
src="https://github.com/user-attachments/assets/eb51f6b5-2560-478f-865a-c127f1cf008d"
/>

- overall it shows Bun is >= 2x faster than NodeJS now but we can
probably makes it better because this decomposition strategy makes it
easier for a native binding (which I will give it a try next)

---------

Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
2025-10-22 15:20:11 -04:00
Nazar Hussain
a0d00ac6dc chore: cleanup types exports for all packages (#8434)
**Motivation**

Make the types exports consistent for all packages. 

All modern runtimes support [conditional
exports](https://nodejs.org/api/packages.html#conditional-exports) and
there are caveats when we have both conditional exports and normal
exports present in a package.json. This PR tend to make all exports
follow same consistent and modern pattern.

**Description**

- We were using subpath exports for some packages and module exports for
other
- Keep all the types export consistent as subpath exports.
- Remove "types" and "exports` directive from package.json 
- Remove `typesVersions`, this is useful only if we have different
version of types for different versions of Typescript. Or having
different types files for different file paths.


**Steps to test or reproduce**

- Run all CI
2025-10-20 09:03:08 -04:00
twoeths
6d67a79656 feat: track computeDeltas metrics (#8531)
**Motivation**

- track/maintain computeDeltas() metrics

**Description**

- track computeDeltas() duration, number of 0 deltas,
equivocatingValidators, oldInactiveValidators, newInactiveValidators,
unchangedVoteValidators, newVoteValidators
- as part of investigation of #8519 we want to make sure metrics are the
same with Bun

part of #8519

**Metrics collected**
- hoodi

<img width="1020" height="609" alt="Screenshot 2025-10-14 at 15 08 29"
src="https://github.com/user-attachments/assets/4b0ab871-ce04-43c9-8b79-73c13a843f4a"
/>

- mainnet
<img width="958" height="617" alt="Screenshot 2025-10-14 at 15 08 54"
src="https://github.com/user-attachments/assets/bc264eb1-905d-4f90-bd17-39fb58068608"
/>

- updateHead() is actually ~5ms increase

<img width="842" height="308" alt="Screenshot 2025-10-14 at 15 09 50"
src="https://github.com/user-attachments/assets/ec082257-c7c0-4ca3-9908-cd006d23e1de"
/>

- but it's worth to have more details of `computeDeltas`, we saved ~25ms
after #8525

<img width="1461" height="358" alt="Screenshot 2025-10-14 at 15 11 29"
src="https://github.com/user-attachments/assets/4cffee0e-d0c0-4f74-a647-59f69af0fd99"
/>

---------

Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
2025-10-14 09:47:45 -04:00
twoeths
4fe86ae0ee fix: avoid Set.has() in computeDeltas() (#8525)
**Motivation**

- while investigating #8519 I found a performance issue with
`computeDeltas()` where we check for `Set.has()` for every item in the
big validator index loop

**Description**

- sort the `equivocatingIndices` set then track
equivocatingValidatorIndex to avoid `Set.has()` there
- fix perf test to include some equivocating indices


**Benchmark on my local environment**

- NodeJS: it's 1.53x faster

before
```
  computeDeltas
    ✔ computeDeltas 1400000 validators 300 proto nodes                    73.65370 ops/s    13.57705 ms/op        -        931 runs   30.1 s
    ✔ computeDeltas 1400000 validators 1200 proto nodes                   73.44709 ops/s    13.61524 ms/op        -        922 runs   30.0 s
    ✔ computeDeltas 1400000 validators 7200 proto nodes                   73.59195 ops/s    13.58844 ms/op        -        937 runs   30.0 s
    ✔ computeDeltas 2100000 validators 300 proto nodes                    49.27426 ops/s    20.29457 ms/op        -        623 runs   30.1 s
    ✔ computeDeltas 2100000 validators 1200 proto nodes                   49.11422 ops/s    20.36070 ms/op        -        614 runs   30.1 s
    ✔ computeDeltas 2100000 validators 7200 proto nodes                   48.75805 ops/s    20.50943 ms/op        -        619 runs   30.1 s

```

after
```
  computeDeltas
    ✔ computeDeltas 1400000 validators 300 proto nodes                    113.6256 ops/s    8.800830 ms/op        -       1076 runs   30.1 s
    ✔ computeDeltas 1400000 validators 1200 proto nodes                   112.0909 ops/s    8.921329 ms/op        -       1079 runs   30.0 s
    ✔ computeDeltas 1400000 validators 7200 proto nodes                   111.5792 ops/s    8.962247 ms/op        -       1068 runs   30.1 s
    ✔ computeDeltas 2100000 validators 300 proto nodes                    75.48259 ops/s    13.24809 ms/op        -        727 runs   30.1 s
    ✔ computeDeltas 2100000 validators 1200 proto nodes                   74.93052 ops/s    13.34570 ms/op        -        707 runs   30.1 s
    ✔ computeDeltas 2100000 validators 7200 proto nodes                   74.82280 ops/s    13.36491 ms/op        -        751 runs   30.0 s

```

- Bun: it's 3.88x faster
before
```
  computeDeltas
    ✔ computeDeltas 1400000 validators 300 proto nodes                    103.6817 ops/s    9.644905 ms/op   x1.578       1791 runs   30.0 s
    ✔ computeDeltas 1400000 validators 1200 proto nodes                   103.4132 ops/s    9.669949 ms/op   x1.580       1800 runs   30.1 s
    ✔ computeDeltas 1400000 validators 7200 proto nodes                   103.7312 ops/s    9.640297 ms/op   x1.578       1745 runs   30.1 s
    ✔ computeDeltas 2100000 validators 300 proto nodes                    68.86443 ops/s    14.52128 ms/op   x1.583       1188 runs   30.0 s
    ✔ computeDeltas 2100000 validators 1200 proto nodes                   68.66082 ops/s    14.56435 ms/op   x1.585       1195 runs   30.1 s
    ✔ computeDeltas 2100000 validators 7200 proto nodes                   68.49115 ops/s    14.60043 ms/op   x1.592       1194 runs   30.1 s
```

after
```
  computeDeltas
    ✔ computeDeltas 1400000 validators 300 proto nodes                    407.0697 ops/s    2.456582 ms/op   x0.255       3117 runs   30.1 s
    ✔ computeDeltas 1400000 validators 1200 proto nodes                   402.2402 ops/s    2.486077 ms/op   x0.257       2838 runs   30.0 s
    ✔ computeDeltas 1400000 validators 7200 proto nodes                   401.5803 ops/s    2.490162 ms/op   x0.258       2852 runs   30.0 s
    ✔ computeDeltas 2100000 validators 300 proto nodes                    265.5509 ops/s    3.765757 ms/op   x0.259       1988 runs   30.1 s
    ✔ computeDeltas 2100000 validators 1200 proto nodes                   267.6306 ops/s    3.736494 ms/op   x0.257       2026 runs   30.0 s
    ✔ computeDeltas 2100000 validators 7200 proto nodes                   266.0949 ops/s    3.758058 ms/op   x0.257       2035 runs   30.1 s
```

Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
2025-10-13 09:05:52 -04:00
philknows
825a186b76 chore: bump package versions to 1.35.0 2025-10-08 18:10:13 -04:00
NC
39be8f0882 feat: use bps instead of INTERVALS_PER_SLOT for deadlines (#8091)
Closes #8013

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-09-25 19:01:20 -07:00
Nazar Hussain
8689cc3545 chore: add src to the package to have working source map (#8460)
**Motivation**

Add `src` directory to package sources along with the `lib` files to
have working source map.

**Description**

- Add `src` to the files.


**Steps to test or reproduce**

- Run all tests
2025-09-25 07:23:58 -04:00
Cayman
6494939cd0 chore: add bun exports to packages (#8448)
**Motivation**

- #7280 

**Description**

- Add `"bun"` export to all packages that points to the _typescript
source_ rather than the transpiled javascript
- Allows for bun to use typescript directly
2025-09-23 12:19:11 +01:00
Nazar Hussain
feed916580 chore: enable organize imports for linting (#8410)
**Motivation**

Enable the organize import back which was disabled in #7982 to isolate
the changes for import ordering

**Description**

- Update the organize import config 
- Fix all linting errors

**Steps to test or reproduce**

- Run all tests

---------

Co-authored-by: Cayman <caymannava@gmail.com>
2025-09-19 19:59:28 -04:00
Phil Ngo
86490969b7 chore: bump package versions to 1.34.1 2025-09-10 16:34:42 -04:00
Phil Ngo
1a17514b02 chore: bump package versions to 1.34.0 2025-09-05 12:24:08 -04:00
Nazar Hussain
22a04f4543 chore: upgrade @biomejs/biome to newer type aware version (#7982)
**Motivation**

Use the more type aware version of Biome to get benefit from type safety
rules.

**Description**

- Keep the rules matching to previous behavior 
- Add explanation to all ignore as it's required in new version

**Steps to test or reproduce**

Run all tests

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-09-02 16:53:47 +02:00
Ekaterina Riazantseva
6398efaba5 refactor: move fork-choice metrics to fork-choice package (#8265)
**Motivation**

Fork-choice package doesn't have its own metrics. Some fork-choice
metrics are scraped in beacon-chain through the onScrapeMetrics. This PR
is a part of metrics refactoring #7098. There is also a need to add new
fork-choice metrics for FOCIL.

**Description**

Fork-choice metrics from beacon node were moved to fork-choice package. 

Part of #7098

**Steps to test or reproduce**

Check Lodestar Grafana dashboard with this branch running.

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-09-01 12:48:28 +01:00
Nazar Hussain
b9950594aa refactor: remove cpu features direct dependency (#8261)
**Motivation**

Make the code transition for compatibility with the Bun. 

**Description**

- The dependency `cpu-features` is not compatible with the `Bun`
- Removed the direct dependency
- Upgrade the `@chainsafe/persistent-merkle-tree` and `@chainsafe/ssz`
so the hasher detection is done implicitly.
- Latest commit for
[hahstree](e86a8b136a)
has the support for fallback, which is not used in the
`@chainsafe/persistent-merkle-tree`


**Steps to test or reproduce**

Run all tests
2025-08-25 17:22:23 -04:00
Phil Ngo
7afce97ce3 chore: bump package versions to 1.33.0 2025-07-31 15:05:32 -04:00
Nico Flaig
ea1977daef fix: detect weak head when predicting proposer head (#8079)
**Motivation**

There was a regression in
https://github.com/ChainSafe/lodestar/pull/7810 which caused us to not
detect weak head when predicting proposer head.

**Description**

This PR addresses the issue to correctly detect weak head when
predicting proposer head and updates few logs / misc changes while
reviewing the code.

I tested this on Kurtosis by artificially delaying some blocks. Let's
look at the example of proposer for slot 54 which re-orged out the late
block from slot 53.

The block was received after 4 seconds into the slot via gossip
```
Received gossip block slot=53, root=0x77cc…92e1, currentSlot=53, peerId=16Uiu2HAmQ8AL3EKjxSs7V6AG1CA4xMXvWXnVEZ6jybSShxCX48Fy, delaySec=4.1579999923706055, pending=null, haveBlobs=0, expectedBlobs=0, recvToValLatency=0.003000020980834961
```
We correctly determined during block import that it's a weak block and
skipped fcu call
```
Block is weak. Should override forkchoice update blockRoot=0x77cc3e39bc0c843f25c9556141f30e16901516a49dfb956fdc68e9c6f98592e1, slot=53
Weak block detected. Skip fcu call in importBlock blockRoot=0x77cc3e39bc0c843f25c9556141f30e16901516a49dfb956fdc68e9c6f98592e1, slot=53
```
When preparing next slot, we predicted that next block will be built on
parent (at start of next slot)
```
Current head is weak. Predicting next block to be built on parent of head. slot=53, weakHead=0x77cc3e39bc0c843f25c9556141f30e16901516a49dfb956fdc68e9c6f98592e1, proposerHead=0xfe8dfdd3ebc9715bbf9fac23d14024cf9dc29bfe78d352a9ea7eeea5f8cd25f1
```
Which turned out to be the case and we re-orged out the weak head
```
Performing single-slot reorg to remove current weak head slot=54, proposerHead=0xfe8dfdd3ebc9715bbf9fac23d14024cf9dc29bfe78d352a9ea7eeea5f8cd25f1, weakHead=0x77cc3e39bc0c843f25c9556141f30e16901516a49dfb956fdc68e9c6f98592e1
```
The node (and other nodes) detected and accepted the re-org as part of
canonical chain
```
Chain reorg depth=2, epoch=1, slot=54, newHeadBlock=0x39be0f98e895e91bf245535becb2ef8d631abe9be6602cce87473d94719099d0, oldHeadBlock=0x77cc3e39bc0c843f25c9556141f30e16901516a49dfb956fdc68e9c6f98592e1, newHeadState=0x5afc8b88b1b805797ea1a37b86f956fb5560bf8bbfe3ed4a449f4cae1851cb6d, oldHeadState=0x2d79bf2fb26881b4efa41bedeae8181fb7f430ddaec839175baeb26a3250045c, executionOptimistic=false
```

<img width="726" height="503" alt="image"
src="https://github.com/user-attachments/assets/7298fe6f-cb4c-4de7-b5ce-f322bcfc7ca0"
/>
2025-07-23 17:54:24 -07:00
NC
899163f126 fix: fix proposer boost reorg by suppressing fcu call during import (#7810)
We need to suppress fcu call during gossip block import when the
incoming block is weak. This is because once notified EL, it will treat
the new block as head and will not reorg back to parent if we try to
reorg.

- Add `shouldOverrideForkChoiceUpdate`
- Call `shouldOverrideForkChoiceUpdate` during gossip block import, and
skip fcu call if result is true
- Modify `predictProposerHead` to be a simple wrapper around
`shouldOverrideForkChoiceUpdate`


Closes #7235

cc. @twoeths @nflaig

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-07-21 15:36:30 -07:00
Phil Ngo
36dbfb2cfe chore: bump package versions to 1.32.0 2025-07-09 14:35:57 -04:00
Phil Ngo
8847b4a92b chore: bump package versions to 1.31.0 2025-06-03 14:16:18 -04:00
Cayman
b819263288 chore: bump ssz to v1.2.1 (#7894)
**Motivation**

- chainsafe/ssz#489

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-05-30 16:03:33 +00:00
Mercy Boma Naps Nkari
a64ca247a0 refactor: add method to get ancestor & non-ancestor nodes in single traversal (#7528) 2025-05-20 12:20:52 +02:00
Phil Ngo
123eb2d9fb chore: bump package versions to 1.30.0 2025-05-09 12:15:00 -04:00
Nico Flaig
fa898bb319 chore: restructure tests (#7793)
Follow up to https://github.com/ChainSafe/lodestar/pull/7610 with a few
restructuring suggestions, see comments below for detailed changes,
revives constants tests we are no longer running in CI and makes each
package executable separately again, ie. `cd packages/<package-name>`
into `yarn test:unit` works for all packages again.

One major change is that unit tests default should be written with
`mainnet` preset in mind as I noticed that makes a lot more sense for a
bunch of existing tests, eg. we have tests that depend on external
fixtures, like api spec tests for events and those are not compatible
with `minimal` preset. Also there doesn't seem to be much downside in
most cases for unit tests to use `mainnet` preset as it does not run
through all the epoch, like for example a e2e or sim test does. So
overall, it allows us to use mainnet fixtures / more "real world" data
which seems better with little to no downside.


Time comparison running unit tests on `unstable` vs. this branch

**unstable**

![image](https://github.com/user-attachments/assets/ba9c8e68-ec1a-4cb7-90fc-eb00cedae4bf)

**nflaig/restructure-tests**

![image](https://github.com/user-attachments/assets/0ffab5a4-4a71-42e1-a26e-32fc5627b873)

There is just a difference of 2 seconds (might be a fluke) in a 6 minute
run, this seems acceptable to me considering the benefits of using
`mainnet` preset noted above.
2025-05-07 18:21:12 +01:00
Nazar Hussain
c91cd9c141 test: use vitest workspace to run all tests (#7610)
**Motivation**

Vitest workspaces is feature to mimic the package manager workspaces for
the tests only.

It provides following benefits:

1. Minimize the need the bunch of config files at every package root 
2. Consolidate vitest configuration in project groups
3. Use consistent test configuration for all projects in the monorepo
4. Providing consistent test environment for all packages
5. Speed up visual interaction with tests in the IDEs (e.g. Visual
Studio Code)

**Description**

- Remove all unnecessary config files
- Update package json scripts to use `--project` flag

Closes #7603


Now we have following test directories. 

| Directory | Description | CurrentPreset | Old Preset | 
|---|---|---|---|
| test/unit | Unit tests | minimal | Default export from `params`
package |
| test/unit-mainnet | Unit tests | mainnet | mainnet | 
| test/e2e | End-to-End Tests | minimal | Default export from `params`
package |
| test/e2e-mainnet | End-to-End Tests | mainnet | Never existed before,
mixed up pattern in different packages |
| test/spec | Spec tests | minimal | Default export from `params`
package, but common perception among team was that it's running with
`minimal` |
| test/spec-mainnet` | Spec tests | mainnet | Never existed as
directory, but mixed up among packages |
| test/browser | Symlink to `unit` for packages which supports browsers
| minimal | Default export from `params` package |
| test/types | Types test | minimal | Default export from `params`
package |


**Steps to test or reproduce**

Run all tests
2025-04-22 11:33:36 +02:00
Phil Ngo
2a4f1bcd49 chore: merge v1.29.0 stable back to unstable (#7732) 2025-04-21 10:46:36 -04:00
Matthew Keil
bb6038a1d1 refactor: deduplicate DataAvailabilityStatus enum (#7703)
**Motivation**

There were two copies of the DataAvailabilityStatus enum. One in
state-transition and the other in fork-choice. Both did essentially the
same thing. Refactor to use only the one.

The is prep work for the BlockInput refactor.

PR 0 of ??
2025-04-21 08:00:36 -04:00
Nico Flaig
51613f0fb0 chore: bump package versions to 1.29.0 2025-04-19 16:27:49 +01:00
twoeths
5bc61255df feat: ssz v1.2.0 (#7608)
**Motivation**

- as v1.28.0 was released, we want to upgrade to ssz v1.2.0 to test the
batch hash asap and unblock other works

**Description**

- replace ssz v1.0.2 by v1.2.0

---------

Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
2025-03-23 15:03:30 +07:00
Phil Ngo
300bed85d8 chore: re-merge v1.28.1 back to unstable (#7613) 2025-03-20 16:09:19 -04:00
Phil Ngo
40d04deac5 chore: bump package versions to 1.28.1 2025-03-20 13:35:15 -04:00
Matthew Keil
a78dbc96dd chore: fix type errors introduced by previous PR (#7606)
**Motivation**

Bugs were introduced by #7533
2025-03-19 20:10:54 +00:00
Nazar Hussain
23195c050b chore: upgrade biomejs to 1.9.4 (#7533)
**Motivation**

Keep the tooling updated.

**Description**

- Enable different useable new rules. 

**Steps to test or reproduce**

Run all tests. 


## Please review commit by commit
For reviewers please review commit by commit.

<img width="426" alt="image"
src="https://github.com/user-attachments/assets/e6ad3082-d311-4e11-896a-99abf715ca8a"
/>
2025-03-19 18:07:18 +00:00
Nico Flaig
461532eeed chore: bump package versions to 1.28.0 2025-03-18 18:38:52 +00:00
Cayman
2229df1c74 feat: use native compute proposer/sync committee (#7499)
**Motivation**

- further https://github.com/ChainSafe/lodestar/pull/7456

## Description

- use native `computeProposerIndex` and `computeSyncCommitteeIndices`
- always treat sync committee indices as a Uint32Array (since that's
what is returned by `ComputeSyncCommitteeIndices`)

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
2025-03-16 11:52:10 +00:00
NC
22695585d1 chore: fix various imports (#7583)
Fixing multiple imports especially those that are referencing js files
2025-03-15 06:49:23 +00:00
Nazar Hussain
9f78c9dad8 chore: fix broken type check for test files (#7567)
**Motivation**

Check the types for test files

**Description**

- Add `test` folder for the `tsconfig.json` files

**Steps to test or reproduce**

- Run all tests
2025-03-13 13:47:22 +00:00
Nazar Hussain
51efa3d604 chore: update the test runner (#7404)
**Motivation**

Update vitest and browser engine.

**Description**

- Move root level shared configs to `configs` directory
- Update to vitest 3.x
- Migrate from `webdriverio` to `playwright` which is more stable and
recommended by Vitest.

**NOTE**
Reverted the `playwright` upgrade. See the comments. 


d2a7af0308/configs/vitest.config.base.browser.ts (L41-L43)

**Steps to test or reproduce**

Run all tests
2025-02-27 10:27:43 -05:00
Nazar Hussain
b2ebe4921b deps: upgrade tyepscript to 5.7 (#7160)
**Motivation**

Keep the deps updated.

**Description**

Use latest features provided by Typescript. See the comments below. 

**Steps to test or reproduce**

- Run all tests
2025-02-25 14:24:14 +01:00
Nico Flaig
3b0ca8df3b chore: bump package versions to 1.27.1 2025-02-24 14:58:39 +00:00
Phil Ngo
2ddcd2052c chore: bump package versions to 1.27.0 2025-02-13 09:06:43 -05:00
Nico Flaig
9c66fac4a4 Merge branch 'stable' into unstable 2025-02-04 18:42:26 +00:00