From 11f35a8c2129e3df718a90682cb0d9aa8bcf961f Mon Sep 17 00:00:00 2001 From: Cayman Date: Fri, 20 Dec 2024 12:09:11 -0500 Subject: [PATCH] chore: release v1.24.0 (#7325) * feat: add keymanager endpoint to retrieve proposer config (#7210) * feat: add keymanager endpoint to retrieve proposer config * Do not return empty builder config * Check all builder proposer config values * Fix settings builder config if undefined * Fix builder config parsing * Use ssz type to handle json serialization Default parsing can't handle BigInt * Revert "Use ssz type to handle json serialization" This reverts commit 01fcea702e32e1f97a0aa351b6623d94dc0fbcea. * Fix boost factor json serialization * Remove unused import * Update test data * Update proposer config test * feat: add mekong network option (#7212) * chore: fix import order with biome syntax (#7211) Fix import order * fix: consistently validate pubkey and throw 404 if not found (#7214) * Throw error if pubkey is unknown when getting graffiti * Consistently validate pubkey and throw 404 if not found * fix: only return local keys from /eth/v1/keystores (#7215) * fix: only return local keys from /eth/v1/keystores * Fix fetching remote keys in node assertion * feat: add and use getBlobsV1 to expedite gossip import (#7134) * hookup the getblobs api to get bob and proof data from el remove unused fix import metrics overhault, test, debugging testing, some feeback fix add nethermind bug dicussion link fix resolve conflicts * deblobs timeout * fix metric * chore: revert async aggregate with randomness (#7218) Revert "feat: asyncAggregateWithRandomness (#7204)" This reverts commit e31d535bb59d209827cbab61cb4381dccac90171. * fix: update config for relaunched mekong network (#7220) * fix: light client generating `LightClientUpdate` with wrong length of branches (#7187) * initial commit * Rewrite SyncCommitteeWitnessRepository * Fix finality branch * Update unit test * fix e2e * Review PR --------- Co-authored-by: Nico Flaig * fix: archive finalized state when shutting down beacon node (#7221) * Fix typo * feat: remove unfinalized pubkey cache (#7230) * Remove unfinalized pubkey cache * lint * Fix unit test * chore: skip web3_provider unit tests (#7252) * fix: prune checkpoint states at syncing time (#7241) * fix: prune checkpoint states at syncing time * fix: lint * fix: check-types in test * fix: sync cached isCompoundingValidatorArr at epoch transition (#7247) * fix: handle outOfRangeData when range sync Deneb (#7249) * fix: handle outOfRangeData for beaconBlocksMaybeBlobsByRange() * fix: lint * fix: archiveBlocks - handle deneb outOfRangeData block * fix: sync cached balance when adding new validator to registry (#7255) * fix: sync cached balance when adding new validator to registry * chore: add more comments * fix: remove persisted checkpoint states from the previous run at startup * fix: do not throw error when trying to prune missing directory (#7257) * docs: update documentation Oct 2024 (#7178) * docs update oct 2024 init * Reconfig quickstart nav and minor fixes * fix lint * spelling fixes * minor fixes and add to wordlist * prettier fix * add to wordlist * sort wordlist * modify dominance to include lighthouse * fix typescript casing and add recommendation * add selection and boost_factor with keymanager notice * update wordlist * remove builder enabled and add keymanager api * spelling --------- Co-authored-by: Nico Flaig * chore(deps): bump cross-spawn from 7.0.3 to 7.0.6 in /docs (#7268) Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.6. - [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md) - [Commits](https://github.com/moxystudio/node-cross-spawn/compare/v7.0.3...v7.0.6) --- updated-dependencies: - dependency-name: cross-spawn dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat: add error log to notifier if execution client auth failed (#7239) * feat: add error log to notifier if execution client auth failed * Update packages/beacon-node/src/node/notifier.ts --------- Co-authored-by: NC <17676176+ensi321@users.noreply.github.com> * docs: display rcConfig flag on CLI reference page (#7270) * docs: display rcConfig flag on CLI reference page * Update word list * chore: remove prettier as default formatter for all file types (#7275) * chore: unhide flags relevant for devnets / testing (#7271) * feat: debug too many shuffling promises (#7251) * feat: add asyncShufflingCalculation to StateTransitionOpts * feat: add asyncShufflingCalculation to all regen / processSlots consumers * fix: default to false for async shuffling and remove unnecessary props * fix: remove unnecessary flags from stateTransition * feat: implement conditional build of shuffling for prepareNextSlot * fix: spec test bug where shufflingCache is present from BeaconChain constructor * feat: sync build next shuffling if not queued async * fix: use getSync to pull next shuffling correctly * docs: add comment to prepareNextSlot * refactor: rename StateCloneOpts to StateRegenerationOpts * feat: pass asyncShufflingCalculation through to afterProcessEpoch and refactor conditional to run purely sync * docs: add issue number to comment * chore: lint * chore: unpin nodejs version from 22.4 (#6982) * Revert "chore: pin nodejs version to 22.4 (#6964)" This reverts commit f20484bb4b6b5f3a27c624556d1e6fb9f448b969. * Don't revert formatting changes --------- Co-authored-by: Nico Flaig Co-authored-by: Cayman * chore: update bootnodes file url for holesky and sepolia (#7276) * feat: add `debug_getHistoricalSummaries` endpoint (#7245) * feat: add new getHistoricalSummaries endpoint to debug namespace * Add JSON response * Restructure to use stateId and add proof to response * add test scaffolding * Address feedback * Move getHistoricalSummaries to lodestar namespace * add lodestar namespace unit test * update route name to lodestar namespace * cast state object as Capella state * Lint * json properties need to be lower case * Make it v1 since it's now part of lodestar namespace * Group with other /lodestar endpoints * Simplify beacon node impl * Rename return type * Update test description * Fix variable name --------- Co-authored-by: Nico Flaig * chore: log sync committee signature errors as `error` (#7283) * fix: update engine_getClientVersionV1 commit encoding (#7282) * fix: check pubkey or validator index known to a state (#7284) * fix: check pubkey or validator index known to a state * chore: add more comments * feat: lodestar script setup (#7254) * feat: lodestar_setup * feat: script_updates + docs * feat: script_addition_in_docs + command_update * Remove duplicate script from docs folder * Minor script updates * Update script to prepare docs and ignore copied file * Update installation page * Wording --------- Co-authored-by: Nico Flaig * feat: add terminal-sized Electra giraffe banner (#7286) * Create giraffeBanners.ts * Wire in banner * Fix file name * lint * Address @nflaig's comment --------- Co-authored-by: NC <17676176+ensi321@users.noreply.github.com> * chore: pin nodejs version to 22.4 (#7291) Revert "chore: unpin nodejs version from 22.4 (#6982)" This reverts commit 69ae688bed4b17f93801494aa16919888935c780. * feat: expose `DOMAIN_APPLICATION_MASK` in config/spec api (#7296) * feat: expose DOMAIN_APPLICATION_MASK in config/spec api * Lint * feat: make `MAX_REQUEST_BLOB_SIDECARS` and `MAX_BLOBS_PER_BLOCK` configurable (#7294) * Init commit * Fix check-types * Add comment on how MAX_REQUEST_BLOB_SIDECARS is calculated * Ensure proper config object is passed * Address comment --------- Co-authored-by: Nico Flaig * feat: use `BLOB_SIDECAR_SUBNET_COUNT` to configure blob subnets (#7297) feat: use BLOB_SIDECAR_SUBNET_COUNT to configure blob subnets * chore: log sync aggregate participants when producing beacon block body (#7300) * chore: log sync aggregate participants when producing beacon block body * Use isForkLightClient instead of ForkSeq * Fix produce block unit tests * chore: print graffiti when producing beacon block body (#7303) * fix: warn if engine / builder failed to produce block within cutoff time (#7305) * feat: add kzg commitment length check when validating gossip blocks (#7302) * feat: add blob sidecar index check (#7313) Validate blobSidecar index * fix: fix blob sidecar index check (#7315) Fix index check * chore: fix format of printed graffiti from hex to utf-8 (#7306) * chore: fix format of printed graffiti from hex to utf-8 * Use Buffer.from no copy with offset * docs: batch commit typos and update contributor readme (#7312) * batch commit typos and update contributor readme * update donation text Co-authored-by: Nico Flaig * correct spelling Co-authored-by: Nico Flaig --------- Co-authored-by: Nico Flaig * chore: remove trailing null bytes from printed graffiti (#7320) * chore: remove trailing null bytes from printed graffiti * Use replaceAll instead of regex * chore: unpin nodejs version from 22.4 (#7324) Revert "chore: pin nodejs version to 22.4 (#7291)" This reverts commit 99794d3b261bb50f9a6c7d9f6ca19291b3f30911. * chore: bump package versions to 1.24.0 --------- Signed-off-by: dependabot[bot] Co-authored-by: Nico Flaig Co-authored-by: Nazar Hussain Co-authored-by: g11tech Co-authored-by: Matthew Keil Co-authored-by: NC <17676176+ensi321@users.noreply.github.com> Co-authored-by: twoeths Co-authored-by: Phil Ngo <58080811+philknows@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com> Co-authored-by: Varun Guleria <152203177+varunguleriaCodes@users.noreply.github.com> Co-authored-by: ClockworkYuzu --- .github/workflows/benchmark.yml | 2 +- .github/workflows/binaries.yml | 2 +- .github/workflows/docs-check.yml | 2 +- .github/workflows/docs.yml | 2 +- .github/workflows/publish-dev.yml | 2 +- .github/workflows/publish-rc.yml | 2 +- .github/workflows/publish-stable.yml | 2 +- .github/workflows/test-sim-merge.yml | 2 +- .github/workflows/test-sim.yml | 12 +- .github/workflows/test.yml | 14 +- .gitignore | 1 + .vscode/settings.json | 9 +- .wordlist.txt | 29 +- CONTRIBUTING.md | 2 + Dockerfile | 6 +- README.md | 4 +- RELEASE.md | 2 +- biome.jsonc | 5 +- docs/README.md | 2 +- docs/docusaurus.config.ts | 32 +- docs/pages/contribution/testing/index.md | 4 +- docs/pages/contribution/tools/heap-dumps.md | 4 +- docs/pages/faqs.md | 2 +- docs/pages/google0c42298b7ec08b7e.html | 1 - docs/pages/index.md | 24 +- docs/pages/introduction.md | 24 +- .../run/beacon-management/starting-a-node.md | 126 +-- .../pages/run/getting-started/installation.md | 12 +- .../quick-start-custom-guide.md | 728 ++++++++++++++++++ docs/pages/run/getting-started/quick-start.md | 28 +- .../logging-and-metrics/client-monitoring.md | 4 +- .../run/logging-and-metrics/dashboards.md | 0 .../run/logging-and-metrics/log-management.md | 3 - .../logging-and-metrics/metrics-management.md | 0 .../logging-and-metrics/prometheus-grafana.md | 10 +- .../validator-management/proposer-config.md | 48 ++ .../validator-management/vc-configuration.md | 4 + docs/pages/supporting-libraries/libraries.md | 4 +- docs/pages/trouble-shooting.md | 1 - docs/sidebars.ts | 21 +- docs/yarn.lock | 6 +- lerna.json | 2 +- packages/api/package.json | 10 +- packages/api/src/beacon/client/debug.ts | 2 +- .../api/src/beacon/routes/beacon/block.ts | 18 +- .../api/src/beacon/routes/beacon/index.ts | 4 +- packages/api/src/beacon/routes/beacon/pool.ts | 8 +- .../api/src/beacon/routes/beacon/rewards.ts | 4 +- .../api/src/beacon/routes/beacon/state.ts | 4 +- packages/api/src/beacon/routes/config.ts | 2 +- packages/api/src/beacon/routes/debug.ts | 6 +- packages/api/src/beacon/routes/events.ts | 24 +- packages/api/src/beacon/routes/lightclient.ts | 16 +- packages/api/src/beacon/routes/lodestar.ts | 45 +- packages/api/src/beacon/routes/node.ts | 4 +- packages/api/src/beacon/routes/proof.ts | 4 +- packages/api/src/beacon/routes/validator.ts | 24 +- packages/api/src/beacon/server/events.ts | 2 +- packages/api/src/beacon/server/index.ts | 2 +- packages/api/src/builder/index.ts | 2 +- packages/api/src/builder/routes.ts | 18 +- packages/api/src/builder/server/index.ts | 4 +- packages/api/src/keymanager/index.ts | 3 +- packages/api/src/keymanager/routes.ts | 39 +- packages/api/src/keymanager/server/index.ts | 4 +- packages/api/src/utils/client/httpClient.ts | 6 +- packages/api/src/utils/codecs.ts | 4 +- packages/api/src/utils/metadata.ts | 4 +- packages/api/src/utils/server/handler.ts | 4 +- packages/api/src/utils/server/route.ts | 2 +- .../beacon/genericServerTest/beacon.test.ts | 4 +- .../beacon/genericServerTest/config.test.ts | 4 +- .../beacon/genericServerTest/debug.test.ts | 16 +- .../beacon/genericServerTest/events.test.ts | 8 +- .../genericServerTest/lightclient.test.ts | 4 +- .../beacon/genericServerTest/lodestar.test.ts | 53 ++ .../beacon/genericServerTest/node.test.ts | 4 +- .../beacon/genericServerTest/proofs.test.ts | 4 +- .../genericServerTest/validator.test.ts | 4 +- .../api/test/unit/beacon/oapiSpec.test.ts | 4 +- .../api/test/unit/beacon/testData/config.ts | 2 +- .../api/test/unit/beacon/testData/events.ts | 2 +- .../test/unit/beacon/testData/lightclient.ts | 2 +- .../test/unit/beacon/testData/validator.ts | 2 +- .../api/test/unit/builder/builder.test.ts | 4 +- .../api/test/unit/builder/oapiSpec.test.ts | 2 +- packages/api/test/unit/builder/testData.ts | 2 +- packages/api/test/unit/client/fetch.test.ts | 2 +- .../api/test/unit/client/httpClient.test.ts | 18 +- .../unit/client/httpClientOptions.test.ts | 2 +- .../api/test/unit/client/urlFormat.test.ts | 6 +- .../test/unit/keymanager/keymanager.test.ts | 4 +- .../api/test/unit/keymanager/oapiSpec.test.ts | 2 +- packages/api/test/unit/keymanager/testData.ts | 15 + packages/api/test/unit/utils/headers.test.ts | 2 +- packages/api/test/unit/utils/serdes.test.ts | 2 +- packages/api/test/utils/checkAgainstSpec.ts | 6 +- packages/api/test/utils/genericServerTest.ts | 8 +- packages/api/test/utils/utils.ts | 6 +- packages/beacon-node/package.json | 26 +- packages/beacon-node/src/api/impl/api.ts | 2 +- .../src/api/impl/beacon/blocks/index.ts | 38 +- .../src/api/impl/beacon/blocks/utils.ts | 8 +- .../beacon-node/src/api/impl/beacon/index.ts | 2 +- .../src/api/impl/beacon/pool/index.ts | 18 +- .../src/api/impl/beacon/state/index.ts | 4 +- .../src/api/impl/beacon/state/utils.ts | 4 +- .../src/api/impl/config/constants.ts | 60 +- .../beacon-node/src/api/impl/config/index.ts | 2 +- .../beacon-node/src/api/impl/debug/index.ts | 6 +- .../src/api/impl/lightclient/index.ts | 6 +- .../src/api/impl/lodestar/index.ts | 37 +- .../beacon-node/src/api/impl/node/index.ts | 2 +- .../beacon-node/src/api/impl/proof/index.ts | 8 +- packages/beacon-node/src/api/impl/types.ts | 4 +- .../src/api/impl/validator/index.ts | 140 ++-- .../src/api/impl/validator/utils.ts | 4 +- packages/beacon-node/src/api/options.ts | 2 +- packages/beacon-node/src/api/rest/base.ts | 6 +- packages/beacon-node/src/api/rest/index.ts | 4 +- .../src/chain/archiver/archiveBlocks.ts | 8 +- .../src/chain/archiver/archiver.ts | 10 +- .../src/chain/archiver/interface.ts | 2 +- .../frequencyStateArchiveStrategy.ts | 12 +- .../beacon-node/src/chain/balancesCache.ts | 4 +- .../src/chain/beaconProposerCache.ts | 2 +- .../src/chain/blocks/importBlock.ts | 20 +- .../beacon-node/src/chain/blocks/index.ts | 10 +- .../beacon-node/src/chain/blocks/types.ts | 8 +- .../src/chain/blocks/utils/checkpoint.ts | 2 +- .../src/chain/blocks/utils/giraffeBanner.ts | 27 + .../src/chain/blocks/verifyBlock.ts | 30 +- .../blocks/verifyBlocksDataAvailability.ts | 38 +- .../blocks/verifyBlocksExecutionPayloads.ts | 38 +- .../chain/blocks/verifyBlocksSanityChecks.ts | 2 +- .../chain/blocks/verifyBlocksSignatures.ts | 4 +- .../blocks/verifyBlocksStateTransitionOnly.ts | 8 +- .../src/chain/bls/multithread/index.ts | 18 +- .../src/chain/bls/multithread/jobItem.ts | 4 +- .../src/chain/bls/multithread/worker.ts | 6 +- packages/beacon-node/src/chain/chain.ts | 134 ++-- packages/beacon-node/src/chain/emitter.ts | 2 +- .../src/chain/errors/attestationError.ts | 2 +- .../src/chain/errors/blobSidecarError.ts | 6 +- .../src/chain/errors/blockError.ts | 7 +- .../src/chain/errors/syncCommitteeError.ts | 2 +- .../beacon-node/src/chain/forkChoice/index.ts | 12 +- .../beacon-node/src/chain/genesis/genesis.ts | 20 +- .../src/chain/genesis/interface.ts | 2 +- .../historicalState/getHistoricalState.ts | 2 +- .../src/chain/historicalState/index.ts | 2 +- .../src/chain/historicalState/worker.ts | 10 +- packages/beacon-node/src/chain/initState.ts | 6 +- packages/beacon-node/src/chain/interface.ts | 78 +- .../opPools/aggregatedAttestationPool.ts | 38 +- .../src/chain/opPools/attestationPool.ts | 8 +- .../beacon-node/src/chain/opPools/opPool.ts | 24 +- .../chain/opPools/syncCommitteeMessagePool.ts | 4 +- .../opPools/syncContributionAndProofPool.ts | 4 +- packages/beacon-node/src/chain/options.ts | 2 +- .../beacon-node/src/chain/prepareNextSlot.ts | 27 +- .../chain/produceBlock/produceBlockBody.ts | 78 +- .../beacon-node/src/chain/regen/errors.ts | 2 +- .../beacon-node/src/chain/regen/interface.ts | 22 +- .../beacon-node/src/chain/regen/queued.ts | 76 +- packages/beacon-node/src/chain/regen/regen.ts | 34 +- packages/beacon-node/src/chain/reprocess.ts | 2 +- .../src/chain/rewards/attestationsRewards.ts | 6 +- .../src/chain/rewards/blockRewards.ts | 4 +- .../src/chain/rewards/syncCommitteeRewards.ts | 4 +- .../chain/seenCache/seenAttestationData.ts | 2 +- .../src/chain/seenCache/seenCommittee.ts | 2 +- .../chain/seenCache/seenGossipBlockInput.ts | 14 +- .../chain/stateCache/blockStateCacheImpl.ts | 10 +- .../chain/stateCache/fifoBlockStateCache.ts | 8 +- .../stateCache/inMemoryCheckpointsCache.ts | 16 +- .../stateCache/persistentCheckpointsCache.ts | 26 +- .../beacon-node/src/chain/stateCache/types.ts | 14 +- .../src/chain/validation/aggregateAndProof.ts | 8 +- .../src/chain/validation/attestation.ts | 52 +- .../src/chain/validation/attesterSlashing.ts | 6 +- .../src/chain/validation/blobSidecar.ts | 34 +- .../beacon-node/src/chain/validation/block.ts | 22 +- .../chain/validation/blsToExecutionChange.ts | 8 +- .../validation/lightClientFinalityUpdate.ts | 6 +- .../validation/lightClientOptimisticUpdate.ts | 6 +- .../src/chain/validation/proposerSlashing.ts | 4 +- .../signatureSets/aggregateAndProof.ts | 8 +- .../signatureSets/contributionAndProof.ts | 4 +- .../signatureSets/selectionProof.ts | 6 +- .../validation/signatureSets/syncCommittee.ts | 4 +- .../syncCommitteeContribution.ts | 4 +- .../syncCommitteeSelectionProof.ts | 4 +- .../src/chain/validation/syncCommittee.ts | 2 +- .../syncCommitteeContributionAndProof.ts | 8 +- .../src/chain/validation/voluntaryExit.ts | 4 +- packages/beacon-node/src/db/beacon.ts | 20 +- packages/beacon-node/src/db/interface.ts | 18 +- .../src/db/repositories/attesterSlashing.ts | 2 +- .../src/db/repositories/backfilledRanges.ts | 2 +- .../src/db/repositories/blobSidecars.ts | 2 +- .../db/repositories/blobSidecarsArchive.ts | 2 +- .../src/db/repositories/blockArchive.ts | 8 +- .../src/db/repositories/blockArchiveIndex.ts | 4 +- .../db/repositories/blsToExecutionChange.ts | 2 +- .../src/db/repositories/depositDataRoot.ts | 4 +- .../src/db/repositories/depositEvent.ts | 2 +- .../src/db/repositories/eth1Data.ts | 4 +- .../db/repositories/lightclientBestUpdate.ts | 2 +- .../lightclientCheckpointHeader.ts | 2 +- .../src/db/repositories/proposerSlashing.ts | 2 +- .../src/db/repositories/stateArchive.ts | 4 +- .../src/db/repositories/stateArchiveIndex.ts | 2 +- .../src/db/repositories/voluntaryExit.ts | 2 +- .../src/db/single/preGenesisState.ts | 2 +- .../preGenesisStateLastProcessedBlock.ts | 2 +- .../src/eth1/eth1DepositDataTracker.ts | 12 +- .../beacon-node/src/eth1/eth1DepositsCache.ts | 10 +- .../src/eth1/eth1MergeBlockTracker.ts | 6 +- packages/beacon-node/src/eth1/index.ts | 2 +- packages/beacon-node/src/eth1/interface.ts | 2 +- .../src/eth1/provider/eth1Provider.ts | 14 +- .../src/eth1/provider/jsonRpcHttpClient.ts | 4 +- .../beacon-node/src/eth1/provider/utils.ts | 2 +- packages/beacon-node/src/eth1/stream.ts | 6 +- .../beacon-node/src/eth1/utils/deposits.ts | 10 +- .../beacon-node/src/eth1/utils/eth1Data.ts | 2 +- .../beacon-node/src/eth1/utils/eth1Vote.ts | 4 +- .../beacon-node/src/execution/builder/http.ts | 26 +- .../src/execution/builder/interface.ts | 16 +- .../src/execution/engine/disabled.ts | 4 + .../beacon-node/src/execution/engine/http.ts | 90 ++- .../beacon-node/src/execution/engine/index.ts | 6 +- .../src/execution/engine/interface.ts | 8 +- .../beacon-node/src/execution/engine/mock.ts | 29 +- .../src/execution/engine/payloadIdCache.ts | 2 +- .../beacon-node/src/execution/engine/types.ts | 33 +- .../beacon-node/src/execution/engine/utils.ts | 6 +- packages/beacon-node/src/metrics/metrics.ts | 14 +- .../beacon-node/src/metrics/metrics/beacon.ts | 130 +++- .../src/metrics/metrics/lodestar.ts | 17 +- .../beacon-node/src/metrics/nodeJsMetrics.ts | 2 +- .../beacon-node/src/metrics/server/http.ts | 4 +- .../src/metrics/utils/avgMinMax.ts | 2 +- .../beacon-node/src/metrics/utils/gauge.ts | 2 +- .../metrics/utils/registryMetricCreator.ts | 2 +- .../src/metrics/validatorMonitor.ts | 14 +- .../beacon-node/src/monitoring/service.ts | 6 +- packages/beacon-node/src/monitoring/system.ts | 2 +- .../src/network/core/networkCore.ts | 62 +- .../src/network/core/networkCoreWorker.ts | 8 +- .../beacon-node/src/network/core/types.ts | 4 +- .../beacon-node/src/network/discv5/index.ts | 8 +- .../beacon-node/src/network/discv5/worker.ts | 16 +- packages/beacon-node/src/network/events.ts | 6 +- packages/beacon-node/src/network/forks.ts | 2 +- .../src/network/gossip/encoding.ts | 10 +- .../src/network/gossip/gossipsub.ts | 26 +- .../src/network/gossip/interface.ts | 24 +- .../src/network/gossip/scoringParameters.ts | 6 +- .../beacon-node/src/network/gossip/topic.ts | 24 +- packages/beacon-node/src/network/interface.ts | 25 +- .../beacon-node/src/network/libp2p/index.ts | 12 +- packages/beacon-node/src/network/metadata.ts | 4 +- packages/beacon-node/src/network/network.ts | 66 +- packages/beacon-node/src/network/options.ts | 2 +- .../src/network/peers/datastore.ts | 2 +- .../beacon-node/src/network/peers/discover.ts | 14 +- .../src/network/peers/peerManager.ts | 30 +- .../src/network/peers/peersData.ts | 2 +- .../peers/utils/enrSubnetsDeserialize.ts | 2 +- .../network/peers/utils/prioritizePeers.ts | 4 +- .../network/processor/extractSlotRootFns.ts | 2 +- .../src/network/processor/gossipHandlers.ts | 73 +- .../network/processor/gossipQueues/index.ts | 4 +- .../network/processor/gossipQueues/linear.ts | 2 +- .../network/processor/gossipValidatorFn.ts | 10 +- .../src/network/processor/index.ts | 18 +- .../src/network/processor/types.ts | 2 +- .../src/network/reqresp/ReqRespBeaconNode.ts | 14 +- .../reqresp/beaconBlocksMaybeBlobsByRange.ts | 4 +- .../reqresp/beaconBlocksMaybeBlobsByRoot.ts | 181 ++++- .../reqresp/handlers/beaconBlocksByRange.ts | 2 +- .../reqresp/handlers/blobSidecarsByRange.ts | 6 +- .../reqresp/handlers/blobSidecarsByRoot.ts | 7 +- .../src/network/reqresp/handlers/index.ts | 7 +- .../reqresp/handlers/lightClientBootstrap.ts | 6 +- .../handlers/lightClientFinalityUpdate.ts | 4 +- .../handlers/lightClientOptimisticUpdate.ts | 4 +- .../handlers/lightClientUpdatesByRange.ts | 8 +- .../src/network/reqresp/handlers/status.ts | 2 +- .../src/network/reqresp/protocols.ts | 10 +- .../src/network/reqresp/rateLimit.ts | 29 +- .../beacon-node/src/network/reqresp/types.ts | 12 +- .../src/network/reqresp/utils/collect.ts | 2 +- .../utils/collectSequentialBlocksInRange.ts | 2 +- .../src/network/subnets/attnetsService.ts | 14 +- .../src/network/subnets/interface.ts | 2 +- .../src/network/subnets/syncnetsService.ts | 4 +- packages/beacon-node/src/node/nodejs.ts | 26 +- packages/beacon-node/src/node/notifier.ts | 22 +- packages/beacon-node/src/node/options.ts | 24 +- .../src/node/utils/interop/deposits.ts | 8 +- .../src/node/utils/interop/state.ts | 4 +- packages/beacon-node/src/node/utils/state.ts | 2 +- .../beacon-node/src/sync/backfill/backfill.ts | 12 +- .../beacon-node/src/sync/backfill/errors.ts | 2 +- .../beacon-node/src/sync/backfill/verify.ts | 4 +- packages/beacon-node/src/sync/interface.ts | 10 +- packages/beacon-node/src/sync/range/batch.ts | 6 +- packages/beacon-node/src/sync/range/chain.ts | 16 +- packages/beacon-node/src/sync/range/range.ts | 14 +- .../src/sync/range/utils/hashBlocks.ts | 2 +- packages/beacon-node/src/sync/sync.ts | 18 +- packages/beacon-node/src/sync/unknownBlock.ts | 35 +- .../src/sync/utils/pendingBlocksTree.ts | 2 +- .../src/sync/utils/remoteSyncType.ts | 2 +- packages/beacon-node/src/util/blobs.ts | 4 +- packages/beacon-node/src/util/clock.ts | 6 +- packages/beacon-node/src/util/graffiti.ts | 9 + packages/beacon-node/src/util/kzg.ts | 11 +- packages/beacon-node/src/util/multifork.ts | 2 +- packages/beacon-node/src/util/peerId.ts | 2 +- .../beacon-node/src/util/queue/fnQueue.ts | 2 +- .../beacon-node/src/util/queue/itemQueue.ts | 4 +- packages/beacon-node/src/util/sszBytes.ts | 2 +- packages/beacon-node/src/util/types.ts | 7 +- .../api/impl/beacon/block/endpoint.test.ts | 10 +- .../api/impl/beacon/node/endpoints.test.ts | 8 +- .../api/impl/beacon/state/endpoint.test.ts | 8 +- .../test/e2e/api/impl/config.test.ts | 10 +- .../e2e/api/impl/lightclient/endpoint.test.ts | 16 +- .../test/e2e/api/lodestar/lodestar.test.ts | 16 +- .../test/e2e/chain/bls/multithread.test.ts | 4 +- .../test/e2e/chain/lightclient.test.ts | 16 +- .../test/e2e/chain/proposerBoostReorg.test.ts | 14 +- .../stateCache/nHistoricalStates.test.ts | 18 +- .../beacon/repositories/blockArchive.test.ts | 2 +- .../e2e/doppelganger/doppelganger.test.ts | 12 +- .../e2e/eth1/eth1ForBlockProduction.test.ts | 12 +- .../e2e/eth1/eth1MergeBlockTracker.test.ts | 8 +- .../test/e2e/eth1/eth1Provider.test.ts | 8 +- .../test/e2e/eth1/jsonRpcHttpClient.test.ts | 4 +- .../beacon-node/test/e2e/eth1/stream.test.ts | 8 +- .../test/e2e/interop/genesisState.test.ts | 4 +- .../test/e2e/network/gossipsub.test.ts | 8 +- .../beacon-node/test/e2e/network/mdns.test.ts | 18 +- .../test/e2e/network/network.test.ts | 4 +- .../onWorker/dataSerialization.test.ts | 28 +- .../e2e/network/onWorker/workerEchoHandler.ts | 2 +- .../e2e/network/peers/peerManager.test.ts | 24 +- .../test/e2e/network/reqresp.test.ts | 12 +- .../test/e2e/network/reqrespEncode.test.ts | 20 +- .../test/e2e/sync/finalizedSync.test.ts | 18 +- .../test/e2e/sync/unknownBlockSync.test.ts | 20 +- packages/beacon-node/test/globalSetup.ts | 2 +- .../test/memory/unfinalizedPubkey2Index.ts | 54 -- packages/beacon-node/test/mocks/clock.ts | 2 +- packages/beacon-node/test/mocks/loggerMock.ts | 2 +- .../test/mocks/mockedBeaconChain.ts | 29 +- .../beacon-node/test/mocks/mockedBeaconDb.ts | 12 +- .../beacon-node/test/mocks/mockedNetwork.ts | 4 +- packages/beacon-node/test/mocks/regenMocks.ts | 2 +- .../beacon-node/test/mocks/shufflingMock.ts | 2 +- .../beacon-node/test/perf/bls/bls.test.ts | 2 +- .../opPools/aggregatedAttestationPool.test.ts | 6 +- .../test/perf/chain/opPools/opPool.test.ts | 2 +- .../produceBlock/produceBlockBody.test.ts | 4 +- .../seenCache/seenAggregateAndProof.test.ts | 2 +- .../inMemoryCheckpointsCache.test.ts | 4 +- .../updateUnfinalizedPubkeys.test.ts | 114 --- .../perf/chain/validation/attestation.test.ts | 4 +- .../perf/chain/verifyImportBlocks.test.ts | 12 +- .../test/perf/eth1/pickEth1Vote.test.ts | 4 +- .../test/perf/misc/bytesHex.test.ts | 2 +- .../perf/network/gossip/fastMsgIdFn.test.ts | 4 +- .../test/perf/network/noise/sendData.test.ts | 8 +- .../peers/enrSubnetsDeserialize.test.ts | 4 +- .../peers/util/prioritizePeers.test.ts | 2 +- .../test/perf/util/bitArray.test.ts | 2 +- packages/beacon-node/test/setupPreset.ts | 2 +- .../test/sim/electra-interop.test.ts | 55 +- .../beacon-node/test/sim/mergemock.test.ts | 18 +- packages/beacon-node/test/spec/bls/bls.ts | 2 +- .../beacon-node/test/spec/bls/index.test.ts | 2 +- .../beacon-node/test/spec/downloadTests.ts | 2 +- packages/beacon-node/test/spec/general/bls.ts | 8 +- .../test/spec/general/index.test.ts | 4 +- .../test/spec/general/ssz_generic.ts | 4 +- .../test/spec/general/ssz_generic_types.ts | 10 +- .../spec/presets/epoch_processing.test.ts | 12 +- .../test/spec/presets/finality.test.ts | 6 +- .../test/spec/presets/fork.test.ts | 12 +- .../test/spec/presets/fork_choice.test.ts | 56 +- .../test/spec/presets/genesis.test.ts | 12 +- .../light_client/single_merkle_proof.ts | 6 +- .../test/spec/presets/light_client/sync.ts | 12 +- .../presets/light_client/update_ranking.ts | 6 +- .../test/spec/presets/merkle.test.ts | 10 +- .../test/spec/presets/operations.test.ts | 10 +- .../test/spec/presets/rewards.test.ts | 8 +- .../test/spec/presets/sanity.test.ts | 6 +- .../test/spec/presets/shuffling.test.ts | 4 +- .../test/spec/presets/ssz_static.test.ts | 8 +- .../test/spec/presets/transition.test.ts | 10 +- .../test/spec/utils/expectEqualBeaconState.ts | 4 +- .../replaceUintTypeWithUintBigintType.ts | 6 +- .../test/spec/utils/runValidSszTest.ts | 4 +- .../test/spec/utils/specTestIterator.ts | 2 +- .../test/spec/utils/sszTestCaseParser.ts | 6 +- .../network/gossip/scoringParameters.test.ts | 6 +- .../unit-mainnet/network/subnets/util.test.ts | 2 +- .../test/unit/api/impl/beacon/beacon.test.ts | 4 +- .../beacon/blocks/getBlockHeaders.test.ts | 6 +- .../unit/api/impl/beacon/state/utils.test.ts | 2 +- .../test/unit/api/impl/config/config.test.ts | 2 +- .../test/unit/api/impl/events/events.test.ts | 4 +- .../test/unit/api/impl/swaggerUI.test.ts | 2 +- .../impl/validator/duties/proposer.test.ts | 12 +- .../validator/produceAttestationData.test.ts | 6 +- .../api/impl/validator/produceBlockV2.test.ts | 22 +- .../api/impl/validator/produceBlockV3.test.ts | 12 +- .../unit/api/impl/validator/utils.test.ts | 4 +- .../unit/chain/archive/blockArchiver.test.ts | 12 +- .../unit/chain/archive/nonCheckpoint.test.ts | 2 +- .../unit/chain/archive/stateArchiver.test.ts | 2 +- .../test/unit/chain/beaconProposerCache.ts | 2 +- .../rejectFirstInvalidResolveAllValid.test.ts | 2 +- .../blocks/verifyBlocksSanityChecks.test.ts | 10 +- .../test/unit/chain/bls/bls.test.ts | 4 +- .../test/unit/chain/bls/utils.test.ts | 2 +- .../unit/chain/forkChoice/forkChoice.test.ts | 8 +- .../test/unit/chain/genesis/genesis.test.ts | 10 +- .../upgradeLightClientHeader.test.ts | 6 +- .../opPools/aggregatedAttestationPool.test.ts | 22 +- .../chain/opPools/attestationPool.test.ts | 6 +- .../unit/chain/opPools/syncCommittee.test.ts | 4 +- .../opPools/syncCommitteeContribution.test.ts | 10 +- .../test/unit/chain/prepareNextSlot.test.ts | 12 +- .../test/unit/chain/reprocess.test.ts | 2 +- .../unit/chain/rewards/blockRewards.test.ts | 8 +- .../chain/seenCache/aggregateAndProof.test.ts | 4 +- .../seenCache/seenAttestationData.test.ts | 2 +- .../seenCache/seenGossipBlockInput.test.ts | 4 +- .../chain/seenCache/syncCommittee.test.ts | 4 +- .../test/unit/chain/shufflingCache.test.ts | 2 +- .../stateCache/blockStateCacheImpl.test.ts | 6 +- .../stateCache/fifoBlockStateCache.test.ts | 4 +- .../inMemoryCheckpointsCache.test.ts | 4 +- .../persistentCheckpointsCache.test.ts | 14 +- .../validation/aggregateAndProof.test.ts | 8 +- ...hufflingForAttestationVerification.test.ts | 8 +- .../attestation/validateAttestation.test.ts | 2 +- ...idateGossipAttestationsSameAttData.test.ts | 2 +- .../chain/validation/attesterSlashing.test.ts | 8 +- .../test/unit/chain/validation/block.test.ts | 51 +- .../validation/blsToExecutionChange.test.ts | 20 +- .../lightClientFinalityUpdate.test.ts | 6 +- .../lightClientOptimisticUpdate.test.ts | 6 +- .../chain/validation/proposerSlashing.test.ts | 6 +- .../chain/validation/syncCommittee.test.ts | 12 +- .../chain/validation/voluntaryExit.test.ts | 16 +- .../db/api/repositories/blockArchive.test.ts | 10 +- .../test/unit/db/api/repository.test.ts | 6 +- .../unit/eth1/eth1DepositDataTracker.test.ts | 8 +- .../unit/eth1/eth1MergeBlockTracker.test.ts | 4 +- .../test/unit/eth1/hexEncoding.test.ts | 8 +- .../beacon-node/test/unit/eth1/jwt.test.ts | 4 +- .../unit/eth1/utils/depositContract.test.ts | 4 +- .../test/unit/eth1/utils/deposits.test.ts | 16 +- .../test/unit/eth1/utils/eth1Data.test.ts | 14 +- .../unit/eth1/utils/eth1DepositEvent.test.ts | 2 +- .../test/unit/eth1/utils/eth1Vote.test.ts | 12 +- .../utils/groupDepositEventsByBlock.test.ts | 2 +- .../optimizeNextBlockDiffForGenesis.test.ts | 4 +- .../test/unit/execution/engine/utils.test.ts | 8 +- .../test/unit/executionEngine/http.test.ts | 12 +- .../unit/executionEngine/httpRetry.test.ts | 10 +- .../test/unit/metrics/beacon.test.ts | 2 +- .../test/unit/metrics/metrics.test.ts | 2 +- .../test/unit/metrics/server/http.test.ts | 4 +- .../test/unit/metrics/utils.test.ts | 2 +- .../beacon-node/test/unit/metrics/utils.ts | 2 +- .../test/unit/monitoring/clientStats.test.ts | 4 +- .../test/unit/monitoring/properties.test.ts | 2 +- .../test/unit/monitoring/service.test.ts | 10 +- .../beaconBlocksMaybeBlobsByRange.test.ts | 12 +- .../test/unit/network/fork.test.ts | 6 +- .../test/unit/network/gossip/topic.test.ts | 6 +- .../test/unit/network/metadata.test.ts | 4 +- .../test/unit/network/peers/client.test.ts | 4 +- .../test/unit/network/peers/datastore.test.ts | 2 +- .../test/unit/network/peers/discover.test.ts | 4 +- .../unit/network/peers/priorization.test.ts | 8 +- .../test/unit/network/peers/score.test.ts | 8 +- .../peers/utils/assertPeerRelevance.test.ts | 4 +- .../network/peers/utils/enrSubnets.test.ts | 2 +- .../processor/aggregatorTracker.test.ts | 2 +- .../processor/gossipQueues/indexed.test.ts | 2 +- .../processor/gossipQueues/linear.test.ts | 2 +- .../test/unit/network/processorQueues.test.ts | 2 +- .../collectSequentialBlocksInRange.test.ts | 6 +- .../test/unit/network/reqresp/utils.ts | 6 +- .../network/subnets/attnetsService.test.ts | 8 +- .../test/unit/network/subnets/util.test.ts | 4 +- .../unavailableBeaconBlobsByRoot.test.ts | 257 +++++++ .../test/unit/network/util.test.ts | 4 +- .../test/unit/sync/backfill/verify.test.ts | 8 +- .../test/unit/sync/range/batch.test.ts | 10 +- .../test/unit/sync/range/chain.test.ts | 14 +- .../unit/sync/range/utils/batches.test.ts | 8 +- .../sync/range/utils/peerBalancer.test.ts | 2 +- .../sync/range/utils/updateChains.test.ts | 4 +- .../test/unit/sync/unknownBlock.test.ts | 18 +- .../unit/sync/utils/pendingBlocksTree.test.ts | 2 +- .../unit/sync/utils/remoteSyncType.test.ts | 6 +- .../test/unit/util/address.test.ts | 2 +- .../beacon-node/test/unit/util/array.test.ts | 4 +- .../test/unit/util/binarySearch.test.ts | 4 +- .../test/unit/util/bitArray.test.ts | 2 +- .../test/unit/util/bufferPool.test.ts | 2 +- .../beacon-node/test/unit/util/bytes.test.ts | 2 +- .../test/unit/util/chunkify.test.ts | 2 +- .../beacon-node/test/unit/util/clock.test.ts | 4 +- .../test/unit/util/dependentRoot.test.ts | 4 +- .../beacon-node/test/unit/util/error.test.ts | 2 +- .../beacon-node/test/unit/util/file.test.ts | 2 +- .../test/unit/util/graffiti.test.ts | 4 +- .../test/unit/util/itTrigger.test.ts | 2 +- .../beacon-node/test/unit/util/kzg.test.ts | 12 +- .../beacon-node/test/unit/util/map.test.ts | 2 +- .../test/unit/util/metadata.test.ts | 4 +- .../beacon-node/test/unit/util/peerId.test.ts | 2 +- .../beacon-node/test/unit/util/queue.test.ts | 2 +- .../beacon-node/test/unit/util/set.test.ts | 2 +- .../test/unit/util/shuffle.test.ts | 2 +- .../beacon-node/test/unit/util/sortBy.test.ts | 2 +- .../test/unit/util/sszBytes.test.ts | 18 +- .../beacon-node/test/unit/util/time.test.ts | 2 +- .../test/unit/util/timeSeries.test.ts | 2 +- .../test/unit/util/wrapError.test.ts | 2 +- packages/beacon-node/test/utils/api.ts | 6 +- .../test/utils/cachedBeaconState.ts | 2 +- .../utils/cliTools/kzgTrustedSetupFromJson.ts | 2 +- packages/beacon-node/test/utils/clock.ts | 2 +- packages/beacon-node/test/utils/config.ts | 2 +- packages/beacon-node/test/utils/db.ts | 2 +- packages/beacon-node/test/utils/errors.ts | 2 +- packages/beacon-node/test/utils/logger.ts | 4 +- .../test/utils/networkWithMockDb.ts | 2 +- .../beacon-node/test/utils/node/beacon.ts | 18 +- .../beacon-node/test/utils/node/simTest.ts | 14 +- .../beacon-node/test/utils/node/validator.ts | 12 +- packages/beacon-node/test/utils/peer.ts | 2 +- packages/beacon-node/test/utils/runEl.ts | 6 +- packages/beacon-node/test/utils/state.ts | 14 +- packages/beacon-node/test/utils/testnet.ts | 4 +- .../beacon-node/test/utils/typeGenerator.ts | 2 +- .../utils/validationData/aggregateAndProof.ts | 4 +- .../test/utils/validationData/attestation.ts | 18 +- packages/cli/package.json | 26 +- packages/cli/src/applyPreset.ts | 2 +- packages/cli/src/cli.ts | 2 +- packages/cli/src/cmds/beacon/handler.ts | 22 +- packages/cli/src/cmds/beacon/index.ts | 2 +- .../cli/src/cmds/beacon/initBeaconState.ts | 28 +- .../cli/src/cmds/beacon/initPeerIdAndEnr.ts | 8 +- packages/cli/src/cmds/beacon/options.ts | 7 +- packages/cli/src/cmds/beacon/paths.ts | 2 +- packages/cli/src/cmds/bootnode/handler.ts | 16 +- packages/cli/src/cmds/bootnode/index.ts | 2 +- packages/cli/src/cmds/bootnode/options.ts | 4 +- packages/cli/src/cmds/dev/files.ts | 4 +- packages/cli/src/cmds/dev/handler.ts | 12 +- packages/cli/src/cmds/dev/index.ts | 2 +- packages/cli/src/cmds/dev/options.ts | 2 +- packages/cli/src/cmds/index.ts | 4 +- packages/cli/src/cmds/lightclient/handler.ts | 2 +- packages/cli/src/cmds/lightclient/index.ts | 2 +- .../cmds/validator/blsToExecutionChange.ts | 10 +- packages/cli/src/cmds/validator/handler.ts | 30 +- packages/cli/src/cmds/validator/import.ts | 6 +- packages/cli/src/cmds/validator/index.ts | 10 +- .../keymanager/decryptKeystoreDefinitions.ts | 6 +- .../keymanager/decryptKeystores/threadPool.ts | 4 +- .../keymanager/decryptKeystores/worker.ts | 4 +- .../cli/src/cmds/validator/keymanager/impl.ts | 68 +- .../validator/keymanager/keystoreCache.ts | 2 +- .../validator/keymanager/persistedKeys.ts | 4 +- .../src/cmds/validator/keymanager/server.ts | 2 +- packages/cli/src/cmds/validator/options.ts | 2 +- .../cli/src/cmds/validator/signers/index.ts | 14 +- .../src/cmds/validator/signers/logSigners.ts | 2 +- .../validator/slashingProtection/export.ts | 10 +- .../validator/slashingProtection/import.ts | 8 +- .../validator/slashingProtection/index.ts | 4 +- .../validator/slashingProtection/utils.ts | 10 +- .../cli/src/cmds/validator/voluntaryExit.ts | 14 +- packages/cli/src/config/beaconNodeOptions.ts | 4 +- packages/cli/src/config/beaconParams.ts | 14 +- packages/cli/src/config/peerId.ts | 4 +- packages/cli/src/index.ts | 2 +- packages/cli/src/networks/dev.ts | 4 +- packages/cli/src/networks/holesky.ts | 2 +- packages/cli/src/networks/index.ts | 20 +- packages/cli/src/networks/sepolia.ts | 2 +- .../cli/src/options/beaconNodeOptions/api.ts | 2 +- .../src/options/beaconNodeOptions/builder.ts | 2 +- .../src/options/beaconNodeOptions/chain.ts | 2 +- .../cli/src/options/beaconNodeOptions/eth1.ts | 2 +- .../options/beaconNodeOptions/execution.ts | 2 +- .../src/options/beaconNodeOptions/metrics.ts | 2 +- .../options/beaconNodeOptions/monitoring.ts | 2 +- .../src/options/beaconNodeOptions/network.ts | 4 +- .../cli/src/options/beaconNodeOptions/sync.ts | 2 +- packages/cli/src/options/globalOptions.ts | 10 +- packages/cli/src/options/logOptions.ts | 2 +- packages/cli/src/util/gitData/gitDataPath.ts | 2 +- packages/cli/src/util/gitData/index.ts | 2 +- packages/cli/src/util/logger.ts | 6 +- packages/cli/src/util/proposerConfig.ts | 15 +- packages/cli/src/util/pruneOldFilesInDir.ts | 4 + .../cli/test/e2e/blsToExecutionchange.test.ts | 4 +- .../cli/test/e2e/importFromFsDirect.test.ts | 4 +- .../cli/test/e2e/importFromFsPreStep.test.ts | 4 +- .../test/e2e/importKeystoresFromApi.test.ts | 10 +- .../test/e2e/importRemoteKeysFromApi.test.ts | 8 +- .../e2e/propserConfigfromKeymanager.test.ts | 6 +- packages/cli/test/e2e/runDevCmd.test.ts | 4 +- packages/cli/test/e2e/validatorList.test.ts | 8 +- packages/cli/test/e2e/voluntaryExit.test.ts | 6 +- .../cli/test/e2e/voluntaryExitFromApi.test.ts | 2 +- .../e2e/voluntaryExitRemoteSigner.test.ts | 10 +- .../cli/test/sim/backupEthProvider.test.ts | 4 +- packages/cli/test/sim/deneb.test.ts | 4 +- packages/cli/test/sim/endpoints.test.ts | 6 +- packages/cli/test/sim/mixedClient.test.ts | 4 +- packages/cli/test/sim/multiFork.test.ts | 14 +- packages/cli/test/unit/cmds/beacon.test.ts | 12 +- .../test/unit/cmds/initPeerIdAndEnr.test.ts | 2 +- .../keymanager/keystoreCache.test.ts | 8 +- .../unit/config/beaconNodeOptions.test.ts | 2 +- .../cli/test/unit/config/beaconParams.test.ts | 6 +- packages/cli/test/unit/config/peerId.test.ts | 4 +- .../unit/options/beaconNodeOptions.test.ts | 6 +- .../test/unit/options/paramsOptions.test.ts | 4 +- .../cli/test/unit/paths/globalPaths.test.ts | 2 +- .../unit/util/extractJwtHexSecret.test.ts | 2 +- packages/cli/test/unit/util/format.test.ts | 2 +- packages/cli/test/unit/util/gitData.test.ts | 2 +- packages/cli/test/unit/util/logger.test.ts | 2 +- .../test/unit/util/parseBootnodesFile.test.ts | 2 +- packages/cli/test/unit/util/progress.test.ts | 2 +- .../test/unit/util/pruneOldFilesInDir.test.ts | 6 +- .../test/unit/util/stripOffNewlines.test.ts | 2 +- .../decryptKeystoreDefinitions.test.ts | 10 +- packages/cli/test/unit/validator/keys.test.ts | 2 +- .../cli/test/unit/validator/options.test.ts | 2 +- .../validator/parseProposerConfig.test.ts | 5 +- packages/cli/test/utils.ts | 2 +- .../assertions/accountBalanceAssertion.ts | 2 +- .../crucible/assertions/blobsAssertion.ts | 2 +- .../defaults/attestationCountAssertion.ts | 4 +- .../attestationParticipationAssertion.ts | 2 +- .../defaults/connectedPeerCountAssertion.ts | 2 +- .../assertions/defaults/finalizedAssertion.ts | 2 +- .../assertions/defaults/headAssertion.ts | 2 +- .../defaults/inclusionDelayAssertion.ts | 2 +- .../defaults/missedBlocksAssertion.ts | 2 +- .../syncCommitteeParticipationAssertion.ts | 2 +- .../assertions/executionHeadAssertion.ts | 4 +- .../crucible/assertions/forkAssertion.ts | 2 +- .../lighthousePeerScoreAssertion.ts | 2 +- .../crucible/assertions/mergeAssertion.ts | 2 +- .../crucible/assertions/nodeAssertion.ts | 11 +- .../assertions/withdrawalsAssertion.ts | 4 +- .../crucible/clients/beacon/lighthouse.ts | 4 +- .../utils/crucible/clients/beacon/lodestar.ts | 2 +- .../utils/crucible/clients/execution/geth.ts | 2 +- .../utils/crucible/clients/execution/index.ts | 4 +- .../crucible/clients/execution/nethermind.ts | 4 +- .../utils/crucible/clients/validator/index.ts | 4 +- .../crucible/clients/validator/lighthouse.ts | 6 +- .../crucible/clients/validator/lodestar.ts | 2 +- .../utils/crucible/externalSignerServer.ts | 4 +- .../cli/test/utils/crucible/interfaces.ts | 6 +- .../crucible/runner/childProcessRunner.ts | 2 +- .../utils/crucible/runner/dockerRunner.ts | 2 +- .../cli/test/utils/crucible/simulation.ts | 20 +- .../test/utils/crucible/simulationTracker.ts | 14 +- .../utils/crucible/utils/executionGenesis.ts | 2 +- .../cli/test/utils/crucible/utils/index.ts | 2 +- .../cli/test/utils/crucible/utils/keys.ts | 2 +- .../cli/test/utils/crucible/utils/paths.ts | 2 +- .../cli/test/utils/crucible/utils/ports.ts | 6 +- .../cli/test/utils/crucible/utils/syncing.ts | 4 +- .../web3js/blobsEIP4844Transaction.ts | 2 +- .../cli/test/utils/mockBeaconApiServer.ts | 4 +- packages/cli/test/utils/validator.ts | 4 +- packages/config/package.json | 8 +- packages/config/src/beaconConfig.ts | 4 +- .../config/src/chainConfig/configs/mainnet.ts | 6 +- .../config/src/chainConfig/configs/minimal.ts | 6 +- packages/config/src/chainConfig/default.ts | 2 +- packages/config/src/chainConfig/index.ts | 2 +- packages/config/src/chainConfig/json.ts | 2 +- .../src/chainConfig/networks/ephemery.ts | 2 +- .../config/src/chainConfig/networks/gnosis.ts | 4 +- .../src/chainConfig/networks/holesky.ts | 2 +- .../src/chainConfig/networks/mainnet.ts | 2 +- .../config/src/chainConfig/networks/mekong.ts | 2 +- .../src/chainConfig/networks/sepolia.ts | 2 +- packages/config/src/chainConfig/types.ts | 6 + packages/config/src/forkConfig/index.ts | 18 +- packages/config/src/genesisConfig/index.ts | 12 +- packages/config/src/networks.ts | 8 +- packages/config/test/unit/index.test.ts | 4 +- packages/config/test/unit/json.test.ts | 4 +- packages/db/package.json | 8 +- packages/db/src/controller/level.ts | 4 +- .../db/test/unit/controller/level.test.ts | 4 +- packages/db/test/unit/schema.test.ts | 2 +- packages/flare/package.json | 14 +- packages/flare/src/cli.ts | 2 +- packages/flare/src/cmds/index.ts | 2 +- packages/flare/src/cmds/selfSlashAttester.ts | 8 +- packages/flare/src/cmds/selfSlashProposer.ts | 8 +- packages/flare/src/index.ts | 2 +- packages/flare/test/unit/utils/format.test.ts | 2 +- packages/fork-choice/package.json | 12 +- packages/fork-choice/src/forkChoice/errors.ts | 2 +- .../fork-choice/src/forkChoice/forkChoice.ts | 44 +- .../fork-choice/src/forkChoice/interface.ts | 10 +- packages/fork-choice/src/forkChoice/store.ts | 6 +- .../src/protoArray/computeDeltas.ts | 4 +- .../fork-choice/src/protoArray/interface.ts | 2 +- .../fork-choice/src/protoArray/protoArray.ts | 8 +- .../perf/forkChoice/onAttestation.test.ts | 6 +- .../test/perf/forkChoice/updateHead.test.ts | 2 +- .../fork-choice/test/perf/forkChoice/util.ts | 6 +- .../perf/protoArray/computeDeltas.test.ts | 2 +- .../test/unit/forkChoice/forkChoice.test.ts | 14 +- .../unit/forkChoice/getProposerHead.test.ts | 10 +- .../test/unit/forkChoice/utils.test.ts | 4 +- .../unit/protoArray/computeDeltas.test.ts | 2 +- .../protoArray/executionStatusUpdates.test.ts | 8 +- .../unit/protoArray/getCommonAncestor.test.ts | 4 +- .../test/unit/protoArray/protoArray.test.ts | 4 +- packages/light-client/README.md | 8 +- packages/light-client/package.json | 12 +- packages/light-client/src/index.ts | 18 +- packages/light-client/src/spec/index.ts | 2 +- .../src/spec/processLightClientUpdate.ts | 4 +- packages/light-client/src/spec/utils.ts | 20 +- .../src/spec/validateLightClientBootstrap.ts | 4 +- .../src/spec/validateLightClientUpdate.ts | 26 +- .../light-client/src/transport/interface.ts | 2 +- packages/light-client/src/transport/rest.ts | 6 +- packages/light-client/src/utils/api.ts | 2 +- packages/light-client/src/utils/domain.ts | 2 +- packages/light-client/src/utils/utils.ts | 2 +- .../src/utils/verifyMerkleBranch.ts | 2 +- .../test/mocks/BeaconChainLcMock.ts | 2 +- .../test/mocks/LightclientServerApiMock.ts | 8 +- .../unit/isValidLightClientHeader.test.ts | 4 +- .../light-client/test/unit/sync.node.test.ts | 26 +- .../test/unit/syncInMemory.test.ts | 6 +- packages/light-client/test/unit/utils.test.ts | 6 +- .../test/unit/utils/chunkify.test.ts | 2 +- .../light-client/test/unit/validation.test.ts | 8 +- .../test/unit/webEsmBundle.browser.test.ts | 6 +- .../light-client/test/utils/naive/update.ts | 8 +- .../test/utils/prepareUpdateNaive.ts | 4 +- packages/light-client/test/utils/server.ts | 6 +- packages/light-client/test/utils/utils.ts | 4 +- packages/logger/package.json | 6 +- packages/logger/src/browser.ts | 4 +- packages/logger/src/interface.ts | 2 +- packages/logger/src/node.ts | 6 +- packages/logger/src/utils/format.ts | 4 +- packages/logger/src/winston.ts | 2 +- .../test/e2e/logger/workerLoggerHandler.ts | 2 +- .../logger/test/e2e/logger/workerLogs.test.ts | 4 +- packages/logger/test/unit/browser.test.ts | 6 +- packages/logger/test/unit/env.node.test.ts | 6 +- packages/logger/test/unit/node.node.test.ts | 2 +- packages/logger/test/unit/utils/json.test.ts | 2 +- .../logger/test/unit/utils/timeFormat.test.ts | 2 +- .../logger/test/unit/winston.node.test.ts | 2 +- packages/params/README.md | 2 +- packages/params/package.json | 2 +- packages/params/src/index.ts | 8 +- packages/params/src/presets/mainnet.ts | 1 - packages/params/src/presets/minimal.ts | 1 - packages/params/src/setPreset.ts | 2 +- packages/params/src/types.ts | 2 - .../test/e2e/ensure-config-is-synced.test.ts | 7 +- .../params/test/e2e/overridePreset.test.ts | 6 +- .../params/test/e2e/overridePresetError.ts | 2 +- packages/params/test/e2e/overridePresetOk.ts | 2 +- packages/params/test/e2e/setPreset.test.ts | 6 +- packages/params/test/e2e/setPresetError.ts | 2 +- packages/params/test/e2e/setPresetOk.ts | 2 +- .../params/test/unit/activePreset.test.ts | 6 +- .../test/unit/applicationDomains.test.ts | 4 +- packages/params/test/unit/forkName.test.ts | 2 +- packages/params/test/yaml.ts | 2 +- packages/prover/README.md | 4 +- packages/prover/package.json | 18 +- packages/prover/src/cli/applyPreset.ts | 2 +- packages/prover/src/cli/cli.ts | 2 +- packages/prover/src/cli/cmds/start/handler.ts | 4 +- packages/prover/src/cli/options.ts | 2 +- packages/prover/src/interfaces.ts | 2 +- .../src/proof_provider/payload_store.ts | 4 +- .../src/proof_provider/proof_provider.ts | 2 +- packages/prover/src/utils/consensus.ts | 2 +- packages/prover/src/utils/evm.ts | 10 +- packages/prover/src/utils/execution.ts | 2 +- .../prover/src/utils/gitData/gitDataPath.ts | 2 +- packages/prover/src/utils/gitData/index.ts | 2 +- packages/prover/src/utils/json_rpc.ts | 10 +- packages/prover/src/utils/process.ts | 10 +- packages/prover/src/utils/validation.ts | 4 +- packages/prover/src/utils/verification.ts | 2 +- .../prover/src/verified_requests/eth_call.ts | 2 +- .../src/verified_requests/eth_getBalance.ts | 2 +- .../verified_requests/eth_getBlockByHash.ts | 2 +- .../verified_requests/eth_getBlockByNumber.ts | 2 +- .../src/verified_requests/eth_getCode.ts | 2 +- .../eth_getTransactionCount.ts | 4 +- packages/prover/src/web3_provider.ts | 2 +- .../prover/src/web3_provider_inspector.ts | 4 +- packages/prover/src/web3_proxy.ts | 6 +- .../prover/test/e2e/cli/cmds/start.test.ts | 10 +- .../test/e2e/web3_batch_request.test.ts | 6 +- .../prover/test/e2e/web3_provider.test.ts | 6 +- packages/prover/test/mocks/request_handler.ts | 12 +- .../unit/proof_provider/orderd_map.test.ts | 2 +- .../unit/proof_provider/payload_store.test.ts | 10 +- .../ethers_provider_type.test.ts | 2 +- .../legacy_provider_type.test.ts | 2 +- .../web3js_provider_type.test.ts | 2 +- .../prover/test/unit/utils/conversion.test.ts | 2 +- .../prover/test/unit/utils/execution.test.ts | 6 +- .../unit/verified_requests/eth_call.test.ts | 6 +- .../verified_requests/eth_estimateGas.test.ts | 8 +- .../verified_requests/eth_getBalance.test.ts | 6 +- .../eth_getBlockByHash.test.ts | 6 +- .../eth_getBlockByNumber.test.ts | 4 +- .../verified_requests/eth_getCode.test.ts | 6 +- .../eth_getTransactionCount.test.ts | 6 +- .../test/unit/web3_provider.node.test.ts | 10 +- .../test/unit/web3_provider_inspector.test.ts | 6 +- packages/reqresp/package.json | 12 +- packages/reqresp/src/ReqResp.ts | 10 +- .../reqresp/src/encoders/requestDecode.ts | 2 +- .../reqresp/src/encoders/requestEncode.ts | 2 +- .../reqresp/src/encoders/responseDecode.ts | 8 +- .../reqresp/src/encoders/responseEncode.ts | 4 +- .../encodingStrategies/sszSnappy/decode.ts | 4 +- .../sszSnappy/snappyFrames/compress.ts | 2 +- packages/reqresp/src/request/errors.ts | 2 +- packages/reqresp/src/request/index.ts | 12 +- packages/reqresp/src/response/index.ts | 12 +- packages/reqresp/src/utils/collectExactOne.ts | 2 +- .../test/fixtures/encodingStrategies.ts | 4 +- packages/reqresp/test/fixtures/messages.ts | 2 +- packages/reqresp/test/fixtures/protocols.ts | 6 +- packages/reqresp/test/unit/ReqResp.test.ts | 8 +- .../test/unit/encoders/reqestEncode.test.ts | 2 +- .../test/unit/encoders/requestDecode.test.ts | 2 +- .../test/unit/encoders/responseDecode.test.ts | 6 +- .../test/unit/encoders/responseEncode.test.ts | 4 +- .../sszSnappy/decode.test.ts | 4 +- .../sszSnappy/encode.test.ts | 2 +- .../sszSnappy/snappyFrames/uncompress.test.ts | 6 +- .../sszSnappy/utils.test.ts | 2 +- .../unit/rate_limiter/rateLimiterGRCA.test.ts | 2 +- .../reqresp/test/unit/request/index.test.ts | 18 +- .../reqresp/test/unit/response/index.test.ts | 6 +- .../test/unit/utils/protocolId.test.ts | 2 +- packages/reqresp/test/utils/errors.ts | 2 +- packages/reqresp/test/utils/index.ts | 8 +- packages/spec-test-util/package.json | 4 +- packages/spec-test-util/src/downloadTests.ts | 4 +- packages/spec-test-util/src/single.ts | 4 +- packages/spec-test-util/src/sszGeneric.ts | 4 +- .../test/e2e/single/index.test.ts | 4 +- packages/state-transition/package.json | 13 +- packages/state-transition/src/block/index.ts | 10 +- .../src/block/isValidIndexedAttestation.ts | 2 +- .../src/block/processAttestationPhase0.ts | 6 +- .../src/block/processAttestations.ts | 2 +- .../src/block/processAttestationsAltair.ts | 8 +- .../src/block/processAttesterSlashing.ts | 6 +- .../src/block/processBlockHeader.ts | 2 +- .../src/block/processBlsToExecutionChange.ts | 4 +- .../src/block/processConsolidationRequest.ts | 13 +- .../src/block/processDeposit.ts | 6 +- .../src/block/processDepositRequest.ts | 2 +- .../src/block/processExecutionPayload.ts | 12 +- .../src/block/processOperations.ts | 10 +- .../src/block/processProposerSlashing.ts | 6 +- .../src/block/processRandao.ts | 4 +- .../src/block/processSyncCommittee.ts | 6 +- .../src/block/processVoluntaryExit.ts | 4 +- .../src/block/processWithdrawalRequest.ts | 8 +- .../src/block/processWithdrawals.ts | 10 +- .../src/block/slashValidator.ts | 4 +- .../state-transition/src/cache/epochCache.ts | 265 ++----- .../src/cache/epochTransitionCache.ts | 17 +- .../state-transition/src/cache/pubkeyCache.ts | 36 - .../state-transition/src/cache/stateCache.ts | 6 +- .../src/cache/syncCommitteeCache.ts | 4 +- packages/state-transition/src/cache/types.ts | 2 +- .../src/epoch/computeUnrealizedCheckpoints.ts | 4 +- .../src/epoch/getAttestationDeltas.ts | 6 +- .../src/epoch/getRewardsAndPenalties.ts | 2 +- packages/state-transition/src/epoch/index.ts | 10 +- .../epoch/processEffectiveBalanceUpdates.ts | 2 +- .../src/epoch/processEth1DataReset.ts | 2 +- .../src/epoch/processHistoricalRootsUpdate.ts | 2 +- .../epoch/processHistoricalSummariesUpdate.ts | 2 +- .../processJustificationAndFinalization.ts | 2 +- .../src/epoch/processPendingDeposits.ts | 8 +- .../src/epoch/processRandaoMixesReset.ts | 2 +- .../src/epoch/processRegistryUpdates.ts | 4 +- .../src/epoch/processSlashings.ts | 2 +- .../src/epoch/processSlashingsReset.ts | 2 +- .../src/epoch/processSyncCommitteeUpdates.ts | 2 +- packages/state-transition/src/index.ts | 7 +- packages/state-transition/src/metrics.ts | 9 +- .../src/signatureSets/attesterSlashings.ts | 4 +- .../src/signatureSets/blsToExecutionChange.ts | 4 +- .../src/signatureSets/index.ts | 8 +- .../src/signatureSets/indexedAttestation.ts | 4 +- .../src/signatureSets/proposer.ts | 2 +- .../src/signatureSets/proposerSlashings.ts | 2 +- .../src/signatureSets/randao.ts | 6 +- .../src/signatureSets/voluntaryExits.ts | 6 +- packages/state-transition/src/slot/index.ts | 2 +- .../src/slot/upgradeStateToAltair.ts | 10 +- .../src/slot/upgradeStateToBellatrix.ts | 2 +- .../src/slot/upgradeStateToCapella.ts | 2 +- .../src/slot/upgradeStateToDeneb.ts | 2 +- .../src/slot/upgradeStateToElectra.ts | 6 +- .../state-transition/src/stateTransition.ts | 30 +- .../state-transition/src/util/aggregator.ts | 6 +- .../state-transition/src/util/attestation.ts | 2 +- .../state-transition/src/util/blindedBlock.ts | 16 +- .../state-transition/src/util/blockRoot.ts | 10 +- .../src/util/calculateCommitteeAssignments.ts | 2 +- .../src/util/computeAnchorCheckpoint.ts | 2 +- packages/state-transition/src/util/domain.ts | 2 +- packages/state-transition/src/util/electra.ts | 19 +- packages/state-transition/src/util/epoch.ts | 2 +- .../src/util/epochShuffling.ts | 12 +- .../state-transition/src/util/execution.ts | 18 +- packages/state-transition/src/util/genesis.ts | 14 +- packages/state-transition/src/util/interop.ts | 2 +- .../src/util/loadState/loadState.ts | 6 +- .../state-transition/src/util/rootCache.ts | 2 +- packages/state-transition/src/util/seed.ts | 6 +- packages/state-transition/src/util/slot.ts | 4 +- .../src/util/syncCommittee.ts | 4 +- .../state-transition/src/util/validator.ts | 4 +- .../src/util/weakSubjectivity.ts | 2 +- .../test/perf/analyzeEpochs.ts | 4 +- .../perf/block/processAttestation.test.ts | 2 +- .../perf/block/processBlockAltair.test.ts | 4 +- .../perf/block/processBlockPhase0.test.ts | 2 +- .../test/perf/block/processEth1Data.test.ts | 2 +- .../perf/block/processWithdrawals.test.ts | 4 +- .../state-transition/test/perf/block/util.ts | 14 +- .../test/perf/dataStructures/arrayish.test.ts | 2 +- .../test/perf/epoch/epochAltair.test.ts | 32 +- .../test/perf/epoch/epochCapella.test.ts | 32 +- .../test/perf/epoch/epochPhase0.test.ts | 28 +- .../processEffectiveBalanceUpdates.test.ts | 8 +- .../perf/epoch/processRegistryUpdates.test.ts | 4 +- .../epoch/processRewardsAndPenalties.test.ts | 4 +- .../processRewardsAndPenaltiesPhase0.test.ts | 2 +- .../epoch/processSlashingsAllForks.test.ts | 8 +- .../test/perf/epoch/utilPhase0.ts | 2 +- .../test/perf/hashing.test.ts | 4 +- .../test/perf/misc/aggregationBits.test.ts | 2 +- .../test/perf/misc/byteArrayEquals.test.ts | 2 +- .../test/perf/misc/rootEquals.test.ts | 2 +- .../test/perf/sanityCheck.test.ts | 2 +- .../test/perf/slot/slots.test.ts | 2 +- packages/state-transition/test/perf/types.ts | 2 +- packages/state-transition/test/perf/util.ts | 24 +- .../test/perf/util/balance.test.ts | 4 +- .../test/perf/util/epochContext.test.ts | 2 +- .../loadState/findModifiedValidators.test.ts | 6 +- .../perf/util/loadState/loadState.test.ts | 6 +- .../test/perf/util/rootCache.test.ts | 4 +- .../test/perf/util/shufflings.test.ts | 6 +- .../test/perf/util/signingRoot.test.ts | 2 +- .../block/isValidIndexedAttestation.test.ts | 4 +- .../unit/block/processWithdrawals.test.ts | 4 +- .../test/unit/cachedBeaconState.test.ts | 48 +- .../test/unit/constants.test.ts | 2 +- .../unit/signatureSets/signatureSets.test.ts | 6 +- .../test/unit/upgradeState.test.ts | 10 +- .../test/unit/util/aggregator.test.ts | 4 +- .../test/unit/util/balance.test.ts | 8 +- .../test/unit/util/cachedBeaconState.test.ts | 2 +- .../test/unit/util/deposit.test.ts | 4 +- .../test/unit/util/epoch.test.ts | 6 +- .../test/unit/util/flags.test.ts | 2 +- .../test/unit/util/loadState.test.ts | 6 +- .../findModifiedInactivityScores.test.ts | 2 +- .../loadState/findModifiedValidators.test.ts | 2 +- .../unit/util/loadState/loadValidator.test.ts | 2 +- .../test/unit/util/misc.test.ts | 4 +- .../test/unit/util/seed.test.ts | 2 +- .../test/unit/util/shuffling.test.ts | 6 +- .../test/unit/util/slashing.test.ts | 2 +- .../test/unit/util/slot.test.ts | 2 +- .../test/unit/util/validator.test.ts | 4 +- .../test/unit/util/weakSubjectivity.test.ts | 4 +- .../state-transition/test/utils/capella.ts | 6 +- packages/state-transition/test/utils/state.ts | 10 +- .../test/utils/testFileCache.ts | 4 +- packages/test-utils/package.json | 6 +- packages/test-utils/src/childProcess.ts | 4 +- packages/test-utils/src/cli.ts | 4 +- packages/test-utils/src/doubles.ts | 2 +- packages/test-utils/src/externalSigner.ts | 4 +- packages/test-utils/src/http.ts | 2 +- packages/types/package.json | 4 +- packages/types/src/altair/index.ts | 2 +- packages/types/src/altair/sszTypes.ts | 8 +- packages/types/src/bellatrix/index.ts | 2 +- packages/types/src/bellatrix/sszTypes.ts | 6 +- packages/types/src/capella/index.ts | 2 +- packages/types/src/capella/sszTypes.ts | 16 +- packages/types/src/deneb/index.ts | 2 +- packages/types/src/deneb/sszTypes.ts | 17 +- packages/types/src/deneb/types.ts | 5 +- packages/types/src/electra/index.ts | 2 +- packages/types/src/electra/sszTypes.ts | 22 +- packages/types/src/phase0/index.ts | 2 +- packages/types/src/phase0/sszTypes.ts | 2 +- packages/types/src/primitive/index.ts | 2 +- packages/types/src/primitive/sszTypes.ts | 2 +- packages/types/src/sszTypes.ts | 2 +- packages/types/src/types.ts | 2 +- packages/types/src/utils/executionAddress.ts | 2 +- packages/types/test/constants/blobs.test.ts | 2 +- .../types/test/constants/lightclient.test.ts | 2 +- packages/types/test/unit/blinded.test.ts | 2 +- .../types/test/unit/executionAddress.test.ts | 2 +- .../types/test/unit/phase0/sszTypes.test.ts | 2 +- packages/types/test/unit/ssz.test.ts | 2 +- .../types/test/unit/validatorStatus.test.ts | 4 +- packages/utils/package.json | 2 +- packages/utils/src/bytes.ts | 2 +- packages/utils/src/bytes/index.ts | 8 +- packages/utils/src/command.ts | 2 +- packages/utils/src/format.ts | 7 + packages/utils/src/yaml/int.ts | 2 +- packages/utils/test/perf/bytes.test.ts | 4 +- packages/utils/test/types/metrics.test-d.ts | 2 +- packages/utils/test/unit/assert.test.ts | 2 +- packages/utils/test/unit/base64.test.ts | 4 +- packages/utils/test/unit/bytes.test.ts | 10 +- packages/utils/test/unit/err.test.ts | 4 +- packages/utils/test/unit/format.test.ts | 2 +- packages/utils/test/unit/math.test.ts | 4 +- packages/utils/test/unit/objects.test.ts | 2 +- packages/utils/test/unit/promise.node.test.ts | 2 +- packages/utils/test/unit/promise.test.ts | 4 +- packages/utils/test/unit/promiserace.test.ts | 4 +- packages/utils/test/unit/retry.test.ts | 4 +- packages/utils/test/unit/sleep.test.ts | 4 +- packages/utils/test/unit/timeout.test.ts | 4 +- packages/utils/test/unit/waitFor.test.ts | 4 +- packages/validator/package.json | 18 +- packages/validator/src/genesis.ts | 2 +- .../src/repositories/metaDataRepository.ts | 4 +- .../validator/src/services/attestation.ts | 18 +- .../src/services/attestationDuties.ts | 12 +- packages/validator/src/services/block.ts | 22 +- .../validator/src/services/blockDuties.ts | 8 +- .../src/services/chainHeaderTracker.ts | 4 +- .../src/services/doppelgangerService.ts | 6 +- packages/validator/src/services/emitter.ts | 2 +- .../src/services/externalSignerSync.ts | 2 +- packages/validator/src/services/indices.ts | 4 +- .../src/services/prepareBeaconProposer.ts | 4 +- .../validator/src/services/syncCommittee.ts | 16 +- .../src/services/syncCommitteeDuties.ts | 12 +- .../src/services/syncingStatusTracker.ts | 4 +- .../validator/src/services/validatorStore.ts | 56 +- .../attestationByTargetRepository.ts | 6 +- .../attestationLowerBoundRepository.ts | 4 +- .../slashingProtection/attestation/index.ts | 4 +- .../block/blockBySlotRepository.ts | 6 +- .../src/slashingProtection/block/index.ts | 4 +- .../validator/src/slashingProtection/index.ts | 12 +- .../interchange/formats/completeV4.ts | 2 +- .../interchange/formats/v5.ts | 2 +- .../interchange/parseInterchange.ts | 2 +- .../interchange/serializeInterchange.ts | 2 +- .../src/slashingProtection/interface.ts | 2 +- .../minMaxSurround/distanceStoreRepository.ts | 2 +- .../minMaxSurround/minMaxSurround.ts | 2 +- packages/validator/src/types.ts | 2 +- packages/validator/src/util/clock.ts | 6 +- .../src/util/externalSignerClient.ts | 22 +- packages/validator/src/util/params.ts | 6 +- packages/validator/src/validator.ts | 30 +- .../validator/test/e2e/web3signer.test.ts | 16 +- packages/validator/test/spec/downloadTests.ts | 2 +- packages/validator/test/spec/index.test.ts | 10 +- packages/validator/test/spec/spec.test.ts | 8 +- .../test/unit/services/attestation.test.ts | 14 +- .../unit/services/attestationDuties.test.ts | 18 +- .../test/unit/services/block.test.ts | 12 +- .../test/unit/services/blockDuties.test.ts | 10 +- .../test/unit/services/doppelganger.test.ts | 10 +- .../unit/services/externalSignerSync.test.ts | 6 +- .../test/unit/services/indicesService.test.ts | 8 +- .../unit/services/syncCommitteDuties.test.ts | 16 +- .../test/unit/services/syncCommittee.test.ts | 14 +- .../services/syncingStatusTracker.test.ts | 6 +- .../test/unit/services/utils.test.ts | 2 +- .../interchange/index.test.ts | 2 +- .../minMaxSurround/surroundTests.test.ts | 2 +- .../minMaxSurround/updateSpans.test.ts | 6 +- .../minMaxSurround/utils.ts | 2 +- .../unit/slashingProtection/utils.test.ts | 2 +- .../validator/test/unit/utils/batch.test.ts | 2 +- .../validator/test/unit/utils/clock.test.ts | 4 +- .../test/unit/utils/difference.test.ts | 2 +- .../validator/test/unit/utils/metrics.test.ts | 2 +- .../validator/test/unit/utils/params.test.ts | 8 +- .../test/unit/validatorStore.test.ts | 10 +- packages/validator/test/utils/apiStub.ts | 2 +- packages/validator/test/utils/logger.ts | 2 +- .../validator/test/utils/validatorStore.ts | 2 +- scripts/await-release.sh | 2 +- scripts/install-binary.sh | 91 +++ scripts/prepare-docs.sh | 3 + types/vitest/index.d.ts | 4 +- yarn.lock | 5 - 1149 files changed, 6116 insertions(+), 4608 deletions(-) delete mode 100644 docs/pages/google0c42298b7ec08b7e.html create mode 100644 docs/pages/run/getting-started/quick-start-custom-guide.md delete mode 100644 docs/pages/run/logging-and-metrics/dashboards.md delete mode 100644 docs/pages/run/logging-and-metrics/log-management.md delete mode 100644 docs/pages/run/logging-and-metrics/metrics-management.md create mode 100644 docs/pages/run/validator-management/proposer-config.md delete mode 100644 docs/pages/trouble-shooting.md create mode 100644 packages/api/test/unit/beacon/genericServerTest/lodestar.test.ts create mode 100644 packages/beacon-node/src/chain/blocks/utils/giraffeBanner.ts delete mode 100644 packages/beacon-node/test/memory/unfinalizedPubkey2Index.ts delete mode 100644 packages/beacon-node/test/perf/chain/stateCache/updateUnfinalizedPubkeys.test.ts create mode 100644 packages/beacon-node/test/unit/network/unavailableBeaconBlobsByRoot.test.ts create mode 100755 scripts/install-binary.sh diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 671434fe19ad..e515bef7f92a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22.4 + node-version: 22 check-latest: true cache: yarn - name: Node.js version diff --git a/.github/workflows/binaries.yml b/.github/workflows/binaries.yml index 722894424b91..469b0803c378 100644 --- a/.github/workflows/binaries.yml +++ b/.github/workflows/binaries.yml @@ -42,7 +42,7 @@ jobs: sudo apt-get install -y build-essential python3 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - run: | mkdir -p dist yarn global add caxa@3.0.1 diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.yml index bd7310995d62..180f1c16fdaa 100644 --- a/.github/workflows/docs-check.yml +++ b/.github/workflows/docs-check.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22.4 + node-version: 22 cache: yarn - name: Node.js version id: node diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index a4c0f18cdbe3..cec2bca86b4b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -31,7 +31,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 22.4 + node-version: 22 check-latest: true cache: yarn diff --git a/.github/workflows/publish-dev.yml b/.github/workflows/publish-dev.yml index 4e8c76e0dfdd..cb08c5c8fae0 100644 --- a/.github/workflows/publish-dev.yml +++ b/.github/workflows/publish-dev.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v4 with: - node-version: 22.4 + node-version: 22 registry-url: "https://registry.npmjs.org" check-latest: true cache: yarn diff --git a/.github/workflows/publish-rc.yml b/.github/workflows/publish-rc.yml index 936072de42c9..e16cbce814dc 100644 --- a/.github/workflows/publish-rc.yml +++ b/.github/workflows/publish-rc.yml @@ -61,7 +61,7 @@ jobs: - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Generate changelog run: node scripts/generate_changelog.mjs ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md diff --git a/.github/workflows/publish-stable.yml b/.github/workflows/publish-stable.yml index c2909a7e4e24..26fee0ba6052 100644 --- a/.github/workflows/publish-stable.yml +++ b/.github/workflows/publish-stable.yml @@ -67,7 +67,7 @@ jobs: - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Generate changelog run: node scripts/generate_changelog.mjs ${{ needs.tag.outputs.prev_tag }} ${{ needs.tag.outputs.tag }} CHANGELOG.md diff --git a/.github/workflows/test-sim-merge.yml b/.github/workflows/test-sim-merge.yml index 0042a9337bc3..ad79bc2c0035 100644 --- a/.github/workflows/test-sim-merge.yml +++ b/.github/workflows/test-sim-merge.yml @@ -30,7 +30,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22.4 + node-version: 22 check-latest: true cache: yarn - name: Node.js version diff --git a/.github/workflows/test-sim.yml b/.github/workflows/test-sim.yml index fbe2691da637..ff28149537d3 100644 --- a/.github/workflows/test-sim.yml +++ b/.github/workflows/test-sim.yml @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 sim-test-multifork: name: Multifork sim test @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Load env variables uses: ./.github/actions/dotenv - name: Download required docker images before running tests @@ -71,7 +71,7 @@ jobs: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Load env variables uses: ./.github/actions/dotenv - name: Download required docker images before running tests @@ -100,7 +100,7 @@ jobs: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Load env variables uses: ./.github/actions/dotenv - name: Download required docker images before running tests @@ -129,7 +129,7 @@ jobs: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Load env variables uses: ./.github/actions/dotenv - name: Download required docker images before running tests @@ -158,7 +158,7 @@ jobs: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" with: - node: 22.4 + node: 22 - name: Load env variables uses: ./.github/actions/dotenv - name: Download required docker images before running tests diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5514f6e896b7..47e17c56f042 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: # - Uses YAML anchors in the future - uses: actions/checkout@v4 @@ -42,7 +42,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" @@ -71,7 +71,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: - uses: actions/checkout@v4 @@ -92,7 +92,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" @@ -131,7 +131,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: # - Uses YAML anchors in the future - uses: actions/checkout@v4 @@ -168,7 +168,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: # - Uses YAML anchors in the future - uses: actions/checkout@v4 @@ -192,7 +192,7 @@ jobs: strategy: fail-fast: false matrix: - node: [22.4] + node: [22] steps: - uses: actions/checkout@v4 - uses: "./.github/actions/setup-and-build" diff --git a/.gitignore b/.gitignore index 52d9bc66e5b6..e54f7440864d 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ docs/pages/libraries/lightclient-prover/lightclient.md docs/pages/libraries/lightclient-prover/prover.md docs/pages/api/api-reference.md docs/pages/contribution/getting-started.md +docs/static/install ## Docusaurus docs/.docusaurus/ docs/build/ diff --git a/.vscode/settings.json b/.vscode/settings.json index fbc0552fe61c..d36535917835 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "window.title": "${activeEditorShort}${separator}${rootName}${separator}${profileName}${separator}[${activeRepositoryBranchName}]", - "editor.defaultFormatter": "esbenp.prettier-vscode", // For `sysoev.vscode-open-in-github` extension "openInGitHub.defaultBranch": "unstable", "editor.formatOnSave": true, @@ -18,5 +17,11 @@ }, "[jsonc]": { "editor.defaultFormatter": "biomejs.biome" - } + }, + "[yaml]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, + "[markdown]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + }, } diff --git a/.wordlist.txt b/.wordlist.txt index a2e642a926a0..d74291a2fb0c 100644 --- a/.wordlist.txt +++ b/.wordlist.txt @@ -1,3 +1,4 @@ +API APIs Andreas Antonopoulos @@ -13,6 +14,7 @@ Casper Chai ChainSafe Codespaces +CoinCashew Corepack Customizations DPoS @@ -29,6 +31,7 @@ ENRs ETH Edgington Erigon +Esat EthStaker EtherScan Ethereum @@ -37,8 +40,11 @@ FINDNODE FX Flamegraph Flamegraphs +GPG Geth Github +Goerli +Golang Gossipsub Grafana Grandine @@ -46,6 +52,7 @@ HTTPS HackMD Hashicorp Homebrew +Hyperledger IPFS IPv Infura @@ -60,15 +67,18 @@ LGPLv LMD LPoS LTS +LVM Lerna MEV MacOS Metamask +MevBoost ModuleNotFoundError Monorepo NPM NVM Nethermind +Nim NodeJS NodeSource OSI @@ -81,9 +91,11 @@ Quickstart RPC Reth Ryzen +SFTP SHA SSD SSZ +Somer Stakehouse TOC TTD @@ -98,11 +110,13 @@ Vitalik Vitest Wagyu api +args async backfill beaconcha blockRoot blockchain +blockspace blst bootnode bootnodes @@ -110,6 +124,7 @@ bundlers chainConfig chainsafe chiado +chmod cli cmd codebase @@ -125,6 +140,8 @@ dApp dApps ddos decrypt +decrypted +derypted deserialization dev devcontainer @@ -139,30 +156,38 @@ env envs ephemery ethers +feeRecipient flamegraph flamegraphs floodsub +fsSL getNetworkIdentity gnosis +gpg heapdump heaptrack holesky interop js +keymanager keypair +keyrings keystore keystores libp lightclient linter +liveness lldb llnode lockfile mainnet malloc +mbps mdns merkle merkleization +misconfiguration mmeshsub monorepo multiaddr @@ -173,7 +198,6 @@ namespaces nodemodule orchestrator osx -overriden params performant pid @@ -199,6 +223,7 @@ ssz stakers subnet subnets +sudo tcp testnet testnets @@ -215,6 +240,8 @@ vite vitest webpack wip +xRelayPubKey xcode yaml yamux +yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24d087810980..ca5a28442fd8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -126,6 +126,8 @@ Unsure where to begin contributing to Lodestar? Here are some ideas! 5. Make an open pull request when you're ready for it to be reviewed. We review PRs on a regular basis. See Pull request etiquette for more information. 6. You may be asked to sign a Contributor License Agreement (CLA). We make it relatively painless with CLA-bot. +Please note that trivial, non-code contributions such as spelling, grammar, typos, corrections, comments and link fixes are not acceptable pull requests. Although we appreciate the effort to fix these valid concerns, it is not practical for us to run our CI systems to accommodate minor external contributions which generate minimal value for the purpose of contribution/airdrop farming. It would be appreciated for you to open up an issue instead for our team to aggregate these types of contributions into a batch commit. + ## Github Style Guide **Branch Naming** diff --git a/Dockerfile b/Dockerfile index 0ee8083c85e2..5a1f51bfcee6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # --platform=$BUILDPLATFORM is used build javascript source with host arch # Otherwise TS builds on emulated archs and can be extremely slow (+1h) -FROM --platform=${BUILDPLATFORM:-amd64} node:22.4-slim AS build_src +FROM --platform=${BUILDPLATFORM:-amd64} node:22-slim AS build_src ARG COMMIT WORKDIR /usr/app RUN apt-get update && apt-get install -y g++ make python3 python3-setuptools && apt-get clean && rm -rf /var/lib/apt/lists/* @@ -21,7 +21,7 @@ RUN cd packages/cli && GIT_COMMIT=${COMMIT} yarn write-git-data # Copy built src + node_modules to build native packages for archs different than host. # Note: This step is redundant for the host arch -FROM node:22.4-slim AS build_deps +FROM node:22-slim AS build_deps WORKDIR /usr/app RUN apt-get update && apt-get install -y g++ make python3 python3-setuptools && apt-get clean && rm -rf /var/lib/apt/lists/* @@ -35,7 +35,7 @@ RUN cd node_modules/classic-level && yarn rebuild # Copy built src + node_modules to a new layer to prune unnecessary fs # Previous layer weights 7.25GB, while this final 488MB (as of Oct 2020) -FROM node:22.4-slim +FROM node:22-slim WORKDIR /usr/app COPY --from=build_deps /usr/app . diff --git a/README.md b/README.md index e03de683a9de..53c53cee8621 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,9 @@ Read our [contributors document](/CONTRIBUTING.md), [submit an issue](https://gi ## Meetings -Weekly contributor meetings are public and announced on Discord. Feel free to check out our meeting notes and documents on [HackMD](https://hackmd.io/@wemeetagain/rJTEOdqPS/%2FXBzvaQgMTyyMJuToWAEDjw). Post-September 2021, meeting notes can be found on the [Lodestar Wiki Page](https://github.com/ChainSafe/lodestar/wiki). +Weekly contributor meetings are posted under [Discussions](https://github.com/ChainSafe/lodestar/discussions) and topics are welcomed by any participant in the relevant meeting thread. Feel free to check out our meeting notes and documents on [HackMD](https://hackmd.io/@wemeetagain/rJTEOdqPS/%2FXBzvaQgMTyyMJuToWAEDjw). Post-September 2021, meeting notes can be found on the [Lodestar Wiki Page](https://github.com/ChainSafe/lodestar/wiki). ## Donations We are a local group of Toronto open-source developers. As such, all of our open-source work is funded by grants. We all take the time out of our hectic lives to contribute to the Ethereum ecosystem. -If you want to donate, you can send us ETH at the following address: `lodestar.chainsafe.eth` +If you want to donate, you can find the ETH address under "Sponsor this project" on this repository. diff --git a/RELEASE.md b/RELEASE.md index bb40b611ebe5..6d831ddb3bd4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -69,7 +69,7 @@ Tagging a release candidate will trigger CI to publish to NPM, dockerhub, and Gi Once a release candidate is created, the Lodestar team begins a testing period. -If there is a bug discovered during the testing period which significantly impacts performance, security, or stability, and it is determined that it is no longer prudent to promote the `rc.x` candidate to `stable`, then it will await a bug fix by the team. The fix will be committed to `unstable` first, then cherrypicked into the `rc/v1.1.0` branch. Then we publish and promote the new commit to `rc.x+1`. The 3 day testing period will reset. +If there is a bug discovered during the testing period which significantly impacts performance, security, or stability, and it is determined that it is no longer prudent to promote the `rc.x` candidate to `stable`, then it will await a bug fix by the team. The fix will be committed to `unstable` first, then cherrypicked into the `rc/v1.1.0` branch. Then we publish and promote the new commit to `rc.x+1`. The 3-day testing period will reset. For example: After 3-5 days of testing, is performance equal to or better than latest stable? diff --git a/biome.jsonc b/biome.jsonc index 212a61d86aa2..f50f4ad9c8d1 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -18,10 +18,7 @@ "ignore": ["**/lib", "**/.nyc_output", "./packages/*/spec-tests", "**/node_modules", "./packages/*/node_modules/**"] }, "organizeImports": { - // TODO: We will enable this settings as soon mono-repo support is provided in biome. - // Currently it didn't recognize local packages in repo and sort those higher than npm packages - // https://github.com/biomejs/biome/issues/2228 - "enabled": false + "enabled": true }, "linter": { "enabled": true, diff --git a/docs/README.md b/docs/README.md index 759ca59d8b03..3ac8fd612325 100644 --- a/docs/README.md +++ b/docs/README.md @@ -22,4 +22,4 @@ This command starts a local development server and opens up a browser window. Mo $ yarn build ``` -This command generates static content into the `build` directory and can be served using any static contents hosting service. +This command generates static content into the `build` directory and can be served using any static content hosting service. diff --git a/docs/docusaurus.config.ts b/docs/docusaurus.config.ts index e37cee619e81..3e57867009f8 100644 --- a/docs/docusaurus.config.ts +++ b/docs/docusaurus.config.ts @@ -97,29 +97,23 @@ const config: Config = { style: "dark", links: [ { - title: "Docs", - items: [ - { - label: "Introduction", - to: "/introduction", - }, - ], + label: 'Lodestar Website', + href: 'https://lodestar.chainsafe.io', }, { - title: "Community", - items: [ - { - label: "Discord", - href: "https://discord.com/invite/yjyvFRP", - }, - { - label: "Twitter", - href: "https://twitter.com/lodestar_eth", - }, - ], + label: 'Discord', + href: 'https://discord.com/invite/yjyvFRP', + }, + { + label: 'Twitter/X', + href: 'https://x.com/lodestar_eth', + }, + { + label: 'Github', + href: 'https://github.com/ChainSafe/lodestar', }, ], - copyright: `Copyright © ${new Date().getFullYear()} ChainSafe, Inc.`, + copyright: `Copyright © ${new Date().getFullYear()} ChainSafe. Built with Docusaurus.` , }, colorMode: { respectPrefersColorScheme: false, diff --git a/docs/pages/contribution/testing/index.md b/docs/pages/contribution/testing/index.md index ecef1ef22c56..a9795670fa82 100644 --- a/docs/pages/contribution/testing/index.md +++ b/docs/pages/contribution/testing/index.md @@ -2,7 +2,7 @@ Testing is critical to the Lodestar project and there are many types of tests that are run to build a product that is both effective AND efficient. This page will help to break down the different types of tests you will find in the Lodestar repo. -There are few flags you can set through env variables to override behavior of testing and it's output. +There are a few flags you can set through env variables to override behavior of testing and its output. | ENV variable | Effect | Impact | | ------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------- | @@ -24,7 +24,7 @@ Node.js is an unforgiving virtual machine when it comes to high performance, mul ### End-To-End Tests -E2E test are where Lodestar is run in its full form, often from the CLI as a user would to check that the system as a whole works as expected. These tests are meant to exercise the entire system in isolation and there is no network interaction, nor interaction with any other code outside of Lodestar. See the [End-To-End Testing](./end-to-end-tests.md) page for more information. +E2E tests are where Lodestar is run in its full form, often from the CLI as a user would to check that the system as a whole works as expected. These tests are meant to exercise the entire system in isolation and there is no network interaction, nor interaction with any other code outside of Lodestar. See the [End-To-End Testing](./end-to-end-tests.md) page for more information. ### Integration Tests diff --git a/docs/pages/contribution/tools/heap-dumps.md b/docs/pages/contribution/tools/heap-dumps.md index 97f2be51dfac..612dfebc3f83 100644 --- a/docs/pages/contribution/tools/heap-dumps.md +++ b/docs/pages/contribution/tools/heap-dumps.md @@ -40,7 +40,7 @@ Click on the `Open dedicated DevTools for Node` link to open the node specific w ![Memory Tab](/images/heap-dumps/memory-tab.png) -Load the profile by either right clicking on the left pane or by clicking the `Load` button at the bottom. +Load the profile by either right-clicking on the left pane or by clicking the `Load` button at the bottom. ![Load Profile](/images/heap-dumps/load-profile.png) @@ -70,7 +70,7 @@ Having a good understanding of the codebase will help to narrow down where to lo _**note: collecting a native heap dump is only supported on linux, analysis can be done from linux or Mac**_ -There are several tools that can be used to do native heap dump analysis. The most common are [`massif`](https://valgrind.org/docs/manual/ms-manual.html) from the [`Valgrind`](https://valgrind.org/) suite, google's [`gperftools`](https://github.com/gperftools/gperftools) and `heaptrack` from [KDE](https://community.kde.org/Main_Page). Of the three, `heaptrack` is the most user friendly tool, and it is specifically designed for the task. It is much faster than `Valgrind`, easier to integrate than `gperftools` and also includes a gui for result analysis. Often times there are also memory allocations that are not related to memory leaks, and tools like `Valgrind` and `gperftools` become less useful. This is why `heaptrack` is the recommended tool for heap dump analysis on Lodestar. +There are several tools that can be used to do native heap dump analysis. The most common are [`massif`](https://valgrind.org/docs/manual/ms-manual.html) from the [`Valgrind`](https://valgrind.org/) suite, google's [`gperftools`](https://github.com/gperftools/gperftools) and `heaptrack` from [KDE](https://community.kde.org/Main_Page). Of the three, `heaptrack` is the most user-friendly tool, and it is specifically designed for the task. It is much faster than `Valgrind`, easier to integrate than `gperftools` and also includes a gui for result analysis. Often times there are also memory allocations that are not related to memory leaks, and tools like `Valgrind` and `gperftools` become less useful. This is why `heaptrack` is the recommended tool for heap dump analysis on Lodestar. There are a few things that will make the results with `heaptrack` far better. The most important is using debug builds of all libraries included in a binary, including the application itself. This will make the results usable. Not to say that they will be useless without debug symbols but it will be kinda tough to optimize functions without knowing the function names nor the file and line numbers. diff --git a/docs/pages/faqs.md b/docs/pages/faqs.md index e7ac490bf9b9..ebe2a2158a2d 100644 --- a/docs/pages/faqs.md +++ b/docs/pages/faqs.md @@ -1,6 +1,6 @@ # Frequently Asked Questions -This section of the documentation will cover common questions and encounters often asked by users and developers. +This section of the documentation will cover common questions and common encounters by users and developers. ## Tooling diff --git a/docs/pages/google0c42298b7ec08b7e.html b/docs/pages/google0c42298b7ec08b7e.html deleted file mode 100644 index 7edebde149af..000000000000 --- a/docs/pages/google0c42298b7ec08b7e.html +++ /dev/null @@ -1 +0,0 @@ -google-site-verification: google0c42298b7ec08b7e.html \ No newline at end of file diff --git a/docs/pages/index.md b/docs/pages/index.md index c74ad6470d7d..2bca344b84cb 100644 --- a/docs/pages/index.md +++ b/docs/pages/index.md @@ -4,14 +4,14 @@ title: Home ![lodestar logo](../../assets/lodestar_icon_text_black_stroke.png) -## Welcome to the Lodestar documentation +## Welcome to the Lodestar Documentation -> **Lodestar is an open-source Ethereum Consensus client and Typescript ecosystem, maintained by ChainSafe Systems** +> **Lodestar is an open-source Ethereum Consensus client and TypeScript ecosystem, maintained by ChainSafe Systems** -### Getting started +### Getting Started - Follow the instructions for [build from source](./run/getting-started/installation#build-from-source), [binaries](./run/getting-started/installation#binaries), or [Docker](./run/getting-started/installation#docker-installation) to install Lodestar. Or use our [Lodestar Quickstart scripts](https://github.com/ChainSafe/lodestar-quickstart). -- Use [Lodestar libraries](./supporting-libraries/index.md) in your next Ethereum Typescript project. +- Use [Lodestar libraries](./supporting-libraries/index.md) in your next Ethereum TypeScript project. - Run a beacon node on [mainnet or a public testnet](./run/beacon-management/starting-a-node.md). - Utilize the whole stack by [starting a local testnet](./contribution/advanced-topics/setting-up-a-testnet.md). - View the Lodestar Beacon [CLI commands and options](./run/beacon-management/beacon-cli.md) @@ -26,14 +26,18 @@ Hardware specifications minimum / recommended, to run the Lodestar client. | | Minimum | Recommended | | --------- | -------------------------------------- | -------------------------------------- | | Processor | Intel Core i3–9100 or AMD Ryzen 5 3450 | Intel Core i7–9700 or AMD Ryzen 7 4700 | -| Memory | 16GB RAM | 32GB RAM | -| Storage | 100GB available space SSD | 1TB available space SSD | -| Internet | Broadband connection | Broadband connection | +| Memory | 8 GB RAM | 16 GB RAM | +| Storage | 130 GB available space SSD | 200 GB available space SSD | +| Internet | Reliable broadband with 10mbps upload | Reliable broadband with >10mbps upload | -## About these docs +### Execution Client -This documentation is open source, contribute at [Github Lodestar repository /docs](https://github.com/ChainSafe/lodestar/tree/unstable/docs). +If you run the [execution client](https://ethereum.org/en/developers/docs/nodes-and-clients/#execution-clients) on the same host, you will need to check their requirements and add them to the above requirements. Broadly, to run both an execution and a consensus client on the same machine, we recommend a 4 TB SSD and 32 GB RAM. -## Need assistance? +## About These Docs + +This documentation is open source, contribute on our [Github Lodestar repository /docs](https://github.com/ChainSafe/lodestar/tree/unstable/docs). + +## Need Assistance? If you have questions about this documentation, feel free to talk to us on our [ChainSafe Discord](https://discord.gg/yjyvFRP) or [open an issue](https://github.com/ChainSafe/lodestar/issues/new/choose) and a member of the team or our community will be happy to assist you. diff --git a/docs/pages/introduction.md b/docs/pages/introduction.md index ab864b8a9df8..5633131dd600 100644 --- a/docs/pages/introduction.md +++ b/docs/pages/introduction.md @@ -1,29 +1,29 @@ # Introduction -Ethereum is one of the most profoundly important inventions in recent history. It is a decentralized, open-source blockchain featuring smart contract functionality. It is the second-largest cryptocurrency by market capitalization, after Bitcoin, and is the most actively used blockchain. Ethereum was proposed in 2013 by programmer Vitalik Buterin. Development was crowdfunded in 2014, and the network went live on 30 July 2015, with 72 million coins premined. ChainSafe was founded not too long afterwards and has been actively working in the Ethereum space ever since. We are proud to develop Lodestar and to present this documentation as a resource for the Ethereum community. +Ethereum is one of the most profoundly important inventions in recent history. It is a decentralized, open-source blockchain featuring smart contract functionality. It is the second-largest cryptocurrency by market capitalization, after Bitcoin, and is the second-largest blockchain by market capitalization. Ethereum was proposed in 2013 by programmer Vitalik Buterin. Development was crowdfunded in 2014, and the network went live on 30 July 2015, with 72 million coins premined. ChainSafe was founded not too long afterwards in 2017 and has been actively working in the Ethereum ecosystem ever since. We are proud to develop Lodestar, the only TypeScript based consensus client, and to present this documentation as a resource for the Ethereum community. ## Proof of Stake -In Ethereum's Proof of Stake (PoS) model, validators replace miners from the Proof of Work (PoW) system. Validators are Ethereum stakeholders who lock up a portion of their Ether as a stake. The protocol randomly selects these validators to propose new blocks. The chance of being chosen is tied to the size of their stake: the more Ether staked, the higher the probability of being selected to propose the block. Proposers receive transaction fees and block rewards as incentives. Validators are also responsible for voting on the validity of blocks proposed by other validators. However, they face penalties, known as slashing, for actions like double-signing, votes on a block that is not in the majority or going offline, ensuring network integrity and reliability. The PoS mechanism significantly reduces energy consumption compared to PoW, because it does not require extensive computational power. Moreover, PoS tends to facilitate faster transaction validations and block creations, enhancing the overall performance and scalability of the network. +In Ethereum's Proof of Stake (PoS) model, validators replace miners from the Proof of Work (PoW) system. Validators are Ethereum stakeholders who lock up a portion of their Ether as a stake. The protocol randomly selects these validators to propose new blocks. The chance of being chosen is tied to the size of their stake: the more Ether staked, the higher the probability of being selected to propose the block. Proposers receive transaction fees and block rewards as incentives. Validators are also responsible for voting on the validity of blocks proposed by other validators. However, they also face penalties, known as slashing, for actions like signing two different block proposals in the same slot or voting on two different attestations for the same target epoch, which creates conflicting states. The PoS mechanism significantly reduces energy consumption compared to PoW, because it does not require extensive computational power. Moreover, PoS tends to facilitate faster transaction validations and block creations, enhancing the overall performance and scalability of the network. ## Consensus Clients -In an effort to promote client diversity there are several beacon-nodes being developed. Each is programmed in a different language and by a different team. The following is a list of the current beacon-node clients: +In an effort to promote client diversity there are several consensus beacon nodes being developed. Each is programmed in a different language and by a different team. The following is a list of the current open source consensus clients in alphabetical order: -- [Lodestar](https://lodestar.chainsafe.io/) -- [Prysm](https://prysmaticlabs.com/) -- [Lighthouse](https://lighthouse.sigmaprime.io/) -- [Teku](https://consensys.net/knowledge-base/ethereum-2/teku/) -- [Nimbus](https://nimbus.team/) -- [Grandine](https://grandine.io) +- [Grandine (Rust)](https://grandine.io) +- [Lighthouse (Rust)](https://lighthouse.sigmaprime.io/) +- [Lodestar (TypeScript)](https://lodestar.chainsafe.io/) +- [Nimbus (Nim)](https://nimbus.team/) +- [Prysm (Golang)](https://prysmaticlabs.com/) +- [Teku (Java)](https://consensys.net/knowledge-base/ethereum-2/teku/) ## Why Client Diversity? -The Ethereum network's robustness is significantly enhanced by its client diversity, whereby multiple, independently-developed clients conforming to a common specification facilitate seamless interaction and function equivalently across nodes. This client variety not only fosters a rich ecosystem but also provides a buffer against network-wide issues stemming from bugs or malicious attacks targeted at particular clients. For instance, during the Shanghai denial-of-service attack in 2016, the diversified client structure enabled the network to withstand the assault, underscoring the resilience afforded by multiple client configurations. +The Ethereum network's robustness is significantly enhanced by its client diversity, whereby multiple, independently-developed clients conforming to a common specification, facilitating seamless interaction and function equivalently across different nodes. This client variety not only fosters a rich ecosystem but also provides a buffer against network-wide issues stemming from bugs or malicious attacks targeted at particular clients. For instance, during the Shanghai denial-of-service attack in 2016, the diversified client structure enabled the network to withstand the assault, underscoring the resilience afforded by multiple client configurations. -On the consensus layer, client distribution is crucial for maintaining network integrity and finality, ensuring transactions are irreversible once validated. A balanced spread of nodes across various clients helps mitigate risks associated with potential bugs or attacks that could, in extreme cases, derail the consensus process or lead to incorrect chain splits, thereby jeopardizing the network's stability and trust. While the data suggests a dominance of Prysm client on the consensus layer, efforts are ongoing to promote a more even distribution among others like Lighthouse, Teku, Nimbus and Grandine. Encouraging the adoption of minority clients, bolstering their documentation, and leveraging real-time client diversity dashboards are among the strategies being employed to enhance client diversity, which in turn fortifies the Ethereum consensus layer against adversities and fosters a healthier decentralized network ecosystem. +On the consensus layer, client distribution is crucial for maintaining network integrity and finality, ensuring transactions are irreversible once validated. A balanced spread of nodes across various clients help to mitigate risks associated with potential bugs or attacks that could, in extreme cases, derail the consensus process (liveness failure) or lead to incorrect chain splits (forking), thereby jeopardizing the network's stability and trust. While the data suggests a [dominance of the Prysm and Lighthouse clients](https://clientdiversity.org) on the consensus layer, efforts are ongoing to promote a more even distribution among others clients. Encouraging the adoption of minority clients, bolstering their documentation, and leveraging real-time client diversity dashboards are among the strategies being employed to enhance client diversity, which in turn fortifies the Ethereum consensus layer against adversities and fosters a healthier decentralized network. -The non-finality event in May 2023 on the Ethereum network posed a significant challenge. The issue arose from attestations for a fork, which necessitated state replays to validate the attestations, causing a notable strain on system resources. As a result, nodes fell out of sync, which deterred the accurate tracking of the actual head of the chain. This situation was exacerbated by a decline in attestations during specific epochs, further hampering the consensus mechanism. The Lodestar team noticed late attestations several weeks prior to the event and implemented a feature that attempted to address such challenges by not processing untimely attestations, and thus not requiring expensive state replays​. While it was done for slightly different reasons, the result was the same. Lodestar was able to follow the chain correctly and helped to stabilize the network. This example underscored the importance of client diversity and network resilience against potential forks and replay attacks. These are considered realistic threats, especially in the context of system complexity like in Ethereum's consensus mechanism. +The [non-finality event of May 2023](https://medium.com/offchainlabs/post-mortem-report-ethereum-mainnet-finality-05-11-2023-95e271dfd8b2) on the Ethereum network posed a significant challenge. The issue arose from attestations for a fork, which necessitated state replays to validate the attestations, causing a notable strain on system resources. As a result, nodes fell out of sync, which deterred the accurate tracking of the actual head of the chain. This situation was exacerbated by a decline in attestations during specific epochs, further hampering the consensus mechanism from reaching finality. The Lodestar team noticed late attestations several weeks prior to the event and implemented a feature that attempted to address such challenges by not processing untimely attestations, and thus not requiring expensive state replays​. While it was done for slightly different reasons, the result was the same. Lodestar was able to follow the chain correctly and helped to stabilize the network. This example underscored the importance of client diversity and network resilience against potential forks and replay attacks. These are considered realistic threats, especially in the context of system complexity like in Ethereum's consensus mechanism. ## Ethereum Reading List diff --git a/docs/pages/run/beacon-management/starting-a-node.md b/docs/pages/run/beacon-management/starting-a-node.md index 6838e14304d6..7aa0799b6e83 100644 --- a/docs/pages/run/beacon-management/starting-a-node.md +++ b/docs/pages/run/beacon-management/starting-a-node.md @@ -2,15 +2,13 @@ title: Starting a Node --- -# Beacon management +# Beacon Management -The following instructions are required to setup and run a Lodestar beacon node. +Running a Lodestar node on mainnet or a testnet only requires basic familiarity with the terminal. The following instructions are required to configure and run the Lodestar beacon node. This page assumes you have already setup an Ethereum execution client. -## Connect to mainnet or a public testnet +## Connect to Mainnet or a Public Testnet -Running a Lodestar node on mainnet or a testnet only requires basic familiarity with the terminal. - -Make sure Lodestar is installed in your local environment, following the chosen install method. The following command should return a non error message. +Make sure Lodestar is installed in your local environment, following the chosen [Installation](../getting-started/installation.md) method. The following command should return a non-error message. ```bash ./lodestar --help @@ -18,25 +16,21 @@ Make sure Lodestar is installed in your local environment, following the chosen For a complete list of beacon node CLI commands and options, see the [`beacon` CLI Command](../beacon-management/beacon-cli.md) section. -To select a known testnet or mainnet, use the `--network` flag. `mainnet` is selected by default, and a list of available networks is listed with the `--help` flag. Setting the `--network` flag will conveniently configure the beacon node or validator client for the selected network. For power users, any configuration option should be able to be overridden. +To select a known testnet or mainnet, use the `--network` flag. The option `mainnet` is selected by default, and a list of available networks is listed with the `--help` flag. Setting the `--network` flag will conveniently configure the beacon node for the selected network. For power users, any configuration option should be able to be overridden. -## Configure the Lodestar JWT authentication token +## Configure the Lodestar JWT Authentication Token -Post-Merge Ethereum will require [secure authentication with the Engine API](https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md) connection on your chosen Execution node. +Ethereum requires a [secure authentication with the Engine API](https://github.com/ethereum/execution-apis/blob/main/src/engine/authentication.md) for connecting to your chosen execution client on port 8551. -:::info -Post-Merge Ethereum **requires** a secure, authenticated connection to the Execution client on port 8551. We recommend setting this up now to ensure a proper configuration before the Merge. -::: - -### Generate a secret key +### Generate a Secret Key You must generate a secret 32-byte (64 characters) hexadecimal string that will be used to authenticate with an execution node. You can use the following command in most terminals to generate a random secret: `openssl rand -hex 32`. Or you can use an [online generator](https://codebeautify.org/generate-random-hexadecimal-numbers). Save this secret key into a text file and note where you store this file. -### Configure Lodestar to locate the JWT secret +### Configure Lodestar to Locate the JWT Secret When starting up a Lodestar beacon node in any configuration, ensure you add the `--jwtSecret $JWT_SECRET_PATH` flag to point to the saved secret key file. -### Ensure JWT is configured with your execution node +### Configure the Execution Client with the JWT Secret **For Go Ethereum:** Use the `--authrpc.jwtsecret /path/to/jwtsecret.hex` flag to configure the secret. Use their documentation [here](https://geth.ethereum.org/docs/getting-started#start-geth). @@ -53,59 +47,68 @@ Use the `--authrpc.jwtsecret /path/to/jwtsecret.hex` flag to configure the secre **For Reth:** Use the `--authrpc.jwtsecret /path/to/jwtsecret.hex` flag to configure the secret. Use their documentation [here](https://reth.rs/run/mainnet.html?highlight=jwt#running-the-reth-node). -## Run a beacon node +## Run the Beacon Node -To start a Lodestar beacon run the command: +To start the Lodestar beacon, run the command: ```bash ./lodestar beacon --network $NETWORK_NAME --jwtSecret $JWT_SECRET_PATH ``` -This will assume an execution-layer client is available at the default -location of `https://localhost:8545`. +This will assume an execution client is available at the default location of `https://localhost:8545`. -In case execution-layer clients are available at different locations, use `--execution.urls` to specify these locations in the command: +If the execution clients are available at different locations, use the flag `--execution.urls` to specify these locations in the command: ```bash ./lodestar beacon --network $NETWORK_NAME --jwtSecret $JWT_SECRET_PATH --execution.urls $EL_URL1 $EL_URL2 ``` -Immediately you should see confirmation that the node has started +Your initial logs should confirm that the node has started. ```txt -Apr-20 15:12:45.274[] info: Lodestar network=mainnet, version=v1.7.2, commit= -Apr-20 15:12:45.327[] info: Connected to LevelDB database path=/data/mt1/chain-db -Apr-20 15:12:57.747[] info: Initializing beacon from a valid db state slot=6264480, epoch=195765, stateRoot=0x8133cd4d0be59c3e94405f902fe0ad68ffaa5013b525dddb6285b91ad79716f6, isWithinWeakSubjectivityPeriod=true -Apr-20 15:13:18.077[network] info: PeerId 16Uiu2HAmDsGet67va6VCnaW2Tu1Ae2yujiDMnmURMMWNvssER7ZQ, Multiaddrs /ip4/127.0.0.1/tcp/9000/p2p/16Uiu2HAmDsGet67va6VCnaW2Tu1Ae2yujiDMnmURMMWNvssER7ZQ,/ip4/10.244.0.199/tcp/9000/p2p/16Uiu2HAmDsGet67va6VCnaW2Tu1Ae2yujiDMnmURMMWNvssER7ZQ -Apr-20 15:13:18.270[rest] info: Started REST API server address=http://127.0.0.1:9596 -Apr-20 15:13:18.271[] warn: Low peer count peers=0 -Apr-20 15:13:18.280[] info: Searching peers - peers: 0 - slot: 6264964 - head: (slot - 484) 0x7ee6…2a15 - exec-block: syncing(17088043 0x9442…) - finalized: 0xe359…4d7e:195763 -Apr-20 15:13:23.009[chain] info: Validated transition configuration with execution client terminalTotalDifficulty=0xc70d808a128d7380000, terminalBlockHash=0x0000000000000000000000000000000000000000000000000000000000000000, terminalBlockNumber=0x0 -Apr-20 15:13:29.287[] info: Syncing - ? left - 0.00 slots/s - slot: 6264965 - head: (slot - 485) 0x7ee6…2a15 - exec-block: syncing(17088043 0x9442…) - finalized: 0xe359…4d7e:195763 - peers: 1 -Apr-20 15:14:41.003[] info: Syncing - 22 seconds left - 4.92 slots/s - slot: 6264971 - head: (slot - 108) 0xd15f…b605 - exec-block: valid(17088414 0x3dba…) - finalized: 0x70fd…5157:195775 - peers: 4 -Apr-20 15:14:53.001[] info: Syncing - 9 seconds left - 5.00 slots/s - slot: 6264972 - head: (slot - 45) 0x44e4…20a4 - exec-block: valid(17088475 0xca61…) - finalized: 0x9cbd…ba83:195776 - peers: 8 -Apr-20 15:15:01.443[network] info: Subscribed gossip core topics -Apr-20 15:15:01.446[sync] info: Subscribed gossip core topics -Apr-20 15:15:05.000[] info: Synced - slot: 6264973 - head: 0x90ea…c655 - exec-block: valid(17088521 0xca9b…) - finalized: 0x6981…682f:195778 - peers: 6 +Jul-31 13:35:27.967[] info: Lodestar network=mainnet, version=v1.21.0/ff35faa, commit=ff35faae4ad1697b86d708a0367a95a71648ab6e +Jul-31 13:35:28.344[] info: Connected to LevelDB database path=/data/lodestar/chain-db +Jul-31 13:35:49.828[] info: Initializing beacon from a valid db state slot=9633504, epoch=301047, stateRoot=0xfa2845a6877b98555906a1654941c97d9c05bdd41e61cc0870a967dc9030b156, isWithinWeakSubjectivityPeriod=true +Jul-31 13:35:51.955[chain] info: Historical state worker started +Jul-31 13:35:51.969[eth1] info: Eth1 provider urls=http://localhost:8551 +Jul-31 13:35:51.975[execution] info: Execution client urls=http://localhost:8551 +Jul-31 13:35:51.977[] info: External builder url=http://localhost:8661 +Jul-31 13:36:21.128[network] info: running libp2p instance in worker thread +Jul-31 13:36:21.727[network] info: libp2p worker started peer=15Uiu2HAmACcmCEXcgt3zCtJL2rqJZ2Mvdjh6U6fe26HgD2FoNRwW +Jul-31 13:36:27.677[network] info: discv5 worker started peerId=16Uiu2HAmACcmCEXcgt3zCtJL2rqJZ2Mvdjh6U6fe26HgD2FoNRwW, initialENR=enr:-IO4QHGTUd1Zg8LAhUAioOz_ySTKoJLIOa6zltSP_AvvhTFVYw6M6YB35IxsiKxQG7nUgCpUB5SIsNxMntCNlTK9sMEBgmlkgnY0iXNlY3AyNTZrMaEC24cdmzuGnWqSwF-8Hw2gbkAZDzMWW3LsHJfp_kDhy-GDdGNwgiMog3VkcIIeWH, bindAddr4=/ip4/0.0.0.0/udp/9000 +Jul-31 13:36:28.134[network] info: PeerId 16Uiu2HAmACcmCEXcgt3zCtJL2rqJZ2Mvdjh6U6fe26HgD2FoNRwW, Multiaddrs /ip4/0.0.0.0/tcp/9000 +Jul-31 13:36:28.137[metrics] info: Started metrics HTTP server address=http://127.0.0.1:8008 +Jul-31 13:36:28.256[rest] info: Started REST API server address=http://0.0.0.0:9596 +Jul-31 13:36:28.257[] info: Searching peers - peers: 0 - slot: 9634080 - head: (slot -576) 0x9d88…d02a - exec-block: syncing(20426302 0xcec4…) - finalized: 0x7feb…c130:301045 +Jul-31 13:36:36.461[execution] info: Execution client is synced oldState=ONLINE, newState=SYNCED +Jul-31 13:36:53.019[] info: Syncing - 3.7 minutes left - 2.32 slots/s - slot: 9634082 - head: (slot -515) 0x792f…f8aa - exec-block: valid(20426365 0x58b1…) - finalized: 0x9d88…d02a:301047 - peers: 11 +Jul-31 13:38:53.168[] info: Syncing - 11 seconds left - 4.01 slots/s - slot: 9634092 - head: (slot -44) 0x7491…f63e - exec-block: valid(20426841 0xd4b2…) - finalized: 0x1e00…6e6b:301062 - peers: 59 +Jul-31 13:38:58.051[network] info: Subscribed gossip core topics +Jul-31 13:38:58.132[sync] info: Subscribed gossip core topics +Jul-31 13:39:05.001[] info: Synced - slot: 9634093 - head: 0x35de…1f0e - exec-block: valid(20426886 0x10ff…) - finalized: 0x88f8…5375:301063 - peers: 70 +Jul-31 13:39:17.000[] info: Synced - slot: 9634094 - head: 0x7844…3b3e - exec-block: valid(20426887 0x67d1…) - finalized: 0x88f8…5375:301063 - peers: 69 +Jul-31 13:39:29.000[] info: Synced - slot: 9634095 - head: 0x5516…ba12 - exec-block: valid(20426888 0x4ceb…) - finalized: 0x88f8…5375:301063 - peers: 74 ``` :::info -If your node is stuck with `Searching for peers` review your network configuration to make sure your ports are open. +If your node is stuck with `Searching peers`, review your network configuration to make sure your ports are open and forwarded to your host machine. ::: By default, Lodestar stores all configuration and chain data at the path `$XDG_DATA_HOME/lodestar/$NETWORK_NAME`. -A young testnet should take a few hours to sync. If you see multiple or consistent errors in the logs, please open a [Github issue](https://github.com/ChainSafe/lodestar/issues/new/choose) or reach out to us in [Discord](https://discord.gg/yjyvFRP). Just by reporting anomalies you are helping accelerate the progress of Ethereum Consensus, thanks for contributing! +A young testnet should take a few hours to sync. If you see multiple or consistent errors in the logs, please open a [Github issue](https://github.com/ChainSafe/lodestar/issues/new/choose) or reach out to us in [Discord](https://discord.gg/yjyvFRP). By reporting anomalies, you are helping to accelerate the progress of Ethereum consensus and we thank you for contributing! :::warning -It is dangerous to expose your Beacon APIs publicly as there is no default authentication mechanism provided. Ensure your beacon node host is not exposing ports 8545 or 9596 outside of your internal network. +It is dangerous to expose your Beacon or Execution APIs publicly as there is no default authentication mechanism provided. Ensure your beacon node host is not exposing ports 8545 or 9596 outside of your internal network. ::: ### Checkpoint Sync -If you are starting your node from a blank db, like starting from genesis, or from the last saved state in db and the network is now far ahead, your node will be susceptible to "long range attacks." Ethereum's solution to this is via something called weak subjectivity. [Read Vitalik's illuminating post explaining weak subjectivity.](https://blog.ethereum.org/2014/11/25/proof-stake-learned-love-weak-subjectivity/). +If you are starting your node from a blank database, or from a last saved database state that is too old (outside of the weak subjectivity period), your node will be susceptible to "long range attacks." Ethereum's solution to this attack is via something called weak subjectivity. [Read Vitalik's illuminating post explaining weak subjectivity.](https://blog.ethereum.org/2014/11/25/proof-stake-learned-love-weak-subjectivity/). -If you have a synced beacon node available (e.g., your friend's node or an infrastructure provider) and a trusted checkpoint you can rely on, you can start off your beacon node in under a minute! And at the same time kicking the "long range attack" in its butt! +If you have a synced beacon node available (e.g., your friend's node or a trusted infrastructure provider) to serve a trusted checkpoint you can rely on, you can start syncing your beacon node from that available checkpoint with the flag `--checkpointSyncUrl` and passing in the URL of the checkpoint provider. This will allow your beacon node to sync within minutes rather than several days. + +The Ethereum community has maintained a set of [public beacon chain checkpoints](https://eth-clients.github.io/checkpoint-sync-endpoints/) that serve these sync endpoints to the larger community. You can correlate the state root and the block root with more than one provider to verify the checkpoints being served follow the same canonical chain. Just supply these **extra arguments** to your beacon node command: @@ -113,28 +116,27 @@ Just supply these **extra arguments** to your beacon node command: --checkpointSyncUrl [--wssCheckpoint ] ``` -In case you really trust `checkpointSyncUrl` then you may skip providing `wssCheckpoint`, which will then result into your beacon node syncing and starting off the recently finalized state from the trusted URL. +In case you really trust the `--checkpointSyncUrl` provider, then you may skip providing `--wssCheckpoint`, which will then result into your beacon node syncing and starting off the recently finalized state from the trusted URL. :::warning -Please use this option very carefully (and at your own risk), a malicious server URL can put you on the wrong chain with a danger of you losing your funds by social engineering. -If possible, validate your `wssCheckpoint` from multiple places (e.g. different client distributions) or from other trusted sources. This will highly reduce the risk of starting off on a malicious chain. -This list of [public endpoints](https://eth-clients.github.io/checkpoint-sync-endpoints/) maintained by the Ethereum community may be used for reference. +Please be aware that a malicious checkpoint sync server URL can put you on the wrong chain with a danger of you losing your funds by social engineering. +If possible, validate your `wssCheckpoint` state from multiple places (e.g. different client distributions) or from other trusted sources. This will highly reduce the risk of starting off on a malicious chain. This list of [public endpoints](https://eth-clients.github.io/checkpoint-sync-endpoints/) maintained by the Ethereum community may be used for reference. ::: -**Taking too long to sync?** +#### Still Taking Long to Sync? -After your node has been offline for a while, it might be the case that it takes a long time to sync even though a `checkpointSyncUrl` is specified. -This is due to the fact that the last db state is still within the weak subjectivity period (~15 days on mainnet) which causes the node -to sync from the db state instead of the checkpoint state. +After your node has been offline for a while, it might be the case that it takes a long time to sync even though a `--checkpointSyncUrl` is specified. +This is due to the fact that the last database state is still within the weak subjectivity period (~15 days on mainnet) which causes the node +to sync from the database state instead of the checkpoint state. -It is possible to force syncing from checkpoint state by supplying the `--forceCheckpointSync` flag. This option is only recommended if it is absolutely +It is possible to force syncing from a checkpoint state by supplying the `--forceCheckpointSync` flag. This option is only recommended if it is absolutely necessary for the node to be synced right away to fulfill its duties as there is an inherent risk each time the state is obtained from an external source. -### Guide to the sync logs +### Sync Log Guide -Lodestar beacon sync log aims to provide information of utmost importance about your node and yet be succinct at the same time. You may see the sync logs in the following format: +The Lodestar beacon sync log aims to provide information of utmost importance about the state of your node and be succinct at the same time. You may see the sync logs in the following format: -`[Sync status] - [ Slot info ] - [Head info] - [Exec block info] - [Finalized info] - [Peers info]` +`[Sync status] - [ Slot info ] - [Head info] - [Execution block info] - [Finalized info] - [Peers info]` See the following example of different kinds of sync log: @@ -171,16 +173,20 @@ Apr-20 15:16:05.000[] info: Synced - slot: 6264978 - head: 0xc9f Apr-20 15:16:17.017[] info: Synced - slot: 6264979 - head: 0xde91…d4cb - exec-block: valid(17088527 0xa488…) - finalized: 0x6981…682f:195778 - peers: 7 ``` -1. Sync status: Takes three values : `Synced` or `Syncing` (along with sync speed info) or `Searching` if node is is still looking for viable peers from where it can download blocks. +1. Sync status: This status takes three values: + +- `Synced`: The node is currently synced +- `Syncing` The node is currently in the syncing process +- `Searching`: The node is is still looking for viable peers from where it can download blocks -2. Slot (clock) info: What is the current ongoing slot as per the chain genesis +2. Slot (clock) info: The current ongoing slot as per the chain genesis -3. Head info: It specifies where the local chain head hash is. In case its far behind the Slot (clock) then it independently shows the head slot else it show how far behind from the Slot it is if difference < 1000. +3. Head info: Specifies where the local beacon chain head hash is. In case it's far behind the Slot (clock), then it independently shows the head slot. Else, it will show how far behind the node is from the Slot (if the difference is < 1000) -4. Execution block info: It provides the execution information about the head whether its confirmed `valid` or execution layer is still `syncing` to it, as well as its number and a short hash to easy identification. +4. Execution block info: Provides the information about the execution block head, whether its confirmed `valid` or still `syncing` to it. In parenthesis, it shows the current execution block number and a short hash for easy identification -5. Finalized info: What is the current local `finalized` checkpoint in the format of `[checkpoint root]:[checkpoint epoch]`, for e.g.: `0xd7ba…8386:189636` +5. Finalized info: Shows the current local `finalized` checkpoint in the format of `[checkpoint root]:[checkpoint epoch]`. For example: `0xd7ba…8386:189636` shows a checkpoint root of `0xd7ba…8386` in epoch `189636` -6. Peer info: Current total number of outbound or inbound peers, for e.g.: `peers: 27` +6. Peer info: Current total number of outbound and inbound peers -For more insight into how a Lodestar beacon node is functioning, you may setup lodestar metrics and use the prepared Grafana dashboards that are found in the repository. Check out our section on [Prometheus and Grafana](../logging-and-metrics/prometheus-grafana.md) for more details. +For more insight into how a Lodestar beacon node is functioning, you may setup Lodestar metrics with the `--metrics` flag and use the prepared Grafana dashboards that are found in the repository. Check out our section on [Prometheus and Grafana](../logging-and-metrics/prometheus-grafana.md) for more details. diff --git a/docs/pages/run/getting-started/installation.md b/docs/pages/run/getting-started/installation.md index 52cb2770725b..b2b4003f90a5 100644 --- a/docs/pages/run/getting-started/installation.md +++ b/docs/pages/run/getting-started/installation.md @@ -1,8 +1,14 @@ -# Installation +# Install Options ## Binaries -Binaries can be downloaded from [the release page](https://github.com/ChainSafe/lodestar/releases/latest) under the `Assets` section. +Binaries can be downloaded from the Lodestar [release page](https://github.com/ChainSafe/lodestar/releases/latest) under the `Assets` section. + +Run the following command to install the latest version + +```bash +curl -fsSL https://chainsafe.github.io/lodestar/install | bash +``` ## Docker Installation @@ -100,5 +106,5 @@ pip3 install setuptools --force-reinstall --user ## Install from NPM [not recommended] :::danger -For mainnet (production) usage, we only recommend installing with docker due to [NPM supply chain attacks](https://hackaday.com/2021/10/22/supply-chain-attack-npm-library-used-by-facebook-and-others-was-compromised/). Until a [safer installation method has been found](https://github.com/ChainSafe/lodestar/issues/3596), do not use this install method except for experimental purposes only. +For mainnet (production) usage, we only recommend installing with Docker, using binaries or building from source due to [NPM supply chain attacks](https://hackaday.com/2021/10/22/supply-chain-attack-npm-library-used-by-facebook-and-others-was-compromised/). Until a [safer installation method has been found](https://github.com/ChainSafe/lodestar/issues/3596), do not use this install method except for experimental purposes only. ::: diff --git a/docs/pages/run/getting-started/quick-start-custom-guide.md b/docs/pages/run/getting-started/quick-start-custom-guide.md new file mode 100644 index 000000000000..8afc11c00ebf --- /dev/null +++ b/docs/pages/run/getting-started/quick-start-custom-guide.md @@ -0,0 +1,728 @@ +# Quick Start Custom Setup Guide + +This is a step-by-step guide to utilize [@ChainSafe/lodestar-quickstart](https://github.com/ChainSafe/lodestar-quickstart) to setup a Ubuntu-based full Ethereum node using a local execution client and ChainSafe's Lodestar consensus client via Docker (the recommended method to use Lodestar for production environments). This is an adaptation of [Somer Esat's guides](https://someresat.medium.com/) for the Ethereum staking community. + +This guide will provide instructions which include running a local execution node. This guide uses Lodestar's `stable` release branch and supports **Holesky** testnet setups and **Mainnet**. + +:::info +This guide specifically focuses on using Lodestar's Quickstart scripts which allows for near instant setup with the following technologies: + +- [Ubuntu v22.04 (LTS) x64 server](https://releases.ubuntu.com/22.04/) +- Ethereum Execution (eth1) clients: + - [Erigon](https://github.com/ledgerwatch/erigon/releases) | [Github](https://github.com/ledgerwatch/erigon) + - [Go-Ethereum (Geth)](https://geth.ethereum.org/) | [Github](https://github.com/ethereum/go-ethereum/releases/) + - [Hyperledger Besu](https://www.hyperledger.org/) | [Github](https://github.com/hyperledger/besu) + - [Nethermind](https://nethermind.io/) | [Github](https://github.com/NethermindEth/nethermind) + - [Rust](https://reth.rs) | [Github](https://github.com/paradigmxyz/reth) +- [ChainSafe's Lodestar Ethereum Consensus Client](https://lodestar.chainsafe.io/) | [Github](https://github.com/ChainSafe/lodestar) +- [Docker Engine](https://docs.docker.com/engine/) + ::: + +:::danger +This guide **_does not_** assist with securing your server such as secure SSH logins or enabling firewalls. Ensure you have limited access to your server and blocked unused ports with guides such as [CoinCashew's Security Best Practices for your ETH staking validator node](https://www.coincashew.com/coins/overview-eth/guide-or-how-to-setup-a-validator-on-eth2-mainnet/part-i-installation/guide-or-security-best-practices-for-a-eth2-validator-beaconchain-node) before continuing with this guide. +::: + +:::warning +This guide is for informational purposes only and does not constitute professional advice. The author does not guarantee accuracy of the information in this article and the author is not responsible for any damages or losses incurred by following this article. A full disclaimer can be found at the bottom of this page — please read before continuing. +::: + +## Support + +For technical support please reach out to: + +- The Lodestar team actively develops and collaborates on the [ChainSafe Discord Server](https://discord.gg/642wB3XC3Q) under **_#:star2:-lodestar-general_** channel. +- Please subscribe to our Discord server announcements on the [ChainSafe Discord Server](https://discord.gg/642wB3XC3Q) under **_#lodestar-announcements_** channel. + +## Prerequisites + +This guide assumes knowledge of Ethereum (ETH), Docker, staking and Linux. + +You require the following before getting started: + +- [Ubuntu Server v22.04 (LTS) amd64](https://releases.ubuntu.com/22.04/) or newer, installed and running on a local machine or in the cloud. _A locally running machine is encouraged for greater decentralization — if the cloud provider goes down then all nodes hosted with that provider go down._ + +- 32 ETH to run a solo validator with Lodestar. If running on testnet, contact us in our [ChainSafe Discord Server](https://discord.gg/642wB3XC3Q) for testnet Ether. + +## Testnet to Mainnet + +If moving from a testnet setup to a mainnet setup it is strongly recommended that you start on a fresh (newly installed) server instance. This guide has not been tested for migration scenarios and does not guarantee success if you are using an existing instance with previously installed testnet software. + +## Hardware Requirements + +| | Minimum | Recommended | +| --------- | -------------------------------------- | -------------------------------------- | +| Processor | Intel Core i3–9100 or AMD Ryzen 5 3450 | Intel Core i7–9700 or AMD Ryzen 7 4700 | +| Memory | 8 GB RAM | 16 GB RAM | +| Storage | 130 GB available space SSD | 200 GB available space SSD | +| Internet | Reliable broadband with 10mbps upload | Reliable broadband with >10mbps upload | + +:::info +Check your available disk space. Even you have a large SSD there are cases where Ubuntu is reporting only 100GB free. If this applies to you then take a look at [**_Appendix A — Expanding the Logical Volume._**](#appendix-a---expanding-the-logical-volume) +::: + +--- + +## Setup Machine & Repository + +### Install Docker Engine & Docker Compose + +We must install Docker Engine to run the images on your local machine. + +#### Add Docker's GPG keyrings + +Run each line one at a time. + +```bash= +sudo apt-get update +sudo apt-get install ca-certificates curl gnupg +sudo install -m 0755 -d /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg +sudo chmod a+r /etc/apt/keyrings/docker.gpg +``` + +#### Add the repository to Apt sources + +Copy and paste the entire command below. + +```bash +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +``` + +#### Update Ubuntu + +Ensure all updates to your Ubuntu Server are complete. + +```bash= +sudo apt-get update +sudo apt-get upgrade -y +``` + +Hit `Enter` if required to restart services. + +#### Install Docker Engine + +```bash +sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin +``` + +#### Test Docker + +```bash +sudo docker run hello-world +``` + +If you see the message `Hello from Docker! +This message shows that your installation appears to be working correctly.`, you can move on to the next step. + +#### Clone lodestar-quickstart repository + +Clone the [lodestar-quickstart](https://github.com/ChainSafe/lodestar-quickstart) from Github into your local server. + +```bash +cd ~ && git clone https://github.com/ChainSafe/lodestar-quickstart.git +``` + +## Configure Lodestar Quick Scripts + +### Navigate to the root directory + +The script and required files are located within the `lodestar-quickstart` folder. + +``` +cd lodestar-quickstart +``` + +### Create your own JWT Secret + +We will generate a JWT secret that is shared by the Execution client and Lodestar in order to have a required secure connection for the `Engine API` on port `8551`. + +``` +openssl rand -hex 32 | tr -d "\n" > "jwtsecret" +``` + +Confirm that your JWT token created. + +``` +cat jwtsecret ; echo +``` + +Your terminal should display the secret. Copy the token for the next step. Be careful to only copy the 64 characters corresponding to the secret and nothing else. + +:::danger +:rotating_light: **WARNING:** Do not share this secret as it protects your authenticated port 8551. +::: + +### Input your JWT Secret into the `import-args.sh` script + +Edit the `import-args.sh` file. + +```sh +nano import-args.sh +``` + +Replace the 64 characters after `0x` with your token. + +If you are not running validators, press `CTRL` + `x` then `y` then `Enter` to save and exit. Proceed to Configuring your Network. + +### Configure feeRecipient + +:::warning +If you are running validators, Ethereum requires validators to set a **Fee Recipient** which allows you to receive priority fees and MEV rewards when proposing blocks. If you do not set this address, your rewards will be sent to the [burn address by default](https://etherscan.io/address/0x0000000000000000000000000000000000000000). +::: + +Configure your validator client's feeRecipient address by changing the `FEE_RECIPIENT` line. Ensure you specify an Ethereum address you control. + +An example of a fee recipient set with the address `0xB7576e9d314Df41EC5506494293Afb1bd5D3f65d`, you would change the configuration to: + +``` +FEE_RECIPIENT="0xB7576e9d314Df41EC5506494293Afb1bd5D3f65d" +``` + +If you would like to run [MEV-Boost](https://boost.flashbots.net) with your validators, proceed to the next section. + +If you do not want to run MEV-Boost, press `CTRL` + `x` then `y` then `Enter` to save and exit. Proceed to [Configuring your Network](#configuring-your-network). + +### Set minimum bid for MEV-Boost validators + +:::info +(Optional): If you are running validators and would like to use MEV-Boost, follow this section. Otherwise, skip this section. +::: + +Validators running MEV-Boost maximize their staking reward by selling blockspace to an open market of builders. MEV-Boost v1.4+ allows you to set a minimum bid threshold to only use an externally built block if it meets or exceeds this parameter. + +The `min-bid` parameter is denominated in ETH. For example, if you want to set your threshold to 0.03 ETH, set your configuration to `MIN_BUILDERBID=0.03` + +When complete, press `CTRL` + `x` then `y` then `Enter` to save and exit. + +### Configuring your Network + +When using the quick scripts, each supported network has a `.vars` file to define the parameters required for configuring the clients to the specified network. + +To view the available files, use the command: + +``` +ls *.vars +``` + +### Select your Network + +Each network has specifics variables that you may want to setup for use. We will use `Holesky` to demonstrate connecting to a public testnet. + +Open the `holesky.vars` file. + +```bash +nano holesky.vars +``` + +### Configure MEV-boost relays + +:::info +(Optional): If you have validators you intend to use for MEV-boost, you can input the relays you want to connect here. Otherwise, skip this section. +::: + +You can list multiple relays simply by pasting the relay URL as a variable in this file. + +```shell= +RELAY_A=https://0xRelayPubKey@relay.com +RELAY_B=https://0xRelayPubKey@relay2.com +``` + +Make sure to identify the ones you want to use by editing the line: + +```shell= +RELAYS="$RELAY_A,$RELAY_B" +``` + +### Configure Lodestar version + +The lodestar-quickstart scripts currently defaults to using our `stable` release branch. To use our nightly `unstable` release instead, replace `LODESTAR_IMAGE=chainsafe/lodestar:latest` with `LODESTAR_IMAGE=chainsafe/lodestar:next` in the `import-images.sh` file. + +You may also choose to use a specific version release of Lodestar. To select a specific version, replace the image with `LODESTAR_IMAGE=chainsafe/lodestar:v1.x.x` + +:::warning +:warning: We do not recommend using the `unstable` branch or `@chainsafe/lodestar:next` docker versions of Lodestar for production related tasks. +::: + +### Modify your weak subjectivity (checkpoint sync) provider + +:::note +(Optional): We use ChainSafe's Lodestar checkpoints by default. You may choose to point your trusted checkpoint at another source or verify the checkpoints with other providers. If you would rather sync from genesis (not recommended), you can skip this step. +::: + +Weak subjectivity (checkpoint sync) allows your beacon node to sync within minutes by utilizing a trusted checkpoint from a trusted provider. + +**We highly recommend using this feature** so you do not need to wait days to sync from genesis and will mitigate your susceptibility to [long-range attacks](https://blog.ethereum.org/2014/11/25/proof-stake-learned-love-weak-subjectivity/). + +Minimize your risk of syncing a malicious chain from a malicious checkpoint by verifying the trusted checkpoint from multiple sources. + +1. View the community maintained list of [Beacon Chain checkpoint sync endpoints](https://eth-clients.github.io/checkpoint-sync-endpoints/) +2. Verify multiple endpoint links and ensure the latest finalized and latest justified block roots are the same +3. Choose one of those endpoint URLs +4. Replace the `--checkpointSyncUrl` address with your chosen provider. + +:::info +**NOTE**: Ensure you use checkpoint URLs from the list above corresponding to the network you are trying to sync or you **will** receive errors. +::: + +When complete, press `CTRL` + `x` then `y` then `Enter` to save and exit. + +## Modify other client parameters (For advanced users) + +:::info +(Optional): We have already set fixed parameters for a seamless setup. If you are looking to customize the default parameters of the clients you are using, follow this section. Otherwise, skip this section. +::: + +Fixed parameters for clients can be modified under the `fixed.vars` configuration file. + +Under the selected client, modify or add the custom arguments on their corresponding line. + +:::note +The following are links to client documentation for CLI commands: + +- [**Lodestar CLI Commands**](https://chainsafe.github.io/lodestar/reference/cli/) +- [**Nethermind CLI Commands**](https://docs.nethermind.io/fundamentals/configuration#command-line-options) +- [**Besu CLI Commands**](https://besu.hyperledger.org/en/stable/Reference/CLI/CLI-Syntax/) +- [**Go Ethereum CLI commands**](https://geth.ethereum.org/docs/interface/command-line-options) +- [**Erigon CLI commands**](https://github.com/ledgerwatch/erigon#beacon-chain) +- [**Reth CLI commands**](https://reth.rs/cli/reth.html) + ::: + +Once complete, press `CTRL` + `x` then `y` then `Enter` to save and exit. + +--- + +## Setup Validators + +:::info +Optional: Skip this entire section if you do not intend to run validators. +::: + +### Create validator keystore password + +Make sure you are in your main quickstart directory. Create the `pass.txt` file containing your validator's decryption password for use. + +``` +cd ~/lodestar-quickstart +``` + +``` +nano pass.txt +``` + +Enter the password for your validators. + +:::info +Once the validator container is running, you can delete this file from your server. Note that every time you restart this container, you will need this password to decrypt your keystore.json files. +::: + +Once complete, press `CTRL` + `x` then `y` then `Enter` to save and exit. + +### Option 1: Setup validators with keystores + +If you want to setup validators with your `keystores.json` files follow this section. Otherwise, skip this step. + +#### Copy/Move keystores to `lodestar-quickstart/keystores` directory + +Your `keystore.json` file(s) generated from the [`staking-deposit-cli`](https://github.com/ethereum/staking-deposit-cli) or similar generator for validator keys will be placed in the `lodestar-quickstart/keystores` directory using the `cp` command to copy or `mv` command to move the files. + +``` +mkdir keystores +``` + +:::info +You may choose to use your own method (e.g. SFTP) for copying/uploading keys to your server. This is only a guide. +::: + +The format of the command to use is below: + +``` +cp +``` + +An example usage of this command is: + +``` +cp /home/user/validator_keys/keystore-x.json ~/lodestar-quickstart/keystores +``` + +Ensure your `keystore.json` files are in the `lodestar-quickstart/keystores` directory using `ls` command. + +``` +ls -lsah ~/lodestar-quickstart/keystores/ +``` + +You should see the keystore files within the directory. + +:::info +Ensure the `/keystores` directory only has the `keystore-m_xxxxx.json` files and nothing else. If you copied in the `deposit_data-xxxxx.json` files, you can remove them by using the `sudo rm ` command. + +Example: + +``` +sudo rm deposit_data-1552658472.json +``` + +::: + +Continue to the [**Startup Quickstart Script**](#startup-quickstart-script) section. + +### Option 2: Setup multiple validator sets with keystores encrypted under different passwords + +Optional: If you want to setup validators with your `keystores.json` files but they are not encrypted with the same password, follow this section. Otherwise, skip this step. + +This option will allow you to run multiple validator clients corresponding to each validator keystore set encrypted with the same password. Therefore, we will setup `validatorset1` with one decryption password and `validatorset2` with another decryption password. You can repeat these steps to create subsequent validator sets with different keystore decryption passwords. + +#### Create validator keystore set directory + +Ensure you are in the `lodestar-quickstart` directory and create a folder for your first validator keystore set. + +``` +cd ~/lodestar-quickstart +``` + +Make the new directory for set one. + +``` +mkdir validatorset1 +``` + +Navigate into the directory. + +``` +cd validatorset1 +``` + +#### Create validator keystore password + +Create the `pass.txt` file containing your validator's decryption password for use. + +``` +nano pass.txt +``` + +Enter the password for your validators. + +:::info +Once the validator container is running, you can delete this file from your server. Note that every time you restart this container, you will need this password to decrypt your keystore.json files. +::: + +Once complete, press `CTRL` + `x` then `y` then `Enter` to save and exit. + +#### Copy/Move keystores to `lodestar-quickstart/validatorset1/keystores` directory + +Your `keystore.json` file(s) generated from the [`staking-deposit-cli`](https://github.com/ethereum/staking-deposit-cli) or similar generator for validator keys will be placed in the `lodestar-quickstart/validatorset1/keystores` directory using the `sudo cp` command to copy or `sudo mv` command to move the files. + +``` +mkdir keystores +``` + +The format of the command to use is below: + +``` +cp +``` + +An example usage of this command is: + +``` +cp /home/user/validator_keys/keystore-x.json ~/lodestar-quickstart/validatorset1/keystores +``` + +Ensure your `keystore.json` files are in the `lodestar-quickstart/validatorset1/keystores` directory using `ls` command. + +``` +ls -lsah ~/lodestar-quickstart/validatorset1/keystores/ +``` + +You should see the keystore files within the directory. + +:::info +Ensure the `/keystores` directory only has the `keystore-m_xxxxx.json` files and nothing else. If you copied in the `deposit_data-xxxxx.json` files, you can remove them by using the `sudo rm ` command. + +Example: + +``` +sudo rm deposit_data-1552658472.json +``` + +::: + +Repeat the same steps above for `validatorset2` and any subsequent sets of validators you require. When complete you should have a similar looking directory tree such as the one below: + +Then, continue to the [**Startup Quickstart Script**](#startup-quickstart-script) section. Pay particular attention to startup script example five (5) and (6). + +### Option 3: Setup validators with mnemonic + +:::warning +**TESTNET USE ONLY:** Do not use this method unless you're validating on a testnet. Your mnemonic will be stored in plaintext on your server, which is unsafe. +::: + +Optional: If you want to setup validators with your mnemonic. Otherwise, skip this step. + +#### Setup Mnemonic + +Select the `.vars` file corresponding to the network you want to run. For Holesky, select `holesky.vars`. Open the file with the `nano` text editor and edit the configuration: + +``` +nano holesky.vars +``` + +We will modify the `LODESTAR_VALIDATOR_MNEMONIC_ARGS=`. Specifically, the mnemonic located after the `--fromMnemonic` flag. + +- Replace the default mnemonic with your mnemonic. Ensure it is between the quotations + +- Indicate which indexes of the mnemonic you wish Lodestar to run. Specify a specific index number `--mnemonicIndexes 0` or a range of numbers `--mnemonicIndexes 0..5` + +:::info +If you created your mnemonic with one key, it is likely located in index 0. If you've added to it, the generated keys are likely the subsequent indexes. + +Therefore, if you generated one key, it is likely in index 0, so you would use `--mnemonicIndexes 0`. If you generated five keys, it is likely in index 0 to 4, so you would use `--mnemonicIndexes 0..4` +::: + +Once complete, press `CTRL` + `x` then `y` then `Enter` to save and exit. + +Continue to the [**Startup Quickstart Script**](#startup-quickstart-script) section. + +--- + +## Startup Quickstart Script + +Ensure you are in the `~/lodestar-quickstart folder. + +``` +cd ~/lodestar-quickstart +``` + +The following are **_example commands_** as a template for initiating the quickstart script: + +1. Startup a Sepolia beacon node with no validators and Go Ethereum (Geth) execution client with terminals attached: + +``` +./setup.sh --dataDir sepolia-data --elClient geth --network sepolia --dockerWithSudo --withTerminal "gnome-terminal --disable-factory --" +``` + +2. Startup Mainnet beacon node with no validators and Nethermind execution client detached from containers (Recommended only when you've verified the setup has initiated properly with terminals attached): + +``` +./setup.sh --dataDir mainnet-data --elClient nethermind --network mainnet --dockerWithSudo --detached +``` + +3. Startup Holesky beacon node with validator client (using mnemonic in /keystores) and Erigon execution client detached from containers: + +``` +./setup.sh --dataDir holesky-data --elClient erigon --network holesky --dockerWithSudo --detached --withValidatorMnemonic ~/lodestar-quickstart/ +``` + +4. Startup Mainnet beacon node with validator client (using keystores) with MEV-Boost and Hyperledger Besu execution client detached from containers: + +``` +./setup.sh --dataDir mainnet-data --elClient besu --network mainnet --dockerWithSudo --detached --withValidatorKeystore ~/lodestar-quickstart/ --withMevBoost +``` + +5. Startup Holesky beacon node with validator client set one (using keystores) and execution client Geth detached from containers: + +``` +./setup.sh --dataDir holesky-data --elClient geth --network holesky --dockerWithSudo --detached --withValidatorKeystore ~/lodestar-quickstart/validatorset1 +``` + +:::warning +You can only start up one set of validator keystores per validator client on the same command. Use the below command (#6) to startup another validator client for another set of validator keys. +::: + +6. Startup validator client only with validator client set two (using keystores) and execution client Geth detached from containers: + +``` +./setup.sh --dataDir holesky-data --elClient geth --network holesky --dockerWithSudo --detached --withValidatorKeystore ~/lodestar-quickstart/validatorset2 --justVC +``` + +:::info +The script will standardize naming your containers so running the `setup.sh` twice, will not create two instances of the same containers. The script will standardize naming your containers so running the `./setup.sh ` a second time, will not create two instances of the same containers. +::: + +Configure the above commands with what you intend to run using the Quickstart Script Help table below. + +## Quickstart Script Help + +| Command | Required/Optional | Description | +| ------------------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `dataDir` | Required | File location (volume) of the configuration & data for setup. This directory should be non-existent for the first run. If the directory exists, it will skip fetching the configuration, assuming it has been done previously. You can also clean individual directors of CL/EL between the re-runs. | +| `elClient` | Required | The selected EL client you want to run with Lodestar. Options are `nethermind`, `besu`, `erigon` or `geth`. | +| `network` | Required | The network/chain you want to load, reads the corresponding `.vars` (for e.g. `holesky.vars`) network configuration , like images, or urls for EL/CL to interact. Example: Default for Holesky is `--network holesky` using `holesky.vars`. | +| `dockerWithSudo` | Optional | Provide this argument if your Docker needs a `sudo` prefix. | +| `--withTerminal` | Optional\* | Provide the terminal command prefix for CL and EL processes to run in your favourite terminal. You may use an alias or a terminal launching script as long as it waits for the command it runs till ends and then closes. If not provided, it will launch the docker processes in in-terminal mode. | +| `--detached` | Optional\* | By default the script will wait for processes and use user input (ctrl +c) to end the processes, however you can pass this option to skip this behavior and just return, for e.g. in case you just want to leave it running. | +| `--withValidatorKeystore` | Optional\*\* | Launch a validator client using `LODESTAR_VALIDATOR_MNEMONIC_ARGS` (`--withValidatorMnemonic`) or using a folder (`--withValidatorKeystore --justVC` connecting to same beacon node. | +| `--withValidatorMnemonic` | Optional\*\* | Launch a validator client using mnemonic method.(`LODESTAR_VALIDATOR_MNEMONIC_ARGS`) as set in the network vars file. | +| `--withMevBoost` | Optional | Launch a MEV-Boost container to interface with multiple relays picked for the corresponding network vars file. When paired with `--justCL` or `--justVC` this only activates the builder arguments in the beacon/validator and use the builder url set in MEVBOOST_URL variable in fixed.vars | +| `--justEL` | Optional | Launch only the Execution Layer client. | +| `--justCL` | Optional | Launch only the Lodestar beacon node. | +| `--justVC` | Optional | Launch only the Lodestar validator. | +| `--skipImagePull` | Optional | Launch with only the local Docker images. Do not update them on this run. | + +:::note +`*` : Only one of the two options should be provided. +`**` : Only one of the two options should be provided. +::: + +### Check Containers + +You can check the status and get the name of your containers by using the `docker ps` command: + +``` +sudo docker ps +``` + +The containers should not constantly restart. If they restart, likely a misconfiguration occurred. + +### Check Container Logs + +You can check the status of what your container is logging to diagnose a problem or follow along the status of your container output. + +Check the logs by using the `docker logs` command: + +``` +sudo docker logs +``` + +Follow along the logs by adding the `-f` flag: + +``` +sudo docker logs -f +``` + +Limit the fetched logs by indicating the latest container out puts by number of lines using the `-n ` flag. For the last 10 lines: + +``` +sudo docker logs -n 10 +``` + +### Check beacon node is progressing + +Your beacon node should initialize and you should see something similar to: + +``` +Jul-31 13:35:27.967[] info: Lodestar network=mainnet, version=v1.21.0/ff35faa, commit=ff35faae4ad1697b86d708a0367a95a71648ab6e +Jul-31 13:35:28.344[] info: Connected to LevelDB database path=/data/lodestar/chain-db +Jul-31 13:35:49.828[] info: Initializing beacon from a valid db state slot=9633504, epoch=301047, stateRoot=0xfa2845a6877b98555906a1654941c97d9c05bdd41e61cc0870a967dc9030b156, isWithinWeakSubjectivityPeriod=true +Jul-31 13:35:51.955[chain] info: Historical state worker started +Jul-31 13:35:51.969[eth1] info: Eth1 provider urls=http://localhost:8551 +Jul-31 13:35:51.975[execution] info: Execution client urls=http://localhost:8551 +Jul-31 13:35:51.977[] info: External builder url=http://localhost:8661 +Jul-31 13:36:21.128[network] info: running libp2p instance in worker thread +Jul-31 13:36:21.727[network] info: libp2p worker started peer=15Uiu2HAmACcmCEXcgt3zCtJL2rqJZ2Mvdjh6U6fe26HgD2FoNRwW +Jul-31 13:36:27.677[network] info: discv5 worker started peerId=16Uiu2HAmACcmCEXcgt3zCtJL2rqJZ2Mvdjh6U6fe26HgD2FoNRwW, initialENR=enr:-IO4QHGTUd1Zg8LAhUAioOz_ySTKoJLIOa6zltSP_AvvhTFVYw6M6YB35IxsiKxQG7nUgCpUB5SIsNxMntCNlTK9sMEBgmlkgnY0iXNlY3AyNTZrMaEC24cdmzuGnWqSwF-8Hw2gbkAZDzMWW3LsHJfp_kDhy-GDdGNwgiMog3VkcIIeWH, bindAddr4=/ip4/0.0.0.0/udp/9000 +Jul-31 13:36:28.134[network] info: PeerId 16Uiu2HAmACcmCEXcgt3zCtJL2rqJZ2Mvdjh6U6fe26HgD2FoNRwW, Multiaddrs /ip4/0.0.0.0/tcp/9000 +Jul-31 13:36:28.137[metrics] info: Started metrics HTTP server address=http://127.0.0.1:8008 +Jul-31 13:36:28.256[rest] info: Started REST API server address=http://0.0.0.0:9596 +Jul-31 13:36:28.257[] info: Searching peers - peers: 0 - slot: 9634080 - head: (slot -576) 0x9d88…d02a - exec-block: syncing(20426302 0xcec4…) - finalized: 0x7feb…c130:301045 +Jul-31 13:36:36.461[execution] info: Execution client is synced oldState=ONLINE, newState=SYNCED +Jul-31 13:36:53.019[] info: Syncing - 3.7 minutes left - 2.32 slots/s - slot: 9634082 - head: (slot -515) 0x792f…f8aa - exec-block: valid(20426365 0x58b1…) - finalized: 0x9d88…d02a:301047 - peers: 11 +Jul-31 13:38:53.168[] info: Syncing - 11 seconds left - 4.01 slots/s - slot: 9634092 - head: (slot -44) 0x7491…f63e - exec-block: valid(20426841 0xd4b2…) - finalized: 0x1e00…6e6b:301062 - peers: 59 +Jul-31 13:38:58.051[network] info: Subscribed gossip core topics +Jul-31 13:38:58.132[sync] info: Subscribed gossip core topics +Jul-31 13:39:05.001[] info: Synced - slot: 9634093 - head: 0x35de…1f0e - exec-block: valid(20426886 0x10ff…) - finalized: 0x88f8…5375:301063 - peers: 70 +Jul-31 13:39:17.000[] info: Synced - slot: 9634094 - head: 0x7844…3b3e - exec-block: valid(20426887 0x67d1…) - finalized: 0x88f8…5375:301063 - peers: 69 +Jul-31 13:39:29.000[] info: Synced - slot: 9634095 - head: 0x5516…ba12 - exec-block: valid(20426888 0x4ceb…) - finalized: 0x88f8…5375:301063 - peers: 74 +``` + +### Check validators are detected and decrypted + +> OPTIONAL: If you are running validators, you can check the validator client logs to ensure the validator keys exist, has been detected and decrypted. + +Here is an example command if you are running validators on Goerli with the lodestar-quickstart script: + +``` +sudo docker logs goerli-validator +``` + +You should see something similar to: + +``` +Mar-01 03:06:35.048[] info: Lodestar network=holesky, version=v1.16.0/6ad9740, commit=6ad9740a085574306cf46c7642e749d6ec9a4264 +Mar-01 03:06:35.050[] info: Connecting to LevelDB database path=/keystoresDir/validator-db-holesky +Mar-01 03:06:35.697[] info: 100% of keystores imported. current=2 total=2 rate=1318.68keys/m +Mar-01 03:06:35.698[] info: 2 local keystores +Mar-01 03:06:35.698[] info: 0xa6fcfca12e1db6c7341d82327010cd57224dc239d1c5e4fb18286cc32edb877d813c5af1c870d474aef7b3ff7ab927ea +Mar-01 03:06:35.698[] info: 0x8f868e53bbe1451bcf6d42c9ab6d292cbd7fbfa09c59b6b99c1dd6a4977e2e7b4b752c328784ca2788dd6f63ffcbdb7e +Mar-01 03:06:35.732[] info: Beacon node urls=http://127.0.0.1:9596 +Mar-01 03:09:23.813[] info: Genesis fetched from the beacon node +Mar-01 03:09:23.816[] info: Verified connected beacon node and validator have same the config +Mar-01 03:09:23.818[] info: Verified connected beacon node and validator have the same genesisValidatorRoot +Mar-01 03:09:23.818[] info: Initializing validator useProduceBlockV3=deneb+, broadcastValidation=gossip, defaultBuilderSelection=executiononly, suggestedFeeRecipient=0xeeef273281fB83F56182eE960aA4bAfe7fE075DE, strictFeeRecipientCheck=false +Mar-01 03:09:23.830[] info: Validator seen on beacon chain validatorIndex=1234567, pubKey=0xa6fcfca12e1db6c7341d82327010cd57224dc239d1c5e4fb18286cc32edb877d813c5af1c870d474aef7b3ff7ab927ea +Mar-01 03:09:23.830[] info: Validator seen on beacon chain validatorIndex=1234568, pubKey=0x8f868e53bbe1451bcf6d42c9ab6d292cbd7fbfa09c59b6b99c1dd6a4977e2e7b4b752c328784ca2788dd6f63ffcbdb7e +Mar-01 03:09:23.830[] info: Validator statuses active=2, total=2 +Mar-01 03:15:50.191[] info: Published attestations slot=1113379, count=1 +Mar-01 03:16:02.728[] info: Published attestations slot=1113380, count=1 +``` + +:::info +It is normal to see `Error on getProposerDuties` in your validator logs as your beacon node and execution node sync up. Give it time. +::: + +## Stop Containers + +You can stop the running containers by using the `docker stop` command and apply it to more than one container if necessary. + +``` +sudo docker stop +``` + +Ensure to remove the container if you don't plan to restart it with the same parameters. + +``` +sudo docker rm +``` + +--- + +# Appendix + +## Appendix A - Expanding the Logical Volume + +There are cases where Ubuntu is provisioning only 200GB of a larger SSD causing users to run out of disk space when syncing their Eth1 node. The error message is similar to: + +`Fatal: Failed to register the Ethereum service: write /var/lib/goethereum/geth/chaindata/383234.ldb: no space left on device` + +To address this issue, assuming you have a SSD that is larger than 200GB, expand the space allocation for the LVM by following these steps: + +``` +sudo lvdisplay <-- Check your logical volume size +sudo lvm +lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv +lvextend -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv +exit +sudo resize2fs /dev/ubuntu-vg/ubuntu-lv +df -h <-- Check results +``` + +That should resize your disk to the maximum available space. + +If you need support, please check with the [ChainSafe Discord](https://discord.gg/642wB3XC3Q) under the #:star2:-lodestar-general channel. + +## Appendix B - Update client images + +To update client images, you just need to stop all the containers, remove them and restart the lodestar-quickstart script to automatically check for new images. + +You can stop the running containers by using the `docker stop` command with the container names. + +``` +sudo docker stop +``` + +Remove the containers by using the `docker rm` command. + +``` +sudo docker rm +``` + +Restart your containers using your [Startup Quickstart Script](#startup-quickstart-script) command. + +--- + +## Full Disclaimer + +This article (the guide) is for informational purposes only and does not constitute professional advice. The author does not warrant or guarantee the accuracy, integrity, quality, completeness, currency, or validity of any information in this article. All information herein is provided “as is” without warranty of any kind and is subject to change at any time without notice. The author disclaims all express, implied, and statutory warranties of any kind, including warranties as to accuracy, timeliness, completeness, or fitness of the information in this article for any particular purpose. The author is not responsible for any direct, indirect, incidental, consequential or any other damages arising out of or in connection with the use of this article or in reliance on the information available on this article. This includes any personal injury, business interruption, loss of use, lost data, lost profits, or any other pecuniary loss, whether in an action of contract, negligence, or other misuse, even if the author has been informed of the possibility. diff --git a/docs/pages/run/getting-started/quick-start.md b/docs/pages/run/getting-started/quick-start.md index a28de8014b6a..e1a77face695 100644 --- a/docs/pages/run/getting-started/quick-start.md +++ b/docs/pages/run/getting-started/quick-start.md @@ -1,26 +1,20 @@ --- -title: Quick Start +title: Lodestar Quick Start Scripts --- -## Lodestar Quickstart +In order to make things easier and quicker for all types of users to bootstrap the Lodestar consensus client with a variety of execution clients, we have come up with [Lodestar Quickstart](https://github.com/ChainSafe/lodestar-quickstart) Docker scripts! -In order to make things easy for users to onboard and try the Ethereum **Proof of Stake** we have come up with [Lodestar quick start](https://github.com/ChainSafe/lodestar-quickstart) scripts! +- ✅ Zero configuration +- ✅ Single command startup +- ✅ All testnets supported along with mainnet +- ✅ All mainstream execution clients integrated -✅ Zero Configuration -✅ All testnets supported along with `mainnet` -✅ All mainstream Execution Clients integrated - -With just single command you can run lodestar with various execution engines, switch them up to see the Optimistic sync work its magic and eventually brings lodestar and the execution engine in sync - -### Customizations - -You can adapt them to your production setups with ease! Here is a simple guide for you to follow along: +### Support -👉 [Lodestar Quick Setup Guide](https://hackmd.io/@philknows/rJegZyH9q) +We actively maintain and update the configurations of running Lodestar with the most commonly used execution clients for various test/production networks so there is minimal configuration required for a standard setup. -### Support +If you have questions about these scripts, documentation or repository, feel free to talk to us on our [ChainSafe Discord](https://discord.gg/yjyvFRP) or [open an issue](https://github.com/ChainSafe/lodestar-quickstart/issues/new) and a member of the team or our community will be happy to assist you. -We actively maintain and update the configurations of running lodestar with the top of the line execution engines for various PoS networks so you have the minimum possible figuring out to do. +### Customizations (Optional) -In case you are facing any issues with the quick start guide, do reach us out on lodestar discord! -Happy to help! 🙏🙏🙏 +You can further adapt our Quickstart Docker scripts to your node setups with ease! Use our [Quickstart Custom Setup Guide](./quick-start-custom-guide.md)! diff --git a/docs/pages/run/logging-and-metrics/client-monitoring.md b/docs/pages/run/logging-and-metrics/client-monitoring.md index dc707f2b31d0..31a20600ecf3 100644 --- a/docs/pages/run/logging-and-metrics/client-monitoring.md +++ b/docs/pages/run/logging-and-metrics/client-monitoring.md @@ -1,4 +1,4 @@ -# Client monitoring +# Client Monitoring Lodestar has the ability to send client stats to a remote service for collection. At the moment, the main service offering remote monitoring is [beaconcha.in](https://beaconcha.in/). @@ -27,7 +27,7 @@ When sending data to a remote service you should be conscious about security: - Only use a service that you trust as this will send information which may identify you and associate your validators, IP address and other personal information. -- Always use a HTTPS connection (i.e. a URL starting with `https://`) to prevent the traffic +- Always use an HTTPS connection (i.e. a URL starting with `https://`) to prevent the traffic from being intercepted in transit and leaking information. ::: diff --git a/docs/pages/run/logging-and-metrics/dashboards.md b/docs/pages/run/logging-and-metrics/dashboards.md deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/docs/pages/run/logging-and-metrics/log-management.md b/docs/pages/run/logging-and-metrics/log-management.md deleted file mode 100644 index a0ee1d5fec07..000000000000 --- a/docs/pages/run/logging-and-metrics/log-management.md +++ /dev/null @@ -1,3 +0,0 @@ -# Log Management - -Check back soon for more information!! diff --git a/docs/pages/run/logging-and-metrics/metrics-management.md b/docs/pages/run/logging-and-metrics/metrics-management.md deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/docs/pages/run/logging-and-metrics/prometheus-grafana.md b/docs/pages/run/logging-and-metrics/prometheus-grafana.md index f49a44f37209..c36c52a72a0c 100644 --- a/docs/pages/run/logging-and-metrics/prometheus-grafana.md +++ b/docs/pages/run/logging-and-metrics/prometheus-grafana.md @@ -1,8 +1,12 @@ -# Prometheus and Grafana +# Prometheus and Grafana Setup Prometheus is an open-source monitoring system with efficient time series database and a modern alerting approach. Together with Grafana it's the recommended way to make sure that your node and validator(s) are performing correctly. -## Prometheus +## Localized Docker Metrics Script + +The Lodestar team has setup a script which will copy the latest dashboards compiled by our team for development purposes. By utilizing the script located in `/docker/docker-compose.local_dev.sh`, you can instantly setup the latest dockerized metrics alongside your local beacon node. + +## Prometheus Setup To start, download Prometheus from https://prometheus.io/download/. Unzip the downloaded .zip file and run Prometheus from its installed location with the lodestar `prometheus.yml` passed in as the configuration file @@ -23,7 +27,7 @@ lodestar --metrics=true --metrics.port=8008 Navigate to http://localhost:9090/ in your browser to verify that Prometheus is monitoring Lodestar -## Grafana +## Grafana Setup Download and install Grafana from its official repository https://grafana.com/docs/grafana/latest/installation/debian/ diff --git a/docs/pages/run/validator-management/proposer-config.md b/docs/pages/run/validator-management/proposer-config.md new file mode 100644 index 000000000000..444789a9f8b0 --- /dev/null +++ b/docs/pages/run/validator-management/proposer-config.md @@ -0,0 +1,48 @@ +# Proposer Configuration + +:::warning +This is an alpha feature. The feature and its format are subject to change. +::: + +With Lodestar's validator client, you can assign specific metadata for each proposer/public key using a proposer configuration file written in YAML file. This will allow you to set specific graffiti, fee recipients and builder settings per validator key. + +### Example proposer_config.yaml + +```yaml +proposer_config: + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c": + graffiti: "graffiti" + strict_fee_recipient_check: false + fee_recipient: "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + builder: + gas_limit: "30000000" + selection: "executionalways" + boost_factor: "0" + "0xa4855c83d868f772a579133d9f23818008417b743e8447e235d8eb78b1d8f8a9f63f98c551beb7de254400f89592314d": + fee_recipient: "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + builder: + gas_limit: "3000000" + selection: "maxprofit" + boost_factor: "100" +default_config: + graffiti: "default graffiti" + strict_fee_recipient_check: true + fee_recipient: "0xcccccccccccccccccccccccccccccccccccccccc" + builder: + gas_limit: "30000000" + selection: "default" + boost_factor: "90" +``` + +### Enable Proposer Configuration + +After you have configured your proposer configuration YAML file, you can start Lodestar with an additional CLI flag option pointing to the file: `--proposerSettingsFile /path/to/proposer_config.yaml`. + +:::info +The proposer configuration can also be retrieved via the keymanager API endpoint: + +``` +GET /eth/v0/validator/{pubkey}/proposer_config +``` + +::: diff --git a/docs/pages/run/validator-management/vc-configuration.md b/docs/pages/run/validator-management/vc-configuration.md index ce6db52b3a66..a51791eff494 100644 --- a/docs/pages/run/validator-management/vc-configuration.md +++ b/docs/pages/run/validator-management/vc-configuration.md @@ -74,6 +74,10 @@ Configure your validator client's fee recipient address by using the [`--suggest You may choose to use the [`--strictFeeRecipientCheck`](./validator-cli.md#--strictfeerecipientcheck) flag to enable a strict check of the fee recipient address with the one returned by the beacon node for added reassurance. +:::note +If you would like to set unique proposer metadata (e.g. fee recipient address) for each validator you are running, see the [Proposer Configuration](./proposer-config.md) feature. This feature is also available via the keymanager API. +::: + ### Configure your builder selection and/or builder boost factor If you are running a beacon node with connected builder relays, you may use these validator configurations to signal which block (builder vs. local execution) the beacon node should produce. diff --git a/docs/pages/supporting-libraries/libraries.md b/docs/pages/supporting-libraries/libraries.md index e76ccc2f9ec7..58796e56cd15 100644 --- a/docs/pages/supporting-libraries/libraries.md +++ b/docs/pages/supporting-libraries/libraries.md @@ -1,13 +1,13 @@ # Lodestar libraries -The Lodestar project is divided into Typescript packages that can be used independently of the CLI. These packages span the breadth of the Ethereum Consensus layer, and are perfect for Typescript developers looking to build around Ethereum. +The Lodestar project is divided into TypeScript packages that can be used independently of the CLI. These packages span the breadth of the Ethereum Consensus layer, and are perfect for TypeScript developers looking to build around Ethereum. ## Monorepo libraries Several useful Ethereum consensus libraries are developed as part of the [Lodestar monorepo](https://github.com/ChainSafe/lodestar) and may be useful when used individually. - [`params`](https://github.com/ChainSafe/lodestar/tree/unstable/packages/params) - Ethereum consensus constants and fork names -- [`types`](https://github.com/ChainSafe/lodestar/tree/unstable/packages/types) - Ethereum consensus types, Typescript interfaces and SSZ type objects +- [`types`](https://github.com/ChainSafe/lodestar/tree/unstable/packages/types) - Ethereum consensus types, TypeScript interfaces and SSZ type objects - [`config`](https://github.com/ChainSafe/lodestar/tree/unstable/packages/config) - Ethereum consensus run-time network configuration - [`api`](https://github.com/ChainSafe/lodestar/tree/unstable/packages/api) - Ethereum consensus REST API client - [`flare`](https://github.com/ChainSafe/lodestar/tree/unstable/packages/flare) - Beacon chain multi-purpose and debugging tool diff --git a/docs/pages/trouble-shooting.md b/docs/pages/trouble-shooting.md deleted file mode 100644 index 144aeb90ce20..000000000000 --- a/docs/pages/trouble-shooting.md +++ /dev/null @@ -1 +0,0 @@ -# Trouble Shooting diff --git a/docs/sidebars.ts b/docs/sidebars.ts index d9a4839a90c4..1b6eb1ac055d 100644 --- a/docs/sidebars.ts +++ b/docs/sidebars.ts @@ -10,11 +10,18 @@ const sidebars: SidebarsConfig = { label: "Run A Node", collapsed: false, items: [ - "run/getting-started/quick-start", "run/getting-started/installation", { type: "category", - label: "Beacon node", + label: "Quick Start", + items: [ + "run/getting-started/quick-start", + "run/getting-started/quick-start-custom-guide", + ], + }, + { + type: "category", + label: "Beacon Node", items: [ "run/beacon-management/starting-a-node", "run/beacon-management/beacon-cli", @@ -31,17 +38,23 @@ const sidebars: SidebarsConfig = { "run/validator-management/vc-configuration", "run/validator-management/validator-cli", "run/validator-management/external-signer", + "run/validator-management/proposer-config", ], }, { type: "category", label: "Logging and Metrics", - items: ["run/logging-and-metrics/prometheus-grafana", "run/logging-and-metrics/client-monitoring"], + items: [ + "run/logging-and-metrics/prometheus-grafana", + "run/logging-and-metrics/client-monitoring", + ], }, { type: "category", label: "Discv5 Bootnode", - items: ["run/bootnode/bootnode-cli"], + items: [ + "run/bootnode/bootnode-cli", + ], }, ], }, diff --git a/docs/yarn.lock b/docs/yarn.lock index 046829e3530b..80cd3a321a5a 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -3684,9 +3684,9 @@ cosmiconfig@^8.3.5: path-type "^4.0.0" cross-spawn@^7.0.3: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0" diff --git a/lerna.json b/lerna.json index cdd74f75b2cf..99654f9e81de 100644 --- a/lerna.json +++ b/lerna.json @@ -4,7 +4,7 @@ ], "npmClient": "yarn", "useNx": true, - "version": "1.23.1", + "version": "1.24.0", "stream": true, "command": { "version": { diff --git a/packages/api/package.json b/packages/api/package.json index 1f4f3e7c3fdf..f650a377f6a5 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.23.1", + "version": "1.24.0", "type": "module", "exports": { ".": { @@ -72,10 +72,10 @@ "dependencies": { "@chainsafe/persistent-merkle-tree": "^0.8.0", "@chainsafe/ssz": "^0.18.0", - "@lodestar/config": "^1.23.1", - "@lodestar/params": "^1.23.1", - "@lodestar/types": "^1.23.1", - "@lodestar/utils": "^1.23.1", + "@lodestar/config": "^1.24.0", + "@lodestar/params": "^1.24.0", + "@lodestar/types": "^1.24.0", + "@lodestar/utils": "^1.24.0", "eventsource": "^2.0.2", "qs": "^6.11.1" }, diff --git a/packages/api/src/beacon/client/debug.ts b/packages/api/src/beacon/client/debug.ts index 4df3bef12cf8..c0f2514fa3eb 100644 --- a/packages/api/src/beacon/client/debug.ts +++ b/packages/api/src/beacon/client/debug.ts @@ -1,5 +1,5 @@ import {ChainForkConfig} from "@lodestar/config"; -import {ApiClientMethods, createApiClientMethods, IHttpClient} from "../../utils/client/index.js"; +import {ApiClientMethods, IHttpClient, createApiClientMethods} from "../../utils/client/index.js"; import {Endpoints, getDefinitions} from "../routes/debug.js"; export type ApiClient = ApiClientMethods; diff --git a/packages/api/src/beacon/routes/beacon/block.ts b/packages/api/src/beacon/routes/beacon/block.ts index cd3cae9fd7ff..8fadfa1b9002 100644 --- a/packages/api/src/beacon/routes/beacon/block.ts +++ b/packages/api/src/beacon/routes/beacon/block.ts @@ -1,21 +1,23 @@ import {ContainerType, ListCompositeType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; +import {ForkName, ForkPreElectra, ForkPreExecution, isForkBlobs, isForkExecution} from "@lodestar/params"; import { - Slot, - ssz, + BeaconBlockBody, RootHex, - deneb, - isSignedBlockContents, SignedBeaconBlock, - BeaconBlockBody, SignedBeaconBlockOrContents, SignedBlindedBeaconBlock, SignedBlockContents, + Slot, + deneb, + isSignedBlockContents, + ssz, sszTypesFor, } from "@lodestar/types"; -import {ForkName, ForkPreElectra, ForkPreExecution, isForkBlobs, isForkExecution} from "@lodestar/params"; -import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js"; import {EmptyMeta, EmptyResponseCodec, EmptyResponseData, WithVersion} from "../../../utils/codecs.js"; +import {getExecutionForkTypes, toForkName} from "../../../utils/fork.js"; +import {fromHeaders} from "../../../utils/headers.js"; +import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js"; import { ExecutionOptimisticAndFinalizedCodec, ExecutionOptimisticAndFinalizedMeta, @@ -23,8 +25,6 @@ import { ExecutionOptimisticFinalizedAndVersionMeta, MetaHeader, } from "../../../utils/metadata.js"; -import {getExecutionForkTypes, toForkName} from "../../../utils/fork.js"; -import {fromHeaders} from "../../../utils/headers.js"; import {WireFormat} from "../../../utils/wireFormat.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/beacon/index.ts b/packages/api/src/beacon/routes/beacon/index.ts index 39d7d995dfb1..5c4a9163a1b7 100644 --- a/packages/api/src/beacon/routes/beacon/index.ts +++ b/packages/api/src/beacon/routes/beacon/index.ts @@ -1,11 +1,11 @@ import {ChainForkConfig} from "@lodestar/config"; import {phase0, ssz} from "@lodestar/types"; +import {EmptyArgs, EmptyMeta, EmptyMetaCodec, EmptyRequest, EmptyRequestCodec} from "../../../utils/codecs.js"; import {Endpoint, RouteDefinitions} from "../../../utils/types.js"; -import {EmptyArgs, EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest} from "../../../utils/codecs.js"; import * as block from "./block.js"; import * as pool from "./pool.js"; -import * as state from "./state.js"; import * as rewards from "./rewards.js"; +import * as state from "./state.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/beacon/pool.ts b/packages/api/src/beacon/routes/beacon/pool.ts index 3f0b8ac74284..4d909c2aac7b 100644 --- a/packages/api/src/beacon/routes/beacon/pool.ts +++ b/packages/api/src/beacon/routes/beacon/pool.ts @@ -1,22 +1,22 @@ import {ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {isForkPostElectra} from "@lodestar/params"; -import {phase0, capella, CommitteeIndex, Slot, ssz, electra, AttesterSlashing} from "@lodestar/types"; -import {Schema, Endpoint, RouteDefinitions} from "../../../utils/index.js"; +import {AttesterSlashing, CommitteeIndex, Slot, capella, electra, phase0, ssz} from "@lodestar/types"; import { ArrayOf, EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, EmptyResponseCodec, EmptyResponseData, WithVersion, } from "../../../utils/codecs.js"; -import {MetaHeader, VersionCodec, VersionMeta} from "../../../utils/metadata.js"; import {toForkName} from "../../../utils/fork.js"; import {fromHeaders} from "../../../utils/headers.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../../utils/index.js"; +import {MetaHeader, VersionCodec, VersionMeta} from "../../../utils/metadata.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/beacon/rewards.ts b/packages/api/src/beacon/routes/beacon/rewards.ts index d41b5ef705f0..3acb09955cb4 100644 --- a/packages/api/src/beacon/routes/beacon/rewards.ts +++ b/packages/api/src/beacon/routes/beacon/rewards.ts @@ -2,10 +2,10 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {Epoch, ssz} from "@lodestar/types"; -import {Schema, Endpoint, RouteDefinitions} from "../../../utils/index.js"; -import {fromValidatorIdsStr, toValidatorIdsStr} from "../../../utils/serdes.js"; import {ArrayOf, JsonOnlyReq} from "../../../utils/codecs.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../../utils/index.js"; import {ExecutionOptimisticAndFinalizedCodec, ExecutionOptimisticAndFinalizedMeta} from "../../../utils/metadata.js"; +import {fromValidatorIdsStr, toValidatorIdsStr} from "../../../utils/serdes.js"; import {BlockArgs} from "./block.js"; import {ValidatorId} from "./state.js"; diff --git a/packages/api/src/beacon/routes/beacon/state.ts b/packages/api/src/beacon/routes/beacon/state.ts index 4127bb1ce793..d1284558f98f 100644 --- a/packages/api/src/beacon/routes/beacon/state.ts +++ b/packages/api/src/beacon/routes/beacon/state.ts @@ -1,9 +1,9 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params"; -import {phase0, CommitteeIndex, Slot, Epoch, ssz, RootHex, StringType, ValidatorStatus} from "@lodestar/types"; -import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js"; +import {CommitteeIndex, Epoch, RootHex, Slot, StringType, ValidatorStatus, phase0, ssz} from "@lodestar/types"; import {ArrayOf, JsonOnlyReq} from "../../../utils/codecs.js"; +import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js"; import {ExecutionOptimisticAndFinalizedCodec, ExecutionOptimisticAndFinalizedMeta} from "../../../utils/metadata.js"; import {fromValidatorIdsStr, toValidatorIdsStr} from "../../../utils/serdes.js"; import {WireFormat} from "../../../utils/wireFormat.js"; diff --git a/packages/api/src/beacon/routes/config.ts b/packages/api/src/beacon/routes/config.ts index afce0898908c..cd76c2bf41b2 100644 --- a/packages/api/src/beacon/routes/config.ts +++ b/packages/api/src/beacon/routes/config.ts @@ -4,10 +4,10 @@ import {ssz} from "@lodestar/types"; import { ArrayOf, EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, JsonOnlyResp, } from "../../utils/codecs.js"; import {Endpoint, RouteDefinitions} from "../../utils/index.js"; diff --git a/packages/api/src/beacon/routes/debug.ts b/packages/api/src/beacon/routes/debug.ts index 349684f62ccd..9afc96d5a637 100644 --- a/packages/api/src/beacon/routes/debug.ts +++ b/packages/api/src/beacon/routes/debug.ts @@ -1,22 +1,22 @@ import {ContainerType, Type, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; -import {ssz, StringType, BeaconState} from "@lodestar/types"; +import {BeaconState, StringType, ssz} from "@lodestar/types"; import { ArrayOf, EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, WithVersion, } from "../../utils/codecs.js"; import { ExecutionOptimisticFinalizedAndVersionCodec, ExecutionOptimisticFinalizedAndVersionMeta, } from "../../utils/metadata.js"; +import {Schema} from "../../utils/schema.js"; import {Endpoint, RouteDefinitions} from "../../utils/types.js"; import {WireFormat} from "../../utils/wireFormat.js"; -import {Schema} from "../../utils/schema.js"; import {StateArgs} from "./beacon/state.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/events.ts b/packages/api/src/beacon/routes/events.ts index 5fa218bc02f3..81bd6e7a7f5e 100644 --- a/packages/api/src/beacon/routes/events.ts +++ b/packages/api/src/beacon/routes/events.ts @@ -1,27 +1,27 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; +import {ForkName} from "@lodestar/params"; import { + Attestation, + AttesterSlashing, Epoch, - phase0, - capella, + LightClientFinalityUpdate, + LightClientOptimisticUpdate, + RootHex, + SSEPayloadAttributes, Slot, - ssz, StringType, - RootHex, - altair, UintNum64, - LightClientOptimisticUpdate, - LightClientFinalityUpdate, - SSEPayloadAttributes, - Attestation, - AttesterSlashing, + altair, + capella, + phase0, + ssz, sszTypesFor, } from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; -import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import {EmptyMeta, EmptyResponseCodec, EmptyResponseData} from "../../utils/codecs.js"; import {getExecutionForkTypes, getLightClientForkTypes} from "../../utils/fork.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import {VersionType} from "../../utils/metadata.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/lightclient.ts b/packages/api/src/beacon/routes/lightclient.ts index bac73b43ddb2..d3e60a69bae9 100644 --- a/packages/api/src/beacon/routes/lightclient.ts +++ b/packages/api/src/beacon/routes/lightclient.ts @@ -1,27 +1,27 @@ import {ListCompositeType, ValueOf} from "@chainsafe/ssz"; +import {BeaconConfig, ChainForkConfig, createBeaconConfig} from "@lodestar/config"; +import {NetworkName, genesisData} from "@lodestar/config/networks"; +import {ForkName, ZERO_HASH} from "@lodestar/params"; import { LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, - ssz, SyncPeriod, + ssz, } from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; -import {ForkName, ZERO_HASH} from "@lodestar/params"; -import {BeaconConfig, ChainForkConfig, createBeaconConfig} from "@lodestar/config"; -import {genesisData, NetworkName} from "@lodestar/config/networks"; -import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; -import {MetaHeader, VersionCodec, VersionMeta} from "../../utils/metadata.js"; -import {getLightClientForkTypes, toForkName} from "../../utils/fork.js"; import { EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, WithVersion, } from "../../utils/codecs.js"; +import {getLightClientForkTypes, toForkName} from "../../utils/fork.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; +import {MetaHeader, VersionCodec, VersionMeta} from "../../utils/metadata.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/lodestar.ts b/packages/api/src/beacon/routes/lodestar.ts index 1d3c62ca2082..de05b7f2bb44 100644 --- a/packages/api/src/beacon/routes/lodestar.ts +++ b/packages/api/src/beacon/routes/lodestar.ts @@ -1,15 +1,19 @@ +import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; -import {Epoch, RootHex, Slot} from "@lodestar/types"; -import {Schema, Endpoint, RouteDefinitions} from "../../utils/index.js"; +import {Epoch, RootHex, Slot, ssz} from "@lodestar/types"; import { + ArrayOf, EmptyArgs, - EmptyRequestCodec, EmptyMeta, + EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, EmptyResponseCodec, EmptyResponseData, JsonOnlyResponseCodec, } from "../../utils/codecs.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; +import {StateArgs} from "./beacon/state.js"; import {FilterGetPeers, NodePeer, PeerDirection, PeerState} from "./node.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes @@ -75,6 +79,16 @@ export type LodestarNodePeer = NodePeer & { export type LodestarThreadType = "main" | "network" | "discv5"; +const HistoricalSummariesResponseType = new ContainerType( + { + historicalSummaries: ssz.capella.HistoricalSummaries, + proof: ArrayOf(ssz.Bytes8), + }, + {jsonCase: "eth2"} +); + +export type HistoricalSummariesResponse = ValueOf; + export type Endpoints = { /** Trigger to write a heapdump to disk at `dirpath`. May take > 1min */ writeHeapdump: Endpoint< @@ -214,6 +228,16 @@ export type Endpoints = { {count: number} >; + /** Returns historical summaries and proof for a given state ID */ + getHistoricalSummaries: Endpoint< + // ⏎ + "GET", + StateArgs, + {params: {state_id: string}}, + HistoricalSummariesResponse, + EmptyMeta + >; + /** Dump Discv5 Kad values */ discv5GetKadValues: Endpoint< // ⏎ @@ -365,6 +389,21 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions ({params: {state_id: stateId.toString()}}), + parseReq: ({params}) => ({stateId: params.state_id}), + schema: { + params: {state_id: Schema.StringRequired}, + }, + }, + resp: { + data: HistoricalSummariesResponseType, + meta: EmptyMetaCodec, + }, + }, discv5GetKadValues: { url: "/eth/v1/debug/discv5_kad_values", method: "GET", diff --git a/packages/api/src/beacon/routes/node.ts b/packages/api/src/beacon/routes/node.ts index c7a6c2e36361..e98c0f42ec56 100644 --- a/packages/api/src/beacon/routes/node.ts +++ b/packages/api/src/beacon/routes/node.ts @@ -1,19 +1,19 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {ssz, stringType} from "@lodestar/types"; -import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import { ArrayOf, EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, EmptyResponseCodec, EmptyResponseData, JsonOnlyResponseCodec, } from "../../utils/codecs.js"; import {HttpStatusCode} from "../../utils/httpStatusCode.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import {WireFormat} from "../../utils/wireFormat.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/routes/proof.ts b/packages/api/src/beacon/routes/proof.ts index 0c6d5a058cea..63f6765e3873 100644 --- a/packages/api/src/beacon/routes/proof.ts +++ b/packages/api/src/beacon/routes/proof.ts @@ -1,10 +1,10 @@ import {CompactMultiProof, ProofType} from "@chainsafe/persistent-merkle-tree"; import {ByteListType, ContainerType} from "@chainsafe/ssz"; -import {fromHex, toHex} from "@lodestar/utils"; import {ChainForkConfig} from "@lodestar/config"; import {ssz} from "@lodestar/types"; -import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; +import {fromHex, toHex} from "@lodestar/utils"; import {ArrayOf} from "../../utils/codecs.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import {VersionCodec, VersionMeta} from "../../utils/metadata.js"; export const CompactMultiProofType = new ContainerType({ diff --git a/packages/api/src/beacon/routes/validator.ts b/packages/api/src/beacon/routes/validator.ts index cf30d5748a46..313459f4db97 100644 --- a/packages/api/src/beacon/routes/validator.ts +++ b/packages/api/src/beacon/routes/validator.ts @@ -2,27 +2,24 @@ import {ContainerType, Type, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {isForkBlobs, isForkPostElectra} from "@lodestar/params"; import { - altair, + Attestation, BLSSignature, + BeaconBlockOrContents, + BlindedBeaconBlock, CommitteeIndex, Epoch, - phase0, + ProducedBlockSource, Root, Slot, - ssz, UintBn64, ValidatorIndex, - ProducedBlockSource, - stringType, - BeaconBlockOrContents, - BlindedBeaconBlock, - Attestation, + altair, + phase0, + ssz, sszTypesFor, + stringType, } from "@lodestar/types"; import {fromHex, toHex, toRootHex} from "@lodestar/utils"; -import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; -import {fromGraffitiHex, toBoolean, toGraffitiHex} from "../../utils/serdes.js"; -import {getExecutionForkTypes, toForkName} from "../../utils/fork.js"; import { ArrayOf, EmptyMeta, @@ -33,6 +30,9 @@ import { WithMeta, WithVersion, } from "../../utils/codecs.js"; +import {getExecutionForkTypes, toForkName} from "../../utils/fork.js"; +import {fromHeaders} from "../../utils/headers.js"; +import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js"; import { ExecutionOptimisticAndDependentRootCodec, ExecutionOptimisticAndDependentRootMeta, @@ -43,7 +43,7 @@ import { VersionMeta, VersionType, } from "../../utils/metadata.js"; -import {fromHeaders} from "../../utils/headers.js"; +import {fromGraffitiHex, toBoolean, toGraffitiHex} from "../../utils/serdes.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/beacon/server/events.ts b/packages/api/src/beacon/server/events.ts index b9027ab1879d..a68edb6c4146 100644 --- a/packages/api/src/beacon/server/events.ts +++ b/packages/api/src/beacon/server/events.ts @@ -1,6 +1,6 @@ import {ChainForkConfig} from "@lodestar/config"; import {ApiError, ApplicationMethods, FastifyRoutes, createFastifyRoutes} from "../../utils/server/index.js"; -import {Endpoints, getDefinitions, eventTypes, getEventSerdes} from "../routes/events.js"; +import {Endpoints, eventTypes, getDefinitions, getEventSerdes} from "../routes/events.js"; export function getRoutes(config: ChainForkConfig, methods: ApplicationMethods): FastifyRoutes { const eventSerdes = getEventSerdes(config); diff --git a/packages/api/src/beacon/server/index.ts b/packages/api/src/beacon/server/index.ts index 304f4d42be17..cc5005aa2740 100644 --- a/packages/api/src/beacon/server/index.ts +++ b/packages/api/src/beacon/server/index.ts @@ -1,5 +1,5 @@ -import type {FastifyInstance} from "fastify"; import {ChainForkConfig} from "@lodestar/config"; +import type {FastifyInstance} from "fastify"; import {ApplicationMethods, FastifyRoute} from "../../utils/server/index.js"; import {Endpoints} from "../routes/index.js"; diff --git a/packages/api/src/builder/index.ts b/packages/api/src/builder/index.ts index d1d9d31a17ab..9497cd5e95ba 100644 --- a/packages/api/src/builder/index.ts +++ b/packages/api/src/builder/index.ts @@ -1,7 +1,7 @@ import {ChainForkConfig} from "@lodestar/config"; import {HttpClient, HttpClientModules, HttpClientOptions, IHttpClient} from "../utils/client/httpClient.js"; -import {Endpoints} from "./routes.js"; import type {ApiClient} from "./client.js"; +import {Endpoints} from "./routes.js"; import * as builder from "./client.js"; diff --git a/packages/api/src/builder/routes.ts b/packages/api/src/builder/routes.ts index 3911a515e1c6..91042539f96b 100644 --- a/packages/api/src/builder/routes.ts +++ b/packages/api/src/builder/routes.ts @@ -1,27 +1,25 @@ +import {ChainForkConfig} from "@lodestar/config"; +import {ForkName, isForkBlobs} from "@lodestar/params"; import { - ssz, - bellatrix, - Slot, - Root, BLSPubkey, ExecutionPayload, ExecutionPayloadAndBlobsBundle, + Root, SignedBlindedBeaconBlock, SignedBuilderBid, + Slot, WithOptionalBytes, + bellatrix, + ssz, } from "@lodestar/types"; -import {ForkName, isForkBlobs} from "@lodestar/params"; -import {ChainForkConfig} from "@lodestar/config"; import {fromHex, toPubkeyHex, toRootHex} from "@lodestar/utils"; -import {Endpoint, RouteDefinitions, Schema} from "../utils/index.js"; -import {MetaHeader, VersionCodec, VersionMeta} from "../utils/metadata.js"; import { ArrayOf, EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyRequest, + EmptyRequestCodec, EmptyResponseCodec, EmptyResponseData, JsonOnlyReq, @@ -29,6 +27,8 @@ import { } from "../utils/codecs.js"; import {getBlobsForkTypes, getExecutionForkTypes, toForkName} from "../utils/fork.js"; import {fromHeaders} from "../utils/headers.js"; +import {Endpoint, RouteDefinitions, Schema} from "../utils/index.js"; +import {MetaHeader, VersionCodec, VersionMeta} from "../utils/metadata.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes diff --git a/packages/api/src/builder/server/index.ts b/packages/api/src/builder/server/index.ts index 888d6bb64bec..5e59e5d9807b 100644 --- a/packages/api/src/builder/server/index.ts +++ b/packages/api/src/builder/server/index.ts @@ -1,8 +1,8 @@ -import type {FastifyInstance} from "fastify"; import {ChainForkConfig} from "@lodestar/config"; +import type {FastifyInstance} from "fastify"; +import {AnyEndpoint} from "../../utils/codecs.js"; import {ApplicationMethods, FastifyRoute, FastifyRoutes, createFastifyRoutes} from "../../utils/server/index.js"; import {Endpoints, getDefinitions} from "../routes.js"; -import {AnyEndpoint} from "../../utils/codecs.js"; export type BuilderApiMethods = ApplicationMethods; diff --git a/packages/api/src/keymanager/index.ts b/packages/api/src/keymanager/index.ts index 1ffcaef897eb..24e7e08da444 100644 --- a/packages/api/src/keymanager/index.ts +++ b/packages/api/src/keymanager/index.ts @@ -1,5 +1,5 @@ import {ChainForkConfig} from "@lodestar/config"; -import {IHttpClient, HttpClient, HttpClientModules, HttpClientOptions} from "../utils/client/index.js"; +import {HttpClient, HttpClientModules, HttpClientOptions, IHttpClient} from "../utils/client/index.js"; import type {ApiClient} from "./client.js"; import * as keymanager from "./client.js"; @@ -18,6 +18,7 @@ export type { GraffitiData, GasLimitData, BuilderBoostFactorData, + ProposerConfigResponse, } from "./routes.js"; export type {ApiClient}; diff --git a/packages/api/src/keymanager/routes.ts b/packages/api/src/keymanager/routes.ts index 0db096d14e83..05eddeefd604 100644 --- a/packages/api/src/keymanager/routes.ts +++ b/packages/api/src/keymanager/routes.ts @@ -1,19 +1,19 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {Epoch, phase0, ssz, stringType} from "@lodestar/types"; -import {Schema, Endpoint, RouteDefinitions} from "../utils/index.js"; -import {WireFormat} from "../utils/wireFormat.js"; import { EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyMetaCodec, EmptyRequest, + EmptyRequestCodec, EmptyResponseCodec, EmptyResponseData, JsonOnlyReq, JsonOnlyResponseCodec, } from "../utils/codecs.js"; +import {Endpoint, RouteDefinitions, Schema} from "../utils/index.js"; +import {WireFormat} from "../utils/wireFormat.js"; export enum ImportStatus { /** Keystore successfully decrypted and imported to keymanager permanent storage */ @@ -109,6 +109,17 @@ export type SignerDefinition = { export type RemoteSignerDefinition = Pick; +export type ProposerConfigResponse = { + graffiti?: string; + strictFeeRecipientCheck?: boolean; + feeRecipient?: string; + builder?: { + gasLimit?: number; + selection?: string; + boostFactor?: string; + }; +}; + /** * JSON serialized representation of a single keystore in EIP-2335: BLS12-381 Keystore format. * ``` @@ -356,6 +367,15 @@ export type Endpoints = { EmptyMeta >; + getProposerConfig: Endpoint< + // ⏎ + "GET", + {pubkey: PubkeyHex}, + {params: {pubkey: string}}, + ProposerConfigResponse, + EmptyMeta + >; + /** * Create a signed voluntary exit message for an active validator, identified by a public key known to the validator * client. This endpoint returns a `SignedVoluntaryExit` object, which can be used to initiate voluntary exit via the @@ -635,6 +655,19 @@ export function getDefinitions(_config: ChainForkConfig): RouteDefinitions ({params: {pubkey}}), + parseReq: ({params: {pubkey}}) => ({pubkey}), + schema: { + params: {pubkey: Schema.StringRequired}, + }, + }, + resp: JsonOnlyResponseCodec, + }, + signVoluntaryExit: { url: "/eth/v1/validator/{pubkey}/voluntary_exit", method: "POST", diff --git a/packages/api/src/keymanager/server/index.ts b/packages/api/src/keymanager/server/index.ts index f4d0e75f971e..065bcb5ac5d8 100644 --- a/packages/api/src/keymanager/server/index.ts +++ b/packages/api/src/keymanager/server/index.ts @@ -1,8 +1,8 @@ -import type {FastifyInstance} from "fastify"; import {ChainForkConfig} from "@lodestar/config"; +import type {FastifyInstance} from "fastify"; +import {AnyEndpoint} from "../../utils/codecs.js"; import {ApplicationMethods, FastifyRoute, FastifyRoutes, createFastifyRoutes} from "../../utils/server/index.js"; import {Endpoints, getDefinitions} from "../routes.js"; -import {AnyEndpoint} from "../../utils/codecs.js"; export type KeymanagerApiMethods = ApplicationMethods; diff --git a/packages/api/src/utils/client/httpClient.ts b/packages/api/src/utils/client/httpClient.ts index 33b93e3a9d41..85585e8f40f7 100644 --- a/packages/api/src/utils/client/httpClient.ts +++ b/packages/api/src/utils/client/httpClient.ts @@ -1,8 +1,10 @@ import {ErrorAborted, Logger, MapDef, TimeoutError, isValidHttpUrl, retry, toPrintableUrl} from "@lodestar/utils"; import {mergeHeaders} from "../headers.js"; +import {HttpStatusCode} from "../httpStatusCode.js"; import {Endpoint} from "../types.js"; import {WireFormat} from "../wireFormat.js"; -import {HttpStatusCode} from "../httpStatusCode.js"; +import {fetch, isFetchError} from "./fetch.js"; +import {Metrics} from "./metrics.js"; import { ApiRequestInit, ApiRequestInitRequired, @@ -13,8 +15,6 @@ import { createApiRequest, } from "./request.js"; import {ApiResponse} from "./response.js"; -import {Metrics} from "./metrics.js"; -import {fetch, isFetchError} from "./fetch.js"; /** A higher default timeout, validator will set its own shorter timeoutMs */ const DEFAULT_TIMEOUT_MS = 60_000; diff --git a/packages/api/src/utils/codecs.ts b/packages/api/src/utils/codecs.ts index c075d8592a46..fad6396af085 100644 --- a/packages/api/src/utils/codecs.ts +++ b/packages/api/src/utils/codecs.ts @@ -2,12 +2,12 @@ import {ArrayType, ListBasicType, ListCompositeType, Type, isBasicType, isCompos import {ForkName} from "@lodestar/params"; import {objectToExpectedCase} from "@lodestar/utils"; import { - RequestWithoutBodyCodec, + Endpoint, RequestWithBodyCodec, + RequestWithoutBodyCodec, ResponseCodec, ResponseDataCodec, ResponseMetadataCodec, - Endpoint, SszRequestMethods, } from "./types.js"; import {WireFormat} from "./wireFormat.js"; diff --git a/packages/api/src/utils/metadata.ts b/packages/api/src/utils/metadata.ts index 2ee9b2f51f0e..6186c06a7047 100644 --- a/packages/api/src/utils/metadata.ts +++ b/packages/api/src/utils/metadata.ts @@ -1,10 +1,10 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ForkName} from "@lodestar/params"; import {StringType, ssz, stringType} from "@lodestar/types"; -import {ResponseMetadataCodec} from "./types.js"; -import {toBoolean} from "./serdes.js"; import {toForkName} from "./fork.js"; import {HttpHeader} from "./headers.js"; +import {toBoolean} from "./serdes.js"; +import {ResponseMetadataCodec} from "./types.js"; export const VersionType = new ContainerType({ /** diff --git a/packages/api/src/utils/server/handler.ts b/packages/api/src/utils/server/handler.ts index 035f4328141a..b444d263cf09 100644 --- a/packages/api/src/utils/server/handler.ts +++ b/packages/api/src/utils/server/handler.ts @@ -2,15 +2,15 @@ import type * as fastify from "fastify"; import {HttpHeader, MediaType, SUPPORTED_MEDIA_TYPES, parseAcceptHeader, parseContentTypeHeader} from "../headers.js"; import { Endpoint, - RequestData, JsonRequestData, JsonRequestMethods, + RequestData, RequestWithBodyCodec, + RequestWithoutBodyCodec, RouteDefinition, SszRequestData, SszRequestMethods, isRequestWithoutBody, - RequestWithoutBodyCodec, } from "../types.js"; import {WireFormat, fromWireFormat, getWireFormat} from "../wireFormat.js"; import {ApiError} from "./error.js"; diff --git a/packages/api/src/utils/server/route.ts b/packages/api/src/utils/server/route.ts index aa04a1f11cf7..26bf07b6790e 100644 --- a/packages/api/src/utils/server/route.ts +++ b/packages/api/src/utils/server/route.ts @@ -1,5 +1,5 @@ -import type * as fastify from "fastify"; import {mapValues} from "@lodestar/utils"; +import type * as fastify from "fastify"; import {getFastifySchema} from "../schema.js"; import {Endpoint, RouteDefinition, RouteDefinitions} from "../types.js"; import {toColonNotationPath} from "../urlFormat.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/beacon.test.ts b/packages/api/test/unit/beacon/genericServerTest/beacon.test.ts index f8c13b33afb6..5f2c2d4d50e7 100644 --- a/packages/api/test/unit/beacon/genericServerTest/beacon.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/beacon.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {Endpoints} from "../../../../src/beacon/routes/beacon/index.js"; +import {describe} from "vitest"; import {getClient} from "../../../../src/beacon/client/beacon.js"; +import {Endpoints} from "../../../../src/beacon/routes/beacon/index.js"; import {getRoutes} from "../../../../src/beacon/server/beacon.js"; import {runGenericServerTest} from "../../../utils/genericServerTest.js"; import {testData} from "../testData/beacon.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/config.test.ts b/packages/api/test/unit/beacon/genericServerTest/config.test.ts index 91075f96d1e3..a66eb1768e2c 100644 --- a/packages/api/test/unit/beacon/genericServerTest/config.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/config.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; import {config} from "@lodestar/config/default"; -import {Endpoints, getDefinitions} from "../../../../src/beacon/routes/config.js"; +import {describe, expect, it} from "vitest"; import {getClient} from "../../../../src/beacon/client/config.js"; +import {Endpoints, getDefinitions} from "../../../../src/beacon/routes/config.js"; import {getRoutes} from "../../../../src/beacon/server/config.js"; import {runGenericServerTest} from "../../../utils/genericServerTest.js"; import {testData} from "../testData/config.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/debug.test.ts b/packages/api/test/unit/beacon/genericServerTest/debug.test.ts index f329382dbe46..d6140fa20512 100644 --- a/packages/api/test/unit/beacon/genericServerTest/debug.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/debug.test.ts @@ -1,19 +1,19 @@ -import {describe, it, expect, beforeAll, afterAll, vi} from "vitest"; import {toHexString} from "@chainsafe/ssz"; -import {FastifyInstance} from "fastify"; +import {config} from "@lodestar/config/default"; import {ForkName} from "@lodestar/params"; import {ssz} from "@lodestar/types"; -import {config} from "@lodestar/config/default"; -import {Endpoints, getDefinitions} from "../../../../src/beacon/routes/debug.js"; +import {FastifyInstance} from "fastify"; +import {afterAll, beforeAll, describe, expect, it, vi} from "vitest"; import {getClient} from "../../../../src/beacon/client/debug.js"; +import {Endpoints, getDefinitions} from "../../../../src/beacon/routes/debug.js"; import {getRoutes} from "../../../../src/beacon/server/debug.js"; -import {runGenericServerTest} from "../../../utils/genericServerTest.js"; -import {getMockApi, getTestServer} from "../../../utils/utils.js"; import {HttpClient} from "../../../../src/utils/client/httpClient.js"; -import {testData} from "../testData/debug.js"; -import {FastifyRoute} from "../../../../src/utils/server/index.js"; import {AnyEndpoint} from "../../../../src/utils/codecs.js"; +import {FastifyRoute} from "../../../../src/utils/server/index.js"; import {WireFormat} from "../../../../src/utils/wireFormat.js"; +import {runGenericServerTest} from "../../../utils/genericServerTest.js"; +import {getMockApi, getTestServer} from "../../../utils/utils.js"; +import {testData} from "../testData/debug.js"; describe("beacon / debug", () => { // Extend timeout since states are very big diff --git a/packages/api/test/unit/beacon/genericServerTest/events.test.ts b/packages/api/test/unit/beacon/genericServerTest/events.test.ts index 16123ec624e8..c0480c8368c9 100644 --- a/packages/api/test/unit/beacon/genericServerTest/events.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/events.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect, beforeEach, afterEach, beforeAll, afterAll} from "vitest"; -import {FastifyInstance} from "fastify"; -import {sleep} from "@lodestar/utils"; import {config} from "@lodestar/config/default"; -import {Endpoints, getDefinitions, EventType, BeaconEvent} from "../../../../src/beacon/routes/events.js"; +import {sleep} from "@lodestar/utils"; +import {FastifyInstance} from "fastify"; +import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from "vitest"; import {getClient} from "../../../../src/beacon/client/events.js"; +import {BeaconEvent, Endpoints, EventType, getDefinitions} from "../../../../src/beacon/routes/events.js"; import {getRoutes} from "../../../../src/beacon/server/events.js"; import {getMockApi, getTestServer} from "../../../utils/utils.js"; import {eventTestData} from "../testData/events.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/lightclient.test.ts b/packages/api/test/unit/beacon/genericServerTest/lightclient.test.ts index 5bf8b7827161..84c06d2a0d17 100644 --- a/packages/api/test/unit/beacon/genericServerTest/lightclient.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/lightclient.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {config} from "@lodestar/config/default"; -import {Endpoints} from "../../../../src/beacon/routes/lightclient.js"; +import {describe} from "vitest"; import {getClient} from "../../../../src/beacon/client/lightclient.js"; +import {Endpoints} from "../../../../src/beacon/routes/lightclient.js"; import {getRoutes} from "../../../../src/beacon/server/lightclient.js"; import {runGenericServerTest} from "../../../utils/genericServerTest.js"; import {testData} from "../testData/lightclient.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/lodestar.test.ts b/packages/api/test/unit/beacon/genericServerTest/lodestar.test.ts new file mode 100644 index 000000000000..b0f78f4bd62c --- /dev/null +++ b/packages/api/test/unit/beacon/genericServerTest/lodestar.test.ts @@ -0,0 +1,53 @@ +import {config} from "@lodestar/config/default"; +import {FastifyInstance} from "fastify"; +import {afterAll, beforeAll, describe, expect, it, vi} from "vitest"; +import {getClient} from "../../../../src/beacon/client/lodestar.js"; +import {Endpoints, getDefinitions} from "../../../../src/beacon/routes/lodestar.js"; +import {getRoutes} from "../../../../src/beacon/server/lodestar.js"; +import {HttpClient} from "../../../../src/utils/client/httpClient.js"; +import {AnyEndpoint} from "../../../../src/utils/codecs.js"; +import {FastifyRoute} from "../../../../src/utils/server/index.js"; +import {WireFormat} from "../../../../src/utils/wireFormat.js"; +import {getMockApi, getTestServer} from "../../../utils/utils.js"; + +describe("beacon / lodestar", () => { + describe("get HistoricalSummaries as json", () => { + const mockApi = getMockApi(getDefinitions(config)); + let baseUrl: string; + let server: FastifyInstance; + + beforeAll(async () => { + const res = getTestServer(); + server = res.server; + for (const route of Object.values(getRoutes(config, mockApi))) { + server.route(route as FastifyRoute); + } + baseUrl = await res.start(); + }); + + afterAll(async () => { + if (server !== undefined) await server.close(); + }); + + it("getHistoricalSummaries", async () => { + mockApi.getHistoricalSummaries.mockResolvedValue({ + data: { + historicalSummaries: [], + proof: [], + }, + }); + + const httpClient = new HttpClient({baseUrl}); + const client = getClient(config, httpClient); + + const res = await client.getHistoricalSummaries({stateId: "head"}, {responseWireFormat: WireFormat.json}); + + expect(res.ok).toBe(true); + expect(res.wireFormat()).toBe(WireFormat.json); + expect(res.json().data).toStrictEqual({ + historical_summaries: [], + proof: [], + }); + }); + }); +}); diff --git a/packages/api/test/unit/beacon/genericServerTest/node.test.ts b/packages/api/test/unit/beacon/genericServerTest/node.test.ts index 0affaf014c4a..c54737b387ae 100644 --- a/packages/api/test/unit/beacon/genericServerTest/node.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/node.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {config} from "@lodestar/config/default"; -import {Endpoints} from "../../../../src/beacon/routes/node.js"; +import {describe} from "vitest"; import {getClient} from "../../../../src/beacon/client/node.js"; +import {Endpoints} from "../../../../src/beacon/routes/node.js"; import {getRoutes} from "../../../../src/beacon/server/node.js"; import {runGenericServerTest} from "../../../utils/genericServerTest.js"; import {testData} from "../testData/node.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/proofs.test.ts b/packages/api/test/unit/beacon/genericServerTest/proofs.test.ts index d31137886e2f..518c3f70381d 100644 --- a/packages/api/test/unit/beacon/genericServerTest/proofs.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/proofs.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {config} from "@lodestar/config/default"; -import {Endpoints} from "../../../../src/beacon/routes/proof.js"; +import {describe} from "vitest"; import {getClient} from "../../../../src/beacon/client/proof.js"; +import {Endpoints} from "../../../../src/beacon/routes/proof.js"; import {getRoutes} from "../../../../src/beacon/server/proof.js"; import {runGenericServerTest} from "../../../utils/genericServerTest.js"; import {testData} from "../testData/proofs.js"; diff --git a/packages/api/test/unit/beacon/genericServerTest/validator.test.ts b/packages/api/test/unit/beacon/genericServerTest/validator.test.ts index 0aed65cd6f17..650bc6c8f9a2 100644 --- a/packages/api/test/unit/beacon/genericServerTest/validator.test.ts +++ b/packages/api/test/unit/beacon/genericServerTest/validator.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {config} from "@lodestar/config/default"; -import {Endpoints} from "../../../../src/beacon/routes/validator.js"; +import {describe} from "vitest"; import {getClient} from "../../../../src/beacon/client/validator.js"; +import {Endpoints} from "../../../../src/beacon/routes/validator.js"; import {getRoutes} from "../../../../src/beacon/server/validator.js"; import {runGenericServerTest} from "../../../utils/genericServerTest.js"; import {testData} from "../testData/validator.js"; diff --git a/packages/api/test/unit/beacon/oapiSpec.test.ts b/packages/api/test/unit/beacon/oapiSpec.test.ts index f6a38505e264..a3033355c984 100644 --- a/packages/api/test/unit/beacon/oapiSpec.test.ts +++ b/packages/api/test/unit/beacon/oapiSpec.test.ts @@ -1,11 +1,11 @@ import path from "node:path"; import {fileURLToPath} from "node:url"; -import {describe, it, beforeAll, expect} from "vitest"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {OpenApiFile} from "../../utils/parseOpenApiSpec.js"; +import {beforeAll, describe, expect, it} from "vitest"; import {routes} from "../../../src/beacon/index.js"; import {IgnoredProperty, runTestCheckAgainstSpec} from "../../utils/checkAgainstSpec.js"; import {fetchOpenApiSpec} from "../../utils/fetchOpenApiSpec.js"; +import {OpenApiFile} from "../../utils/parseOpenApiSpec.js"; // Import all testData and merge below import {testData as beaconTestData} from "./testData/beacon.js"; import {testData as configTestData} from "./testData/config.js"; diff --git a/packages/api/test/unit/beacon/testData/config.ts b/packages/api/test/unit/beacon/testData/config.ts index dddc90ae6b25..ab0437650df7 100644 --- a/packages/api/test/unit/beacon/testData/config.ts +++ b/packages/api/test/unit/beacon/testData/config.ts @@ -1,7 +1,7 @@ -import {ssz} from "@lodestar/types"; import {chainConfigToJson} from "@lodestar/config"; import {chainConfig} from "@lodestar/config/default"; import {activePreset, presetToJson} from "@lodestar/params"; +import {ssz} from "@lodestar/types"; import {Endpoints} from "../../../../src/beacon/routes/config.js"; import {GenericServerTestCases} from "../../../utils/genericServerTest.js"; diff --git a/packages/api/test/unit/beacon/testData/events.ts b/packages/api/test/unit/beacon/testData/events.ts index 3d2ffb708965..c9ba39d24efe 100644 --- a/packages/api/test/unit/beacon/testData/events.ts +++ b/packages/api/test/unit/beacon/testData/events.ts @@ -1,5 +1,5 @@ -import {ssz} from "@lodestar/types"; import {ForkName} from "@lodestar/params"; +import {ssz} from "@lodestar/types"; import {Endpoints, EventData, EventType, blobSidecarSSE} from "../../../../src/beacon/routes/events.js"; import {GenericServerTestCases} from "../../../utils/genericServerTest.js"; diff --git a/packages/api/test/unit/beacon/testData/lightclient.ts b/packages/api/test/unit/beacon/testData/lightclient.ts index f405d514fc5d..715f823a1d29 100644 --- a/packages/api/test/unit/beacon/testData/lightclient.ts +++ b/packages/api/test/unit/beacon/testData/lightclient.ts @@ -1,6 +1,6 @@ import {toHexString} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; import {ForkName} from "@lodestar/params"; +import {ssz} from "@lodestar/types"; import {Endpoints} from "../../../../src/beacon/routes/lightclient.js"; import {GenericServerTestCases} from "../../../utils/genericServerTest.js"; diff --git a/packages/api/test/unit/beacon/testData/validator.ts b/packages/api/test/unit/beacon/testData/validator.ts index d4fae4bfe290..327100cedab1 100644 --- a/packages/api/test/unit/beacon/testData/validator.ts +++ b/packages/api/test/unit/beacon/testData/validator.ts @@ -1,5 +1,5 @@ import {ForkName} from "@lodestar/params"; -import {ssz, ProducedBlockSource} from "@lodestar/types"; +import {ProducedBlockSource, ssz} from "@lodestar/types"; import {BuilderSelection, Endpoints} from "../../../../src/beacon/routes/validator.js"; import {GenericServerTestCases} from "../../../utils/genericServerTest.js"; diff --git a/packages/api/test/unit/builder/builder.test.ts b/packages/api/test/unit/builder/builder.test.ts index d2e25916069e..00a38563a100 100644 --- a/packages/api/test/unit/builder/builder.test.ts +++ b/packages/api/test/unit/builder/builder.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {Endpoints} from "../../../src/builder/routes.js"; +import {describe} from "vitest"; import {getClient} from "../../../src/builder/client.js"; +import {Endpoints} from "../../../src/builder/routes.js"; import {getRoutes} from "../../../src/builder/server/index.js"; import {runGenericServerTest} from "../../utils/genericServerTest.js"; import {testData} from "./testData.js"; diff --git a/packages/api/test/unit/builder/oapiSpec.test.ts b/packages/api/test/unit/builder/oapiSpec.test.ts index d972b64905e5..8f567a5c0e1e 100644 --- a/packages/api/test/unit/builder/oapiSpec.test.ts +++ b/packages/api/test/unit/builder/oapiSpec.test.ts @@ -2,10 +2,10 @@ import path from "node:path"; import {fileURLToPath} from "node:url"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {OpenApiFile} from "../../utils/parseOpenApiSpec.js"; import {getDefinitions} from "../../../src/builder/routes.js"; import {runTestCheckAgainstSpec} from "../../utils/checkAgainstSpec.js"; import {fetchOpenApiSpec} from "../../utils/fetchOpenApiSpec.js"; +import {OpenApiFile} from "../../utils/parseOpenApiSpec.js"; import {testData} from "./testData.js"; // Global variable __dirname no longer available in ES6 modules. diff --git a/packages/api/test/unit/builder/testData.ts b/packages/api/test/unit/builder/testData.ts index a807620258df..ad0ce95f5a8b 100644 --- a/packages/api/test/unit/builder/testData.ts +++ b/packages/api/test/unit/builder/testData.ts @@ -1,6 +1,6 @@ import {fromHexString} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; import {ForkName} from "@lodestar/params"; +import {ssz} from "@lodestar/types"; import {Endpoints} from "../../../src/builder/routes.js"; import {GenericServerTestCases} from "../../utils/genericServerTest.js"; diff --git a/packages/api/test/unit/client/fetch.test.ts b/packages/api/test/unit/client/fetch.test.ts index 1faf7d979a02..067e97e4ba6a 100644 --- a/packages/api/test/unit/client/fetch.test.ts +++ b/packages/api/test/unit/client/fetch.test.ts @@ -1,6 +1,6 @@ import crypto from "node:crypto"; import http from "node:http"; -import {describe, it, expect, afterEach} from "vitest"; +import {afterEach, describe, expect, it} from "vitest"; import {FetchError, FetchErrorType, fetch} from "../../../src/utils/client/fetch.js"; describe("FetchError", () => { diff --git a/packages/api/test/unit/client/httpClient.test.ts b/packages/api/test/unit/client/httpClient.test.ts index 577b860c4cca..aa689967f7b4 100644 --- a/packages/api/test/unit/client/httpClient.test.ts +++ b/packages/api/test/unit/client/httpClient.test.ts @@ -1,26 +1,26 @@ import {IncomingMessage} from "node:http"; -import {describe, it, afterEach, expect, vi} from "vitest"; -import {RouteOptions, fastify} from "fastify"; import {BooleanType, ContainerType, UintNumberType, ValueOf} from "@chainsafe/ssz"; import {ErrorAborted, TimeoutError, toBase64} from "@lodestar/utils"; +import {RouteOptions, fastify} from "fastify"; +import {afterEach, describe, expect, it, vi} from "vitest"; +import {WireFormat} from "../../../src/index.js"; +import {addSszContentTypeParser} from "../../../src/server/index.js"; import {HttpClient, RouteDefinitionExtra} from "../../../src/utils/client/index.js"; -import {HttpStatusCode} from "../../../src/utils/httpStatusCode.js"; import { AnyEndpoint, EmptyArgs, - EmptyRequestCodec, EmptyMeta, EmptyRequest, + EmptyRequestCodec, EmptyResponseCodec, + EmptyResponseData, JsonOnlyReq, JsonOnlyResponseCodec, - EmptyResponseData, } from "../../../src/utils/codecs.js"; -import {compileRouteUrlFormatter} from "../../../src/utils/urlFormat.js"; -import {Endpoint, Schema} from "../../../src/utils/index.js"; -import {WireFormat} from "../../../src/index.js"; import {HttpHeader, MediaType} from "../../../src/utils/headers.js"; -import {addSszContentTypeParser} from "../../../src/server/index.js"; +import {HttpStatusCode} from "../../../src/utils/httpStatusCode.js"; +import {Endpoint, Schema} from "../../../src/utils/index.js"; +import {compileRouteUrlFormatter} from "../../../src/utils/urlFormat.js"; /* eslint-disable @typescript-eslint/return-await */ diff --git a/packages/api/test/unit/client/httpClientOptions.test.ts b/packages/api/test/unit/client/httpClientOptions.test.ts index 9bc7ab2bfaf8..b2eb374e26c9 100644 --- a/packages/api/test/unit/client/httpClientOptions.test.ts +++ b/packages/api/test/unit/client/httpClientOptions.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {HttpClient} from "../../../src/index.js"; describe("HTTPClient options", () => { diff --git a/packages/api/test/unit/client/urlFormat.test.ts b/packages/api/test/unit/client/urlFormat.test.ts index 5132044b7631..a97a2dfe94a1 100644 --- a/packages/api/test/unit/client/urlFormat.test.ts +++ b/packages/api/test/unit/client/urlFormat.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import { - compileRouteUrlFormatter, - toColonNotationPath, Token, TokenType, + compileRouteUrlFormatter, + toColonNotationPath, urlToTokens, } from "../../../src/utils/urlFormat.js"; diff --git a/packages/api/test/unit/keymanager/keymanager.test.ts b/packages/api/test/unit/keymanager/keymanager.test.ts index 42e6a3dbf511..64778dcab7fc 100644 --- a/packages/api/test/unit/keymanager/keymanager.test.ts +++ b/packages/api/test/unit/keymanager/keymanager.test.ts @@ -1,7 +1,7 @@ -import {describe} from "vitest"; import {config} from "@lodestar/config/default"; -import {Endpoints} from "../../../src/keymanager/routes.js"; +import {describe} from "vitest"; import {getClient} from "../../../src/keymanager/client.js"; +import {Endpoints} from "../../../src/keymanager/routes.js"; import {getRoutes} from "../../../src/keymanager/server/index.js"; import {runGenericServerTest} from "../../utils/genericServerTest.js"; import {testData} from "./testData.js"; diff --git a/packages/api/test/unit/keymanager/oapiSpec.test.ts b/packages/api/test/unit/keymanager/oapiSpec.test.ts index aab4e1823ab0..d3817598029b 100644 --- a/packages/api/test/unit/keymanager/oapiSpec.test.ts +++ b/packages/api/test/unit/keymanager/oapiSpec.test.ts @@ -1,10 +1,10 @@ import path from "node:path"; import {fileURLToPath} from "node:url"; import {config} from "@lodestar/config/default"; -import {OpenApiFile} from "../../utils/parseOpenApiSpec.js"; import {getDefinitions} from "../../../src/keymanager/routes.js"; import {runTestCheckAgainstSpec} from "../../utils/checkAgainstSpec.js"; import {fetchOpenApiSpec} from "../../utils/fetchOpenApiSpec.js"; +import {OpenApiFile} from "../../utils/parseOpenApiSpec.js"; import {testData} from "./testData.js"; // Global variable __dirname no longer available in ES6 modules. diff --git a/packages/api/test/unit/keymanager/testData.ts b/packages/api/test/unit/keymanager/testData.ts index bd37798c4685..6b17611d1e0b 100644 --- a/packages/api/test/unit/keymanager/testData.ts +++ b/packages/api/test/unit/keymanager/testData.ts @@ -112,4 +112,19 @@ export const testData: GenericServerTestCases = { args: {pubkey: pubkeyRand}, res: undefined, }, + getProposerConfig: { + args: {pubkey: pubkeyRand}, + res: { + data: { + graffiti: graffitiRandUtf8, + strictFeeRecipientCheck: false, + feeRecipient: ethaddressRand, + builder: { + gasLimit: gasLimitRand, + selection: "maxprofit", + boostFactor: builderBoostFactorRand.toString(), + }, + }, + }, + }, }; diff --git a/packages/api/test/unit/utils/headers.test.ts b/packages/api/test/unit/utils/headers.test.ts index 3416335b0dcd..a96a36233505 100644 --- a/packages/api/test/unit/utils/headers.test.ts +++ b/packages/api/test/unit/utils/headers.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {MediaType, SUPPORTED_MEDIA_TYPES, mergeHeaders, parseAcceptHeader} from "../../../src/utils/headers.js"; describe("utils / headers", () => { diff --git a/packages/api/test/unit/utils/serdes.test.ts b/packages/api/test/unit/utils/serdes.test.ts index 5b55ef66805e..e9e178782bb2 100644 --- a/packages/api/test/unit/utils/serdes.test.ts +++ b/packages/api/test/unit/utils/serdes.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {fromGraffitiHex, toGraffitiHex} from "../../../src/utils/serdes.js"; describe("utils / serdes", () => { diff --git a/packages/api/test/utils/checkAgainstSpec.ts b/packages/api/test/utils/checkAgainstSpec.ts index a3f943ad4816..be076dfeb381 100644 --- a/packages/api/test/utils/checkAgainstSpec.ts +++ b/packages/api/test/utils/checkAgainstSpec.ts @@ -1,9 +1,9 @@ import Ajv, {ErrorObject} from "ajv"; -import {expect, describe, beforeAll, it} from "vitest"; -import {WireFormat} from "../../src/utils/wireFormat.js"; +import {beforeAll, describe, expect, it} from "vitest"; import {Endpoint, RequestWithBodyCodec, RouteDefinitions, isRequestWithoutBody} from "../../src/utils/types.js"; -import {applyRecursively, JsonSchema, OpenApiJson, parseOpenApiSpec} from "./parseOpenApiSpec.js"; +import {WireFormat} from "../../src/utils/wireFormat.js"; import {GenericServerTestCases} from "./genericServerTest.js"; +import {JsonSchema, OpenApiJson, applyRecursively, parseOpenApiSpec} from "./parseOpenApiSpec.js"; const ajv = new Ajv({ strict: true, diff --git a/packages/api/test/utils/genericServerTest.ts b/packages/api/test/utils/genericServerTest.ts index 1c01bb449306..3223ff5ca5a5 100644 --- a/packages/api/test/utils/genericServerTest.ts +++ b/packages/api/test/utils/genericServerTest.ts @@ -1,10 +1,10 @@ -import {it, expect, describe, beforeAll, afterAll, MockInstance} from "vitest"; -import {FastifyInstance} from "fastify"; import {ChainForkConfig} from "@lodestar/config"; +import {FastifyInstance} from "fastify"; +import {MockInstance, afterAll, beforeAll, describe, expect, it} from "vitest"; +import {ApiClientMethods, ApiRequestInit, HttpClient, IHttpClient} from "../../src/utils/client/index.js"; import {Endpoint} from "../../src/utils/index.js"; -import {WireFormat} from "../../src/utils/wireFormat.js"; import {ApplicationMethods, ApplicationResponse, FastifyRoutes} from "../../src/utils/server/index.js"; -import {ApiClientMethods, ApiRequestInit, HttpClient, IHttpClient} from "../../src/utils/client/index.js"; +import {WireFormat} from "../../src/utils/wireFormat.js"; import {getMockApi, getTestServer} from "./utils.js"; export type GenericServerTestCases> = { diff --git a/packages/api/test/utils/utils.ts b/packages/api/test/utils/utils.ts index d3ecbc964435..26302db60792 100644 --- a/packages/api/test/utils/utils.ts +++ b/packages/api/test/utils/utils.ts @@ -1,7 +1,7 @@ -import {MockedObject, vi} from "vitest"; -import {parse as parseQueryString} from "qs"; -import {FastifyInstance, fastify} from "fastify"; import {mapValues} from "@lodestar/utils"; +import {FastifyInstance, fastify} from "fastify"; +import {parse as parseQueryString} from "qs"; +import {MockedObject, vi} from "vitest"; import {Endpoint} from "../../src/utils/index.js"; import {ApplicationMethods, addSszContentTypeParser} from "../../src/utils/server/index.js"; diff --git a/packages/beacon-node/package.json b/packages/beacon-node/package.json index ffce2f3eacfe..f80dc93b1314 100644 --- a/packages/beacon-node/package.json +++ b/packages/beacon-node/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.23.1", + "version": "1.24.0", "type": "module", "exports": { ".": { @@ -120,18 +120,18 @@ "@libp2p/peer-id-factory": "^4.1.0", "@libp2p/prometheus-metrics": "^3.0.21", "@libp2p/tcp": "9.0.23", - "@lodestar/api": "^1.23.1", - "@lodestar/config": "^1.23.1", - "@lodestar/db": "^1.23.1", - "@lodestar/fork-choice": "^1.23.1", - "@lodestar/light-client": "^1.23.1", - "@lodestar/logger": "^1.23.1", - "@lodestar/params": "^1.23.1", - "@lodestar/reqresp": "^1.23.1", - "@lodestar/state-transition": "^1.23.1", - "@lodestar/types": "^1.23.1", - "@lodestar/utils": "^1.23.1", - "@lodestar/validator": "^1.23.1", + "@lodestar/api": "^1.24.0", + "@lodestar/config": "^1.24.0", + "@lodestar/db": "^1.24.0", + "@lodestar/fork-choice": "^1.24.0", + "@lodestar/light-client": "^1.24.0", + "@lodestar/logger": "^1.24.0", + "@lodestar/params": "^1.24.0", + "@lodestar/reqresp": "^1.24.0", + "@lodestar/state-transition": "^1.24.0", + "@lodestar/types": "^1.24.0", + "@lodestar/utils": "^1.24.0", + "@lodestar/validator": "^1.24.0", "@multiformats/multiaddr": "^12.1.3", "c-kzg": "^2.1.2", "datastore-core": "^9.1.1", diff --git a/packages/beacon-node/src/api/impl/api.ts b/packages/beacon-node/src/api/impl/api.ts index 3647feed2d7c..65d79112f50c 100644 --- a/packages/beacon-node/src/api/impl/api.ts +++ b/packages/beacon-node/src/api/impl/api.ts @@ -1,6 +1,5 @@ import {BeaconApiMethods} from "@lodestar/api/beacon/server"; import {ApiOptions} from "../options.js"; -import {ApiModules} from "./types.js"; import {getBeaconApi} from "./beacon/index.js"; import {getConfigApi} from "./config/index.js"; import {getDebugApi} from "./debug/index.js"; @@ -9,6 +8,7 @@ import {getLightclientApi} from "./lightclient/index.js"; import {getLodestarApi} from "./lodestar/index.js"; import {getNodeApi} from "./node/index.js"; import {getProofApi} from "./proof/index.js"; +import {ApiModules} from "./types.js"; import {getValidatorApi} from "./validator/index.js"; export function getApi(opts: ApiOptions, modules: ApiModules): BeaconApiMethods { diff --git a/packages/beacon-node/src/api/impl/beacon/blocks/index.ts b/packages/beacon-node/src/api/impl/beacon/blocks/index.ts index 2d36505d822a..66935df25b2b 100644 --- a/packages/beacon-node/src/api/impl/beacon/blocks/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/blocks/index.ts @@ -1,40 +1,40 @@ import {routes} from "@lodestar/api"; import {ApiError, ApplicationMethods} from "@lodestar/api/server"; +import {ForkExecution, SLOTS_PER_HISTORICAL_ROOT, isForkExecution, isForkPostElectra} from "@lodestar/params"; import { computeEpochAtSlot, computeTimeAtSlot, reconstructFullBlockOrContents, signedBeaconBlockToBlinded, } from "@lodestar/state-transition"; -import {ForkExecution, SLOTS_PER_HISTORICAL_ROOT, isForkExecution, isForkPostElectra} from "@lodestar/params"; -import {sleep, fromHex, toRootHex} from "@lodestar/utils"; import { - deneb, - isSignedBlockContents, ProducedBlockSource, SignedBeaconBlock, SignedBeaconBlockOrContents, SignedBlindedBeaconBlock, WithOptionalBytes, + deneb, + isSignedBlockContents, } from "@lodestar/types"; +import {fromHex, sleep, toRootHex} from "@lodestar/utils"; import { - BlockSource, - getBlockInput, - ImportBlockOpts, - BlockInput, BlobsSource, + BlockInput, BlockInputDataBlobs, + BlockSource, + ImportBlockOpts, + getBlockInput, } from "../../../../chain/blocks/types.js"; -import {promiseAllMaybeAsync} from "../../../../util/promises.js"; -import {isOptimisticBlock} from "../../../../util/forkChoice.js"; -import {computeBlobSidecars} from "../../../../util/blobs.js"; +import {verifyBlocksInEpoch} from "../../../../chain/blocks/verifyBlock.js"; +import {BeaconChain} from "../../../../chain/chain.js"; import {BlockError, BlockErrorCode, BlockGossipError} from "../../../../chain/errors/index.js"; +import {validateGossipBlock} from "../../../../chain/validation/block.js"; import {OpSource} from "../../../../metrics/validatorMonitor.js"; import {NetworkEvent} from "../../../../network/index.js"; +import {computeBlobSidecars} from "../../../../util/blobs.js"; +import {isOptimisticBlock} from "../../../../util/forkChoice.js"; +import {promiseAllMaybeAsync} from "../../../../util/promises.js"; import {ApiModules} from "../../types.js"; -import {validateGossipBlock} from "../../../../chain/validation/block.js"; -import {verifyBlocksInEpoch} from "../../../../chain/blocks/verifyBlock.js"; -import {BeaconChain} from "../../../../chain/chain.js"; import {getBlockResponse, toBeaconHeaderResponse} from "./utils.js"; type PublishBlockOpts = ImportBlockOpts; @@ -215,12 +215,12 @@ export function getBeaconBlockApi({ // specification is very clear that this is the desired behaviour. // // i) Publish blobs and block before importing so that network can see them asap - // ii) publish blobs first because - // a) by the times nodes see block, they might decide to pull blobs - // b) they might require more hops to reach recipients in peerDAS kind of setup where - // blobs might need to hop between nodes because of partial subnet subscription - ...blobSidecars.map((blobSidecar) => () => network.publishBlobSidecar(blobSidecar)), + // ii) publish block first because + // a) as soon as node sees block they can start processing it while blobs arrive + // b) getting block first allows nodes to use getBlobs from local ELs and save + // import latency and hopefully bandwidth () => network.publishBeaconBlock(signedBlock) as Promise, + ...blobSidecars.map((blobSidecar) => () => network.publishBlobSidecar(blobSidecar)), () => // there is no rush to persist block since we published it to gossip anyway chain diff --git a/packages/beacon-node/src/api/impl/beacon/blocks/utils.ts b/packages/beacon-node/src/api/impl/beacon/blocks/utils.ts index 44152ff4b8a9..b1030c6de58b 100644 --- a/packages/beacon-node/src/api/impl/beacon/blocks/utils.ts +++ b/packages/beacon-node/src/api/impl/beacon/blocks/utils.ts @@ -1,12 +1,12 @@ import {routes} from "@lodestar/api"; -import {blockToHeader} from "@lodestar/state-transition"; import {ChainForkConfig} from "@lodestar/config"; -import {RootHex, SignedBeaconBlock, Slot} from "@lodestar/types"; import {IForkChoice} from "@lodestar/fork-choice"; -import {GENESIS_SLOT} from "../../../../constants/index.js"; -import {ApiError, ValidationError} from "../../errors.js"; +import {blockToHeader} from "@lodestar/state-transition"; +import {RootHex, SignedBeaconBlock, Slot} from "@lodestar/types"; import {IBeaconChain} from "../../../../chain/interface.js"; +import {GENESIS_SLOT} from "../../../../constants/index.js"; import {rootHexRegex} from "../../../../eth1/provider/utils.js"; +import {ApiError, ValidationError} from "../../errors.js"; export function toBeaconHeaderResponse( config: ChainForkConfig, diff --git a/packages/beacon-node/src/api/impl/beacon/index.ts b/packages/beacon-node/src/api/impl/beacon/index.ts index 2e75dc76782c..0003e9c97878 100644 --- a/packages/beacon-node/src/api/impl/beacon/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/index.ts @@ -3,8 +3,8 @@ import {ApplicationMethods} from "@lodestar/api/server"; import {ApiModules} from "../types.js"; import {getBeaconBlockApi} from "./blocks/index.js"; import {getBeaconPoolApi} from "./pool/index.js"; -import {getBeaconStateApi} from "./state/index.js"; import {getBeaconRewardsApi} from "./rewards/index.js"; +import {getBeaconStateApi} from "./state/index.js"; export function getBeaconApi( modules: Pick diff --git a/packages/beacon-node/src/api/impl/beacon/pool/index.ts b/packages/beacon-node/src/api/impl/beacon/pool/index.ts index 9343dd67a399..c283d6d3214c 100644 --- a/packages/beacon-node/src/api/impl/beacon/pool/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/pool/index.ts @@ -1,22 +1,22 @@ import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; -import {Attestation, Epoch, isElectraAttestation, ssz} from "@lodestar/types"; import {ForkName, SYNC_COMMITTEE_SUBNET_SIZE, isForkPostElectra} from "@lodestar/params"; -import {validateApiAttestation} from "../../../../chain/validation/index.js"; -import {validateApiAttesterSlashing} from "../../../../chain/validation/attesterSlashing.js"; -import {validateApiProposerSlashing} from "../../../../chain/validation/proposerSlashing.js"; -import {validateApiVoluntaryExit} from "../../../../chain/validation/voluntaryExit.js"; -import {validateApiBlsToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js"; -import {validateApiSyncCommittee} from "../../../../chain/validation/syncCommittee.js"; -import {ApiModules} from "../../types.js"; +import {Attestation, Epoch, isElectraAttestation, ssz} from "@lodestar/types"; import { AttestationError, AttestationErrorCode, GossipAction, SyncCommitteeError, } from "../../../../chain/errors/index.js"; +import {validateApiAttesterSlashing} from "../../../../chain/validation/attesterSlashing.js"; +import {validateApiBlsToExecutionChange} from "../../../../chain/validation/blsToExecutionChange.js"; +import {validateApiAttestation} from "../../../../chain/validation/index.js"; +import {validateApiProposerSlashing} from "../../../../chain/validation/proposerSlashing.js"; +import {validateApiSyncCommittee} from "../../../../chain/validation/syncCommittee.js"; +import {validateApiVoluntaryExit} from "../../../../chain/validation/voluntaryExit.js"; import {validateGossipFnRetryUnknownRoot} from "../../../../network/processor/gossipHandlers.js"; import {ApiError, FailureList, IndexedError} from "../../errors.js"; +import {ApiModules} from "../../types.js"; export function getBeaconPoolApi({ chain, @@ -257,7 +257,7 @@ export function getBeaconPoolApi({ } failures.push({index: i, message: (e as Error).message}); - logger.debug( + logger.error( `Error on submitPoolSyncCommitteeSignatures [${i}]`, {slot: signature.slot, validatorIndex: signature.validatorIndex}, e as Error diff --git a/packages/beacon-node/src/api/impl/beacon/state/index.ts b/packages/beacon-node/src/api/impl/beacon/state/index.ts index a1e17b80ea84..916507cc56fc 100644 --- a/packages/beacon-node/src/api/impl/beacon/state/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/state/index.ts @@ -1,5 +1,6 @@ import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; +import {EPOCHS_PER_HISTORICAL_VECTOR} from "@lodestar/params"; import { BeaconStateAllForks, CachedBeaconStateAltair, @@ -8,12 +9,11 @@ import { getCurrentEpoch, getRandaoMix, } from "@lodestar/state-transition"; -import {EPOCHS_PER_HISTORICAL_VECTOR} from "@lodestar/params"; import {getValidatorStatus} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; import {ApiError} from "../../errors.js"; import {ApiModules} from "../../types.js"; -import {filterStateValidatorsByStatus, getStateValidatorIndex, getStateResponse, toValidatorResponse} from "./utils.js"; +import {filterStateValidatorsByStatus, getStateResponse, getStateValidatorIndex, toValidatorResponse} from "./utils.js"; export function getBeaconStateApi({ chain, diff --git a/packages/beacon-node/src/api/impl/beacon/state/utils.ts b/packages/beacon-node/src/api/impl/beacon/state/utils.ts index 392262a563be..f23fd52f0286 100644 --- a/packages/beacon-node/src/api/impl/beacon/state/utils.ts +++ b/packages/beacon-node/src/api/impl/beacon/state/utils.ts @@ -1,10 +1,10 @@ import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; import {routes} from "@lodestar/api"; +import {CheckpointWithHex, IForkChoice} from "@lodestar/fork-choice"; import {GENESIS_SLOT} from "@lodestar/params"; import {BeaconStateAllForks} from "@lodestar/state-transition"; -import {BLSPubkey, Epoch, getValidatorStatus, phase0, RootHex, Slot, ValidatorIndex} from "@lodestar/types"; +import {BLSPubkey, Epoch, RootHex, Slot, ValidatorIndex, getValidatorStatus, phase0} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; -import {CheckpointWithHex, IForkChoice} from "@lodestar/fork-choice"; import {IBeaconChain} from "../../../../chain/index.js"; import {ApiError, ValidationError} from "../../errors.js"; diff --git a/packages/beacon-node/src/api/impl/config/constants.ts b/packages/beacon-node/src/api/impl/config/constants.ts index e951da35bdd2..6b390727cec3 100644 --- a/packages/beacon-node/src/api/impl/config/constants.ts +++ b/packages/beacon-node/src/api/impl/config/constants.ts @@ -1,44 +1,45 @@ import { - GENESIS_SLOT, - GENESIS_EPOCH, - FAR_FUTURE_EPOCH, + ATTESTATION_SUBNET_COUNT, BASE_REWARDS_PER_EPOCH, - DEPOSIT_CONTRACT_TREE_DEPTH, - JUSTIFICATION_BITS_LENGTH, + BLOB_TX_TYPE, BLS_WITHDRAWAL_PREFIX, - ETH1_ADDRESS_WITHDRAWAL_PREFIX, - DOMAIN_BEACON_PROPOSER, + COMPOUNDING_WITHDRAWAL_PREFIX, + DEPOSIT_CONTRACT_TREE_DEPTH, + DOMAIN_AGGREGATE_AND_PROOF, + DOMAIN_APPLICATION_BUILDER, + DOMAIN_APPLICATION_MASK, DOMAIN_BEACON_ATTESTER, - DOMAIN_RANDAO, + DOMAIN_BEACON_PROPOSER, + DOMAIN_BLS_TO_EXECUTION_CHANGE, + DOMAIN_CONTRIBUTION_AND_PROOF, DOMAIN_DEPOSIT, - DOMAIN_VOLUNTARY_EXIT, + DOMAIN_RANDAO, DOMAIN_SELECTION_PROOF, - DOMAIN_AGGREGATE_AND_PROOF, DOMAIN_SYNC_COMMITTEE, DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF, - DOMAIN_CONTRIBUTION_AND_PROOF, - DOMAIN_BLS_TO_EXECUTION_CHANGE, - DOMAIN_APPLICATION_BUILDER, - TIMELY_SOURCE_FLAG_INDEX, - TIMELY_TARGET_FLAG_INDEX, - TIMELY_HEAD_FLAG_INDEX, - TIMELY_SOURCE_WEIGHT, - TIMELY_TARGET_WEIGHT, - TIMELY_HEAD_WEIGHT, - SYNC_REWARD_WEIGHT, + DOMAIN_VOLUNTARY_EXIT, + EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION, + ETH1_ADDRESS_WITHDRAWAL_PREFIX, + FAR_FUTURE_EPOCH, + FULL_EXIT_REQUEST_AMOUNT, + GENESIS_EPOCH, + GENESIS_SLOT, + JUSTIFICATION_BITS_LENGTH, PROPOSER_WEIGHT, - WEIGHT_DENOMINATOR, - TARGET_AGGREGATORS_PER_COMMITTEE, RANDOM_SUBNETS_PER_VALIDATOR, - EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION, - ATTESTATION_SUBNET_COUNT, - TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE, SYNC_COMMITTEE_SUBNET_COUNT, - BLOB_TX_TYPE, - VERSIONED_HASH_VERSION_KZG, - COMPOUNDING_WITHDRAWAL_PREFIX, + SYNC_REWARD_WEIGHT, + TARGET_AGGREGATORS_PER_COMMITTEE, + TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE, + TIMELY_HEAD_FLAG_INDEX, + TIMELY_HEAD_WEIGHT, + TIMELY_SOURCE_FLAG_INDEX, + TIMELY_SOURCE_WEIGHT, + TIMELY_TARGET_FLAG_INDEX, + TIMELY_TARGET_WEIGHT, UNSET_DEPOSIT_REQUESTS_START_INDEX, - FULL_EXIT_REQUEST_AMOUNT, + VERSIONED_HASH_VERSION_KZG, + WEIGHT_DENOMINATOR, } from "@lodestar/params"; /** @@ -67,6 +68,7 @@ export const specConstants = { DOMAIN_VOLUNTARY_EXIT, DOMAIN_SELECTION_PROOF, DOMAIN_AGGREGATE_AND_PROOF, + DOMAIN_APPLICATION_MASK, DOMAIN_APPLICATION_BUILDER, // phase0/validator.md diff --git a/packages/beacon-node/src/api/impl/config/index.ts b/packages/beacon-node/src/api/impl/config/index.ts index 9b8694aa5914..f9d3924430ad 100644 --- a/packages/beacon-node/src/api/impl/config/index.ts +++ b/packages/beacon-node/src/api/impl/config/index.ts @@ -1,6 +1,6 @@ import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; -import {chainConfigToJson, ChainConfig, specValuesToJson} from "@lodestar/config"; +import {ChainConfig, chainConfigToJson, specValuesToJson} from "@lodestar/config"; import {activePreset, presetToJson} from "@lodestar/params"; import {ApiModules} from "../types.js"; import {specConstants} from "./constants.js"; diff --git a/packages/beacon-node/src/api/impl/debug/index.ts b/packages/beacon-node/src/api/impl/debug/index.ts index e5b6450b206f..a004bd80e8f2 100644 --- a/packages/beacon-node/src/api/impl/debug/index.ts +++ b/packages/beacon-node/src/api/impl/debug/index.ts @@ -1,12 +1,12 @@ import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; import {ExecutionStatus} from "@lodestar/fork-choice"; -import {BeaconState} from "@lodestar/types"; import {ZERO_HASH_HEX} from "@lodestar/params"; -import {getStateResponseWithRegen} from "../beacon/state/utils.js"; -import {ApiModules} from "../types.js"; +import {BeaconState, ssz} from "@lodestar/types"; import {isOptimisticBlock} from "../../../util/forkChoice.js"; import {getStateSlotFromBytes} from "../../../util/multifork.js"; +import {getStateResponseWithRegen} from "../beacon/state/utils.js"; +import {ApiModules} from "../types.js"; export function getDebugApi({ chain, diff --git a/packages/beacon-node/src/api/impl/lightclient/index.ts b/packages/beacon-node/src/api/impl/lightclient/index.ts index 0dd366accf68..850a8312978c 100644 --- a/packages/beacon-node/src/api/impl/lightclient/index.ts +++ b/packages/beacon-node/src/api/impl/lightclient/index.ts @@ -1,9 +1,9 @@ -import {fromHex} from "@lodestar/utils"; import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; -import {MAX_REQUEST_LIGHT_CLIENT_UPDATES, MAX_REQUEST_LIGHT_CLIENT_COMMITTEE_HASHES} from "@lodestar/params"; -import {ApiModules} from "../types.js"; +import {MAX_REQUEST_LIGHT_CLIENT_COMMITTEE_HASHES, MAX_REQUEST_LIGHT_CLIENT_UPDATES} from "@lodestar/params"; +import {fromHex} from "@lodestar/utils"; import {assertLightClientServer} from "../../../node/utils/lightclient.js"; +import {ApiModules} from "../types.js"; // TODO: Import from lightclient/server package export function getLightclientApi({ diff --git a/packages/beacon-node/src/api/impl/lodestar/index.ts b/packages/beacon-node/src/api/impl/lodestar/index.ts index f89959ad9da6..aeef2e11a83e 100644 --- a/packages/beacon-node/src/api/impl/lodestar/index.ts +++ b/packages/beacon-node/src/api/impl/lodestar/index.ts @@ -1,19 +1,21 @@ import fs from "node:fs"; import path from "node:path"; +import {Tree} from "@chainsafe/persistent-merkle-tree"; import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; -import {Repository} from "@lodestar/db"; -import {toHex, toRootHex} from "@lodestar/utils"; -import {getLatestWeakSubjectivityCheckpointEpoch} from "@lodestar/state-transition"; import {ChainForkConfig} from "@lodestar/config"; +import {Repository} from "@lodestar/db"; +import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {BeaconStateCapella, getLatestWeakSubjectivityCheckpointEpoch, loadState} from "@lodestar/state-transition"; import {ssz} from "@lodestar/types"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {toHex, toRootHex} from "@lodestar/utils"; import {BeaconChain} from "../../../chain/index.js"; import {QueuedStateRegenerator, RegenRequest} from "../../../chain/regen/index.js"; -import {GossipType} from "../../../network/index.js"; import {IBeaconDb} from "../../../db/interface.js"; -import {ApiModules} from "../types.js"; +import {GossipType} from "../../../network/index.js"; import {profileNodeJS, writeHeapSnapshot} from "../../../util/profile.js"; +import {getStateResponseWithRegen} from "../beacon/state/utils.js"; +import {ApiModules} from "../types.js"; export function getLodestarApi({ chain, @@ -187,6 +189,29 @@ export function getLodestarApi({ async dumpDbStateIndex() { return {data: await db.stateArchive.dumpRootIndexEntries()}; }, + + async getHistoricalSummaries({stateId}) { + const {state} = await getStateResponseWithRegen(chain, stateId); + + const stateView = ( + state instanceof Uint8Array ? loadState(config, chain.getHeadState(), state).state : state.clone() + ) as BeaconStateCapella; + + const fork = config.getForkName(stateView.slot); + if (ForkSeq[fork] < ForkSeq.capella) { + throw new Error("Historical summaries are not supported before Capella"); + } + + const {gindex} = ssz[fork].BeaconState.getPathInfo(["historicalSummaries"]); + const proof = new Tree(stateView.node).getSingleProof(gindex); + + return { + data: { + historicalSummaries: stateView.historicalSummaries.toValue(), + proof: proof, + }, + }; + }, }; } diff --git a/packages/beacon-node/src/api/impl/node/index.ts b/packages/beacon-node/src/api/impl/node/index.ts index bd1fb85522de..0d476df32303 100644 --- a/packages/beacon-node/src/api/impl/node/index.ts +++ b/packages/beacon-node/src/api/impl/node/index.ts @@ -1,8 +1,8 @@ import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; +import {ApiOptions} from "../../options.js"; import {ApiError} from "../errors.js"; import {ApiModules} from "../types.js"; -import {ApiOptions} from "../../options.js"; export function getNodeApi( opts: ApiOptions, diff --git a/packages/beacon-node/src/api/impl/proof/index.ts b/packages/beacon-node/src/api/impl/proof/index.ts index 9e1a33940225..7b61e280015f 100644 --- a/packages/beacon-node/src/api/impl/proof/index.ts +++ b/packages/beacon-node/src/api/impl/proof/index.ts @@ -1,10 +1,10 @@ -import {CompactMultiProof, createProof, ProofType} from "@chainsafe/persistent-merkle-tree"; +import {CompactMultiProof, ProofType, createProof} from "@chainsafe/persistent-merkle-tree"; import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; -import {ApiModules} from "../types.js"; -import {getStateResponse} from "../beacon/state/utils.js"; -import {getBlockResponse} from "../beacon/blocks/utils.js"; import {ApiOptions} from "../../options.js"; +import {getBlockResponse} from "../beacon/blocks/utils.js"; +import {getStateResponse} from "../beacon/state/utils.js"; +import {ApiModules} from "../types.js"; export function getProofApi( opts: ApiOptions, diff --git a/packages/beacon-node/src/api/impl/types.ts b/packages/beacon-node/src/api/impl/types.ts index 6b14e79ef998..4b2649acc556 100644 --- a/packages/beacon-node/src/api/impl/types.ts +++ b/packages/beacon-node/src/api/impl/types.ts @@ -3,9 +3,9 @@ import {Logger} from "@lodestar/utils"; import {IBeaconChain} from "../../chain/index.js"; import {IBeaconDb} from "../../db/index.js"; -import {IBeaconSync} from "../../sync/index.js"; -import {INetwork} from "../../network/index.js"; import {Metrics} from "../../metrics/index.js"; +import {INetwork} from "../../network/index.js"; +import {IBeaconSync} from "../../sync/index.js"; export type ApiModules = { config: ChainForkConfig; diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 2b558577c22c..fe26c559661c 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -1,61 +1,61 @@ import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; import {routes} from "@lodestar/api"; import {ApplicationMethods} from "@lodestar/api/server"; +import {DataAvailabilityStatus, ExecutionStatus} from "@lodestar/fork-choice"; import { - CachedBeaconStateAllForks, - computeStartSlotAtEpoch, - calculateCommitteeAssignments, - proposerShufflingDecisionRoot, - attesterShufflingDecisionRoot, - getBlockRootAtSlot, - computeEpochAtSlot, - getCurrentSlot, - beaconBlockToBlinded, - createCachedBeaconState, - loadState, -} from "@lodestar/state-transition"; -import { + ForkBlobs, + ForkExecution, + ForkPreBlobs, + ForkSeq, GENESIS_SLOT, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT, SYNC_COMMITTEE_SUBNET_SIZE, isForkBlobs, isForkExecution, - ForkSeq, - ForkPreBlobs, - ForkBlobs, - ForkExecution, isForkPostElectra, } from "@lodestar/params"; -import {MAX_BUILDER_BOOST_FACTOR} from "@lodestar/validator"; import { + CachedBeaconStateAllForks, + attesterShufflingDecisionRoot, + beaconBlockToBlinded, + calculateCommitteeAssignments, + computeEpochAtSlot, + computeStartSlotAtEpoch, + createCachedBeaconState, + getBlockRootAtSlot, + getCurrentSlot, + loadState, + proposerShufflingDecisionRoot, +} from "@lodestar/state-transition"; +import { + BLSSignature, + BeaconBlock, + BlindedBeaconBlock, + BlockContents, + Epoch, + ProducedBlockSource, Root, Slot, ValidatorIndex, - ssz, - Epoch, - ProducedBlockSource, + Wei, bellatrix, - BLSSignature, + getValidatorStatus, isBlindedBeaconBlock, isBlockContents, phase0, - Wei, - BeaconBlock, - BlockContents, - BlindedBeaconBlock, - getValidatorStatus, + ssz, } from "@lodestar/types"; -import {ExecutionStatus, DataAvailabilityStatus} from "@lodestar/fork-choice"; import { + TimeoutError, + formatWeiToEth, fromHex, - toHex, - resolveOrRacePromises, prettyWeiToEth, + resolveOrRacePromises, + toHex, toRootHex, - TimeoutError, - formatWeiToEth, } from "@lodestar/utils"; +import {MAX_BUILDER_BOOST_FACTOR} from "@lodestar/validator"; import { AttestationError, AttestationErrorCode, @@ -63,23 +63,23 @@ import { SyncCommitteeError, SyncCommitteeErrorCode, } from "../../../chain/errors/index.js"; +import {ChainEvent, CheckpointHex, CommonBlockBody} from "../../../chain/index.js"; +import {SCHEDULER_LOOKAHEAD_FACTOR} from "../../../chain/prepareNextSlot.js"; +import {RegenCaller} from "../../../chain/regen/index.js"; import {validateApiAggregateAndProof} from "../../../chain/validation/index.js"; +import {validateSyncCommitteeGossipContributionAndProof} from "../../../chain/validation/syncCommitteeContributionAndProof.js"; import {ZERO_HASH} from "../../../constants/index.js"; +import {NoBidReceived} from "../../../execution/builder/http.js"; +import {validateGossipFnRetryUnknownRoot} from "../../../network/processor/gossipHandlers.js"; +import {CommitteeSubscription} from "../../../network/subnets/index.js"; import {SyncState} from "../../../sync/index.js"; import {isOptimisticBlock} from "../../../util/forkChoice.js"; import {getDefaultGraffiti, toGraffitiBuffer} from "../../../util/graffiti.js"; +import {getLodestarClientVersion} from "../../../util/metadata.js"; +import {ApiOptions} from "../../options.js"; +import {getStateResponseWithRegen} from "../beacon/state/utils.js"; import {ApiError, NodeIsSyncing, OnlySupportedByDVT} from "../errors.js"; -import {validateSyncCommitteeGossipContributionAndProof} from "../../../chain/validation/syncCommitteeContributionAndProof.js"; -import {CommitteeSubscription} from "../../../network/subnets/index.js"; import {ApiModules} from "../types.js"; -import {RegenCaller} from "../../../chain/regen/index.js"; -import {getStateResponseWithRegen} from "../beacon/state/utils.js"; -import {validateGossipFnRetryUnknownRoot} from "../../../network/processor/gossipHandlers.js"; -import {SCHEDULER_LOOKAHEAD_FACTOR} from "../../../chain/prepareNextSlot.js"; -import {ChainEvent, CheckpointHex, CommonBlockBody} from "../../../chain/index.js"; -import {ApiOptions} from "../../options.js"; -import {NoBidReceived} from "../../../execution/builder/http.js"; -import {getLodestarClientVersion} from "../../../util/metadata.js"; import {computeSubnetForCommitteesAtSlot, getPubkeysForIndices, selectBlockProductionSource} from "./utils.js"; /** @@ -695,32 +695,46 @@ export function getValidatorApi( throw Error("Builder and engine both failed to produce the block within timeout"); } - if (engine.status === "rejected" && isEngineEnabled) { - logger.warn( - "Engine failed to produce the block", - { - ...loggerContext, - durationMs: engine.durationMs, - }, - engine.reason - ); - } - - if (builder.status === "rejected" && isBuilderEnabled) { - if (builder.reason instanceof NoBidReceived) { - logger.info("Builder did not provide a bid", { - ...loggerContext, - durationMs: builder.durationMs, - }); - } else { + if (isEngineEnabled) { + if (engine.status === "rejected") { logger.warn( - "Builder failed to produce the block", + "Engine failed to produce the block", { ...loggerContext, - durationMs: builder.durationMs, + durationMs: engine.durationMs, }, - builder.reason + engine.reason ); + } else if (engine.status === "pending") { + logger.warn("Engine failed to produce the block within cutoff time", { + ...loggerContext, + cutoffMs, + }); + } + } + + if (isBuilderEnabled) { + if (builder.status === "rejected") { + if (builder.reason instanceof NoBidReceived) { + logger.info("Builder did not provide a bid", { + ...loggerContext, + durationMs: builder.durationMs, + }); + } else { + logger.warn( + "Builder failed to produce the block", + { + ...loggerContext, + durationMs: builder.durationMs, + }, + builder.reason + ); + } + } else if (builder.status === "pending") { + logger.warn("Builder failed to produce the block within cutoff time", { + ...loggerContext, + cutoffMs, + }); } } diff --git a/packages/beacon-node/src/api/impl/validator/utils.ts b/packages/beacon-node/src/api/impl/validator/utils.ts index 36accf34cfda..b8e5aa525f25 100644 --- a/packages/beacon-node/src/api/impl/validator/utils.ts +++ b/packages/beacon-node/src/api/impl/validator/utils.ts @@ -1,6 +1,6 @@ -import {BeaconStateAllForks, computeSlotsSinceEpochStart} from "@lodestar/state-transition"; -import {ATTESTATION_SUBNET_COUNT} from "@lodestar/params"; import {routes} from "@lodestar/api"; +import {ATTESTATION_SUBNET_COUNT} from "@lodestar/params"; +import {BeaconStateAllForks, computeSlotsSinceEpochStart} from "@lodestar/state-transition"; import {BLSPubkey, CommitteeIndex, ProducedBlockSource, Slot, ValidatorIndex} from "@lodestar/types"; import {MAX_BUILDER_BOOST_FACTOR} from "@lodestar/validator"; import {BlockSelectionResult, BuilderBlockSelectionReason, EngineBlockSelectionReason} from "./index.js"; diff --git a/packages/beacon-node/src/api/options.ts b/packages/beacon-node/src/api/options.ts index 811621ba97bf..02d0c9c6cdf6 100644 --- a/packages/beacon-node/src/api/options.ts +++ b/packages/beacon-node/src/api/options.ts @@ -1,4 +1,4 @@ -import {beaconRestApiServerOpts, BeaconRestApiServerOpts} from "./rest/index.js"; +import {BeaconRestApiServerOpts, beaconRestApiServerOpts} from "./rest/index.js"; export type ApiOptions = { maxGindicesInProof?: number; diff --git a/packages/beacon-node/src/api/rest/base.ts b/packages/beacon-node/src/api/rest/base.ts index 276583dc7281..efa01b032230 100644 --- a/packages/beacon-node/src/api/rest/base.ts +++ b/packages/beacon-node/src/api/rest/base.ts @@ -1,9 +1,9 @@ -import {parse as parseQueryString} from "qs"; -import {FastifyInstance, FastifyRequest, fastify, errorCodes} from "fastify"; -import {fastifyCors} from "@fastify/cors"; import bearerAuthPlugin from "@fastify/bearer-auth"; +import {fastifyCors} from "@fastify/cors"; import {addSszContentTypeParser} from "@lodestar/api/server"; import {ErrorAborted, Gauge, Histogram, Logger} from "@lodestar/utils"; +import {FastifyInstance, FastifyRequest, errorCodes, fastify} from "fastify"; +import {parse as parseQueryString} from "qs"; import {isLocalhostIP} from "../../util/ip.js"; import {ApiError, FailureList, IndexedError, NodeIsSyncing} from "../impl/errors.js"; import {HttpActiveSocketsTracker, SocketMetrics} from "./activeSockets.js"; diff --git a/packages/beacon-node/src/api/rest/index.ts b/packages/beacon-node/src/api/rest/index.ts index 6beaf061588c..1d31080327e6 100644 --- a/packages/beacon-node/src/api/rest/index.ts +++ b/packages/beacon-node/src/api/rest/index.ts @@ -1,10 +1,10 @@ import {Endpoints} from "@lodestar/api"; import {BeaconApiMethods} from "@lodestar/api/beacon/server"; import {registerRoutes} from "@lodestar/api/beacon/server"; -import {ErrorAborted, Logger} from "@lodestar/utils"; import {ChainForkConfig} from "@lodestar/config"; +import {ErrorAborted, Logger} from "@lodestar/utils"; import {NodeIsSyncing} from "../impl/errors.js"; -import {RestApiServer, RestApiServerModules, RestApiServerMetrics, RestApiServerOpts} from "./base.js"; +import {RestApiServer, RestApiServerMetrics, RestApiServerModules, RestApiServerOpts} from "./base.js"; import {registerSwaggerUIRoutes} from "./swaggerUI.js"; export {allNamespaces} from "@lodestar/api"; diff --git a/packages/beacon-node/src/chain/archiver/archiveBlocks.ts b/packages/beacon-node/src/chain/archiver/archiveBlocks.ts index 320715f09dda..ad0ac0ff2c6b 100644 --- a/packages/beacon-node/src/chain/archiver/archiveBlocks.ts +++ b/packages/beacon-node/src/chain/archiver/archiveBlocks.ts @@ -1,10 +1,10 @@ -import {Epoch, Slot, RootHex} from "@lodestar/types"; +import {ChainForkConfig} from "@lodestar/config"; +import {KeyValue} from "@lodestar/db"; import {IForkChoice} from "@lodestar/fork-choice"; -import {Logger, fromHex, toRootHex} from "@lodestar/utils"; import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params"; import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {KeyValue} from "@lodestar/db"; -import {ChainForkConfig} from "@lodestar/config"; +import {Epoch, RootHex, Slot} from "@lodestar/types"; +import {Logger, fromHex, toRootHex} from "@lodestar/utils"; import {IBeaconDb} from "../../db/index.js"; import {BlockArchiveBatchPutBinaryItem} from "../../db/repositories/index.js"; import {LightClientServer} from "../lightClient/index.js"; diff --git a/packages/beacon-node/src/chain/archiver/archiver.ts b/packages/beacon-node/src/chain/archiver/archiver.ts index 007eeeed0c94..6d54a7f64911 100644 --- a/packages/beacon-node/src/chain/archiver/archiver.ts +++ b/packages/beacon-node/src/chain/archiver/archiver.ts @@ -1,13 +1,13 @@ -import {Logger} from "@lodestar/utils"; import {CheckpointWithHex} from "@lodestar/fork-choice"; +import {Logger} from "@lodestar/utils"; import {IBeaconDb} from "../../db/index.js"; +import {Metrics} from "../../metrics/metrics.js"; import {JobItemQueue} from "../../util/queue/index.js"; -import {IBeaconChain} from "../interface.js"; import {ChainEvent} from "../emitter.js"; -import {Metrics} from "../../metrics/metrics.js"; -import {FrequencyStateArchiveStrategy} from "./strategies/frequencyStateArchiveStrategy.js"; +import {IBeaconChain} from "../interface.js"; import {archiveBlocks} from "./archiveBlocks.js"; -import {StateArchiveMode, ArchiverOpts, StateArchiveStrategy} from "./interface.js"; +import {ArchiverOpts, StateArchiveMode, StateArchiveStrategy} from "./interface.js"; +import {FrequencyStateArchiveStrategy} from "./strategies/frequencyStateArchiveStrategy.js"; export const DEFAULT_STATE_ARCHIVE_MODE = StateArchiveMode.Frequency; diff --git a/packages/beacon-node/src/chain/archiver/interface.ts b/packages/beacon-node/src/chain/archiver/interface.ts index d5ac3dac8790..4c9eb27ecbdc 100644 --- a/packages/beacon-node/src/chain/archiver/interface.ts +++ b/packages/beacon-node/src/chain/archiver/interface.ts @@ -1,6 +1,6 @@ import {CheckpointWithHex} from "@lodestar/fork-choice"; -import {Metrics} from "../../metrics/metrics.js"; import {RootHex} from "@lodestar/types"; +import {Metrics} from "../../metrics/metrics.js"; export enum StateArchiveMode { Frequency = "frequency", diff --git a/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts b/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts index c6e4dccfbf6c..dca7a8ed1f22 100644 --- a/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts +++ b/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts @@ -1,14 +1,14 @@ -import {Logger} from "@lodestar/utils"; +import {CheckpointWithHex} from "@lodestar/fork-choice"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {Slot, Epoch, RootHex} from "@lodestar/types"; import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {CheckpointWithHex} from "@lodestar/fork-choice"; +import {Epoch, RootHex, Slot} from "@lodestar/types"; +import {Logger} from "@lodestar/utils"; import {IBeaconDb} from "../../../db/index.js"; -import {IStateRegenerator} from "../../regen/interface.js"; +import {Metrics} from "../../../metrics/metrics.js"; +import {AllocSource, BufferPool} from "../../../util/bufferPool.js"; import {getStateSlotFromBytes} from "../../../util/multifork.js"; +import {IStateRegenerator} from "../../regen/interface.js"; import {serializeState} from "../../serializeState.js"; -import {AllocSource, BufferPool} from "../../../util/bufferPool.js"; -import {Metrics} from "../../../metrics/metrics.js"; import {StateArchiveStrategy, StatesArchiverOpts} from "../interface.js"; /** diff --git a/packages/beacon-node/src/chain/balancesCache.ts b/packages/beacon-node/src/chain/balancesCache.ts index d29a6998f600..8fe09df4c275 100644 --- a/packages/beacon-node/src/chain/balancesCache.ts +++ b/packages/beacon-node/src/chain/balancesCache.ts @@ -1,11 +1,11 @@ +import {CheckpointWithHex} from "@lodestar/fork-choice"; import { CachedBeaconStateAllForks, - computeStartSlotAtEpoch, EffectiveBalanceIncrements, + computeStartSlotAtEpoch, getBlockRootAtSlot, getEffectiveBalanceIncrementsZeroInactive, } from "@lodestar/state-transition"; -import {CheckpointWithHex} from "@lodestar/fork-choice"; import {Epoch, RootHex} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; diff --git a/packages/beacon-node/src/chain/beaconProposerCache.ts b/packages/beacon-node/src/chain/beaconProposerCache.ts index f8638aa64bf7..dd46821e6d57 100644 --- a/packages/beacon-node/src/chain/beaconProposerCache.ts +++ b/packages/beacon-node/src/chain/beaconProposerCache.ts @@ -1,5 +1,5 @@ -import {Epoch} from "@lodestar/types"; import {routes} from "@lodestar/api"; +import {Epoch} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; import {Metrics} from "../metrics/index.js"; diff --git a/packages/beacon-node/src/chain/blocks/importBlock.ts b/packages/beacon-node/src/chain/blocks/importBlock.ts index 596f01f391a4..6b23112b03fe 100644 --- a/packages/beacon-node/src/chain/blocks/importBlock.ts +++ b/packages/beacon-node/src/chain/blocks/importBlock.ts @@ -1,26 +1,26 @@ -import {capella, ssz, altair, BeaconBlock} from "@lodestar/types"; +import {routes} from "@lodestar/api"; +import {AncestorStatus, EpochDifference, ForkChoiceError, ForkChoiceErrorCode} from "@lodestar/fork-choice"; import {ForkLightClient, ForkSeq, INTERVALS_PER_SLOT, MAX_SEED_LOOKAHEAD, SLOTS_PER_EPOCH} from "@lodestar/params"; import { CachedBeaconStateAltair, + RootCache, computeEpochAtSlot, computeStartSlotAtEpoch, isStateValidatorsNodesPopulated, - RootCache, } from "@lodestar/state-transition"; -import {routes} from "@lodestar/api"; -import {ForkChoiceError, ForkChoiceErrorCode, EpochDifference, AncestorStatus} from "@lodestar/fork-choice"; +import {BeaconBlock, altair, capella, ssz} from "@lodestar/types"; import {isErrorAborted, toHex, toRootHex} from "@lodestar/utils"; import {ZERO_HASH_HEX} from "../../constants/index.js"; -import {toCheckpointHex} from "../stateCache/index.js"; +import {kzgCommitmentToVersionedHash} from "../../util/blobs.js"; +import {callInNextEventLoop} from "../../util/eventLoop.js"; import {isOptimisticBlock} from "../../util/forkChoice.js"; import {isQueueErrorAborted} from "../../util/queue/index.js"; -import {kzgCommitmentToVersionedHash} from "../../util/blobs.js"; -import {ChainEvent, ReorgEventData} from "../emitter.js"; -import {REPROCESS_MIN_TIME_TO_NEXT_SLOT_SEC} from "../reprocess.js"; import type {BeaconChain} from "../chain.js"; -import {callInNextEventLoop} from "../../util/eventLoop.js"; +import {ChainEvent, ReorgEventData} from "../emitter.js"; import {ForkchoiceCaller} from "../forkChoice/index.js"; -import {FullyVerifiedBlock, ImportBlockOpts, AttestationImportOpt, BlockInputType} from "./types.js"; +import {REPROCESS_MIN_TIME_TO_NEXT_SLOT_SEC} from "../reprocess.js"; +import {toCheckpointHex} from "../stateCache/index.js"; +import {AttestationImportOpt, BlockInputType, FullyVerifiedBlock, ImportBlockOpts} from "./types.js"; import {getCheckpointFromState} from "./utils/checkpoint.js"; import {writeBlockInputToDb} from "./writeBlockInputToDb.js"; diff --git a/packages/beacon-node/src/chain/blocks/index.ts b/packages/beacon-node/src/chain/blocks/index.ts index f64e4b1f3813..6e8eed428a4b 100644 --- a/packages/beacon-node/src/chain/blocks/index.ts +++ b/packages/beacon-node/src/chain/blocks/index.ts @@ -1,14 +1,14 @@ -import {isErrorAborted, toRootHex} from "@lodestar/utils"; import {SignedBeaconBlock} from "@lodestar/types"; -import {JobItemQueue, isQueueErrorAborted} from "../../util/queue/index.js"; +import {isErrorAborted, toRootHex} from "@lodestar/utils"; import {Metrics} from "../../metrics/metrics.js"; +import {JobItemQueue, isQueueErrorAborted} from "../../util/queue/index.js"; +import type {BeaconChain} from "../chain.js"; import {BlockError, BlockErrorCode, isBlockErrorAborted} from "../errors/index.js"; import {BlockProcessOpts} from "../options.js"; -import type {BeaconChain} from "../chain.js"; -import {verifyBlocksInEpoch} from "./verifyBlock.js"; import {importBlock} from "./importBlock.js"; -import {assertLinearChainSegment} from "./utils/chainSegment.js"; import {BlockInput, FullyVerifiedBlock, ImportBlockOpts} from "./types.js"; +import {assertLinearChainSegment} from "./utils/chainSegment.js"; +import {verifyBlocksInEpoch} from "./verifyBlock.js"; import {verifyBlocksSanityChecks} from "./verifyBlocksSanityChecks.js"; import {removeEagerlyPersistedBlockInputs} from "./writeBlockInputToDb.js"; export {type ImportBlockOpts, AttestationImportOpt} from "./types.js"; diff --git a/packages/beacon-node/src/chain/blocks/types.ts b/packages/beacon-node/src/chain/blocks/types.ts index 8b793932e951..2b7186e91112 100644 --- a/packages/beacon-node/src/chain/blocks/types.ts +++ b/packages/beacon-node/src/chain/blocks/types.ts @@ -1,8 +1,8 @@ -import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition"; -import {MaybeValidExecutionStatus, DataAvailabilityStatus} from "@lodestar/fork-choice"; -import {deneb, Slot, RootHex, SignedBeaconBlock} from "@lodestar/types"; -import {ForkSeq, ForkBlobs} from "@lodestar/params"; import {ChainForkConfig} from "@lodestar/config"; +import {DataAvailabilityStatus, MaybeValidExecutionStatus} from "@lodestar/fork-choice"; +import {ForkBlobs, ForkSeq} from "@lodestar/params"; +import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition"; +import {RootHex, SignedBeaconBlock, Slot, deneb} from "@lodestar/types"; export enum BlockInputType { // preData is preDeneb diff --git a/packages/beacon-node/src/chain/blocks/utils/checkpoint.ts b/packages/beacon-node/src/chain/blocks/utils/checkpoint.ts index 2ff77600b2b8..855a1b19e741 100644 --- a/packages/beacon-node/src/chain/blocks/utils/checkpoint.ts +++ b/packages/beacon-node/src/chain/blocks/utils/checkpoint.ts @@ -1,5 +1,5 @@ -import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition"; import {phase0, ssz} from "@lodestar/types"; import {ZERO_HASH} from "../../../constants/index.js"; diff --git a/packages/beacon-node/src/chain/blocks/utils/giraffeBanner.ts b/packages/beacon-node/src/chain/blocks/utils/giraffeBanner.ts new file mode 100644 index 000000000000..d3987831a064 --- /dev/null +++ b/packages/beacon-node/src/chain/blocks/utils/giraffeBanner.ts @@ -0,0 +1,27 @@ +export const ELECTRA_GIRAFFE_BANNER = String.raw` + 2048 + :--: + :-@==+-: + :-=++#+#++#> + :-=+=#+: + ::+*--@-*: + :-+=%*#%@-: + MAXEB**=+%*+: + :-*###+*#*=-: + :--=+*+==#*=-: + :-*=+#*=*-#*+%@%%%#*+: + -=+-+**#+#%%%*#@@+%%#=#% + 32 -*=*+#+=%*#%*#%#+*##***-: + : #+**+*+=*+*%*%%*==++@**=: + =++++=: ::----:: +=-@*: + +++=- -++ =+: + -=@ :+- -+ + :-: :+: :- + :+ := -= + := - @ + - @ : + -: -: - + *: :- =- + :- --: =: + ::*-: :::: :-: +`; diff --git a/packages/beacon-node/src/chain/blocks/verifyBlock.ts b/packages/beacon-node/src/chain/blocks/verifyBlock.ts index 4d21342bd8cc..2ce78eb5f3f1 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlock.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlock.ts @@ -1,26 +1,27 @@ +import {ChainForkConfig} from "@lodestar/config"; +import {DataAvailabilityStatus, ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice"; +import {ForkName} from "@lodestar/params"; import { CachedBeaconStateAllForks, + DataAvailableStatus, computeEpochAtSlot, isStateValidatorsNodesPopulated, - DataAvailableStatus, } from "@lodestar/state-transition"; import {bellatrix, deneb} from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; -import {ProtoBlock, ExecutionStatus, DataAvailabilityStatus} from "@lodestar/fork-choice"; -import {ChainForkConfig} from "@lodestar/config"; import {Logger, toRootHex} from "@lodestar/utils"; +import type {BeaconChain} from "../chain.js"; import {BlockError, BlockErrorCode} from "../errors/index.js"; import {BlockProcessOpts} from "../options.js"; import {RegenCaller} from "../regen/index.js"; -import type {BeaconChain} from "../chain.js"; -import {BlockInput, ImportBlockOpts, BlockInputType} from "./types.js"; -import {POS_PANDA_MERGE_TRANSITION_BANNER} from "./utils/pandaMergeTransitionBanner.js"; -import {CAPELLA_OWL_BANNER} from "./utils/ownBanner.js"; +import {BlockInput, BlockInputType, ImportBlockOpts} from "./types.js"; import {DENEB_BLOWFISH_BANNER} from "./utils/blowfishBanner.js"; -import {verifyBlocksStateTransitionOnly} from "./verifyBlocksStateTransitionOnly.js"; -import {verifyBlocksSignatures} from "./verifyBlocksSignatures.js"; -import {verifyBlocksExecutionPayload, SegmentExecStatus} from "./verifyBlocksExecutionPayloads.js"; +import {ELECTRA_GIRAFFE_BANNER} from "./utils/giraffeBanner.js"; +import {CAPELLA_OWL_BANNER} from "./utils/ownBanner.js"; +import {POS_PANDA_MERGE_TRANSITION_BANNER} from "./utils/pandaMergeTransitionBanner.js"; import {verifyBlocksDataAvailability} from "./verifyBlocksDataAvailability.js"; +import {SegmentExecStatus, verifyBlocksExecutionPayload} from "./verifyBlocksExecutionPayloads.js"; +import {verifyBlocksSignatures} from "./verifyBlocksSignatures.js"; +import {verifyBlocksStateTransitionOnly} from "./verifyBlocksStateTransitionOnly.js"; import {writeBlockInputToDb} from "./writeBlockInputToDb.js"; /** @@ -106,7 +107,7 @@ export async function verifyBlocksInEpoch( } as SegmentExecStatus), // data availability for the blobs - verifyBlocksDataAvailability(this, blocksInput, opts), + verifyBlocksDataAvailability(this, blocksInput, abortController.signal, opts), // Run state transition only // TODO: Ensure it yields to allow flushing to workers and engine API @@ -157,6 +158,11 @@ export async function verifyBlocksInEpoch( this.logger.info("Activating blobs", {epoch: this.config.DENEB_FORK_EPOCH}); break; + case ForkName.electra: + this.logger.info(ELECTRA_GIRAFFE_BANNER); + this.logger.info("Activating maxEB", {epoch: this.config.ELECTRA_FORK_EPOCH}); + break; + default: } } diff --git a/packages/beacon-node/src/chain/blocks/verifyBlocksDataAvailability.ts b/packages/beacon-node/src/chain/blocks/verifyBlocksDataAvailability.ts index 98bfae2c1ce3..11e1d8f94567 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlocksDataAvailability.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlocksDataAvailability.ts @@ -1,12 +1,12 @@ -import {computeTimeAtSlot} from "@lodestar/state-transition"; -import {DataAvailabilityStatus} from "@lodestar/fork-choice"; import {ChainForkConfig} from "@lodestar/config"; -import {deneb, UintNum64} from "@lodestar/types"; -import {Logger} from "@lodestar/utils"; +import {DataAvailabilityStatus} from "@lodestar/fork-choice"; +import {computeTimeAtSlot} from "@lodestar/state-transition"; +import {UintNum64, deneb} from "@lodestar/types"; +import {ErrorAborted, Logger} from "@lodestar/utils"; +import {Metrics} from "../../metrics/metrics.js"; import {BlockError, BlockErrorCode} from "../errors/index.js"; import {validateBlobSidecars} from "../validation/blobSidecar.js"; -import {Metrics} from "../../metrics/metrics.js"; -import {BlockInput, BlockInputType, ImportBlockOpts, BlobSidecarValidation, getBlockInput} from "./types.js"; +import {BlobSidecarValidation, BlockInput, BlockInputType, ImportBlockOpts, getBlockInput} from "./types.js"; // we can now wait for full 12 seconds because unavailable block sync will try pulling // the blobs from the network anyway after 500ms of seeing the block @@ -27,6 +27,7 @@ const BLOB_AVAILABILITY_TIMEOUT = 12_000; export async function verifyBlocksDataAvailability( chain: {config: ChainForkConfig; genesisTime: UintNum64; logger: Logger; metrics: Metrics | null}, blocks: BlockInput[], + signal: AbortSignal, opts: ImportBlockOpts ): Promise<{ dataAvailabilityStatuses: DataAvailabilityStatus[]; @@ -43,9 +44,12 @@ export async function verifyBlocksDataAvailability( const availableBlockInputs: BlockInput[] = []; for (const blockInput of blocks) { + if (signal.aborted) { + throw new ErrorAborted("verifyBlocksDataAvailability"); + } // Validate status of only not yet finalized blocks, we don't need yet to propogate the status // as it is not used upstream anywhere - const {dataAvailabilityStatus, availableBlockInput} = await maybeValidateBlobs(chain, blockInput, opts); + const {dataAvailabilityStatus, availableBlockInput} = await maybeValidateBlobs(chain, blockInput, signal, opts); dataAvailabilityStatuses.push(dataAvailabilityStatus); availableBlockInputs.push(availableBlockInput); } @@ -69,6 +73,7 @@ export async function verifyBlocksDataAvailability( async function maybeValidateBlobs( chain: {config: ChainForkConfig; genesisTime: UintNum64; logger: Logger}, blockInput: BlockInput, + signal: AbortSignal, opts: ImportBlockOpts ): Promise<{dataAvailabilityStatus: DataAvailabilityStatus; availableBlockInput: BlockInput}> { switch (blockInput.type) { @@ -92,7 +97,7 @@ async function maybeValidateBlobs( const blobsData = blockInput.type === BlockInputType.availableData ? blockInput.blockData - : await raceWithCutoff(chain, blockInput, blockInput.cachedData.availabilityPromise); + : await raceWithCutoff(chain, blockInput, blockInput.cachedData.availabilityPromise, signal); const {blobs} = blobsData; const {blobKzgCommitments} = (block as deneb.SignedBeaconBlock).message.body; @@ -122,16 +127,21 @@ async function maybeValidateBlobs( async function raceWithCutoff( chain: {config: ChainForkConfig; genesisTime: UintNum64; logger: Logger}, blockInput: BlockInput, - availabilityPromise: Promise + availabilityPromise: Promise, + signal: AbortSignal ): Promise { const {block} = blockInput; const blockSlot = block.message.slot; - const cutoffTime = Math.max( - computeTimeAtSlot(chain.config, blockSlot, chain.genesisTime) * 1000 + BLOB_AVAILABILITY_TIMEOUT - Date.now(), - 0 - ); - const cutoffTimeout = new Promise((_resolve, reject) => setTimeout(reject, cutoffTime)); + const cutoffTime = + computeTimeAtSlot(chain.config, blockSlot, chain.genesisTime) * 1000 + BLOB_AVAILABILITY_TIMEOUT - Date.now(); + const cutoffTimeout = + cutoffTime > 0 + ? new Promise((_resolve, reject) => { + setTimeout(() => reject(new Error("Timeout exceeded")), cutoffTime); + signal.addEventListener("abort", () => reject(signal.reason)); + }) + : Promise.reject(new Error("Cutoff time must be greater than 0")); chain.logger.debug("Racing for blob availabilityPromise", {blockSlot, cutoffTime}); try { diff --git a/packages/beacon-node/src/chain/blocks/verifyBlocksExecutionPayloads.ts b/packages/beacon-node/src/chain/blocks/verifyBlocksExecutionPayloads.ts index e641ff9ae6d9..e37442bfde8f 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlocksExecutionPayloads.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlocksExecutionPayloads.ts @@ -1,32 +1,32 @@ +import {ChainForkConfig} from "@lodestar/config"; +import { + ExecutionStatus, + IForkChoice, + LVHInvalidResponse, + LVHValidResponse, + MaybeValidExecutionStatus, + ProtoBlock, + assertValidTerminalPowBlock, +} from "@lodestar/fork-choice"; +import {ForkSeq, SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params"; import { CachedBeaconStateAllForks, - isExecutionStateType, isExecutionBlockBodyType, - isMergeTransitionBlock as isMergeTransitionBlockFn, isExecutionEnabled, + isExecutionStateType, + isMergeTransitionBlock as isMergeTransitionBlockFn, } from "@lodestar/state-transition"; -import {bellatrix, Slot, deneb, SignedBeaconBlock, electra} from "@lodestar/types"; -import { - IForkChoice, - assertValidTerminalPowBlock, - ProtoBlock, - ExecutionStatus, - MaybeValidExecutionStatus, - LVHValidResponse, - LVHInvalidResponse, -} from "@lodestar/fork-choice"; -import {ChainForkConfig} from "@lodestar/config"; +import {SignedBeaconBlock, Slot, bellatrix, deneb, electra} from "@lodestar/types"; import {ErrorAborted, Logger, toRootHex} from "@lodestar/utils"; -import {ForkSeq, SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params"; +import {IEth1ForBlockProduction} from "../../eth1/index.js"; import {IExecutionEngine} from "../../execution/engine/interface.js"; -import {BlockError, BlockErrorCode} from "../errors/index.js"; -import {IClock} from "../../util/clock.js"; -import {kzgCommitmentToVersionedHash} from "../../util/blobs.js"; -import {BlockProcessOpts} from "../options.js"; import {ExecutionPayloadStatus} from "../../execution/engine/interface.js"; -import {IEth1ForBlockProduction} from "../../eth1/index.js"; import {Metrics} from "../../metrics/metrics.js"; +import {kzgCommitmentToVersionedHash} from "../../util/blobs.js"; +import {IClock} from "../../util/clock.js"; +import {BlockError, BlockErrorCode} from "../errors/index.js"; +import {BlockProcessOpts} from "../options.js"; import {ImportBlockOpts} from "./types.js"; export type VerifyBlockExecutionPayloadModules = { diff --git a/packages/beacon-node/src/chain/blocks/verifyBlocksSanityChecks.ts b/packages/beacon-node/src/chain/blocks/verifyBlocksSanityChecks.ts index 22b20a55fb67..5115f39ebf47 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlocksSanityChecks.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlocksSanityChecks.ts @@ -1,6 +1,6 @@ -import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {ChainForkConfig} from "@lodestar/config"; import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; +import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {Slot} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {IClock} from "../../util/clock.js"; diff --git a/packages/beacon-node/src/chain/blocks/verifyBlocksSignatures.ts b/packages/beacon-node/src/chain/blocks/verifyBlocksSignatures.ts index e86549cda7d3..d133579f97a5 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlocksSignatures.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlocksSignatures.ts @@ -1,10 +1,10 @@ import {CachedBeaconStateAllForks, getBlockSignatureSets} from "@lodestar/state-transition"; -import {Logger} from "@lodestar/utils"; import {SignedBeaconBlock} from "@lodestar/types"; +import {Logger} from "@lodestar/utils"; import {Metrics} from "../../metrics/metrics.js"; +import {nextEventLoop} from "../../util/eventLoop.js"; import {IBlsVerifier} from "../bls/index.js"; import {BlockError, BlockErrorCode} from "../errors/blockError.js"; -import {nextEventLoop} from "../../util/eventLoop.js"; import {ImportBlockOpts} from "./types.js"; /** diff --git a/packages/beacon-node/src/chain/blocks/verifyBlocksStateTransitionOnly.ts b/packages/beacon-node/src/chain/blocks/verifyBlocksStateTransitionOnly.ts index 49cd46220008..b2f70d6274b3 100644 --- a/packages/beacon-node/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +++ b/packages/beacon-node/src/chain/blocks/verifyBlocksStateTransitionOnly.ts @@ -1,16 +1,16 @@ import { CachedBeaconStateAllForks, - stateTransition, - ExecutionPayloadStatus, DataAvailableStatus, + ExecutionPayloadStatus, StateHashTreeRootSource, + stateTransition, } from "@lodestar/state-transition"; import {ErrorAborted, Logger} from "@lodestar/utils"; import {Metrics} from "../../metrics/index.js"; -import {BlockError, BlockErrorCode} from "../errors/index.js"; -import {BlockProcessOpts} from "../options.js"; import {byteArrayEquals} from "../../util/bytes.js"; import {nextEventLoop} from "../../util/eventLoop.js"; +import {BlockError, BlockErrorCode} from "../errors/index.js"; +import {BlockProcessOpts} from "../options.js"; import {BlockInput, ImportBlockOpts} from "./types.js"; /** diff --git a/packages/beacon-node/src/chain/bls/multithread/index.ts b/packages/beacon-node/src/chain/bls/multithread/index.ts index cb18ca86e42f..74e2dbbca4f7 100644 --- a/packages/beacon-node/src/chain/bls/multithread/index.ts +++ b/packages/beacon-node/src/chain/bls/multithread/index.ts @@ -1,24 +1,21 @@ /* eslint-disable @typescript-eslint/strict-boolean-expressions */ import path from "node:path"; -import {spawn, Worker} from "@chainsafe/threads"; +import {Worker, spawn} from "@chainsafe/threads"; // `threads` library creates self global variable which breaks `timeout-abort-controller` https://github.com/jacobheun/timeout-abort-controller/issues/9 // Don't add an eslint disable here as a reminder that this has to be fixed eventually // @ts-ignore // biome-ignore lint/suspicious/noGlobalAssign: self = undefined; import {PublicKey} from "@chainsafe/blst"; -import {Logger} from "@lodestar/utils"; import {ISignatureSet} from "@lodestar/state-transition"; -import {QueueError, QueueErrorCode} from "../../../util/queue/index.js"; +import {Logger} from "@lodestar/utils"; import {Metrics} from "../../../metrics/index.js"; -import {IBlsVerifier, VerifySignatureOpts} from "../interface.js"; -import {getAggregatedPubkey, getAggregatedPubkeysCount} from "../utils.js"; -import {verifySignatureSetsMaybeBatch} from "../maybeBatch.js"; import {LinkedList} from "../../../util/array.js"; import {callInNextEventLoop} from "../../../util/eventLoop.js"; -import {BlsWorkReq, BlsWorkResult, WorkerData, WorkResultCode, WorkResultError} from "./types.js"; -import {chunkifyMaximizeChunkSize} from "./utils.js"; -import {defaultPoolSize} from "./poolSize.js"; +import {QueueError, QueueErrorCode} from "../../../util/queue/index.js"; +import {IBlsVerifier, VerifySignatureOpts} from "../interface.js"; +import {verifySignatureSetsMaybeBatch} from "../maybeBatch.js"; +import {getAggregatedPubkey, getAggregatedPubkeysCount} from "../utils.js"; import { JobQueueItem, JobQueueItemSameMessage, @@ -27,6 +24,9 @@ import { jobItemSigSets, jobItemWorkReq, } from "./jobItem.js"; +import {defaultPoolSize} from "./poolSize.js"; +import {BlsWorkReq, BlsWorkResult, WorkResultCode, WorkResultError, WorkerData} from "./types.js"; +import {chunkifyMaximizeChunkSize} from "./utils.js"; // Worker constructor consider the path relative to the current working directory const workerDir = process.env.NODE_ENV === "test" ? "../../../../lib/chain/bls/multithread" : "./"; diff --git a/packages/beacon-node/src/chain/bls/multithread/jobItem.ts b/packages/beacon-node/src/chain/bls/multithread/jobItem.ts index 035d56e56df2..9f0c74fbcf32 100644 --- a/packages/beacon-node/src/chain/bls/multithread/jobItem.ts +++ b/packages/beacon-node/src/chain/bls/multithread/jobItem.ts @@ -1,9 +1,9 @@ import {PublicKey, aggregateWithRandomness} from "@chainsafe/blst"; import {ISignatureSet, SignatureSetType} from "@lodestar/state-transition"; +import {Metrics} from "../../../metrics/metrics.js"; +import {LinkedList} from "../../../util/array.js"; import {VerifySignatureOpts} from "../interface.js"; import {getAggregatedPubkey} from "../utils.js"; -import {LinkedList} from "../../../util/array.js"; -import {Metrics} from "../../../metrics/metrics.js"; import {BlsWorkReq} from "./types.js"; export type JobQueueItem = JobQueueItemDefault | JobQueueItemSameMessage; diff --git a/packages/beacon-node/src/chain/bls/multithread/worker.ts b/packages/beacon-node/src/chain/bls/multithread/worker.ts index d2794db2e6bf..7fbd1701950b 100644 --- a/packages/beacon-node/src/chain/bls/multithread/worker.ts +++ b/packages/beacon-node/src/chain/bls/multithread/worker.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/strict-boolean-expressions */ import worker from "node:worker_threads"; -import {expose} from "@chainsafe/threads/worker"; import {PublicKey} from "@chainsafe/blst"; -import {verifySignatureSetsMaybeBatch, SignatureSetDeserialized} from "../maybeBatch.js"; -import {WorkerData, BlsWorkReq, WorkResult, WorkResultCode, SerializedSet, BlsWorkResult} from "./types.js"; +import {expose} from "@chainsafe/threads/worker"; +import {SignatureSetDeserialized, verifySignatureSetsMaybeBatch} from "../maybeBatch.js"; +import {BlsWorkReq, BlsWorkResult, SerializedSet, WorkResult, WorkResultCode, WorkerData} from "./types.js"; import {chunkifyMaximizeChunkSize} from "./utils.js"; /** diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index 9141aa994224..415158abb2d5 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -1,106 +1,106 @@ import path from "node:path"; -import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz"; import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; +import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz"; +import {BeaconConfig} from "@lodestar/config"; +import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice"; +import {ForkSeq, GENESIS_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params"; import { BeaconStateAllForks, CachedBeaconStateAllForks, + EffectiveBalanceIncrements, + EpochShuffling, + Index2PubkeyCache, + computeAnchorCheckpoint, + computeEndSlotAtEpoch, computeEpochAtSlot, computeStartSlotAtEpoch, createCachedBeaconState, - EffectiveBalanceIncrements, getEffectiveBalanceIncrementsZeroInactive, isCachedBeaconState, - Index2PubkeyCache, - EpochShuffling, - computeEndSlotAtEpoch, - computeAnchorCheckpoint, } from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; import { - UintNum64, + BeaconBlock, + BlindedBeaconBlock, + BlindedBeaconBlockBody, + Epoch, + ExecutionPayload, Root, - phase0, - Slot, RootHex, - Epoch, + SignedBeaconBlock, + Slot, + UintNum64, ValidatorIndex, - deneb, Wei, bellatrix, + deneb, isBlindedBeaconBlock, - BeaconBlock, - SignedBeaconBlock, - ExecutionPayload, - BlindedBeaconBlock, - BlindedBeaconBlockBody, + phase0, } from "@lodestar/types"; -import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice"; -import {ProcessShutdownCallback} from "@lodestar/validator"; import {Logger, fromHex, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils"; -import {ForkSeq, GENESIS_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {ProcessShutdownCallback} from "@lodestar/validator"; import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js"; import {IBeaconDb} from "../db/index.js"; -import {Metrics} from "../metrics/index.js"; import {IEth1ForBlockProduction} from "../eth1/index.js"; -import {IExecutionEngine, IExecutionBuilder} from "../execution/index.js"; +import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js"; +import {Metrics} from "../metrics/index.js"; +import {BufferPool} from "../util/bufferPool.js"; import {Clock, ClockEvent, IClock} from "../util/clock.js"; import {ensureDir, writeIfNotExist} from "../util/file.js"; import {isOptimisticBlock} from "../util/forkChoice.js"; -import {BufferPool} from "../util/bufferPool.js"; +import {Archiver} from "./archiver/archiver.js"; +import {CheckpointBalancesCache} from "./balancesCache.js"; +import {BeaconProposerCache} from "./beaconProposerCache.js"; import {BlockProcessor, ImportBlockOpts} from "./blocks/index.js"; -import {ChainEventEmitter, ChainEvent} from "./emitter.js"; +import {BlockInput} from "./blocks/types.js"; +import {BlsMultiThreadWorkerPool, BlsSingleThreadVerifier, IBlsVerifier} from "./bls/index.js"; +import {ChainEvent, ChainEventEmitter} from "./emitter.js"; +import {ForkchoiceCaller, initializeForkChoice} from "./forkChoice/index.js"; +import {HistoricalStateRegen} from "./historicalState/index.js"; import { - IBeaconChain, - ProposerPreparationData, BlockHash, - StateGetOpts, CommonBlockBody, FindHeadFnName, + IBeaconChain, + ProposerPreparationData, + StateGetOpts, } from "./interface.js"; -import {IChainOptions} from "./options.js"; -import {QueuedStateRegenerator, RegenCaller} from "./regen/index.js"; -import {ForkchoiceCaller, initializeForkChoice} from "./forkChoice/index.js"; -import {IBlsVerifier, BlsSingleThreadVerifier, BlsMultiThreadWorkerPool} from "./bls/index.js"; -import { - SeenAttesters, - SeenAggregators, - SeenBlockProposers, - SeenSyncCommitteeMessages, - SeenContributionAndProof, -} from "./seenCache/index.js"; +import {LightClientServer} from "./lightClient/index.js"; import { AggregatedAttestationPool, AttestationPool, + OpPool, SyncCommitteeMessagePool, SyncContributionAndProofPool, - OpPool, } from "./opPools/index.js"; -import {LightClientServer} from "./lightClient/index.js"; -import {Archiver} from "./archiver/archiver.js"; +import {IChainOptions} from "./options.js"; import {PrepareNextSlotScheduler} from "./prepareNextSlot.js"; -import {ReprocessController} from "./reprocess.js"; -import {SeenAggregatedAttestations} from "./seenCache/seenAggregateAndProof.js"; -import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js"; -import {BeaconProposerCache} from "./beaconProposerCache.js"; -import {CheckpointBalancesCache} from "./balancesCache.js"; +import {computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js"; import {AssembledBlockType, BlobsResultType, BlockType} from "./produceBlock/index.js"; import {BlockAttributes, produceBlockBody, produceCommonBlockBody} from "./produceBlock/produceBlockBody.js"; -import {computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js"; -import {BlockInput} from "./blocks/types.js"; -import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js"; -import {HistoricalStateRegen} from "./historicalState/index.js"; +import {QueuedStateRegenerator, RegenCaller} from "./regen/index.js"; +import {ReprocessController} from "./reprocess.js"; +import {AttestationsRewards, computeAttestationsRewards} from "./rewards/attestationsRewards.js"; import {BlockRewards, computeBlockRewards} from "./rewards/blockRewards.js"; +import {SyncCommitteeRewards, computeSyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js"; +import { + SeenAggregators, + SeenAttesters, + SeenBlockProposers, + SeenContributionAndProof, + SeenSyncCommitteeMessages, +} from "./seenCache/index.js"; +import {SeenGossipBlockInput} from "./seenCache/index.js"; +import {SeenAggregatedAttestations} from "./seenCache/seenAggregateAndProof.js"; +import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js"; +import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js"; import {ShufflingCache} from "./shufflingCache.js"; import {BlockStateCacheImpl} from "./stateCache/blockStateCacheImpl.js"; -import {SeenGossipBlockInput} from "./seenCache/index.js"; -import {InMemoryCheckpointStateCache} from "./stateCache/inMemoryCheckpointsCache.js"; -import {FIFOBlockStateCache} from "./stateCache/fifoBlockStateCache.js"; -import {PersistentCheckpointStateCache} from "./stateCache/persistentCheckpointsCache.js"; import {DbCPStateDatastore} from "./stateCache/datastore/db.js"; import {FileCPStateDatastore} from "./stateCache/datastore/file.js"; -import {SyncCommitteeRewards, computeSyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js"; -import {AttestationsRewards, computeAttestationsRewards} from "./rewards/attestationsRewards.js"; +import {FIFOBlockStateCache} from "./stateCache/fifoBlockStateCache.js"; +import {InMemoryCheckpointStateCache} from "./stateCache/inMemoryCheckpointsCache.js"; +import {PersistentCheckpointStateCache} from "./stateCache/persistentCheckpointsCache.js"; /** * Arbitrary constants, blobs and payloads should be consumed immediately in the same slot @@ -1046,9 +1046,6 @@ export class BeaconChain implements IBeaconChain { metrics.forkChoice.balancesLength.set(forkChoiceMetrics.balancesLength); metrics.forkChoice.nodes.set(forkChoiceMetrics.nodes); metrics.forkChoice.indices.set(forkChoiceMetrics.indices); - - const headState = this.getHeadState(); - metrics.headState.unfinalizedPubkeyCacheSize.set(headState.epochCtx.unfinalizedPubkey2index.size); } private onClockSlot(slot: Slot): void { @@ -1138,27 +1135,8 @@ export class BeaconChain implements IBeaconChain { this.opPool.pruneAll(headBlock, headState); } - const cpEpoch = cp.epoch; - if (headState === null) { this.logger.verbose("Head state is null"); - } else if (cpEpoch >= this.config.ELECTRA_FORK_EPOCH) { - // Get the validator.length from the state at cpEpoch - // We are confident the last element in the list is from headEpoch - // Thus we query from the end of the list. (cpEpoch - headEpoch - 1) is negative number - const pivotValidatorIndex = headState.epochCtx.getValidatorCountAtEpoch(cpEpoch); - - if (pivotValidatorIndex !== undefined) { - // Note EIP-6914 will break this logic - const newFinalizedValidators = headState.epochCtx.unfinalizedPubkey2index.filter( - (index, _pubkey) => index < pivotValidatorIndex - ); - - // Populate finalized pubkey cache and remove unfinalized pubkey cache - if (!newFinalizedValidators.isEmpty()) { - this.regen.updateUnfinalizedPubkeys(newFinalizedValidators); - } - } } // TODO-Electra: Deprecating eth1Data poll requires a check on a finalized checkpoint state. diff --git a/packages/beacon-node/src/chain/emitter.ts b/packages/beacon-node/src/chain/emitter.ts index 10b6455e48f5..a24c1e37bf92 100644 --- a/packages/beacon-node/src/chain/emitter.ts +++ b/packages/beacon-node/src/chain/emitter.ts @@ -2,9 +2,9 @@ import {EventEmitter} from "node:events"; import {StrictEventEmitter} from "strict-event-emitter-types"; import {routes} from "@lodestar/api"; -import {phase0} from "@lodestar/types"; import {CheckpointWithHex} from "@lodestar/fork-choice"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {phase0} from "@lodestar/types"; /** * Important chain events that occur during normal chain operation. diff --git a/packages/beacon-node/src/chain/errors/attestationError.ts b/packages/beacon-node/src/chain/errors/attestationError.ts index 9f8e86cea1ab..618a334928ae 100644 --- a/packages/beacon-node/src/chain/errors/attestationError.ts +++ b/packages/beacon-node/src/chain/errors/attestationError.ts @@ -1,4 +1,4 @@ -import {Epoch, Slot, ValidatorIndex, RootHex} from "@lodestar/types"; +import {Epoch, RootHex, Slot, ValidatorIndex} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {GossipActionError} from "./gossipValidation.js"; diff --git a/packages/beacon-node/src/chain/errors/blobSidecarError.ts b/packages/beacon-node/src/chain/errors/blobSidecarError.ts index f38aa883002c..216ad9206db4 100644 --- a/packages/beacon-node/src/chain/errors/blobSidecarError.ts +++ b/packages/beacon-node/src/chain/errors/blobSidecarError.ts @@ -1,7 +1,8 @@ -import {Slot, RootHex, ValidatorIndex} from "@lodestar/types"; +import {RootHex, Slot, ValidatorIndex} from "@lodestar/types"; import {GossipActionError} from "./gossipValidation.js"; export enum BlobSidecarErrorCode { + INDEX_TOO_LARGE = "BLOB_SIDECAR_ERROR_INDEX_TOO_LARGE", INVALID_INDEX = "BLOB_SIDECAR_ERROR_INVALID_INDEX", /** !bls.KeyValidate(block.body.blob_kzg_commitments[i]) */ INVALID_KZG = "BLOB_SIDECAR_ERROR_INVALID_KZG", @@ -26,7 +27,8 @@ export enum BlobSidecarErrorCode { } export type BlobSidecarErrorType = - | {code: BlobSidecarErrorCode.INVALID_INDEX; blobIdx: number; gossipIndex: number} + | {code: BlobSidecarErrorCode.INDEX_TOO_LARGE; blobIdx: number; maxBlobsPerBlock: number} + | {code: BlobSidecarErrorCode.INVALID_INDEX; blobIdx: number; subnet: number} | {code: BlobSidecarErrorCode.INVALID_KZG; blobIdx: number} | {code: BlobSidecarErrorCode.INVALID_KZG_TXS} | {code: BlobSidecarErrorCode.INCORRECT_SLOT; blockSlot: Slot; blobSlot: Slot; blobIdx: number} diff --git a/packages/beacon-node/src/chain/errors/blockError.ts b/packages/beacon-node/src/chain/errors/blockError.ts index 6280533c7a68..1dc5b08ccc20 100644 --- a/packages/beacon-node/src/chain/errors/blockError.ts +++ b/packages/beacon-node/src/chain/errors/blockError.ts @@ -1,6 +1,6 @@ +import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {RootHex, SignedBeaconBlock, Slot, ValidatorIndex} from "@lodestar/types"; import {LodestarError, toRootHex} from "@lodestar/utils"; -import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {ExecutionPayloadStatus} from "../../execution/engine/interface.js"; import {QueueErrorCode} from "../../util/queue/index.js"; import {GossipActionError} from "./gossipValidation.js"; @@ -64,6 +64,8 @@ export enum BlockErrorCode { TOO_MANY_SKIPPED_SLOTS = "TOO_MANY_SKIPPED_SLOTS", /** The blobs are unavailable */ DATA_UNAVAILABLE = "BLOCK_ERROR_DATA_UNAVAILABLE", + /** Block contains too many kzg commitments */ + TOO_MANY_KZG_COMMITMENTS = "BLOCK_ERROR_TOO_MANY_KZG_COMMITMENTS", } type ExecutionErrorStatus = Exclude< @@ -105,7 +107,8 @@ export type BlockErrorType = | {code: BlockErrorCode.SAME_PARENT_HASH; blockHash: RootHex} | {code: BlockErrorCode.TRANSACTIONS_TOO_BIG; size: number; max: number} | {code: BlockErrorCode.EXECUTION_ENGINE_ERROR; execStatus: ExecutionErrorStatus; errorMessage: string} - | {code: BlockErrorCode.DATA_UNAVAILABLE}; + | {code: BlockErrorCode.DATA_UNAVAILABLE} + | {code: BlockErrorCode.TOO_MANY_KZG_COMMITMENTS; blobKzgCommitmentsLen: number; commitmentLimit: number}; export class BlockGossipError extends GossipActionError {} diff --git a/packages/beacon-node/src/chain/errors/syncCommitteeError.ts b/packages/beacon-node/src/chain/errors/syncCommitteeError.ts index e4a92729cecd..1564a358ec4c 100644 --- a/packages/beacon-node/src/chain/errors/syncCommitteeError.ts +++ b/packages/beacon-node/src/chain/errors/syncCommitteeError.ts @@ -1,4 +1,4 @@ -import {ValidatorIndex, Slot, RootHex} from "@lodestar/types"; +import {RootHex, Slot, ValidatorIndex} from "@lodestar/types"; import {GossipActionError} from "./gossipValidation.js"; export enum SyncCommitteeErrorCode { diff --git a/packages/beacon-node/src/chain/forkChoice/index.ts b/packages/beacon-node/src/chain/forkChoice/index.ts index 839975de4e26..b3f5d11260f2 100644 --- a/packages/beacon-node/src/chain/forkChoice/index.ts +++ b/packages/beacon-node/src/chain/forkChoice/index.ts @@ -1,26 +1,26 @@ -import {Slot} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import { + DataAvailabilityStatus, + ExecutionStatus, ForkChoice, - ProtoArray, ForkChoiceStore, - ExecutionStatus, JustifiedBalancesGetter, + ProtoArray, ForkChoiceOpts as RawForkChoiceOpts, - DataAvailabilityStatus, } from "@lodestar/fork-choice"; import { CachedBeaconStateAllForks, + computeAnchorCheckpoint, getEffectiveBalanceIncrementsZeroInactive, isExecutionStateType, isMergeTransitionComplete, - computeAnchorCheckpoint, } from "@lodestar/state-transition"; +import {Slot} from "@lodestar/types"; import {Logger, toRootHex} from "@lodestar/utils"; +import {GENESIS_SLOT} from "../../constants/index.js"; import {ChainEventEmitter} from "../emitter.js"; import {ChainEvent} from "../emitter.js"; -import {GENESIS_SLOT} from "../../constants/index.js"; export type ForkChoiceOpts = RawForkChoiceOpts & { // for testing only diff --git a/packages/beacon-node/src/chain/genesis/genesis.ts b/packages/beacon-node/src/chain/genesis/genesis.ts index 0c46f920d614..f56b42a3b89e 100644 --- a/packages/beacon-node/src/chain/genesis/genesis.ts +++ b/packages/beacon-node/src/chain/genesis/genesis.ts @@ -1,25 +1,25 @@ -import {toGindex, Tree} from "@chainsafe/persistent-merkle-tree"; -import {GENESIS_EPOCH, GENESIS_SLOT} from "@lodestar/params"; -import {phase0, ssz} from "@lodestar/types"; +import {Tree, toGindex} from "@chainsafe/persistent-merkle-tree"; import {BeaconConfig, ChainForkConfig} from "@lodestar/config"; +import {GENESIS_EPOCH, GENESIS_SLOT} from "@lodestar/params"; import { - getTemporaryBlockHeader, - getGenesisBeaconState, + BeaconStateAllForks, + CachedBeaconStateAllForks, applyDeposits, - applyTimestamp, applyEth1BlockHash, - CachedBeaconStateAllForks, + applyTimestamp, createCachedBeaconState, - BeaconStateAllForks, createEmptyEpochCacheImmutableData, getActiveValidatorIndices, + getGenesisBeaconState, + getTemporaryBlockHeader, } from "@lodestar/state-transition"; +import {phase0, ssz} from "@lodestar/types"; import {Logger} from "@lodestar/utils"; +import {DepositTree} from "../../db/repositories/depositDataRoot.js"; import {IEth1Provider} from "../../eth1/index.js"; import {IEth1StreamParams} from "../../eth1/interface.js"; import {getDepositsAndBlockStreamForGenesis, getDepositsStream} from "../../eth1/stream.js"; -import {DepositTree} from "../../db/repositories/depositDataRoot.js"; -import {IGenesisBuilder, GenesisResult} from "./interface.js"; +import {GenesisResult, IGenesisBuilder} from "./interface.js"; export type GenesisBuilderKwargs = { config: ChainForkConfig; diff --git a/packages/beacon-node/src/chain/genesis/interface.ts b/packages/beacon-node/src/chain/genesis/interface.ts index d1bae335b9ff..79c402cc29cb 100644 --- a/packages/beacon-node/src/chain/genesis/interface.ts +++ b/packages/beacon-node/src/chain/genesis/interface.ts @@ -1,6 +1,6 @@ import {CompositeViewDU, VectorCompositeType} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; import {Eth1Block} from "../../eth1/interface.js"; export type GenesisResult = { diff --git a/packages/beacon-node/src/chain/historicalState/getHistoricalState.ts b/packages/beacon-node/src/chain/historicalState/getHistoricalState.ts index a9f254dea3f2..20a53c40d73d 100644 --- a/packages/beacon-node/src/chain/historicalState/getHistoricalState.ts +++ b/packages/beacon-node/src/chain/historicalState/getHistoricalState.ts @@ -1,4 +1,5 @@ import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; +import {BeaconConfig} from "@lodestar/config"; import { BeaconStateAllForks, CachedBeaconStateAllForks, @@ -7,7 +8,6 @@ import { createCachedBeaconState, stateTransition, } from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; import {IBeaconDb} from "../../db/index.js"; import {HistoricalStateRegenMetrics, RegenErrorType} from "./types.js"; diff --git a/packages/beacon-node/src/chain/historicalState/index.ts b/packages/beacon-node/src/chain/historicalState/index.ts index 8688bcf9f372..250a80467951 100644 --- a/packages/beacon-node/src/chain/historicalState/index.ts +++ b/packages/beacon-node/src/chain/historicalState/index.ts @@ -1,5 +1,5 @@ import path from "node:path"; -import {ModuleThread, Thread, spawn, Worker} from "@chainsafe/threads"; +import {ModuleThread, Thread, Worker, spawn} from "@chainsafe/threads"; import {chainConfigToJson} from "@lodestar/config"; import {LoggerNode} from "@lodestar/logger/node"; import { diff --git a/packages/beacon-node/src/chain/historicalState/worker.ts b/packages/beacon-node/src/chain/historicalState/worker.ts index 2ea673d0faff..fabb985c66a5 100644 --- a/packages/beacon-node/src/chain/historicalState/worker.ts +++ b/packages/beacon-node/src/chain/historicalState/worker.ts @@ -1,21 +1,21 @@ import worker from "node:worker_threads"; -import {Transfer, expose} from "@chainsafe/threads/worker"; import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; -import {createBeaconConfig, chainConfigFromJson} from "@lodestar/config"; +import {Transfer, expose} from "@chainsafe/threads/worker"; +import {chainConfigFromJson, createBeaconConfig} from "@lodestar/config"; +import {LevelDbController} from "@lodestar/db"; import {getNodeLogger} from "@lodestar/logger/node"; import {EpochTransitionStep, StateCloneSource, StateHashTreeRootSource} from "@lodestar/state-transition"; -import {LevelDbController} from "@lodestar/db"; +import {BeaconDb} from "../../db/index.js"; import {RegistryMetricCreator, collectNodeJSMetrics} from "../../metrics/index.js"; import {JobFnQueue} from "../../util/queue/fnQueue.js"; import {QueueMetrics} from "../../util/queue/options.js"; -import {BeaconDb} from "../../db/index.js"; +import {getHistoricalState} from "./getHistoricalState.js"; import { HistoricalStateRegenMetrics, HistoricalStateWorkerApi, HistoricalStateWorkerData, RegenErrorType, } from "./types.js"; -import {getHistoricalState} from "./getHistoricalState.js"; // most of this setup copied from networkCoreWorker.ts diff --git a/packages/beacon-node/src/chain/initState.ts b/packages/beacon-node/src/chain/initState.ts index 2883cdc8388e..ff683867d14b 100644 --- a/packages/beacon-node/src/chain/initState.ts +++ b/packages/beacon-node/src/chain/initState.ts @@ -1,17 +1,17 @@ +import {ChainForkConfig} from "@lodestar/config"; import { - computeEpochAtSlot, BeaconStateAllForks, CachedBeaconStateAllForks, + computeEpochAtSlot, computeStartSlotAtEpoch, } from "@lodestar/state-transition"; import {SignedBeaconBlock} from "@lodestar/types"; -import {ChainForkConfig} from "@lodestar/config"; import {Logger, toHex, toRootHex} from "@lodestar/utils"; import {GENESIS_SLOT} from "../constants/index.js"; import {IBeaconDb} from "../db/index.js"; import {Eth1Provider} from "../eth1/index.js"; -import {Metrics} from "../metrics/index.js"; import {Eth1Options} from "../eth1/options.js"; +import {Metrics} from "../metrics/index.js"; import {GenesisBuilder} from "./genesis/genesis.js"; import {GenesisResult} from "./genesis/interface.js"; diff --git a/packages/beacon-node/src/chain/interface.ts b/packages/beacon-node/src/chain/interface.ts index 3b44ffd594ae..67b011ec0246 100644 --- a/packages/beacon-node/src/chain/interface.ts +++ b/packages/beacon-node/src/chain/interface.ts @@ -1,64 +1,64 @@ -import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz"; import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; +import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz"; +import {BeaconConfig} from "@lodestar/config"; +import {CheckpointWithHex, IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import { - UintNum64, + BeaconStateAllForks, + CachedBeaconStateAllForks, + EpochShuffling, + Index2PubkeyCache, +} from "@lodestar/state-transition"; +import { + BeaconBlock, + BlindedBeaconBlock, + Epoch, + ExecutionPayload, Root, - phase0, - Slot, RootHex, - Epoch, + SignedBeaconBlock, + Slot, + UintNum64, ValidatorIndex, - deneb, Wei, - capella, altair, - BeaconBlock, - ExecutionPayload, - SignedBeaconBlock, - BlindedBeaconBlock, + capella, + deneb, + phase0, } from "@lodestar/types"; -import { - BeaconStateAllForks, - CachedBeaconStateAllForks, - EpochShuffling, - Index2PubkeyCache, -} from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; import {Logger} from "@lodestar/utils"; -import {CheckpointWithHex, IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {IEth1ForBlockProduction} from "../eth1/index.js"; -import {IExecutionEngine, IExecutionBuilder} from "../execution/index.js"; +import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js"; import {Metrics} from "../metrics/metrics.js"; -import {IClock} from "../util/clock.js"; import {BufferPool} from "../util/bufferPool.js"; +import {IClock} from "../util/clock.js"; +import {CheckpointBalancesCache} from "./balancesCache.js"; +import {BeaconProposerCache, ProposerPreparationData} from "./beaconProposerCache.js"; +import {BlockInput, ImportBlockOpts} from "./blocks/types.js"; +import {IBlsVerifier} from "./bls/index.js"; import {ChainEventEmitter} from "./emitter.js"; +import {ForkchoiceCaller} from "./forkChoice/index.js"; +import {LightClientServer} from "./lightClient/index.js"; +import {AggregatedAttestationPool} from "./opPools/aggregatedAttestationPool.js"; +import {AttestationPool, OpPool, SyncCommitteeMessagePool, SyncContributionAndProofPool} from "./opPools/index.js"; +import {IChainOptions} from "./options.js"; +import {AssembledBlockType, BlockAttributes, BlockType} from "./produceBlock/produceBlockBody.js"; import {IStateRegenerator, RegenCaller} from "./regen/index.js"; -import {IBlsVerifier} from "./bls/index.js"; +import {ReprocessController} from "./reprocess.js"; +import {AttestationsRewards} from "./rewards/attestationsRewards.js"; +import {BlockRewards} from "./rewards/blockRewards.js"; +import {SyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js"; import { - SeenAttesters, SeenAggregators, + SeenAttesters, SeenBlockProposers, - SeenSyncCommitteeMessages, SeenContributionAndProof, + SeenSyncCommitteeMessages, } from "./seenCache/index.js"; -import {AttestationPool, OpPool, SyncCommitteeMessagePool, SyncContributionAndProofPool} from "./opPools/index.js"; -import {LightClientServer} from "./lightClient/index.js"; -import {AggregatedAttestationPool} from "./opPools/aggregatedAttestationPool.js"; -import {BlockInput, ImportBlockOpts} from "./blocks/types.js"; -import {ReprocessController} from "./reprocess.js"; +import {SeenGossipBlockInput} from "./seenCache/index.js"; import {SeenAggregatedAttestations} from "./seenCache/seenAggregateAndProof.js"; -import {BeaconProposerCache, ProposerPreparationData} from "./beaconProposerCache.js"; -import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js"; -import {CheckpointBalancesCache} from "./balancesCache.js"; -import {IChainOptions} from "./options.js"; -import {AssembledBlockType, BlockAttributes, BlockType} from "./produceBlock/produceBlockBody.js"; import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js"; -import {SeenGossipBlockInput} from "./seenCache/index.js"; +import {SeenBlockAttesters} from "./seenCache/seenBlockAttesters.js"; import {ShufflingCache} from "./shufflingCache.js"; -import {BlockRewards} from "./rewards/blockRewards.js"; -import {AttestationsRewards} from "./rewards/attestationsRewards.js"; -import {SyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js"; -import {ForkchoiceCaller} from "./forkChoice/index.js"; export {BlockType, type AssembledBlockType}; export {type ProposerPreparationData}; diff --git a/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts b/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts index 92d7383b8cad..c4d76db96997 100644 --- a/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts +++ b/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts @@ -1,40 +1,40 @@ -import {aggregateSignatures, Signature} from "@chainsafe/blst"; +import {Signature, aggregateSignatures} from "@chainsafe/blst"; import {BitArray} from "@chainsafe/ssz"; +import {ChainForkConfig} from "@lodestar/config"; +import {EpochDifference, IForkChoice} from "@lodestar/fork-choice"; import { ForkName, ForkSeq, - isForkPostElectra, MAX_ATTESTATIONS, MAX_ATTESTATIONS_ELECTRA, MAX_COMMITTEES_PER_SLOT, MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH, + isForkPostElectra, } from "@lodestar/params"; -import { - phase0, - Epoch, - Slot, - ssz, - ValidatorIndex, - RootHex, - electra, - isElectraAttestation, - Attestation, -} from "@lodestar/types"; import { CachedBeaconStateAllForks, - CachedBeaconStatePhase0, CachedBeaconStateAltair, + CachedBeaconStatePhase0, computeEpochAtSlot, computeStartSlotAtEpoch, getBlockRootAtSlot, } from "@lodestar/state-transition"; -import {IForkChoice, EpochDifference} from "@lodestar/fork-choice"; -import {MapDef, toRootHex, assert} from "@lodestar/utils"; -import {ChainForkConfig} from "@lodestar/config"; -import {intersectUint8Arrays, IntersectResult} from "../../util/bitArray.js"; -import {pruneBySlot, signatureFromBytesNoCheck} from "./utils.js"; +import { + Attestation, + Epoch, + RootHex, + Slot, + ValidatorIndex, + electra, + isElectraAttestation, + phase0, + ssz, +} from "@lodestar/types"; +import {assert, MapDef, toRootHex} from "@lodestar/utils"; +import {IntersectResult, intersectUint8Arrays} from "../../util/bitArray.js"; import {InsertOutcome} from "./types.js"; +import {pruneBySlot, signatureFromBytesNoCheck} from "./utils.js"; type DataRootHex = string; diff --git a/packages/beacon-node/src/chain/opPools/attestationPool.ts b/packages/beacon-node/src/chain/opPools/attestationPool.ts index 8d8fbb92c0f1..9809c9c6304a 100644 --- a/packages/beacon-node/src/chain/opPools/attestationPool.ts +++ b/packages/beacon-node/src/chain/opPools/attestationPool.ts @@ -1,9 +1,9 @@ -import {BitArray} from "@chainsafe/ssz"; import {Signature, aggregateSignatures} from "@chainsafe/blst"; -import {Slot, RootHex, isElectraAttestation, Attestation} from "@lodestar/types"; -import {MapDef, assert} from "@lodestar/utils"; -import {isForkPostElectra} from "@lodestar/params"; +import {BitArray} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; +import {isForkPostElectra} from "@lodestar/params"; +import {Attestation, RootHex, Slot, isElectraAttestation} from "@lodestar/types"; +import {assert, MapDef} from "@lodestar/utils"; import {IClock} from "../../util/clock.js"; import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js"; import {isElectraAggregate, pruneBySlot, signatureFromBytesNoCheck} from "./utils.js"; diff --git a/packages/beacon-node/src/chain/opPools/opPool.ts b/packages/beacon-node/src/chain/opPools/opPool.ts index f71186c06d35..5eec1597a24e 100644 --- a/packages/beacon-node/src/chain/opPools/opPool.ts +++ b/packages/beacon-node/src/chain/opPools/opPool.ts @@ -1,3 +1,13 @@ +import {Id, Repository} from "@lodestar/db"; +import { + BLS_WITHDRAWAL_PREFIX, + ForkSeq, + MAX_ATTESTER_SLASHINGS, + MAX_ATTESTER_SLASHINGS_ELECTRA, + MAX_BLS_TO_EXECUTION_CHANGES, + MAX_PROPOSER_SLASHINGS, + MAX_VOLUNTARY_EXITS, +} from "@lodestar/params"; import { CachedBeaconStateAllForks, computeEpochAtSlot, @@ -5,22 +15,12 @@ import { getAttesterSlashableIndices, isValidVoluntaryExit, } from "@lodestar/state-transition"; -import {Repository, Id} from "@lodestar/db"; -import { - MAX_PROPOSER_SLASHINGS, - MAX_VOLUNTARY_EXITS, - MAX_BLS_TO_EXECUTION_CHANGES, - BLS_WITHDRAWAL_PREFIX, - MAX_ATTESTER_SLASHINGS, - ForkSeq, - MAX_ATTESTER_SLASHINGS_ELECTRA, -} from "@lodestar/params"; +import {AttesterSlashing, Epoch, SignedBeaconBlock, ValidatorIndex, capella, phase0, ssz} from "@lodestar/types"; import {fromHex, toHex, toRootHex} from "@lodestar/utils"; -import {Epoch, phase0, capella, ssz, ValidatorIndex, SignedBeaconBlock, AttesterSlashing} from "@lodestar/types"; import {IBeaconDb} from "../../db/index.js"; +import {Metrics} from "../../metrics/metrics.js"; import {SignedBLSToExecutionChangeVersioned} from "../../util/types.js"; import {BlockType} from "../interface.js"; -import {Metrics} from "../../metrics/metrics.js"; import {BlockProductionStep} from "../produceBlock/produceBlockBody.js"; import {isValidBlsToExecutionChangeForBlockInclusion} from "./utils.js"; diff --git a/packages/beacon-node/src/chain/opPools/syncCommitteeMessagePool.ts b/packages/beacon-node/src/chain/opPools/syncCommitteeMessagePool.ts index 4de11e447231..6551ee625491 100644 --- a/packages/beacon-node/src/chain/opPools/syncCommitteeMessagePool.ts +++ b/packages/beacon-node/src/chain/opPools/syncCommitteeMessagePool.ts @@ -1,7 +1,7 @@ -import {BitArray} from "@chainsafe/ssz"; import {Signature, aggregateSignatures} from "@chainsafe/blst"; +import {BitArray} from "@chainsafe/ssz"; import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; -import {altair, Root, Slot, SubcommitteeIndex} from "@lodestar/types"; +import {Root, Slot, SubcommitteeIndex, altair} from "@lodestar/types"; import {MapDef, toRootHex} from "@lodestar/utils"; import {IClock} from "../../util/clock.js"; import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js"; diff --git a/packages/beacon-node/src/chain/opPools/syncContributionAndProofPool.ts b/packages/beacon-node/src/chain/opPools/syncContributionAndProofPool.ts index 81363be218d8..0f25032e1d7e 100644 --- a/packages/beacon-node/src/chain/opPools/syncContributionAndProofPool.ts +++ b/packages/beacon-node/src/chain/opPools/syncContributionAndProofPool.ts @@ -1,8 +1,8 @@ -import {BitArray} from "@chainsafe/ssz"; import {Signature, aggregateSignatures} from "@chainsafe/blst"; +import {BitArray} from "@chainsafe/ssz"; import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params"; -import {altair, Slot, Root, ssz} from "@lodestar/types"; import {G2_POINT_AT_INFINITY} from "@lodestar/state-transition"; +import {Root, Slot, altair, ssz} from "@lodestar/types"; import {MapDef, toRootHex} from "@lodestar/utils"; import {InsertOutcome, OpPoolError, OpPoolErrorCode} from "./types.js"; import {pruneBySlot, signatureFromBytesNoCheck} from "./utils.js"; diff --git a/packages/beacon-node/src/chain/options.ts b/packages/beacon-node/src/chain/options.ts index cf83c4432984..f87fffd7b363 100644 --- a/packages/beacon-node/src/chain/options.ts +++ b/packages/beacon-node/src/chain/options.ts @@ -1,5 +1,6 @@ import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params"; import {defaultOptions as defaultValidatorOptions} from "@lodestar/validator"; +import {DEFAULT_STATE_ARCHIVE_MODE} from "./archiver/archiver.js"; import {ArchiverOpts} from "./archiver/interface.js"; import {ForkChoiceOpts} from "./forkChoice/index.js"; import {LightClientServerOpts} from "./lightClient/index.js"; @@ -7,7 +8,6 @@ import {ShufflingCacheOpts} from "./shufflingCache.js"; import {DEFAULT_MAX_BLOCK_STATES, FIFOBlockStateCacheOpts} from "./stateCache/fifoBlockStateCache.js"; import {PersistentCheckpointStateCacheOpts} from "./stateCache/persistentCheckpointsCache.js"; import {DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY} from "./stateCache/persistentCheckpointsCache.js"; -import {DEFAULT_STATE_ARCHIVE_MODE} from "./archiver/archiver.js"; export {StateArchiveMode} from "./archiver/interface.js"; export {DEFAULT_STATE_ARCHIVE_MODE} from "./archiver/archiver.js"; diff --git a/packages/beacon-node/src/chain/prepareNextSlot.ts b/packages/beacon-node/src/chain/prepareNextSlot.ts index bda618758842..f78c1842bd78 100644 --- a/packages/beacon-node/src/chain/prepareNextSlot.ts +++ b/packages/beacon-node/src/chain/prepareNextSlot.ts @@ -1,24 +1,24 @@ +import {routes} from "@lodestar/api"; +import {ChainForkConfig} from "@lodestar/config"; +import {ForkExecution, ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params"; import { - computeEpochAtSlot, - isExecutionStateType, - computeTimeAtSlot, + CachedBeaconStateAllForks, CachedBeaconStateExecutions, StateHashTreeRootSource, - CachedBeaconStateAllForks, + computeEpochAtSlot, + computeTimeAtSlot, + isExecutionStateType, } from "@lodestar/state-transition"; -import {ChainForkConfig} from "@lodestar/config"; -import {ForkSeq, SLOTS_PER_EPOCH, ForkExecution} from "@lodestar/params"; import {Slot} from "@lodestar/types"; -import {Logger, sleep, fromHex, isErrorAborted} from "@lodestar/utils"; -import {routes} from "@lodestar/api"; +import {Logger, fromHex, isErrorAborted, sleep} from "@lodestar/utils"; import {GENESIS_SLOT, ZERO_HASH_HEX} from "../constants/constants.js"; import {Metrics} from "../metrics/index.js"; import {ClockEvent} from "../util/clock.js"; import {isQueueErrorAborted} from "../util/queue/index.js"; -import {prepareExecutionPayload, getPayloadAttributesForSSE} from "./produceBlock/produceBlockBody.js"; +import {ForkchoiceCaller} from "./forkChoice/index.js"; import {IBeaconChain} from "./interface.js"; +import {getPayloadAttributesForSSE, prepareExecutionPayload} from "./produceBlock/produceBlockBody.js"; import {RegenCaller} from "./regen/index.js"; -import {ForkchoiceCaller} from "./forkChoice/index.js"; /* With 12s slot times, this scheduler will run 4s before the start of each slot (`12 / 3 = 4`). */ export const SCHEDULER_LOOKAHEAD_FACTOR = 3; @@ -114,7 +114,12 @@ export class PrepareNextSlotScheduler { // the slot 0 of next epoch will likely use this Previous Root Checkpoint state for state transition so we transfer cache here // the resulting state with cache will be cached in Checkpoint State Cache which is used for the upcoming block processing // for other slots dontTransferCached=true because we don't run state transition on this state - {dontTransferCache: !isEpochTransition}, + // + // Shuffling calculation will be done asynchronously when passing asyncShufflingCalculation=true. Shuffling will be queued in + // beforeProcessEpoch and should theoretically be ready immediately after the synchronous epoch transition finished and the + // event loop is free. In long periods of non-finality too many forks will cause the shufflingCache to throw an error for + // too many queued shufflings so only run async during normal epoch transition. See issue ChainSafe/lodestar#7244 + {dontTransferCache: !isEpochTransition, asyncShufflingCalculation: true}, RegenCaller.precomputeEpoch ); diff --git a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts index a353c4e54ff9..d7b36e06abc4 100644 --- a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts +++ b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts @@ -1,44 +1,44 @@ +import {ChainForkConfig} from "@lodestar/config"; +import {ForkExecution, ForkSeq, isForkExecution, isForkLightClient} from "@lodestar/params"; import { + CachedBeaconStateAllForks, + CachedBeaconStateBellatrix, + CachedBeaconStateCapella, + CachedBeaconStateExecutions, + computeTimeAtSlot, + getCurrentEpoch, + getExpectedWithdrawals, + getRandaoMix, + isMergeTransitionComplete, +} from "@lodestar/state-transition"; +import { + BLSPubkey, + BLSSignature, + BeaconBlock, + BeaconBlockBody, + BlindedBeaconBlock, + BlindedBeaconBlockBody, Bytes32, + ExecutionPayloadHeader, Root, RootHex, + SSEPayloadAttributes, Slot, - ssz, ValidatorIndex, - BLSPubkey, - BLSSignature, + Wei, capella, deneb, - Wei, - SSEPayloadAttributes, - BeaconBlock, - BeaconBlockBody, - ExecutionPayloadHeader, - BlindedBeaconBlockBody, - BlindedBeaconBlock, - sszTypesFor, electra, + ssz, + sszTypesFor, } from "@lodestar/types"; -import { - CachedBeaconStateAllForks, - CachedBeaconStateCapella, - CachedBeaconStateBellatrix, - CachedBeaconStateExecutions, - computeEpochAtSlot, - computeTimeAtSlot, - getRandaoMix, - getCurrentEpoch, - isMergeTransitionComplete, - getExpectedWithdrawals, -} from "@lodestar/state-transition"; -import {ChainForkConfig} from "@lodestar/config"; -import {ForkSeq, ForkExecution, isForkExecution} from "@lodestar/params"; -import {toHex, sleep, Logger, toRootHex} from "@lodestar/utils"; -import type {BeaconChain} from "../chain.js"; -import {PayloadId, IExecutionEngine, IExecutionBuilder, PayloadAttributes} from "../../execution/index.js"; +import {Logger, sleep, toHex, toRootHex} from "@lodestar/utils"; import {ZERO_HASH, ZERO_HASH_HEX} from "../../constants/index.js"; import {IEth1ForBlockProduction} from "../../eth1/index.js"; import {numToQuantity} from "../../eth1/provider/utils.js"; +import {IExecutionBuilder, IExecutionEngine, PayloadAttributes, PayloadId} from "../../execution/index.js"; +import {fromGraffitiBuffer} from "../../util/graffiti.js"; +import type {BeaconChain} from "../chain.js"; import {CommonBlockBody} from "../interface.js"; import {validateBlobsAndKzgCommitments} from "./validateBlobsAndKzgCommitments.js"; @@ -143,10 +143,19 @@ export async function produceBlockBody( ? Object.assign({}, commonBlockBody) : await produceCommonBlockBody.call(this, blockType, currentState, blockAttr); - const {attestations, deposits, voluntaryExits, attesterSlashings, proposerSlashings, blsToExecutionChanges} = - blockBody; + const { + graffiti, + attestations, + deposits, + voluntaryExits, + attesterSlashings, + proposerSlashings, + syncAggregate, + blsToExecutionChanges, + } = blockBody; Object.assign(logMeta, { + graffiti: fromGraffitiBuffer(graffiti), attestations: attestations.length, deposits: deposits.length, voluntaryExits: voluntaryExits.length, @@ -154,6 +163,12 @@ export async function produceBlockBody( proposerSlashings: proposerSlashings.length, }); + if (isForkLightClient(fork)) { + Object.assign(logMeta, { + syncAggregateParticipants: syncAggregate.syncCommitteeBits.getTrueBitIndexes().length, + }); + } + const endExecutionPayload = stepsMetrics?.startTimer(); if (isForkExecution(fork)) { const safeBlockHash = this.forkChoice.getJustifiedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX; @@ -608,7 +623,6 @@ export async function produceCommonBlockBody( ? this.metrics?.executionBlockProductionTimeSteps : this.metrics?.builderBlockProductionTimeSteps; - const blockEpoch = computeEpochAtSlot(slot); const fork = currentState.config.getForkName(slot); // TODO: @@ -653,7 +667,7 @@ export async function produceCommonBlockBody( } const endSyncAggregate = stepsMetrics?.startTimer(); - if (blockEpoch >= this.config.ALTAIR_FORK_EPOCH) { + if (ForkSeq[fork] >= ForkSeq.altair) { const syncAggregate = this.syncContributionAndProofPool.getAggregate(parentSlot, parentBlockRoot); this.metrics?.production.producedSyncAggregateParticipants.observe( syncAggregate.syncCommitteeBits.getTrueBitIndexes().length diff --git a/packages/beacon-node/src/chain/regen/errors.ts b/packages/beacon-node/src/chain/regen/errors.ts index 7c1573b415f8..eb41e8321da3 100644 --- a/packages/beacon-node/src/chain/regen/errors.ts +++ b/packages/beacon-node/src/chain/regen/errors.ts @@ -1,4 +1,4 @@ -import {Root, Slot, RootHex} from "@lodestar/types"; +import {Root, RootHex, Slot} from "@lodestar/types"; export enum RegenErrorCode { BLOCK_NOT_IN_FORKCHOICE = "REGEN_ERROR_BLOCK_NOT_IN_FORKCHOICE", diff --git a/packages/beacon-node/src/chain/regen/interface.ts b/packages/beacon-node/src/chain/regen/interface.ts index 031d19860789..b9a4e38b5b68 100644 --- a/packages/beacon-node/src/chain/regen/interface.ts +++ b/packages/beacon-node/src/chain/regen/interface.ts @@ -1,7 +1,7 @@ -import {phase0, Slot, RootHex, Epoch, BeaconBlock} from "@lodestar/types"; -import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {routes} from "@lodestar/api"; import {ProtoBlock} from "@lodestar/fork-choice"; +import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {BeaconBlock, Epoch, RootHex, Slot, phase0} from "@lodestar/types"; import {CheckpointHex} from "../stateCache/index.js"; export enum RegenCaller { @@ -28,8 +28,12 @@ export enum RegenFnName { getCheckpointState = "getCheckpointState", } -export type StateCloneOpts = { +export type StateRegenerationOpts = { dontTransferCache: boolean; + /** + * Do not queue shuffling calculation async. Forces sync JIT calculation in afterProcessEpoch if not passed as `true` + */ + asyncShufflingCalculation?: boolean; }; export interface IStateRegenerator extends IStateRegeneratorInternal { @@ -56,7 +60,11 @@ export interface IStateRegeneratorInternal { * Return a valid pre-state for a beacon block * This will always return a state in the latest viable epoch */ - getPreState(block: BeaconBlock, opts: StateCloneOpts, rCaller: RegenCaller): Promise; + getPreState( + block: BeaconBlock, + opts: StateRegenerationOpts, + rCaller: RegenCaller + ): Promise; /** * Return a valid checkpoint state @@ -64,7 +72,7 @@ export interface IStateRegeneratorInternal { */ getCheckpointState( cp: phase0.Checkpoint, - opts: StateCloneOpts, + opts: StateRegenerationOpts, rCaller: RegenCaller ): Promise; @@ -74,12 +82,12 @@ export interface IStateRegeneratorInternal { getBlockSlotState( blockRoot: RootHex, slot: Slot, - opts: StateCloneOpts, + opts: StateRegenerationOpts, rCaller: RegenCaller ): Promise; /** * Return the exact state with `stateRoot` */ - getState(stateRoot: RootHex, rCaller: RegenCaller, opts?: StateCloneOpts): Promise; + getState(stateRoot: RootHex, rCaller: RegenCaller, opts?: StateRegenerationOpts): Promise; } diff --git a/packages/beacon-node/src/chain/regen/queued.ts b/packages/beacon-node/src/chain/regen/queued.ts index 694e8635a3b7..9069b384fd58 100644 --- a/packages/beacon-node/src/chain/regen/queued.ts +++ b/packages/beacon-node/src/chain/regen/queued.ts @@ -1,15 +1,21 @@ -import {phase0, Slot, RootHex, Epoch, BeaconBlock} from "@lodestar/types"; +import {routes} from "@lodestar/api"; import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; -import {CachedBeaconStateAllForks, UnfinalizedPubkeyIndexMap, computeEpochAtSlot} from "@lodestar/state-transition"; +import {CachedBeaconStateAllForks, computeEpochAtSlot} from "@lodestar/state-transition"; +import {BeaconBlock, Epoch, RootHex, Slot, phase0} from "@lodestar/types"; import {Logger, toRootHex} from "@lodestar/utils"; -import {routes} from "@lodestar/api"; -import {CheckpointHex, toCheckpointHex} from "../stateCache/index.js"; import {Metrics} from "../../metrics/index.js"; import {JobItemQueue} from "../../util/queue/index.js"; +import {CheckpointHex, toCheckpointHex} from "../stateCache/index.js"; import {BlockStateCache, CheckpointStateCache} from "../stateCache/types.js"; -import {IStateRegenerator, IStateRegeneratorInternal, RegenCaller, RegenFnName, StateCloneOpts} from "./interface.js"; -import {StateRegenerator, RegenModules} from "./regen.js"; import {RegenError, RegenErrorCode} from "./errors.js"; +import { + IStateRegenerator, + IStateRegeneratorInternal, + RegenCaller, + RegenFnName, + StateRegenerationOpts, +} from "./interface.js"; +import {RegenModules, StateRegenerator} from "./regen.js"; const REGEN_QUEUE_MAX_LEN = 256; // TODO: Should this constant be lower than above? 256 feels high @@ -86,7 +92,7 @@ export class QueuedStateRegenerator implements IStateRegenerator { */ getPreStateSync( block: BeaconBlock, - opts: StateCloneOpts = {dontTransferCache: true} + opts: StateRegenerationOpts = {dontTransferCache: true} ): CachedBeaconStateAllForks | null { const parentRoot = toRootHex(block.parentRoot); const parentBlock = this.forkChoice.getBlockHex(parentRoot); @@ -206,61 +212,13 @@ export class QueuedStateRegenerator implements IStateRegenerator { return this.checkpointStateCache.updatePreComputedCheckpoint(rootHex, epoch); } - /** - * Remove `validators` from all unfinalized cache's epochCtx.UnfinalizedPubkey2Index, - * and add them to epochCtx.pubkey2index and epochCtx.index2pubkey - */ - updateUnfinalizedPubkeys(validators: UnfinalizedPubkeyIndexMap): void { - let numStatesUpdated = 0; - const states = this.blockStateCache.getStates(); - const cpStates = this.checkpointStateCache.getStates(); - - // Add finalized pubkeys to all states. - const addTimer = this.metrics?.regenFnAddPubkeyTime.startTimer(); - - // We only need to add pubkeys to any one of the states since the finalized caches is shared globally across all states - const firstState = (states.next().value ?? cpStates.next().value) as CachedBeaconStateAllForks | undefined; - - if (firstState !== undefined) { - firstState.epochCtx.addFinalizedPubkeys(validators, this.metrics?.epochCache ?? undefined); - } else { - this.logger.warn("Attempt to delete finalized pubkey from unfinalized pubkey cache. But no state is available"); - } - - addTimer?.(); - - // Delete finalized pubkeys from unfinalized pubkey cache for all states - const deleteTimer = this.metrics?.regenFnDeletePubkeyTime.startTimer(); - const pubkeysToDelete = Array.from(validators.keys()); - - for (const s of states) { - s.epochCtx.deleteUnfinalizedPubkeys(pubkeysToDelete); - numStatesUpdated++; - } - - for (const s of cpStates) { - s.epochCtx.deleteUnfinalizedPubkeys(pubkeysToDelete); - numStatesUpdated++; - } - - // Since first state is consumed from the iterator. Will need to perform delete explicitly - if (firstState !== undefined) { - firstState?.epochCtx.deleteUnfinalizedPubkeys(pubkeysToDelete); - numStatesUpdated++; - } - - deleteTimer?.(); - - this.metrics?.regenFnNumStatesUpdated.observe(numStatesUpdated); - } - /** * Get the state to run with `block`. * - State after `block.parentRoot` dialed forward to block.slot */ async getPreState( block: BeaconBlock, - opts: StateCloneOpts, + opts: StateRegenerationOpts, rCaller: RegenCaller ): Promise { this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getPreState}); @@ -279,7 +237,7 @@ export class QueuedStateRegenerator implements IStateRegenerator { async getCheckpointState( cp: phase0.Checkpoint, - opts: StateCloneOpts, + opts: StateRegenerationOpts, rCaller: RegenCaller ): Promise { this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getCheckpointState}); @@ -304,7 +262,7 @@ export class QueuedStateRegenerator implements IStateRegenerator { async getBlockSlotState( blockRoot: RootHex, slot: Slot, - opts: StateCloneOpts, + opts: StateRegenerationOpts, rCaller: RegenCaller ): Promise { this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getBlockSlotState}); @@ -316,7 +274,7 @@ export class QueuedStateRegenerator implements IStateRegenerator { async getState( stateRoot: RootHex, rCaller: RegenCaller, - opts: StateCloneOpts = {dontTransferCache: true} + opts: StateRegenerationOpts = {dontTransferCache: true} ): Promise { this.metrics?.regenFnCallTotal.inc({caller: rCaller, entrypoint: RegenFnName.getState}); diff --git a/packages/beacon-node/src/chain/regen/regen.ts b/packages/beacon-node/src/chain/regen/regen.ts index 7c663c6e0d3d..06d1cee71332 100644 --- a/packages/beacon-node/src/chain/regen/regen.ts +++ b/packages/beacon-node/src/chain/regen/regen.ts @@ -1,26 +1,26 @@ -import {phase0, Slot, RootHex, BeaconBlock, SignedBeaconBlock} from "@lodestar/types"; +import {ChainForkConfig} from "@lodestar/config"; +import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; import { CachedBeaconStateAllForks, + DataAvailableStatus, + ExecutionPayloadStatus, + StateHashTreeRootSource, computeEpochAtSlot, computeStartSlotAtEpoch, - ExecutionPayloadStatus, - DataAvailableStatus, processSlots, stateTransition, - StateHashTreeRootSource, } from "@lodestar/state-transition"; -import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; +import {BeaconBlock, RootHex, SignedBeaconBlock, Slot, phase0} from "@lodestar/types"; import {Logger, fromHex, toRootHex} from "@lodestar/utils"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {ChainForkConfig} from "@lodestar/config"; -import {Metrics} from "../../metrics/index.js"; import {IBeaconDb} from "../../db/index.js"; +import {Metrics} from "../../metrics/index.js"; +import {nextEventLoop} from "../../util/eventLoop.js"; import {getCheckpointFromState} from "../blocks/utils/checkpoint.js"; import {ChainEvent, ChainEventEmitter} from "../emitter.js"; -import {CheckpointStateCache, BlockStateCache} from "../stateCache/types.js"; -import {nextEventLoop} from "../../util/eventLoop.js"; -import {IStateRegeneratorInternal, RegenCaller, StateCloneOpts} from "./interface.js"; +import {BlockStateCache, CheckpointStateCache} from "../stateCache/types.js"; import {RegenError, RegenErrorCode} from "./errors.js"; +import {IStateRegeneratorInternal, RegenCaller, StateRegenerationOpts} from "./interface.js"; export type RegenModules = { db: IBeaconDb; @@ -51,7 +51,7 @@ export class StateRegenerator implements IStateRegeneratorInternal { */ async getPreState( block: BeaconBlock, - opts: StateCloneOpts, + opts: StateRegenerationOpts, regenCaller: RegenCaller ): Promise { const parentBlock = this.modules.forkChoice.getBlock(block.parentRoot); @@ -84,7 +84,7 @@ export class StateRegenerator implements IStateRegeneratorInternal { */ async getCheckpointState( cp: phase0.Checkpoint, - opts: StateCloneOpts, + opts: StateRegenerationOpts, regenCaller: RegenCaller, allowDiskReload = false ): Promise { @@ -99,7 +99,7 @@ export class StateRegenerator implements IStateRegeneratorInternal { async getBlockSlotState( blockRoot: RootHex, slot: Slot, - opts: StateCloneOpts, + opts: StateRegenerationOpts, regenCaller: RegenCaller, allowDiskReload = false ): Promise { @@ -146,7 +146,7 @@ export class StateRegenerator implements IStateRegeneratorInternal { async getState( stateRoot: RootHex, caller: RegenCaller, - opts?: StateCloneOpts, + opts?: StateRegenerationOpts, // internal option, don't want to expose to external caller allowDiskReload = false ): Promise { @@ -322,7 +322,7 @@ async function processSlotsByCheckpoint( preState: CachedBeaconStateAllForks, slot: Slot, regenCaller: RegenCaller, - opts: StateCloneOpts + opts: StateRegenerationOpts ): Promise { let postState = await processSlotsToNearestCheckpoint(modules, preState, slot, regenCaller, opts); if (postState.slot < slot) { @@ -343,7 +343,7 @@ async function processSlotsToNearestCheckpoint( preState: CachedBeaconStateAllForks, slot: Slot, regenCaller: RegenCaller, - opts: StateCloneOpts + opts: StateRegenerationOpts ): Promise { const preSlot = preState.slot; const postSlot = slot; diff --git a/packages/beacon-node/src/chain/reprocess.ts b/packages/beacon-node/src/chain/reprocess.ts index 4c91ef07ff69..a4d8fa43967d 100644 --- a/packages/beacon-node/src/chain/reprocess.ts +++ b/packages/beacon-node/src/chain/reprocess.ts @@ -1,4 +1,4 @@ -import {Slot, RootHex} from "@lodestar/types"; +import {RootHex, Slot} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; import {Metrics} from "../metrics/index.js"; diff --git a/packages/beacon-node/src/chain/rewards/attestationsRewards.ts b/packages/beacon-node/src/chain/rewards/attestationsRewards.ts index 588b310f87ea..14f2f1ccbc79 100644 --- a/packages/beacon-node/src/chain/rewards/attestationsRewards.ts +++ b/packages/beacon-node/src/chain/rewards/attestationsRewards.ts @@ -1,4 +1,5 @@ -import {Epoch, ValidatorIndex} from "@lodestar/types"; +import {routes} from "@lodestar/api"; +import {BeaconConfig} from "@lodestar/config"; import { EFFECTIVE_BALANCE_INCREMENT, ForkName, @@ -10,7 +11,6 @@ import { TIMELY_TARGET_FLAG_INDEX, WEIGHT_DENOMINATOR, } from "@lodestar/params"; -import {routes} from "@lodestar/api"; import { CachedBeaconStateAllForks, CachedBeaconStateAltair, @@ -23,7 +23,7 @@ import { hasMarkers, isInInactivityLeak, } from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; +import {Epoch, ValidatorIndex} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; export type AttestationsRewards = routes.beacon.AttestationsRewards; diff --git a/packages/beacon-node/src/chain/rewards/blockRewards.ts b/packages/beacon-node/src/chain/rewards/blockRewards.ts index 19a59aaa028e..4b9c95de4c3b 100644 --- a/packages/beacon-node/src/chain/rewards/blockRewards.ts +++ b/packages/beacon-node/src/chain/rewards/blockRewards.ts @@ -1,3 +1,5 @@ +import {routes} from "@lodestar/api"; +import {ForkName, WHISTLEBLOWER_REWARD_QUOTIENT} from "@lodestar/params"; import { CachedBeaconStateAllForks, CachedBeaconStateAltair, @@ -6,8 +8,6 @@ import { processAttestationsAltair, } from "@lodestar/state-transition"; import {BeaconBlock, altair, phase0} from "@lodestar/types"; -import {ForkName, WHISTLEBLOWER_REWARD_QUOTIENT} from "@lodestar/params"; -import {routes} from "@lodestar/api"; export type BlockRewards = routes.beacon.BlockRewards; type SubRewardValue = number; // All reward values should be integer diff --git a/packages/beacon-node/src/chain/rewards/syncCommitteeRewards.ts b/packages/beacon-node/src/chain/rewards/syncCommitteeRewards.ts index 71d345e32811..55ab69ec0285 100644 --- a/packages/beacon-node/src/chain/rewards/syncCommitteeRewards.ts +++ b/packages/beacon-node/src/chain/rewards/syncCommitteeRewards.ts @@ -1,7 +1,7 @@ +import {routes} from "@lodestar/api"; +import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "@lodestar/state-transition"; import {BeaconBlock, ValidatorIndex, altair} from "@lodestar/types"; -import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; -import {routes} from "@lodestar/api"; export type SyncCommitteeRewards = routes.beacon.SyncCommitteeRewards; type BalanceRecord = {val: number}; // Use val for convenient way to increment/decrement balance diff --git a/packages/beacon-node/src/chain/seenCache/seenAttestationData.ts b/packages/beacon-node/src/chain/seenCache/seenAttestationData.ts index a0aa6db35893..8e0dfcb3bd96 100644 --- a/packages/beacon-node/src/chain/seenCache/seenAttestationData.ts +++ b/packages/beacon-node/src/chain/seenCache/seenAttestationData.ts @@ -1,5 +1,5 @@ import {BitArray} from "@chainsafe/ssz"; -import {CommitteeIndex, phase0, RootHex, Slot} from "@lodestar/types"; +import {CommitteeIndex, RootHex, Slot, phase0} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; import {Metrics} from "../../metrics/metrics.js"; import {InsertOutcome} from "../opPools/types.js"; diff --git a/packages/beacon-node/src/chain/seenCache/seenCommittee.ts b/packages/beacon-node/src/chain/seenCache/seenCommittee.ts index 38d7f67c74a2..9d7e930c94d7 100644 --- a/packages/beacon-node/src/chain/seenCache/seenCommittee.ts +++ b/packages/beacon-node/src/chain/seenCache/seenCommittee.ts @@ -1,4 +1,4 @@ -import {SubcommitteeIndex, Slot, ValidatorIndex, RootHex} from "@lodestar/types"; +import {RootHex, Slot, SubcommitteeIndex, ValidatorIndex} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; /** diff --git a/packages/beacon-node/src/chain/seenCache/seenGossipBlockInput.ts b/packages/beacon-node/src/chain/seenCache/seenGossipBlockInput.ts index 1c03979b7d77..fd0d396bb0ba 100644 --- a/packages/beacon-node/src/chain/seenCache/seenGossipBlockInput.ts +++ b/packages/beacon-node/src/chain/seenCache/seenGossipBlockInput.ts @@ -1,20 +1,20 @@ -import {deneb, RootHex, SignedBeaconBlock, ssz} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {BLOBSIDECAR_FIXED_SIZE, ForkName, isForkBlobs} from "@lodestar/params"; +import {RootHex, SignedBeaconBlock, deneb, ssz} from "@lodestar/types"; import {pruneSetToMax, toRootHex} from "@lodestar/utils"; -import {BLOBSIDECAR_FIXED_SIZE, isForkBlobs, ForkName} from "@lodestar/params"; +import {Metrics} from "../../metrics/index.js"; import { + BlobsSource, BlockInput, - NullBlockInput, - getBlockInput, - BlockSource, BlockInputDataBlobs, + BlockSource, CachedData, GossipedInputType, + NullBlockInput, + getBlockInput, getBlockInputBlobs, - BlobsSource, } from "../blocks/types.js"; -import {Metrics} from "../../metrics/index.js"; export enum BlockInputAvailabilitySource { GOSSIP = "gossip", diff --git a/packages/beacon-node/src/chain/stateCache/blockStateCacheImpl.ts b/packages/beacon-node/src/chain/stateCache/blockStateCacheImpl.ts index 1cb67cd6cf09..7d87675b7bbc 100644 --- a/packages/beacon-node/src/chain/stateCache/blockStateCacheImpl.ts +++ b/packages/beacon-node/src/chain/stateCache/blockStateCacheImpl.ts @@ -1,9 +1,9 @@ -import {Epoch, RootHex} from "@lodestar/types"; -import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {routes} from "@lodestar/api"; +import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {Epoch, RootHex} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {Metrics} from "../../metrics/index.js"; -import {StateCloneOpts} from "../regen/interface.js"; +import {StateRegenerationOpts} from "../regen/interface.js"; import {MapTracker} from "./mapMetrics.js"; import {BlockStateCache} from "./types.js"; @@ -34,12 +34,12 @@ export class BlockStateCacheImpl implements BlockStateCache { this.maxStates = maxStates; this.cache = new MapTracker(metrics?.stateCache); if (metrics) { - this.metrics = {...metrics.stateCache, ...metrics.epochCache}; + this.metrics = metrics.stateCache; metrics.stateCache.size.addCollect(() => metrics.stateCache.size.set(this.cache.size)); } } - get(rootHex: RootHex, opts?: StateCloneOpts): CachedBeaconStateAllForks | null { + get(rootHex: RootHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null { this.metrics?.lookups.inc(); const item = this.head?.stateRoot === rootHex ? this.head.state : this.cache.get(rootHex); if (!item) { diff --git a/packages/beacon-node/src/chain/stateCache/fifoBlockStateCache.ts b/packages/beacon-node/src/chain/stateCache/fifoBlockStateCache.ts index 7766daf3c5b3..a119efe66887 100644 --- a/packages/beacon-node/src/chain/stateCache/fifoBlockStateCache.ts +++ b/packages/beacon-node/src/chain/stateCache/fifoBlockStateCache.ts @@ -1,10 +1,10 @@ -import {RootHex} from "@lodestar/types"; -import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {routes} from "@lodestar/api"; +import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {RootHex} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {Metrics} from "../../metrics/index.js"; import {LinkedList} from "../../util/array.js"; -import {StateCloneOpts} from "../regen/interface.js"; +import {StateRegenerationOpts} from "../regen/interface.js"; import {MapTracker} from "./mapMetrics.js"; import {BlockStateCache} from "./types.js"; @@ -93,7 +93,7 @@ export class FIFOBlockStateCache implements BlockStateCache { /** * Get a state from this cache given a state root hex. */ - get(rootHex: RootHex, opts?: StateCloneOpts): CachedBeaconStateAllForks | null { + get(rootHex: RootHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null { this.metrics?.lookups.inc(); const item = this.cache.get(rootHex); if (!item) { diff --git a/packages/beacon-node/src/chain/stateCache/inMemoryCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/inMemoryCheckpointsCache.ts index 38aeabb97955..81562d669365 100644 --- a/packages/beacon-node/src/chain/stateCache/inMemoryCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/inMemoryCheckpointsCache.ts @@ -1,11 +1,11 @@ -import {phase0, Epoch, RootHex} from "@lodestar/types"; +import {routes} from "@lodestar/api"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {Epoch, RootHex, phase0} from "@lodestar/types"; import {MapDef, toRootHex} from "@lodestar/utils"; -import {routes} from "@lodestar/api"; import {Metrics} from "../../metrics/index.js"; -import {StateCloneOpts} from "../regen/interface.js"; +import {StateRegenerationOpts} from "../regen/interface.js"; import {MapTracker} from "./mapMetrics.js"; -import {CheckpointStateCache, CacheItemType} from "./types.js"; +import {CacheItemType, CheckpointStateCache} from "./types.js"; export type CheckpointHex = {epoch: Epoch; rootHex: RootHex}; const MAX_EPOCHS = 10; @@ -42,7 +42,7 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache { this.maxEpochs = maxEpochs; } - async getOrReload(cp: CheckpointHex, opts?: StateCloneOpts): Promise { + async getOrReload(cp: CheckpointHex, opts?: StateRegenerationOpts): Promise { return this.get(cp, opts); } @@ -54,7 +54,7 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache { async getOrReloadLatest( rootHex: string, maxEpoch: number, - opts?: StateCloneOpts + opts?: StateRegenerationOpts ): Promise { return this.getLatest(rootHex, maxEpoch, opts); } @@ -64,7 +64,7 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache { return 0; } - get(cp: CheckpointHex, opts?: StateCloneOpts): CachedBeaconStateAllForks | null { + get(cp: CheckpointHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null { this.metrics?.lookups.inc(); const cpKey = toCheckpointKey(cp); const item = this.cache.get(cpKey); @@ -98,7 +98,7 @@ export class InMemoryCheckpointStateCache implements CheckpointStateCache { /** * Searches for the latest cached state with a `root`, starting with `epoch` and descending */ - getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateCloneOpts): CachedBeaconStateAllForks | null { + getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null { // sort epochs in descending order, only consider epochs lte `epoch` const epochs = Array.from(this.epochIndex.keys()) .sort((a, b) => b - a) diff --git a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts index 5573366e3523..9a08aaa75461 100644 --- a/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts +++ b/packages/beacon-node/src/chain/stateCache/persistentCheckpointsCache.ts @@ -1,17 +1,17 @@ -import {phase0, Epoch, RootHex} from "@lodestar/types"; -import {CachedBeaconStateAllForks, computeStartSlotAtEpoch, getBlockRootAtSlot} from "@lodestar/state-transition"; -import {Logger, MapDef, fromHex, sleep, toHex, toRootHex} from "@lodestar/utils"; import {routes} from "@lodestar/api"; -import {loadCachedBeaconState} from "@lodestar/state-transition"; import {INTERVALS_PER_SLOT} from "@lodestar/params"; +import {CachedBeaconStateAllForks, computeStartSlotAtEpoch, getBlockRootAtSlot} from "@lodestar/state-transition"; +import {loadCachedBeaconState} from "@lodestar/state-transition"; +import {Epoch, RootHex, phase0} from "@lodestar/types"; +import {Logger, MapDef, fromHex, sleep, toHex, toRootHex} from "@lodestar/utils"; import {Metrics} from "../../metrics/index.js"; -import {IClock} from "../../util/clock.js"; import {AllocSource, BufferPool, BufferWithKey} from "../../util/bufferPool.js"; -import {StateCloneOpts} from "../regen/interface.js"; +import {IClock} from "../../util/clock.js"; +import {StateRegenerationOpts} from "../regen/interface.js"; import {serializeState} from "../serializeState.js"; +import {CPStateDatastore, DatastoreKey} from "./datastore/index.js"; import {MapTracker} from "./mapMetrics.js"; -import {CPStateDatastore, DatastoreKey, datastoreKeyToCheckpoint} from "./datastore/index.js"; -import {CheckpointHex, CacheItemType, CheckpointStateCache, BlockStateCache} from "./types.js"; +import {BlockStateCache, CacheItemType, CheckpointHex, CheckpointStateCache} from "./types.js"; export type PersistentCheckpointStateCacheOpts = { /** Keep max n states in memory, persist the rest to disk */ @@ -168,7 +168,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { * - Get block for processing * - Regen head state */ - async getOrReload(cp: CheckpointHex, opts?: StateCloneOpts): Promise { + async getOrReload(cp: CheckpointHex, opts?: StateRegenerationOpts): Promise { const stateOrStateBytesData = await this.getStateOrLoadDb(cp, opts); if (stateOrStateBytesData === null || isCachedBeaconState(stateOrStateBytesData)) { return stateOrStateBytesData?.clone(opts?.dontTransferCache) ?? null; @@ -240,7 +240,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { */ async getStateOrLoadDb( cp: CheckpointHex, - opts?: StateCloneOpts + opts?: StateRegenerationOpts ): Promise { const cpKey = toCacheKey(cp); const inMemoryState = this.get(cpKey, opts); @@ -272,7 +272,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { /** * Similar to get() api without reloading from disk */ - get(cpOrKey: CheckpointHex | string, opts?: StateCloneOpts): CachedBeaconStateAllForks | null { + get(cpOrKey: CheckpointHex | string, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null { this.metrics?.cpStateCache.lookups.inc(); const cpKey = typeof cpOrKey === "string" ? cpOrKey : toCacheKey(cpOrKey); const cacheItem = this.cache.get(cpKey); @@ -323,7 +323,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { /** * Searches in-memory state for the latest cached state with a `root` without reload, starting with `epoch` and descending */ - getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateCloneOpts): CachedBeaconStateAllForks | null { + getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null { // sort epochs in descending order, only consider epochs lte `epoch` const epochs = Array.from(this.epochIndex.keys()) .sort((a, b) => b - a) @@ -349,7 +349,7 @@ export class PersistentCheckpointStateCache implements CheckpointStateCache { async getOrReloadLatest( rootHex: RootHex, maxEpoch: Epoch, - opts?: StateCloneOpts + opts?: StateRegenerationOpts ): Promise { // sort epochs in descending order, only consider epochs lte `epoch` const epochs = Array.from(this.epochIndex.keys()) diff --git a/packages/beacon-node/src/chain/stateCache/types.ts b/packages/beacon-node/src/chain/stateCache/types.ts index 1e8d6bd1bd62..19f05c23ee35 100644 --- a/packages/beacon-node/src/chain/stateCache/types.ts +++ b/packages/beacon-node/src/chain/stateCache/types.ts @@ -1,7 +1,7 @@ +import {routes} from "@lodestar/api"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {Epoch, RootHex, phase0} from "@lodestar/types"; -import {routes} from "@lodestar/api"; -import {StateCloneOpts} from "../regen/interface.js"; +import {StateRegenerationOpts} from "../regen/interface.js"; export type CheckpointHex = {epoch: Epoch; rootHex: RootHex}; @@ -21,7 +21,7 @@ export type CheckpointHex = {epoch: Epoch; rootHex: RootHex}; * The cache key is state root */ export interface BlockStateCache { - get(rootHex: RootHex, opts?: StateCloneOpts): CachedBeaconStateAllForks | null; + get(rootHex: RootHex, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null; add(item: CachedBeaconStateAllForks): void; setHeadState(item: CachedBeaconStateAllForks | null): void; /** @@ -60,15 +60,15 @@ export interface BlockStateCache { */ export interface CheckpointStateCache { init?: () => Promise; - getOrReload(cp: CheckpointHex, opts?: StateCloneOpts): Promise; + getOrReload(cp: CheckpointHex, opts?: StateRegenerationOpts): Promise; getStateOrBytes(cp: CheckpointHex): Promise; - get(cpOrKey: CheckpointHex | string, opts?: StateCloneOpts): CachedBeaconStateAllForks | null; + get(cpOrKey: CheckpointHex | string, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null; add(cp: phase0.Checkpoint, state: CachedBeaconStateAllForks): void; - getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateCloneOpts): CachedBeaconStateAllForks | null; + getLatest(rootHex: RootHex, maxEpoch: Epoch, opts?: StateRegenerationOpts): CachedBeaconStateAllForks | null; getOrReloadLatest( rootHex: RootHex, maxEpoch: Epoch, - opts?: StateCloneOpts + opts?: StateRegenerationOpts ): Promise; updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null; prune(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void; diff --git a/packages/beacon-node/src/chain/validation/aggregateAndProof.ts b/packages/beacon-node/src/chain/validation/aggregateAndProof.ts index 6d6eab6ec15a..781e63cf623a 100644 --- a/packages/beacon-node/src/chain/validation/aggregateAndProof.ts +++ b/packages/beacon-node/src/chain/validation/aggregateAndProof.ts @@ -1,15 +1,14 @@ import {ForkName, ForkSeq} from "@lodestar/params"; -import {electra, phase0, RootHex, ssz, IndexedAttestation, SignedAggregateAndProof} from "@lodestar/types"; import { computeEpochAtSlot, - isAggregatorFromCommitteeLength, createAggregateSignatureSetFromComponents, + isAggregatorFromCommitteeLength, } from "@lodestar/state-transition"; +import {IndexedAttestation, RootHex, SignedAggregateAndProof, electra, phase0, ssz} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; -import {IBeaconChain} from "../index.js"; import {AttestationError, AttestationErrorCode, GossipAction} from "../errors/index.js"; +import {IBeaconChain} from "../index.js"; import {RegenCaller} from "../regen/index.js"; -import {getSelectionProofSignatureSet, getAggregateAndProofSignatureSet} from "./signatureSets/index.js"; import { getAttestationDataSigningRoot, getCommitteeIndices, @@ -18,6 +17,7 @@ import { verifyHeadBlockAndTargetRoot, verifyPropagationSlotRange, } from "./attestation.js"; +import {getAggregateAndProofSignatureSet, getSelectionProofSignatureSet} from "./signatureSets/index.js"; export type AggregateAndProofValidationResult = { indexedAttestation: IndexedAttestation; diff --git a/packages/beacon-node/src/chain/validation/attestation.ts b/packages/beacon-node/src/chain/validation/attestation.ts index 0b3f490e4129..e49a3f79450c 100644 --- a/packages/beacon-node/src/chain/validation/attestation.ts +++ b/packages/beacon-node/src/chain/validation/attestation.ts @@ -1,54 +1,54 @@ import {BitArray} from "@chainsafe/ssz"; -import { - phase0, - Epoch, - Root, - Slot, - RootHex, - ssz, - electra, - isElectraAttestation, - CommitteeIndex, - Attestation, - IndexedAttestation, -} from "@lodestar/types"; +import {BeaconConfig} from "@lodestar/config"; import {ProtoBlock} from "@lodestar/fork-choice"; import { ATTESTATION_SUBNET_COUNT, - SLOTS_PER_EPOCH, + DOMAIN_BEACON_ATTESTER, ForkName, ForkSeq, - DOMAIN_BEACON_ATTESTER, + SLOTS_PER_EPOCH, isForkPostElectra, } from "@lodestar/params"; import { - computeEpochAtSlot, - createSingleSignatureSetFromComponents, - SingleSignatureSet, EpochCacheError, EpochCacheErrorCode, EpochShuffling, - computeStartSlotAtEpoch, + SingleSignatureSet, + computeEpochAtSlot, computeSigningRoot, + computeStartSlotAtEpoch, + createSingleSignatureSetFromComponents, } from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; +import { + Attestation, + CommitteeIndex, + Epoch, + IndexedAttestation, + Root, + RootHex, + Slot, + electra, + isElectraAttestation, + phase0, + ssz, +} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; -import {AttestationError, AttestationErrorCode, GossipAction} from "../errors/index.js"; import {MAXIMUM_GOSSIP_CLOCK_DISPARITY_SEC} from "../../constants/index.js"; -import {RegenCaller} from "../regen/index.js"; +import {sszDeserializeAttestation} from "../../network/gossip/topic.js"; +import {getShufflingDependentRoot} from "../../util/dependentRoot.js"; import { getAggregationBitsFromAttestationSerialized, getAttDataFromSignedAggregateAndProofElectra, + getAttDataFromSignedAggregateAndProofPhase0, getCommitteeBitsFromAttestationSerialized, getCommitteeBitsFromSignedAggregateAndProofElectra, - getAttDataFromSignedAggregateAndProofPhase0, getSignatureFromAttestationSerialized, } from "../../util/sszBytes.js"; -import {AttestationDataCacheEntry, SeenAttDataKey} from "../seenCache/seenAttestationData.js"; -import {sszDeserializeAttestation} from "../../network/gossip/topic.js"; import {Result, wrapError} from "../../util/wrapError.js"; +import {AttestationError, AttestationErrorCode, GossipAction} from "../errors/index.js"; import {IBeaconChain} from "../interface.js"; -import {getShufflingDependentRoot} from "../../util/dependentRoot.js"; +import {RegenCaller} from "../regen/index.js"; +import {AttestationDataCacheEntry, SeenAttDataKey} from "../seenCache/seenAttestationData.js"; export type BatchResult = { results: Result[]; diff --git a/packages/beacon-node/src/chain/validation/attesterSlashing.ts b/packages/beacon-node/src/chain/validation/attesterSlashing.ts index 5da146a67a86..c097774ecb02 100644 --- a/packages/beacon-node/src/chain/validation/attesterSlashing.ts +++ b/packages/beacon-node/src/chain/validation/attesterSlashing.ts @@ -1,11 +1,11 @@ -import {phase0} from "@lodestar/types"; import { - getAttesterSlashableIndices, assertValidAttesterSlashing, + getAttesterSlashableIndices, getAttesterSlashingSignatureSets, } from "@lodestar/state-transition"; -import {IBeaconChain} from "../index.js"; +import {phase0} from "@lodestar/types"; import {AttesterSlashingError, AttesterSlashingErrorCode, GossipAction} from "../errors/index.js"; +import {IBeaconChain} from "../index.js"; export async function validateApiAttesterSlashing( chain: IBeaconChain, diff --git a/packages/beacon-node/src/chain/validation/blobSidecar.ts b/packages/beacon-node/src/chain/validation/blobSidecar.ts index 4c82d7be153d..b79db77e3931 100644 --- a/packages/beacon-node/src/chain/validation/blobSidecar.ts +++ b/packages/beacon-node/src/chain/validation/blobSidecar.ts @@ -1,28 +1,38 @@ -import {deneb, Root, Slot, ssz} from "@lodestar/types"; -import {toRootHex, verifyMerkleBranch} from "@lodestar/utils"; -import {computeStartSlotAtEpoch, getBlockHeaderProposerSignatureSet} from "@lodestar/state-transition"; +import {ChainConfig} from "@lodestar/config"; import {KZG_COMMITMENT_INCLUSION_PROOF_DEPTH, KZG_COMMITMENT_SUBTREE_INDEX0} from "@lodestar/params"; +import {computeStartSlotAtEpoch, getBlockHeaderProposerSignatureSet} from "@lodestar/state-transition"; +import {BlobIndex, Root, Slot, deneb, ssz} from "@lodestar/types"; +import {toRootHex, verifyMerkleBranch} from "@lodestar/utils"; -import {BlobSidecarGossipError, BlobSidecarErrorCode} from "../errors/blobSidecarError.js"; -import {GossipAction} from "../errors/gossipValidation.js"; -import {ckzg} from "../../util/kzg.js"; import {byteArrayEquals} from "../../util/bytes.js"; +import {ckzg} from "../../util/kzg.js"; +import {BlobSidecarErrorCode, BlobSidecarGossipError} from "../errors/blobSidecarError.js"; +import {GossipAction} from "../errors/gossipValidation.js"; import {IBeaconChain} from "../interface.js"; import {RegenCaller} from "../regen/index.js"; export async function validateGossipBlobSidecar( chain: IBeaconChain, blobSidecar: deneb.BlobSidecar, - gossipIndex: number + subnet: number ): Promise { const blobSlot = blobSidecar.signedBlockHeader.message.slot; - // [REJECT] The sidecar is for the correct topic -- i.e. sidecar.index matches the topic {index}. - if (blobSidecar.index !== gossipIndex) { + // [REJECT] The sidecar's index is consistent with `MAX_BLOBS_PER_BLOCK` -- i.e. `blob_sidecar.index < MAX_BLOBS_PER_BLOCK`. + if (blobSidecar.index >= chain.config.MAX_BLOBS_PER_BLOCK) { + throw new BlobSidecarGossipError(GossipAction.REJECT, { + code: BlobSidecarErrorCode.INDEX_TOO_LARGE, + blobIdx: blobSidecar.index, + maxBlobsPerBlock: chain.config.MAX_BLOBS_PER_BLOCK, + }); + } + + // [REJECT] The sidecar is for the correct subnet -- i.e. `compute_subnet_for_blob_sidecar(sidecar.index) == subnet_id`. + if (computeSubnetForBlobSidecar(blobSidecar.index, chain.config) !== subnet) { throw new BlobSidecarGossipError(GossipAction.REJECT, { code: BlobSidecarErrorCode.INVALID_INDEX, blobIdx: blobSidecar.index, - gossipIndex, + subnet, }); } @@ -225,3 +235,7 @@ function validateInclusionProof(blobSidecar: deneb.BlobSidecar): boolean { blobSidecar.signedBlockHeader.message.bodyRoot ); } + +function computeSubnetForBlobSidecar(blobIndex: BlobIndex, config: ChainConfig): number { + return blobIndex % config.BLOB_SIDECAR_SUBNET_COUNT; +} diff --git a/packages/beacon-node/src/chain/validation/block.ts b/packages/beacon-node/src/chain/validation/block.ts index aabc1b14958a..b2623aa4f79d 100644 --- a/packages/beacon-node/src/chain/validation/block.ts +++ b/packages/beacon-node/src/chain/validation/block.ts @@ -1,18 +1,18 @@ import {ChainForkConfig} from "@lodestar/config"; +import {ForkName, isForkBlobs} from "@lodestar/params"; import { computeStartSlotAtEpoch, computeTimeAtSlot, + getBlockProposerSignatureSet, isExecutionBlockBodyType, - isExecutionStateType, isExecutionEnabled, - getBlockProposerSignatureSet, + isExecutionStateType, } from "@lodestar/state-transition"; +import {SignedBeaconBlock, deneb} from "@lodestar/types"; import {sleep, toRootHex} from "@lodestar/utils"; -import {ForkName} from "@lodestar/params"; -import {SignedBeaconBlock} from "@lodestar/types"; import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/index.js"; +import {BlockErrorCode, BlockGossipError, GossipAction} from "../errors/index.js"; import {IBeaconChain} from "../interface.js"; -import {BlockGossipError, BlockErrorCode, GossipAction} from "../errors/index.js"; import {RegenCaller} from "../regen/index.js"; export async function validateGossipBlock( @@ -110,6 +110,18 @@ export async function validateGossipBlock( }); } + // [REJECT] The length of KZG commitments is less than or equal to the limitation defined in Consensus Layer -- i.e. validate that len(body.signed_beacon_block.message.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK + if (isForkBlobs(fork)) { + const blobKzgCommitmentsLen = (block as deneb.BeaconBlock).body.blobKzgCommitments.length; + if (blobKzgCommitmentsLen > chain.config.MAX_BLOBS_PER_BLOCK) { + throw new BlockGossipError(GossipAction.REJECT, { + code: BlockErrorCode.TOO_MANY_KZG_COMMITMENTS, + blobKzgCommitmentsLen, + commitmentLimit: chain.config.MAX_BLOBS_PER_BLOCK, + }); + } + } + // use getPreState to reload state if needed. It also checks for whether the current finalized checkpoint is an ancestor of the block. // As a result, we throw an IGNORE (whereas the spec says we should REJECT for this scenario). // this is something we should change this in the future to make the code airtight to the spec. diff --git a/packages/beacon-node/src/chain/validation/blsToExecutionChange.ts b/packages/beacon-node/src/chain/validation/blsToExecutionChange.ts index fff399aada50..53e8b6f5d2b6 100644 --- a/packages/beacon-node/src/chain/validation/blsToExecutionChange.ts +++ b/packages/beacon-node/src/chain/validation/blsToExecutionChange.ts @@ -1,11 +1,11 @@ -import {capella} from "@lodestar/types"; import { - isValidBlsToExecutionChange, - getBlsToExecutionChangeSignatureSet, CachedBeaconStateCapella, + getBlsToExecutionChangeSignatureSet, + isValidBlsToExecutionChange, } from "@lodestar/state-transition"; -import {IBeaconChain} from "../index.js"; +import {capella} from "@lodestar/types"; import {BlsToExecutionChangeError, BlsToExecutionChangeErrorCode, GossipAction} from "../errors/index.js"; +import {IBeaconChain} from "../index.js"; export async function validateApiBlsToExecutionChange( chain: IBeaconChain, diff --git a/packages/beacon-node/src/chain/validation/lightClientFinalityUpdate.ts b/packages/beacon-node/src/chain/validation/lightClientFinalityUpdate.ts index 0b19495abde6..e19b3c28da87 100644 --- a/packages/beacon-node/src/chain/validation/lightClientFinalityUpdate.ts +++ b/packages/beacon-node/src/chain/validation/lightClientFinalityUpdate.ts @@ -1,9 +1,9 @@ import {ChainForkConfig} from "@lodestar/config"; import {LightClientFinalityUpdate} from "@lodestar/types"; -import {IBeaconChain} from "../interface.js"; -import {LightClientError, LightClientErrorCode} from "../errors/lightClientError.js"; -import {GossipAction} from "../errors/index.js"; import {assertLightClientServer} from "../../node/utils/lightclient.js"; +import {GossipAction} from "../errors/index.js"; +import {LightClientError, LightClientErrorCode} from "../errors/lightClientError.js"; +import {IBeaconChain} from "../interface.js"; import {updateReceivedTooEarly} from "./lightClientOptimisticUpdate.js"; // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/p2p-interface.md#light_client_finality_update diff --git a/packages/beacon-node/src/chain/validation/lightClientOptimisticUpdate.ts b/packages/beacon-node/src/chain/validation/lightClientOptimisticUpdate.ts index 7a7dd7f34a91..49bffb3a5305 100644 --- a/packages/beacon-node/src/chain/validation/lightClientOptimisticUpdate.ts +++ b/packages/beacon-node/src/chain/validation/lightClientOptimisticUpdate.ts @@ -1,11 +1,11 @@ import {ChainForkConfig} from "@lodestar/config"; import {computeTimeAtSlot} from "@lodestar/state-transition"; import {LightClientOptimisticUpdate} from "@lodestar/types"; -import {IBeaconChain} from "../interface.js"; -import {LightClientError, LightClientErrorCode} from "../errors/lightClientError.js"; -import {GossipAction} from "../errors/index.js"; import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../constants/index.js"; import {assertLightClientServer} from "../../node/utils/lightclient.js"; +import {GossipAction} from "../errors/index.js"; +import {LightClientError, LightClientErrorCode} from "../errors/lightClientError.js"; +import {IBeaconChain} from "../interface.js"; // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/p2p-interface.md#light_client_optimistic_update export function validateLightClientOptimisticUpdate( diff --git a/packages/beacon-node/src/chain/validation/proposerSlashing.ts b/packages/beacon-node/src/chain/validation/proposerSlashing.ts index 48fe6db326c9..8d76470bb03b 100644 --- a/packages/beacon-node/src/chain/validation/proposerSlashing.ts +++ b/packages/beacon-node/src/chain/validation/proposerSlashing.ts @@ -1,7 +1,7 @@ -import {phase0} from "@lodestar/types"; import {assertValidProposerSlashing, getProposerSlashingSignatureSets} from "@lodestar/state-transition"; +import {phase0} from "@lodestar/types"; +import {GossipAction, ProposerSlashingError, ProposerSlashingErrorCode} from "../errors/index.js"; import {IBeaconChain} from "../index.js"; -import {ProposerSlashingError, ProposerSlashingErrorCode, GossipAction} from "../errors/index.js"; export async function validateApiProposerSlashing( chain: IBeaconChain, diff --git a/packages/beacon-node/src/chain/validation/signatureSets/aggregateAndProof.ts b/packages/beacon-node/src/chain/validation/signatureSets/aggregateAndProof.ts index 31d931818595..6d171aa0c1f4 100644 --- a/packages/beacon-node/src/chain/validation/signatureSets/aggregateAndProof.ts +++ b/packages/beacon-node/src/chain/validation/signatureSets/aggregateAndProof.ts @@ -1,14 +1,14 @@ import {PublicKey} from "@chainsafe/blst"; +import {BeaconConfig} from "@lodestar/config"; import {DOMAIN_AGGREGATE_AND_PROOF, ForkSeq} from "@lodestar/params"; -import {ssz, SignedAggregateAndProof} from "@lodestar/types"; -import {Epoch} from "@lodestar/types"; import { + ISignatureSet, computeSigningRoot, computeStartSlotAtEpoch, createSingleSignatureSetFromComponents, - ISignatureSet, } from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; +import {SignedAggregateAndProof, ssz} from "@lodestar/types"; +import {Epoch} from "@lodestar/types"; export function getAggregateAndProofSigningRoot( config: BeaconConfig, diff --git a/packages/beacon-node/src/chain/validation/signatureSets/contributionAndProof.ts b/packages/beacon-node/src/chain/validation/signatureSets/contributionAndProof.ts index 21e447b83677..4fe5122c0d3f 100644 --- a/packages/beacon-node/src/chain/validation/signatureSets/contributionAndProof.ts +++ b/packages/beacon-node/src/chain/validation/signatureSets/contributionAndProof.ts @@ -1,11 +1,11 @@ import {DOMAIN_CONTRIBUTION_AND_PROOF} from "@lodestar/params"; -import {altair, ssz} from "@lodestar/types"; import { CachedBeaconStateAllForks, - computeSigningRoot, ISignatureSet, SignatureSetType, + computeSigningRoot, } from "@lodestar/state-transition"; +import {altair, ssz} from "@lodestar/types"; export function getContributionAndProofSignatureSet( state: CachedBeaconStateAllForks, diff --git a/packages/beacon-node/src/chain/validation/signatureSets/selectionProof.ts b/packages/beacon-node/src/chain/validation/signatureSets/selectionProof.ts index 5e129a88aa20..6aa0cffc9b94 100644 --- a/packages/beacon-node/src/chain/validation/signatureSets/selectionProof.ts +++ b/packages/beacon-node/src/chain/validation/signatureSets/selectionProof.ts @@ -1,8 +1,8 @@ import {PublicKey} from "@chainsafe/blst"; -import {DOMAIN_SELECTION_PROOF} from "@lodestar/params"; -import {phase0, Slot, ssz} from "@lodestar/types"; -import {computeSigningRoot, createSingleSignatureSetFromComponents, ISignatureSet} from "@lodestar/state-transition"; import {BeaconConfig} from "@lodestar/config"; +import {DOMAIN_SELECTION_PROOF} from "@lodestar/params"; +import {ISignatureSet, computeSigningRoot, createSingleSignatureSetFromComponents} from "@lodestar/state-transition"; +import {Slot, phase0, ssz} from "@lodestar/types"; export function getSelectionProofSigningRoot(config: BeaconConfig, slot: Slot): Uint8Array { // previously, we call `const selectionProofDomain = config.getDomain(state.slot, DOMAIN_SELECTION_PROOF, slot)` diff --git a/packages/beacon-node/src/chain/validation/signatureSets/syncCommittee.ts b/packages/beacon-node/src/chain/validation/signatureSets/syncCommittee.ts index ce2b2e2484ab..7765e4d89ea0 100644 --- a/packages/beacon-node/src/chain/validation/signatureSets/syncCommittee.ts +++ b/packages/beacon-node/src/chain/validation/signatureSets/syncCommittee.ts @@ -1,11 +1,11 @@ import {DOMAIN_SYNC_COMMITTEE} from "@lodestar/params"; -import {altair, ssz} from "@lodestar/types"; import { CachedBeaconStateAllForks, - computeSigningRoot, ISignatureSet, SignatureSetType, + computeSigningRoot, } from "@lodestar/state-transition"; +import {altair, ssz} from "@lodestar/types"; export function getSyncCommitteeSignatureSet( state: CachedBeaconStateAllForks, diff --git a/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeContribution.ts b/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeContribution.ts index 0e1eaefef7c6..f444c48a2103 100644 --- a/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeContribution.ts +++ b/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeContribution.ts @@ -1,7 +1,7 @@ import {PublicKey} from "@chainsafe/blst"; -import {altair, ssz} from "@lodestar/types"; import {DOMAIN_SYNC_COMMITTEE} from "@lodestar/params"; -import {CachedBeaconStateAltair, computeSigningRoot, ISignatureSet, SignatureSetType} from "@lodestar/state-transition"; +import {CachedBeaconStateAltair, ISignatureSet, SignatureSetType, computeSigningRoot} from "@lodestar/state-transition"; +import {altair, ssz} from "@lodestar/types"; export function getSyncCommitteeContributionSignatureSet( state: CachedBeaconStateAltair, diff --git a/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts b/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts index 14fcfad2b92e..b94ae87b240f 100644 --- a/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +++ b/packages/beacon-node/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts @@ -1,11 +1,11 @@ import {DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF} from "@lodestar/params"; -import {altair, ssz} from "@lodestar/types"; import { CachedBeaconStateAllForks, - computeSigningRoot, ISignatureSet, SignatureSetType, + computeSigningRoot, } from "@lodestar/state-transition"; +import {altair, ssz} from "@lodestar/types"; export function getSyncCommitteeSelectionProofSignatureSet( state: CachedBeaconStateAllForks, diff --git a/packages/beacon-node/src/chain/validation/syncCommittee.ts b/packages/beacon-node/src/chain/validation/syncCommittee.ts index f47aa53a314e..c563bf7cf6be 100644 --- a/packages/beacon-node/src/chain/validation/syncCommittee.ts +++ b/packages/beacon-node/src/chain/validation/syncCommittee.ts @@ -1,5 +1,5 @@ +import {SYNC_COMMITTEE_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; -import {SYNC_COMMITTEE_SUBNET_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {altair} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {GossipAction, SyncCommitteeError, SyncCommitteeErrorCode} from "../errors/index.js"; diff --git a/packages/beacon-node/src/chain/validation/syncCommitteeContributionAndProof.ts b/packages/beacon-node/src/chain/validation/syncCommitteeContributionAndProof.ts index 3f9351f2d0d3..611d738b15b6 100644 --- a/packages/beacon-node/src/chain/validation/syncCommitteeContributionAndProof.ts +++ b/packages/beacon-node/src/chain/validation/syncCommitteeContributionAndProof.ts @@ -1,14 +1,14 @@ -import {CachedBeaconStateAltair, isSyncCommitteeAggregator} from "@lodestar/state-transition"; -import {altair, ValidatorIndex} from "@lodestar/types"; import {SYNC_COMMITTEE_SUBNET_SIZE} from "@lodestar/params"; +import {CachedBeaconStateAltair, isSyncCommitteeAggregator} from "@lodestar/state-transition"; +import {ValidatorIndex, altair} from "@lodestar/types"; import {GossipAction, SyncCommitteeError, SyncCommitteeErrorCode} from "../errors/index.js"; import {IBeaconChain} from "../interface.js"; -import {validateGossipSyncCommitteeExceptSig} from "./syncCommittee.js"; import { - getSyncCommitteeSelectionProofSignatureSet, getContributionAndProofSignatureSet, getSyncCommitteeContributionSignatureSet, + getSyncCommitteeSelectionProofSignatureSet, } from "./signatureSets/index.js"; +import {validateGossipSyncCommitteeExceptSig} from "./syncCommittee.js"; /** * Spec v1.1.0-beta.2 diff --git a/packages/beacon-node/src/chain/validation/voluntaryExit.ts b/packages/beacon-node/src/chain/validation/voluntaryExit.ts index 2b38b161423e..79da31084a36 100644 --- a/packages/beacon-node/src/chain/validation/voluntaryExit.ts +++ b/packages/beacon-node/src/chain/validation/voluntaryExit.ts @@ -1,7 +1,7 @@ +import {getVoluntaryExitSignatureSet, isValidVoluntaryExit} from "@lodestar/state-transition"; import {phase0} from "@lodestar/types"; -import {isValidVoluntaryExit, getVoluntaryExitSignatureSet} from "@lodestar/state-transition"; +import {GossipAction, VoluntaryExitError, VoluntaryExitErrorCode} from "../errors/index.js"; import {IBeaconChain} from "../index.js"; -import {VoluntaryExitError, VoluntaryExitErrorCode, GossipAction} from "../errors/index.js"; import {RegenCaller} from "../regen/index.js"; export async function validateApiVoluntaryExit( diff --git a/packages/beacon-node/src/db/beacon.ts b/packages/beacon-node/src/db/beacon.ts index 07cc47fa54d8..1e15aa369141 100644 --- a/packages/beacon-node/src/db/beacon.ts +++ b/packages/beacon-node/src/db/beacon.ts @@ -1,27 +1,27 @@ -import {Db, LevelDbControllerMetrics} from "@lodestar/db"; import {ChainForkConfig} from "@lodestar/config"; +import {Db, LevelDbControllerMetrics} from "@lodestar/db"; import {IBeaconDb} from "./interface.js"; +import {CheckpointStateRepository} from "./repositories/checkpointState.js"; import { AttesterSlashingRepository, + BLSToExecutionChangeRepository, + BackfilledRanges, + BestLightClientUpdateRepository, + BlobSidecarsArchiveRepository, + BlobSidecarsRepository, BlockArchiveRepository, BlockRepository, - DepositEventRepository, + CheckpointHeaderRepository, DepositDataRootRepository, + DepositEventRepository, Eth1DataRepository, ProposerSlashingRepository, StateArchiveRepository, - VoluntaryExitRepository, - BestLightClientUpdateRepository, - CheckpointHeaderRepository, SyncCommitteeRepository, SyncCommitteeWitnessRepository, - BackfilledRanges, - BlobSidecarsRepository, - BlobSidecarsArchiveRepository, - BLSToExecutionChangeRepository, + VoluntaryExitRepository, } from "./repositories/index.js"; import {PreGenesisState, PreGenesisStateLastProcessedBlock} from "./single/index.js"; -import {CheckpointStateRepository} from "./repositories/checkpointState.js"; export type BeaconDbModules = { config: ChainForkConfig; diff --git a/packages/beacon-node/src/db/interface.ts b/packages/beacon-node/src/db/interface.ts index 6ffb8992f635..95336407ef20 100644 --- a/packages/beacon-node/src/db/interface.ts +++ b/packages/beacon-node/src/db/interface.ts @@ -1,25 +1,25 @@ import {LevelDbControllerMetrics} from "@lodestar/db"; +import {CheckpointStateRepository} from "./repositories/checkpointState.js"; import { AttesterSlashingRepository, + BLSToExecutionChangeRepository, + BackfilledRanges, + BestLightClientUpdateRepository, + BlobSidecarsArchiveRepository, + BlobSidecarsRepository, BlockArchiveRepository, BlockRepository, - DepositEventRepository, + CheckpointHeaderRepository, DepositDataRootRepository, + DepositEventRepository, Eth1DataRepository, ProposerSlashingRepository, StateArchiveRepository, - VoluntaryExitRepository, - BestLightClientUpdateRepository, - CheckpointHeaderRepository, SyncCommitteeRepository, SyncCommitteeWitnessRepository, - BackfilledRanges, - BlobSidecarsRepository, - BlobSidecarsArchiveRepository, - BLSToExecutionChangeRepository, + VoluntaryExitRepository, } from "./repositories/index.js"; import {PreGenesisState, PreGenesisStateLastProcessedBlock} from "./single/index.js"; -import {CheckpointStateRepository} from "./repositories/checkpointState.js"; /** * The DB service manages the data layer of the beacon chain diff --git a/packages/beacon-node/src/db/repositories/attesterSlashing.ts b/packages/beacon-node/src/db/repositories/attesterSlashing.ts index a484f605ac15..dd83c25998b6 100644 --- a/packages/beacon-node/src/db/repositories/attesterSlashing.ts +++ b/packages/beacon-node/src/db/repositories/attesterSlashing.ts @@ -1,6 +1,6 @@ -import {phase0, ssz, ValidatorIndex} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import {Db, Repository} from "@lodestar/db"; +import {ValidatorIndex, phase0, ssz} from "@lodestar/types"; import {Bucket, getBucketNameByValue} from "../buckets.js"; /** diff --git a/packages/beacon-node/src/db/repositories/backfilledRanges.ts b/packages/beacon-node/src/db/repositories/backfilledRanges.ts index f86c20288099..c2958a0e972e 100644 --- a/packages/beacon-node/src/db/repositories/backfilledRanges.ts +++ b/packages/beacon-node/src/db/repositories/backfilledRanges.ts @@ -1,6 +1,6 @@ import {ChainForkConfig} from "@lodestar/config"; -import {Slot, ssz} from "@lodestar/types"; import {DatabaseController, Repository} from "@lodestar/db"; +import {Slot, ssz} from "@lodestar/types"; import {bytesToInt} from "@lodestar/utils"; import {Bucket, getBucketNameByValue} from "../buckets.js"; diff --git a/packages/beacon-node/src/db/repositories/blobSidecars.ts b/packages/beacon-node/src/db/repositories/blobSidecars.ts index e5750ed31b58..aaa16f760dd6 100644 --- a/packages/beacon-node/src/db/repositories/blobSidecars.ts +++ b/packages/beacon-node/src/db/repositories/blobSidecars.ts @@ -1,4 +1,4 @@ -import {ValueOf, ContainerType} from "@chainsafe/ssz"; +import {ContainerType, ValueOf} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; import {Db, Repository} from "@lodestar/db"; import {ssz} from "@lodestar/types"; diff --git a/packages/beacon-node/src/db/repositories/blobSidecarsArchive.ts b/packages/beacon-node/src/db/repositories/blobSidecarsArchive.ts index 18293fc2924c..4b6c8fbcf046 100644 --- a/packages/beacon-node/src/db/repositories/blobSidecarsArchive.ts +++ b/packages/beacon-node/src/db/repositories/blobSidecarsArchive.ts @@ -3,7 +3,7 @@ import {Db, Repository} from "@lodestar/db"; import {Slot} from "@lodestar/types"; import {bytesToInt} from "@lodestar/utils"; import {Bucket, getBucketNameByValue} from "../buckets.js"; -import {blobSidecarsWrapperSsz, BlobSidecarsWrapper} from "./blobSidecars.js"; +import {BlobSidecarsWrapper, blobSidecarsWrapperSsz} from "./blobSidecars.js"; /** * blobSidecarsWrapper by slot diff --git a/packages/beacon-node/src/db/repositories/blockArchive.ts b/packages/beacon-node/src/db/repositories/blockArchive.ts index 427650a37bc3..12994ceba5db 100644 --- a/packages/beacon-node/src/db/repositories/blockArchive.ts +++ b/packages/beacon-node/src/db/repositories/blockArchive.ts @@ -1,11 +1,11 @@ -import all from "it-all"; import {ChainForkConfig} from "@lodestar/config"; -import {Db, Repository, KeyValue, FilterOptions} from "@lodestar/db"; -import {Slot, Root, ssz, SignedBeaconBlock} from "@lodestar/types"; +import {Db, FilterOptions, KeyValue, Repository} from "@lodestar/db"; +import {Root, SignedBeaconBlock, Slot, ssz} from "@lodestar/types"; import {bytesToInt} from "@lodestar/utils"; +import all from "it-all"; import {getSignedBlockTypeFromBytes} from "../../util/multifork.js"; import {Bucket, getBucketNameByValue} from "../buckets.js"; -import {getRootIndexKey, getParentRootIndexKey} from "./blockArchiveIndex.js"; +import {getParentRootIndexKey, getRootIndexKey} from "./blockArchiveIndex.js"; import {deleteParentRootIndex, deleteRootIndex, storeParentRootIndex, storeRootIndex} from "./blockArchiveIndex.js"; export interface BlockFilterOptions extends FilterOptions { diff --git a/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts b/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts index 8c2785dbe67c..12e133ec9acd 100644 --- a/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts +++ b/packages/beacon-node/src/db/repositories/blockArchiveIndex.ts @@ -1,7 +1,7 @@ import {Db, encodeKey} from "@lodestar/db"; -import {Slot, Root, ssz, SignedBeaconBlock, SSZTypesFor} from "@lodestar/types"; -import {intToBytes} from "@lodestar/utils"; import {ForkAll} from "@lodestar/params"; +import {Root, SSZTypesFor, SignedBeaconBlock, Slot, ssz} from "@lodestar/types"; +import {intToBytes} from "@lodestar/utils"; import {Bucket} from "../buckets.js"; export async function storeRootIndex(db: Db, slot: Slot, blockRoot: Root): Promise { diff --git a/packages/beacon-node/src/db/repositories/blsToExecutionChange.ts b/packages/beacon-node/src/db/repositories/blsToExecutionChange.ts index a1b32403dd14..c9495f8fc9a6 100644 --- a/packages/beacon-node/src/db/repositories/blsToExecutionChange.ts +++ b/packages/beacon-node/src/db/repositories/blsToExecutionChange.ts @@ -1,6 +1,6 @@ -import {ValidatorIndex} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import {Db, Repository} from "@lodestar/db"; +import {ValidatorIndex} from "@lodestar/types"; import {SignedBLSToExecutionChangeVersioned, signedBLSToExecutionChangeVersionedType} from "../../util/types.js"; import {Bucket, getBucketNameByValue} from "../buckets.js"; diff --git a/packages/beacon-node/src/db/repositories/depositDataRoot.ts b/packages/beacon-node/src/db/repositories/depositDataRoot.ts index 97200ccd0f92..50648655e440 100644 --- a/packages/beacon-node/src/db/repositories/depositDataRoot.ts +++ b/packages/beacon-node/src/db/repositories/depositDataRoot.ts @@ -1,8 +1,8 @@ import {ByteVectorType, CompositeViewDU, ListCompositeType} from "@chainsafe/ssz"; -import {Root, ssz} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {Db, KeyValue, Repository} from "@lodestar/db"; +import {Root, ssz} from "@lodestar/types"; import {bytesToInt} from "@lodestar/utils"; -import {Db, Repository, KeyValue} from "@lodestar/db"; import {Bucket, getBucketNameByValue} from "../buckets.js"; // TODO: Review where is best to put this type diff --git a/packages/beacon-node/src/db/repositories/depositEvent.ts b/packages/beacon-node/src/db/repositories/depositEvent.ts index c1d2dd99047f..f2e180a02c43 100644 --- a/packages/beacon-node/src/db/repositories/depositEvent.ts +++ b/packages/beacon-node/src/db/repositories/depositEvent.ts @@ -1,6 +1,6 @@ import {ChainForkConfig} from "@lodestar/config"; -import {phase0, ssz} from "@lodestar/types"; import {Db, Repository} from "@lodestar/db"; +import {phase0, ssz} from "@lodestar/types"; import {Bucket, getBucketNameByValue} from "../buckets.js"; /** diff --git a/packages/beacon-node/src/db/repositories/eth1Data.ts b/packages/beacon-node/src/db/repositories/eth1Data.ts index f87199a0b80e..5a21e8f7d226 100644 --- a/packages/beacon-node/src/db/repositories/eth1Data.ts +++ b/packages/beacon-node/src/db/repositories/eth1Data.ts @@ -1,7 +1,7 @@ -import {phase0, ssz} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; -import {bytesToInt} from "@lodestar/utils"; import {Db, Repository} from "@lodestar/db"; +import {phase0, ssz} from "@lodestar/types"; +import {bytesToInt} from "@lodestar/utils"; import {Bucket, getBucketNameByValue} from "../buckets.js"; export class Eth1DataRepository extends Repository { diff --git a/packages/beacon-node/src/db/repositories/lightclientBestUpdate.ts b/packages/beacon-node/src/db/repositories/lightclientBestUpdate.ts index 26493e35e408..ad37b1425c58 100644 --- a/packages/beacon-node/src/db/repositories/lightclientBestUpdate.ts +++ b/packages/beacon-node/src/db/repositories/lightclientBestUpdate.ts @@ -1,6 +1,6 @@ import {ChainForkConfig} from "@lodestar/config"; import {DatabaseController, Repository} from "@lodestar/db"; -import {LightClientUpdate, ssz, SyncPeriod} from "@lodestar/types"; +import {LightClientUpdate, SyncPeriod, ssz} from "@lodestar/types"; import {Bucket, getBucketNameByValue} from "../buckets.js"; const SLOT_BYTE_COUNT = 8; diff --git a/packages/beacon-node/src/db/repositories/lightclientCheckpointHeader.ts b/packages/beacon-node/src/db/repositories/lightclientCheckpointHeader.ts index 22d6559792eb..36b7b9c187e7 100644 --- a/packages/beacon-node/src/db/repositories/lightclientCheckpointHeader.ts +++ b/packages/beacon-node/src/db/repositories/lightclientCheckpointHeader.ts @@ -1,8 +1,8 @@ import {ChainForkConfig} from "@lodestar/config"; import {DatabaseController, Repository} from "@lodestar/db"; import {LightClientHeader, ssz} from "@lodestar/types"; -import {Bucket, getBucketNameByValue} from "../buckets.js"; import {getLightClientHeaderTypeFromBytes} from "../../util/multifork.js"; +import {Bucket, getBucketNameByValue} from "../buckets.js"; /** * Block headers by block root. Until finality includes all headers seen by this node. After finality, diff --git a/packages/beacon-node/src/db/repositories/proposerSlashing.ts b/packages/beacon-node/src/db/repositories/proposerSlashing.ts index e599c22a9c32..210d33234d9b 100644 --- a/packages/beacon-node/src/db/repositories/proposerSlashing.ts +++ b/packages/beacon-node/src/db/repositories/proposerSlashing.ts @@ -1,6 +1,6 @@ -import {phase0, ssz, ValidatorIndex} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import {Db, Repository} from "@lodestar/db"; +import {ValidatorIndex, phase0, ssz} from "@lodestar/types"; import {Bucket, getBucketNameByValue} from "../buckets.js"; export class ProposerSlashingRepository extends Repository { diff --git a/packages/beacon-node/src/db/repositories/stateArchive.ts b/packages/beacon-node/src/db/repositories/stateArchive.ts index b3b3d67fd7a0..638499c5fe01 100644 --- a/packages/beacon-node/src/db/repositories/stateArchive.ts +++ b/packages/beacon-node/src/db/repositories/stateArchive.ts @@ -1,8 +1,8 @@ +import {ChainForkConfig} from "@lodestar/config"; +import {Db, Repository} from "@lodestar/db"; import {BeaconStateAllForks} from "@lodestar/state-transition"; import {Epoch, Root, RootHex, Slot, ssz} from "@lodestar/types"; -import {ChainForkConfig} from "@lodestar/config"; import {bytesToInt, toHex} from "@lodestar/utils"; -import {Db, Repository} from "@lodestar/db"; import {getStateTypeFromBytes} from "../../util/multifork.js"; import {Bucket, getBucketNameByValue} from "../buckets.js"; import {getRootIndexKey, storeRootIndex} from "./stateArchiveIndex.js"; diff --git a/packages/beacon-node/src/db/repositories/stateArchiveIndex.ts b/packages/beacon-node/src/db/repositories/stateArchiveIndex.ts index a088aa2413e9..f119cd245080 100644 --- a/packages/beacon-node/src/db/repositories/stateArchiveIndex.ts +++ b/packages/beacon-node/src/db/repositories/stateArchiveIndex.ts @@ -1,4 +1,4 @@ -import {encodeKey, Db} from "@lodestar/db"; +import {Db, encodeKey} from "@lodestar/db"; import {Root, Slot} from "@lodestar/types"; import {intToBytes} from "@lodestar/utils"; import {Bucket} from "../buckets.js"; diff --git a/packages/beacon-node/src/db/repositories/voluntaryExit.ts b/packages/beacon-node/src/db/repositories/voluntaryExit.ts index ea2dc73a2903..8609725b6337 100644 --- a/packages/beacon-node/src/db/repositories/voluntaryExit.ts +++ b/packages/beacon-node/src/db/repositories/voluntaryExit.ts @@ -1,6 +1,6 @@ -import {phase0, ssz, ValidatorIndex} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import {Db, Repository} from "@lodestar/db"; +import {ValidatorIndex, phase0, ssz} from "@lodestar/types"; import {Bucket, getBucketNameByValue} from "../buckets.js"; export class VoluntaryExitRepository extends Repository { diff --git a/packages/beacon-node/src/db/single/preGenesisState.ts b/packages/beacon-node/src/db/single/preGenesisState.ts index 3789e19d1a7d..a43a54c0923c 100644 --- a/packages/beacon-node/src/db/single/preGenesisState.ts +++ b/packages/beacon-node/src/db/single/preGenesisState.ts @@ -1,6 +1,6 @@ -import {ForkAll, GENESIS_SLOT} from "@lodestar/params"; import {ChainForkConfig} from "@lodestar/config"; import {Db} from "@lodestar/db"; +import {ForkAll, GENESIS_SLOT} from "@lodestar/params"; import {BeaconStateAllForks} from "@lodestar/state-transition"; import {SSZTypesFor} from "@lodestar/types"; import {Bucket} from "../buckets.js"; diff --git a/packages/beacon-node/src/db/single/preGenesisStateLastProcessedBlock.ts b/packages/beacon-node/src/db/single/preGenesisStateLastProcessedBlock.ts index 37dcb069acc9..c31382ec9ee6 100644 --- a/packages/beacon-node/src/db/single/preGenesisStateLastProcessedBlock.ts +++ b/packages/beacon-node/src/db/single/preGenesisStateLastProcessedBlock.ts @@ -1,7 +1,7 @@ import {UintNumberType} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import {Db} from "@lodestar/db"; +import {ssz} from "@lodestar/types"; import {Bucket} from "../buckets.js"; export class PreGenesisStateLastProcessedBlock { diff --git a/packages/beacon-node/src/eth1/eth1DepositDataTracker.ts b/packages/beacon-node/src/eth1/eth1DepositDataTracker.ts index 674b6b600f31..815f5aeb8938 100644 --- a/packages/beacon-node/src/eth1/eth1DepositDataTracker.ts +++ b/packages/beacon-node/src/eth1/eth1DepositDataTracker.ts @@ -1,4 +1,3 @@ -import {phase0, ssz} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import { BeaconStateAllForks, @@ -6,19 +5,20 @@ import { CachedBeaconStateElectra, becomesNewEth1Data, } from "@lodestar/state-transition"; -import {ErrorAborted, TimeoutError, fromHex, Logger, isErrorAborted, sleep} from "@lodestar/utils"; +import {phase0, ssz} from "@lodestar/types"; +import {ErrorAborted, Logger, TimeoutError, fromHex, isErrorAborted, sleep} from "@lodestar/utils"; import {IBeaconDb} from "../db/index.js"; import {Metrics} from "../metrics/index.js"; -import {Eth1DepositsCache} from "./eth1DepositsCache.js"; import {Eth1DataCache} from "./eth1DataCache.js"; -import {getEth1VotesToConsider, pickEth1Vote} from "./utils/eth1Vote.js"; -import {getDeposits} from "./utils/deposits.js"; +import {Eth1DepositsCache} from "./eth1DepositsCache.js"; import {Eth1DataAndDeposits, EthJsonRpcBlockRaw, IEth1Provider} from "./interface.js"; import {Eth1Options} from "./options.js"; -import {HttpRpcError} from "./provider/jsonRpcHttpClient.js"; import {parseEth1Block} from "./provider/eth1Provider.js"; +import {HttpRpcError} from "./provider/jsonRpcHttpClient.js"; import {isJsonRpcTruncatedError} from "./provider/utils.js"; +import {getDeposits} from "./utils/deposits.js"; +import {getEth1VotesToConsider, pickEth1Vote} from "./utils/eth1Vote.js"; const MAX_BLOCKS_PER_BLOCK_QUERY = 1000; const MIN_BLOCKS_PER_BLOCK_QUERY = 10; diff --git a/packages/beacon-node/src/eth1/eth1DepositsCache.ts b/packages/beacon-node/src/eth1/eth1DepositsCache.ts index 13dd29013124..16ed7c95a465 100644 --- a/packages/beacon-node/src/eth1/eth1DepositsCache.ts +++ b/packages/beacon-node/src/eth1/eth1DepositsCache.ts @@ -1,14 +1,14 @@ import {byteArrayEquals} from "@chainsafe/ssz"; -import {phase0, ssz} from "@lodestar/types"; -import {FilterOptions} from "@lodestar/db"; import {ChainForkConfig} from "@lodestar/config"; +import {FilterOptions} from "@lodestar/db"; +import {phase0, ssz} from "@lodestar/types"; import {IBeaconDb} from "../db/index.js"; -import {getEth1DataForBlocks} from "./utils/eth1Data.js"; -import {assertConsecutiveDeposits} from "./utils/eth1DepositEvent.js"; -import {getDepositsWithProofs} from "./utils/deposits.js"; import {Eth1Error, Eth1ErrorCode} from "./errors.js"; import {Eth1Block} from "./interface.js"; +import {getDepositsWithProofs} from "./utils/deposits.js"; +import {getEth1DataForBlocks} from "./utils/eth1Data.js"; +import {assertConsecutiveDeposits} from "./utils/eth1DepositEvent.js"; export class Eth1DepositsCache { unsafeAllowDepositDataOverwrite: boolean; diff --git a/packages/beacon-node/src/eth1/eth1MergeBlockTracker.ts b/packages/beacon-node/src/eth1/eth1MergeBlockTracker.ts index 5bf76625dfe8..ea2d134fe4dd 100644 --- a/packages/beacon-node/src/eth1/eth1MergeBlockTracker.ts +++ b/packages/beacon-node/src/eth1/eth1MergeBlockTracker.ts @@ -1,11 +1,11 @@ import {ChainConfig} from "@lodestar/config"; import {RootHex} from "@lodestar/types"; import {Logger, pruneSetToMax, toRootHex} from "@lodestar/utils"; -import {Metrics} from "../metrics/index.js"; import {ZERO_HASH_HEX} from "../constants/index.js"; +import {Metrics} from "../metrics/index.js"; import {enumToIndexMap} from "../util/enum.js"; -import {IEth1Provider, EthJsonRpcBlockRaw, PowMergeBlock, PowMergeBlockTimestamp, TDProgress} from "./interface.js"; -import {quantityToNum, quantityToBigint, dataToRootHex} from "./provider/utils.js"; +import {EthJsonRpcBlockRaw, IEth1Provider, PowMergeBlock, PowMergeBlockTimestamp, TDProgress} from "./interface.js"; +import {dataToRootHex, quantityToBigint, quantityToNum} from "./provider/utils.js"; export enum StatusCode { STOPPED = "STOPPED", diff --git a/packages/beacon-node/src/eth1/index.ts b/packages/beacon-node/src/eth1/index.ts index 42b82d03a848..f8c28afc5aed 100644 --- a/packages/beacon-node/src/eth1/index.ts +++ b/packages/beacon-node/src/eth1/index.ts @@ -1,9 +1,9 @@ import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {Root} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; -import {IEth1ForBlockProduction, Eth1DataAndDeposits, IEth1Provider, PowMergeBlock, TDProgress} from "./interface.js"; import {Eth1DepositDataTracker, Eth1DepositDataTrackerModules} from "./eth1DepositDataTracker.js"; import {Eth1MergeBlockTracker, Eth1MergeBlockTrackerModules} from "./eth1MergeBlockTracker.js"; +import {Eth1DataAndDeposits, IEth1ForBlockProduction, IEth1Provider, PowMergeBlock, TDProgress} from "./interface.js"; import {Eth1Options} from "./options.js"; import {Eth1Provider} from "./provider/eth1Provider.js"; export {Eth1Provider}; diff --git a/packages/beacon-node/src/eth1/interface.ts b/packages/beacon-node/src/eth1/interface.ts index 54fcdd12492f..ccfd3568e479 100644 --- a/packages/beacon-node/src/eth1/interface.ts +++ b/packages/beacon-node/src/eth1/interface.ts @@ -1,6 +1,6 @@ import {BeaconConfig} from "@lodestar/config"; -import {phase0, Root, RootHex} from "@lodestar/types"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; +import {Root, RootHex, phase0} from "@lodestar/types"; export type EthJsonRpcBlockRaw = { /** the block number. null when its pending block. `"0x1b4"` */ diff --git a/packages/beacon-node/src/eth1/provider/eth1Provider.ts b/packages/beacon-node/src/eth1/provider/eth1Provider.ts index d284700ddb1d..8320f1dedac1 100644 --- a/packages/beacon-node/src/eth1/provider/eth1Provider.ts +++ b/packages/beacon-node/src/eth1/provider/eth1Provider.ts @@ -1,16 +1,16 @@ -import {phase0} from "@lodestar/types"; import {ChainConfig} from "@lodestar/config"; -import {fromHex, isErrorAborted, createElapsedTimeTracker, toPrintableUrl, toHex} from "@lodestar/utils"; import {Logger} from "@lodestar/logger"; +import {phase0} from "@lodestar/types"; +import {createElapsedTimeTracker, fromHex, isErrorAborted, toHex, toPrintableUrl} from "@lodestar/utils"; import {FetchError, isFetchError} from "@lodestar/api"; +import {HTTP_CONNECTION_ERROR_CODES, HTTP_FATAL_ERROR_CODES} from "../../execution/engine/utils.js"; +import {isValidAddress} from "../../util/address.js"; import {linspace} from "../../util/numpy.js"; -import {depositEventTopics, parseDepositLog} from "../utils/depositContract.js"; import {Eth1Block, Eth1ProviderState, IEth1Provider} from "../interface.js"; -import {DEFAULT_PROVIDER_URLS, Eth1Options} from "../options.js"; -import {isValidAddress} from "../../util/address.js"; import {EthJsonRpcBlockRaw} from "../interface.js"; -import {HTTP_CONNECTION_ERROR_CODES, HTTP_FATAL_ERROR_CODES} from "../../execution/engine/utils.js"; +import {DEFAULT_PROVIDER_URLS, Eth1Options} from "../options.js"; +import {depositEventTopics, parseDepositLog} from "../utils/depositContract.js"; import { ErrorJsonRpcResponse, HttpRpcError, @@ -19,7 +19,7 @@ import { JsonRpcHttpClientMetrics, ReqOpts, } from "./jsonRpcHttpClient.js"; -import {isJsonRpcTruncatedError, quantityToNum, numToQuantity, dataToBytes} from "./utils.js"; +import {dataToBytes, isJsonRpcTruncatedError, numToQuantity, quantityToNum} from "./utils.js"; /** * Binds return types to Ethereum JSON RPC methods diff --git a/packages/beacon-node/src/eth1/provider/jsonRpcHttpClient.ts b/packages/beacon-node/src/eth1/provider/jsonRpcHttpClient.ts index f2ceae0d8c19..906c9cd883c7 100644 --- a/packages/beacon-node/src/eth1/provider/jsonRpcHttpClient.ts +++ b/packages/beacon-node/src/eth1/provider/jsonRpcHttpClient.ts @@ -1,7 +1,7 @@ import {EventEmitter} from "node:events"; -import {StrictEventEmitter} from "strict-event-emitter-types"; import {fetch} from "@lodestar/api"; import {ErrorAborted, Gauge, Histogram, TimeoutError, isValidHttpUrl, retry} from "@lodestar/utils"; +import {StrictEventEmitter} from "strict-event-emitter-types"; import {IJson, RpcPayload} from "../interface.js"; import {JwtClaim, encodeJwtToken} from "./jwt.js"; @@ -372,7 +372,7 @@ export class HttpRpcError extends Error { /** * JSON RPC spec errors https://www.jsonrpc.org/specification#response_object */ -function parseJsonRpcErrorCode(code: number): string { +export function parseJsonRpcErrorCode(code: number): string { if (code === -32700) return "Parse request error"; if (code === -32600) return "Invalid request object"; if (code === -32601) return "Method not found"; diff --git a/packages/beacon-node/src/eth1/provider/utils.ts b/packages/beacon-node/src/eth1/provider/utils.ts index 7010e1377ca6..39cb9d4b1849 100644 --- a/packages/beacon-node/src/eth1/provider/utils.ts +++ b/packages/beacon-node/src/eth1/provider/utils.ts @@ -1,5 +1,5 @@ import {RootHex} from "@lodestar/types"; -import {bytesToBigInt, bigIntToBytes, toHex, fromHex} from "@lodestar/utils"; +import {bigIntToBytes, bytesToBigInt, fromHex, toHex} from "@lodestar/utils"; import {ErrorParseJson} from "./jsonRpcHttpClient.js"; /** QUANTITY as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API */ diff --git a/packages/beacon-node/src/eth1/stream.ts b/packages/beacon-node/src/eth1/stream.ts index 1e8583bb59a9..f4adaf2829f2 100644 --- a/packages/beacon-node/src/eth1/stream.ts +++ b/packages/beacon-node/src/eth1/stream.ts @@ -1,9 +1,9 @@ -import {sleep} from "@lodestar/utils"; import {phase0} from "@lodestar/types"; -import {Eth1Block, BatchDepositEvents, IEth1Provider, IEth1StreamParams} from "./interface.js"; +import {sleep} from "@lodestar/utils"; +import {BatchDepositEvents, Eth1Block, IEth1Provider, IEth1StreamParams} from "./interface.js"; +import {parseEth1Block} from "./provider/eth1Provider.js"; import {groupDepositEventsByBlock} from "./utils/groupDepositEventsByBlock.js"; import {optimizeNextBlockDiffForGenesis} from "./utils/optimizeNextBlockDiffForGenesis.js"; -import {parseEth1Block} from "./provider/eth1Provider.js"; /** * Phase 1 of genesis building. diff --git a/packages/beacon-node/src/eth1/utils/deposits.ts b/packages/beacon-node/src/eth1/utils/deposits.ts index 36f8c331ebc9..803b4f9deadf 100644 --- a/packages/beacon-node/src/eth1/utils/deposits.ts +++ b/packages/beacon-node/src/eth1/utils/deposits.ts @@ -1,11 +1,11 @@ -import {toGindex, Tree} from "@chainsafe/persistent-merkle-tree"; -import {toRootHex} from "@lodestar/utils"; -import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; -import {phase0, ssz} from "@lodestar/types"; +import {Tree, toGindex} from "@chainsafe/persistent-merkle-tree"; import {FilterOptions} from "@lodestar/db"; +import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {getEth1DepositCount} from "@lodestar/state-transition"; -import {Eth1Error, Eth1ErrorCode} from "../errors.js"; +import {phase0, ssz} from "@lodestar/types"; +import {toRootHex} from "@lodestar/utils"; import {DepositTree} from "../../db/repositories/depositDataRoot.js"; +import {Eth1Error, Eth1ErrorCode} from "../errors.js"; export type DepositGetter = (indexRange: FilterOptions, eth1Data: phase0.Eth1Data) => Promise; diff --git a/packages/beacon-node/src/eth1/utils/eth1Data.ts b/packages/beacon-node/src/eth1/utils/eth1Data.ts index 2b8e976cac2e..96a7031788ff 100644 --- a/packages/beacon-node/src/eth1/utils/eth1Data.ts +++ b/packages/beacon-node/src/eth1/utils/eth1Data.ts @@ -1,7 +1,7 @@ import {Root, phase0} from "@lodestar/types"; +import {DepositTree} from "../../db/repositories/depositDataRoot.js"; import {binarySearchLte} from "../../util/binarySearch.js"; import {Eth1Error, Eth1ErrorCode} from "../errors.js"; -import {DepositTree} from "../../db/repositories/depositDataRoot.js"; import {Eth1Block} from "../interface.js"; type BlockNumber = number; diff --git a/packages/beacon-node/src/eth1/utils/eth1Vote.ts b/packages/beacon-node/src/eth1/utils/eth1Vote.ts index 84d35ae7d434..e1cd47301c22 100644 --- a/packages/beacon-node/src/eth1/utils/eth1Vote.ts +++ b/packages/beacon-node/src/eth1/utils/eth1Vote.ts @@ -1,7 +1,7 @@ -import {EPOCHS_PER_ETH1_VOTING_PERIOD, SLOTS_PER_EPOCH} from "@lodestar/params"; import {ChainForkConfig} from "@lodestar/config"; -import {phase0, RootHex} from "@lodestar/types"; +import {EPOCHS_PER_ETH1_VOTING_PERIOD, SLOTS_PER_EPOCH} from "@lodestar/params"; import {BeaconStateAllForks, computeTimeAtSlot} from "@lodestar/state-transition"; +import {RootHex, phase0} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; export type Eth1DataGetter = ({ diff --git a/packages/beacon-node/src/execution/builder/http.ts b/packages/beacon-node/src/execution/builder/http.ts index b95cfd6a80b9..12e45412bafc 100644 --- a/packages/beacon-node/src/execution/builder/http.ts +++ b/packages/beacon-node/src/execution/builder/http.ts @@ -1,25 +1,25 @@ +import {WireFormat} from "@lodestar/api"; +import {ApiClient as BuilderApi, getClient} from "@lodestar/api/builder"; +import {ChainForkConfig} from "@lodestar/config"; +import {Logger} from "@lodestar/logger"; +import {ForkExecution, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {parseExecutionPayloadAndBlobsBundle, reconstructFullBlockOrContents} from "@lodestar/state-transition"; import { - bellatrix, - Slot, - Root, BLSPubkey, - deneb, - Wei, + ExecutionPayloadHeader, + Root, SignedBeaconBlockOrContents, SignedBlindedBeaconBlock, - ExecutionPayloadHeader, - electra, + Slot, + Wei, WithOptionalBytes, + bellatrix, + deneb, + electra, } from "@lodestar/types"; -import {parseExecutionPayloadAndBlobsBundle, reconstructFullBlockOrContents} from "@lodestar/state-transition"; -import {ChainForkConfig} from "@lodestar/config"; -import {Logger} from "@lodestar/logger"; -import {getClient, ApiClient as BuilderApi} from "@lodestar/api/builder"; -import {SLOTS_PER_EPOCH, ForkExecution} from "@lodestar/params"; import {toPrintableUrl} from "@lodestar/utils"; import {Metrics} from "../../metrics/metrics.js"; import {IExecutionBuilder} from "./interface.js"; -import {WireFormat} from "@lodestar/api"; export type ExecutionBuilderHttpOpts = { enabled: boolean; diff --git a/packages/beacon-node/src/execution/builder/interface.ts b/packages/beacon-node/src/execution/builder/interface.ts index 19a935a9bf7e..06cdc1da4ed0 100644 --- a/packages/beacon-node/src/execution/builder/interface.ts +++ b/packages/beacon-node/src/execution/builder/interface.ts @@ -1,17 +1,17 @@ +import {ForkExecution} from "@lodestar/params"; import { - bellatrix, - Root, - Slot, BLSPubkey, - deneb, - Wei, - SignedBeaconBlockOrContents, ExecutionPayloadHeader, + Root, + SignedBeaconBlockOrContents, SignedBlindedBeaconBlock, - electra, + Slot, + Wei, WithOptionalBytes, + bellatrix, + deneb, + electra, } from "@lodestar/types"; -import {ForkExecution} from "@lodestar/params"; export interface IExecutionBuilder { /** diff --git a/packages/beacon-node/src/execution/engine/disabled.ts b/packages/beacon-node/src/execution/engine/disabled.ts index 68c72dc02ac6..dce9244ef7ab 100644 --- a/packages/beacon-node/src/execution/engine/disabled.ts +++ b/packages/beacon-node/src/execution/engine/disabled.ts @@ -28,4 +28,8 @@ export class ExecutionEngineDisabled implements IExecutionEngine { getPayloadBodiesByRange(): Promise { throw Error("Execution engine disabled"); } + + getBlobs(): Promise { + throw Error("Execution engine disabled"); + } } diff --git a/packages/beacon-node/src/execution/engine/http.ts b/packages/beacon-node/src/execution/engine/http.ts index e5e65746d90f..0d2656ae46e2 100644 --- a/packages/beacon-node/src/execution/engine/http.ts +++ b/packages/beacon-node/src/execution/engine/http.ts @@ -1,43 +1,47 @@ -import {ExecutionPayload, ExecutionRequests, Root, RootHex, Wei} from "@lodestar/types"; -import {SLOTS_PER_EPOCH, ForkName, ForkSeq} from "@lodestar/params"; import {Logger} from "@lodestar/logger"; +import {ForkName, ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {ExecutionPayload, ExecutionRequests, Root, RootHex, Wei} from "@lodestar/types"; +import {BlobAndProof} from "@lodestar/types/deneb"; +import {strip0xPrefix} from "@lodestar/utils"; import { ErrorJsonRpcResponse, HttpRpcError, IJsonRpcHttpClient, JsonRpcHttpClientEvent, ReqOpts, + parseJsonRpcErrorCode, } from "../../eth1/provider/jsonRpcHttpClient.js"; +import {bytesToData, numToQuantity} from "../../eth1/provider/utils.js"; import {Metrics} from "../../metrics/index.js"; -import {JobItemQueue} from "../../util/queue/index.js"; import {EPOCHS_PER_BATCH} from "../../sync/constants.js"; -import {numToQuantity} from "../../eth1/provider/utils.js"; import {getLodestarClientVersion} from "../../util/metadata.js"; +import {JobItemQueue} from "../../util/queue/index.js"; import { - ExecutionPayloadStatus, + BlobsBundle, + ClientCode, + ClientVersion, ExecutePayloadResponse, + ExecutionEngineState, + ExecutionPayloadStatus, IExecutionEngine, - PayloadId, PayloadAttributes, - BlobsBundle, + PayloadId, VersionedHashes, - ExecutionEngineState, - ClientVersion, - ClientCode, } from "./interface.js"; import {PayloadIdCache} from "./payloadIdCache.js"; import { EngineApiRpcParamTypes, EngineApiRpcReturnTypes, - parseExecutionPayload, - serializeExecutionPayload, - serializeVersionedHashes, - serializePayloadAttributes, - serializeBeaconBlockRoot, ExecutionPayloadBody, assertReqSizeLimit, + deserializeBlobAndProofs, deserializeExecutionPayloadBody, + parseExecutionPayload, + serializeBeaconBlockRoot, + serializeExecutionPayload, serializeExecutionRequests, + serializePayloadAttributes, + serializeVersionedHashes, } from "./types.js"; import {getExecutionEngineState} from "./utils.js"; @@ -111,6 +115,7 @@ const getPayloadOpts: ReqOpts = {routeId: "getPayload"}; */ export class ExecutionEngineHttp implements IExecutionEngine { private logger: Logger; + private lastGetBlobsErrorTime = 0; // The default state is ONLINE, it will be updated to SYNCING once we receive the first payload // This assumption is better than the OFFLINE state, since we can't be sure if the EL is offline and being offline may trigger some notifications @@ -461,17 +466,68 @@ export class ExecutionEngineHttp implements IExecutionEngine { return response.map(deserializeExecutionPayloadBody); } + async getBlobs(_fork: ForkName, versionedHashes: VersionedHashes): Promise<(BlobAndProof | null)[]> { + // retry only after a day may be + const GETBLOBS_RETRY_TIMEOUT = 256 * 32 * 12; + const timeNow = Date.now() / 1000; + const timeSinceLastFail = timeNow - this.lastGetBlobsErrorTime; + if (timeSinceLastFail < GETBLOBS_RETRY_TIMEOUT) { + // do not try getblobs since it might not be available + this.logger.debug( + `disabled engine_getBlobsV1 api call since last failed < GETBLOBS_RETRY_TIMEOUT=${GETBLOBS_RETRY_TIMEOUT}`, + timeSinceLastFail + ); + throw Error( + `engine_getBlobsV1 call recently failed timeSinceLastFail=${timeSinceLastFail} < GETBLOBS_RETRY_TIMEOUT=${GETBLOBS_RETRY_TIMEOUT}` + ); + } + + const method = "engine_getBlobsV1"; + assertReqSizeLimit(versionedHashes.length, 128); + const versionedHashesHex = versionedHashes.map(bytesToData); + let response = await this.rpc + .fetchWithRetries({ + method, + params: [versionedHashesHex], + }) + .catch((e) => { + if (e instanceof ErrorJsonRpcResponse && parseJsonRpcErrorCode(e.response.error.code) === "Method not found") { + this.lastGetBlobsErrorTime = timeNow; + this.logger.debug("disabling engine_getBlobsV1 api call since engine responded with method not availeble", { + retryTimeout: GETBLOBS_RETRY_TIMEOUT, + }); + } + throw e; + }); + + // handle nethermind buggy response + // see: https://discord.com/channels/595666850260713488/1293605631785304088/1298956894274060301 + if ( + (response as unknown as {blobsAndProofs: EngineApiRpcReturnTypes[typeof method]}).blobsAndProofs !== undefined + ) { + response = (response as unknown as {blobsAndProofs: EngineApiRpcReturnTypes[typeof method]}).blobsAndProofs; + } + + if (response.length !== versionedHashes.length) { + const error = `Invalid engine_getBlobsV1 response length=${response.length} versionedHashes=${versionedHashes.length}`; + this.logger.error(error); + throw Error(error); + } + + return response.map(deserializeBlobAndProofs); + } + private async getClientVersion(clientVersion: ClientVersion): Promise { const method = "engine_getClientVersionV1"; const response = await this.rpc.fetchWithRetries< EngineApiRpcReturnTypes[typeof method], EngineApiRpcParamTypes[typeof method] - >({method, params: [clientVersion]}); + >({method, params: [{...clientVersion, commit: `0x${clientVersion.commit}`}]}); const clientVersions = response.map((cv) => { const code = cv.code in ClientCode ? ClientCode[cv.code as keyof typeof ClientCode] : ClientCode.XX; - return {code, name: cv.name, version: cv.version, commit: cv.commit}; + return {code, name: cv.name, version: cv.version, commit: strip0xPrefix(cv.commit)}; }); if (clientVersions.length === 0) { diff --git a/packages/beacon-node/src/execution/engine/index.ts b/packages/beacon-node/src/execution/engine/index.ts index dd2de2017c22..d339276e2cc2 100644 --- a/packages/beacon-node/src/execution/engine/index.ts +++ b/packages/beacon-node/src/execution/engine/index.ts @@ -1,14 +1,14 @@ import {fromHex, toPrintableUrl} from "@lodestar/utils"; import {JsonRpcHttpClient} from "../../eth1/provider/jsonRpcHttpClient.js"; -import {IExecutionEngine} from "./interface.js"; import {ExecutionEngineDisabled} from "./disabled.js"; import { ExecutionEngineHttp, - ExecutionEngineModules, ExecutionEngineHttpOpts, + ExecutionEngineModules, defaultExecutionEngineHttpOpts, } from "./http.js"; -import {ExecutionEngineMockOpts, ExecutionEngineMockBackend} from "./mock.js"; +import {IExecutionEngine} from "./interface.js"; +import {ExecutionEngineMockBackend, ExecutionEngineMockOpts} from "./mock.js"; import {ExecutionEngineMockJsonRpcClient, JsonRpcBackend} from "./utils.js"; export {ExecutionEngineHttp, ExecutionEngineDisabled, defaultExecutionEngineHttpOpts}; diff --git a/packages/beacon-node/src/execution/engine/interface.ts b/packages/beacon-node/src/execution/engine/interface.ts index e6f9cfee526b..c32cc1bc7215 100644 --- a/packages/beacon-node/src/execution/engine/interface.ts +++ b/packages/beacon-node/src/execution/engine/interface.ts @@ -1,9 +1,9 @@ import {ForkName} from "@lodestar/params"; -import {KZGCommitment, Blob, KZGProof} from "@lodestar/types/deneb"; -import {Root, RootHex, capella, Wei, ExecutionPayload, ExecutionRequests} from "@lodestar/types"; +import {ExecutionPayload, ExecutionRequests, Root, RootHex, Wei, capella} from "@lodestar/types"; +import {Blob, BlobAndProof, KZGCommitment, KZGProof} from "@lodestar/types/deneb"; import {DATA} from "../../eth1/provider/utils.js"; -import {PayloadIdCache, PayloadId, WithdrawalV1} from "./payloadIdCache.js"; +import {PayloadId, PayloadIdCache, WithdrawalV1} from "./payloadIdCache.js"; import {ExecutionPayloadBody} from "./types.js"; export {PayloadIdCache, type PayloadId, type WithdrawalV1}; @@ -179,4 +179,6 @@ export interface IExecutionEngine { getPayloadBodiesByHash(fork: ForkName, blockHash: DATA[]): Promise<(ExecutionPayloadBody | null)[]>; getPayloadBodiesByRange(fork: ForkName, start: number, count: number): Promise<(ExecutionPayloadBody | null)[]>; + + getBlobs(fork: ForkName, versionedHashes: VersionedHashes): Promise<(BlobAndProof | null)[]>; } diff --git a/packages/beacon-node/src/execution/engine/mock.ts b/packages/beacon-node/src/execution/engine/mock.ts index 8062b68bf572..8a84d2b0148e 100644 --- a/packages/beacon-node/src/execution/engine/mock.ts +++ b/packages/beacon-node/src/execution/engine/mock.ts @@ -1,30 +1,30 @@ import crypto from "node:crypto"; -import {bellatrix, deneb, RootHex, ssz} from "@lodestar/types"; -import {fromHex, toHex} from "@lodestar/utils"; import { + BLOB_TX_TYPE, BYTES_PER_FIELD_ELEMENT, FIELD_ELEMENTS_PER_BLOB, - ForkSeq, ForkExecution, ForkName, - BLOB_TX_TYPE, + ForkSeq, } from "@lodestar/params"; +import {RootHex, bellatrix, deneb, ssz} from "@lodestar/types"; +import {fromHex, toHex} from "@lodestar/utils"; import {ZERO_HASH_HEX} from "../../constants/index.js"; -import {ckzg} from "../../util/kzg.js"; -import {kzgCommitmentToVersionedHash} from "../../util/blobs.js"; import {quantityToNum} from "../../eth1/provider/utils.js"; +import {kzgCommitmentToVersionedHash} from "../../util/blobs.js"; +import {ckzg} from "../../util/kzg.js"; +import {ClientCode, ExecutionPayloadStatus, PayloadIdCache} from "./interface.js"; import { + BlobsBundleRpc, EngineApiRpcParamTypes, EngineApiRpcReturnTypes, - deserializePayloadAttributes, + ExecutionPayloadBodyRpc, + ExecutionPayloadRpc, PayloadStatus, + deserializePayloadAttributes, serializeBlobsBundle, serializeExecutionPayload, - ExecutionPayloadRpc, - BlobsBundleRpc, - ExecutionPayloadBodyRpc, } from "./types.js"; -import {ClientCode, ExecutionPayloadStatus, PayloadIdCache} from "./interface.js"; import {JsonRpcBackend} from "./utils.js"; const INTEROP_GAS_LIMIT = 30e6; @@ -99,6 +99,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend { engine_getPayloadBodiesByHashV1: this.getPayloadBodiesByHash.bind(this), engine_getPayloadBodiesByRangeV1: this.getPayloadBodiesByRange.bind(this), engine_getClientVersionV1: this.getClientVersionV1.bind(this), + engine_getBlobsV1: this.getBlobs.bind(this), }; } @@ -397,6 +398,12 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend { return [{code: ClientCode.XX, name: "mock", version: "", commit: ""}]; } + private getBlobs( + versionedHashes: EngineApiRpcParamTypes["engine_getBlobsV1"][0] + ): EngineApiRpcReturnTypes["engine_getBlobsV1"] { + return versionedHashes.map((_vh) => null); + } + private timestampToFork(timestamp: number): ForkExecution { if (timestamp > (this.opts.electraForkTimestamp ?? Infinity)) return ForkName.electra; if (timestamp > (this.opts.denebForkTimestamp ?? Infinity)) return ForkName.deneb; diff --git a/packages/beacon-node/src/execution/engine/payloadIdCache.ts b/packages/beacon-node/src/execution/engine/payloadIdCache.ts index ea37e0922e9c..f6c18ddac6fa 100644 --- a/packages/beacon-node/src/execution/engine/payloadIdCache.ts +++ b/packages/beacon-node/src/execution/engine/payloadIdCache.ts @@ -1,7 +1,7 @@ import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {pruneSetToMax} from "@lodestar/utils"; -import {Metrics} from "../../metrics/index.js"; import {DATA, QUANTITY} from "../../eth1/provider/utils.js"; +import {Metrics} from "../../metrics/index.js"; import {PayloadAttributesRpc} from "./types.js"; // Idealy this only need to be set to the max head reorgs number diff --git a/packages/beacon-node/src/execution/engine/types.ts b/packages/beacon-node/src/execution/engine/types.ts index 52ddb8548629..f35a63aa3d96 100644 --- a/packages/beacon-node/src/execution/engine/types.ts +++ b/packages/beacon-node/src/execution/engine/types.ts @@ -1,22 +1,23 @@ -import {capella, deneb, electra, Wei, bellatrix, Root, ExecutionPayload, ExecutionRequests, ssz} from "@lodestar/types"; import { + BYTES_PER_FIELD_ELEMENT, BYTES_PER_LOGS_BLOOM, FIELD_ELEMENTS_PER_BLOB, - BYTES_PER_FIELD_ELEMENT, ForkName, ForkSeq, } from "@lodestar/params"; +import {ExecutionPayload, ExecutionRequests, Root, Wei, bellatrix, capella, deneb, electra, ssz} from "@lodestar/types"; +import {BlobAndProof} from "@lodestar/types/deneb"; import { - bytesToData, - numToQuantity, - dataToBytes, - quantityToNum, DATA, QUANTITY, + bytesToData, + dataToBytes, + numToQuantity, quantityToBigint, + quantityToNum, } from "../../eth1/provider/utils.js"; -import {ExecutionPayloadStatus, BlobsBundle, PayloadAttributes, VersionedHashes} from "./interface.js"; +import {BlobsBundle, ExecutionPayloadStatus, PayloadAttributes, VersionedHashes} from "./interface.js"; import {WithdrawalV1} from "./payloadIdCache.js"; export type EngineApiRpcParamTypes = { @@ -67,6 +68,8 @@ export type EngineApiRpcParamTypes = { * Object - Instance of ClientVersion */ engine_getClientVersionV1: [ClientVersionRpc]; + + engine_getBlobsV1: [DATA[]]; }; export type PayloadStatus = { @@ -109,6 +112,8 @@ export type EngineApiRpcReturnTypes = { engine_getPayloadBodiesByRangeV1: (ExecutionPayloadBodyRpc | null)[]; engine_getClientVersionV1: ClientVersionRpc[]; + + engine_getBlobsV1: (BlobAndProofRpc | null)[]; }; type ExecutionPayloadRpcWithValue = { @@ -171,6 +176,11 @@ export type DepositRequestsRpc = DATA; export type WithdrawalRequestsRpc = DATA; export type ConsolidationRequestsRpc = DATA; +export type BlobAndProofRpc = { + blob: DATA; + proof: DATA; +}; + export type VersionedHashesRpc = DATA[]; export type PayloadAttributesRpc = { @@ -462,6 +472,15 @@ export function serializeExecutionPayloadBody(data: ExecutionPayloadBody | null) : null; } +export function deserializeBlobAndProofs(data: BlobAndProofRpc | null): BlobAndProof | null { + return data + ? { + blob: dataToBytes(data.blob, BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_BLOB), + proof: dataToBytes(data.proof, 48), + } + : null; +} + export function assertReqSizeLimit(blockHashesReqCount: number, count: number): void { if (blockHashesReqCount > count) { throw new Error(`Requested blocks must not be > ${count}`); diff --git a/packages/beacon-node/src/execution/engine/utils.ts b/packages/beacon-node/src/execution/engine/utils.ts index 4d84eda52c44..1a88edb22cce 100644 --- a/packages/beacon-node/src/execution/engine/utils.ts +++ b/packages/beacon-node/src/execution/engine/utils.ts @@ -2,14 +2,14 @@ import {isFetchError} from "@lodestar/api"; import {isErrorAborted} from "@lodestar/utils"; import {IJson, RpcPayload} from "../../eth1/interface.js"; import { - IJsonRpcHttpClient, ErrorJsonRpcResponse, HttpRpcError, - JsonRpcHttpClientEventEmitter, + IJsonRpcHttpClient, JsonRpcHttpClientEvent, + JsonRpcHttpClientEventEmitter, } from "../../eth1/provider/jsonRpcHttpClient.js"; import {isQueueErrorAborted} from "../../util/queue/errors.js"; -import {ExecutionPayloadStatus, ExecutionEngineState} from "./interface.js"; +import {ExecutionEngineState, ExecutionPayloadStatus} from "./interface.js"; export type JsonRpcBackend = { // biome-ignore lint/suspicious/noExplicitAny: diff --git a/packages/beacon-node/src/metrics/metrics.ts b/packages/beacon-node/src/metrics/metrics.ts index 58a48e34bbd5..ed607c7521ed 100644 --- a/packages/beacon-node/src/metrics/metrics.ts +++ b/packages/beacon-node/src/metrics/metrics.ts @@ -1,13 +1,13 @@ -import {Metric, Registry} from "prom-client"; -import {Logger} from "@lodestar/utils"; -import {BeaconStateAllForks, getCurrentSlot} from "@lodestar/state-transition"; import {ChainForkConfig} from "@lodestar/config"; -import {createBeaconMetrics, BeaconMetrics} from "./metrics/beacon.js"; -import {createLodestarMetrics, LodestarMetrics} from "./metrics/lodestar.js"; +import {BeaconStateAllForks, getCurrentSlot} from "@lodestar/state-transition"; +import {Logger} from "@lodestar/utils"; +import {Metric, Registry} from "prom-client"; +import {BeaconMetrics, createBeaconMetrics} from "./metrics/beacon.js"; +import {LodestarMetrics, createLodestarMetrics} from "./metrics/lodestar.js"; +import {collectNodeJSMetrics} from "./nodeJsMetrics.js"; import {MetricsOptions} from "./options.js"; import {RegistryMetricCreator} from "./utils/registryMetricCreator.js"; -import {createValidatorMonitor, ValidatorMonitor} from "./validatorMonitor.js"; -import {collectNodeJSMetrics} from "./nodeJsMetrics.js"; +import {ValidatorMonitor, createValidatorMonitor} from "./validatorMonitor.js"; export type Metrics = BeaconMetrics & LodestarMetrics & diff --git a/packages/beacon-node/src/metrics/metrics/beacon.ts b/packages/beacon-node/src/metrics/metrics/beacon.ts index b9a02a3b2059..60a49b0b673d 100644 --- a/packages/beacon-node/src/metrics/metrics/beacon.ts +++ b/packages/beacon-node/src/metrics/metrics/beacon.ts @@ -1,13 +1,13 @@ -import {ProducedBlockSource} from "@lodestar/types"; -import {NotReorgedReason} from "@lodestar/fork-choice/lib/forkChoice/interface.js"; import {UpdateHeadOpt} from "@lodestar/fork-choice"; -import {RegistryMetricCreator} from "../utils/registryMetricCreator.js"; -import {BlockProductionStep, PayloadPreparationType} from "../../chain/produceBlock/index.js"; +import {NotReorgedReason} from "@lodestar/fork-choice/lib/forkChoice/interface.js"; +import {ProducedBlockSource} from "@lodestar/types"; import { BlockSelectionResult, BuilderBlockSelectionReason, EngineBlockSelectionReason, } from "../../api/impl/validator/index.js"; +import {BlockProductionStep, PayloadPreparationType} from "../../chain/produceBlock/index.js"; +import {RegistryMetricCreator} from "../utils/registryMetricCreator.js"; export type BeaconMetrics = ReturnType; @@ -124,13 +124,6 @@ export function createBeaconMetrics(register: RegistryMetricCreator) { }), }, - headState: { - unfinalizedPubkeyCacheSize: register.gauge({ - name: "beacon_head_state_unfinalized_pubkey_cache_size", - help: "Current size of the unfinalizedPubkey2Index cache in the head state", - }), - }, - parentBlockDistance: register.histogram({ name: "beacon_imported_block_parent_distance", help: "Histogram of distance to parent block of valid imported blocks", @@ -220,6 +213,121 @@ export function createBeaconMetrics(register: RegistryMetricCreator) { }), }, + blockInputFetchStats: { + // of already available blocks which didn't have to go through blobs pull + totalDataAvailableBlockInputs: register.gauge({ + name: "beacon_blockinputs_already_available_total", + help: "Total number of block inputs whose blobs were already available", + }), + totalDataAvailableBlockInputBlobs: register.gauge({ + name: "beacon_blockinput_blobs_already_available_total", + help: "Total number of block input blobs that of already available blocks", + }), + + // of those which need to be fetched + dataPromiseBlobsAlreadyAvailable: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_already_available_total", + help: "Count of blocks that were already available in blockinput cache via gossip", + }), + dataPromiseBlobsDelayedGossipAvailable: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_delayed_gossip_available_total", + help: "Count of blobs that became available delayed via gossip post block arrival", + }), + dataPromiseBlobsDeplayedGossipAvailableSavedGetBlobsCompute: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_delayed_gossip_saved_computation_total", + help: "Count of late available blobs that saved blob sidecar computation from getblobs", + }), + dataPromiseBlobsFoundInGetBlobsCacheNotNull: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_found_nonnull_in_getblobs_cache_total", + help: "Count of blobs that were found not null in getblobs cache", + }), + dataPromiseBlobsFoundInGetBlobsCacheNull: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_found_null_in_getblobs_cache_total", + help: "Count of blobs that were found null in the getblobs cache", + }), + dataPromiseBlobsNotAvailableInGetBlobsCache: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_notfound_in_getblobs_cache_total", + help: "Count of blobs that were newly seen and hence in not getblobs cache", + }), + dataPromiseBlobsEngineGetBlobsApiRequests: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_queried_in_getblobs_api_total", + help: "Total number of blobs requested to the getblobs api", + }), + dataPromiseBlobsEngineGetBlobsApiNotNull: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_responded_nonnull_in_getblobs_api_total", + help: "Count of successful engine API responses that were not null", + }), + dataPromiseBlobsEngineGetBlobsApiNull: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_responded_null_in_getblobs_api_total", + help: "Count of engine API responses that were null", + }), + dataPromiseBlobsEngineApiGetBlobsErroredNull: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_errored_as_null_in_getblobs_api_total", + help: "Number of responses marked null due to errors in getblobs api", + }), + dataPromiseBlobsEngineApiGetBlobsUseful: register.gauge({ + name: "beacon_datapromise_blockinput_getblobs_api_nonnull_responses_used_total", + help: "Count of successful non null engine API responses that were found useful", + }), + dataPromiseBlobsFinallyQueriedFromNetwork: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_finally_queried_from_network_total", + help: "Number of blob requests finally sent to the network", + }), + dataPromiseBlobsFinallyAvailableFromNetwork: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_finally_resolved_from_network_total", + help: "Number of blobs successfully fetched from the network", + }), + + totalDataPromiseBlockInputsAvailableUsingGetBlobs: register.gauge({ + name: "beacon_datapromise_blockinputs_available_using_getblobs_total", + help: "Count of block inputs that became available using non-null get blobs requests", + }), + totalDataPromiseBlockInputsTried: register.gauge({ + name: "beacon_datapromise_blockinputs_tried_for_blobs_pull_total", + help: "Total number of block inputs that were tried to resolve", + }), + totalDataPromiseBlockInputsResolvedAvailable: register.gauge({ + name: "beacon_datapromise_blockinputs_available_post_blobs_pull_total", + help: "Total number of block inputs that were successfully resolved as available on blobs pull", + }), + + // retry counts + totalDataPromiseBlockInputsReTried: register.gauge({ + name: "beacon_datapromise_blockinputs_retried_for_blobs_pull_total", + help: "Total number of block inputs that were retried for blobs pull from network", + }), + dataPromiseBlobsRetriedFromNetwork: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_retried_from_network_total", + help: "Number of blob requests required from the network on retries", + }), + dataPromiseBlobsRetriedAvailableFromNetwork: register.gauge({ + name: "beacon_datapromise_blockinput_blobs_retried_and_resolved_from_network_total", + help: "Number of blobs successfully fetched from the network on retries", + }), + totalDataPromiseBlockInputsRetriedAvailableFromNetwork: register.gauge({ + name: "beacon_datapromise_blockinputs_retried_and_resolved_from_network_total", + help: "Number of blockinputs successfully resolved from the network on retries", + }), + + // some caches stats + getBlobsCacheSize: register.gauge({ + name: "getblob_cache_size", + help: "getBlobs cache size", + }), + getBlobsCachePruned: register.gauge({ + name: "getblob_cache_pruned_total", + help: "getblobs cache pruned count", + }), + dataPromiseBlockInputRetryTrackerCacheSize: register.gauge({ + name: "beacon_datapromise_blockinput_retry_tracker_cache_size", + help: "datapromise retry tracker cache size", + }), + dataPromiseBlockInputRetryTrackerCachePruned: register.gauge({ + name: "beacon_datapromise_blockinput_retry_tracker_cache_pruned", + help: "datapromise retry tracker cache pruned count", + }), + }, + // Non-spec'ed clockSlot: register.gauge({ name: "beacon_clock_slot", diff --git a/packages/beacon-node/src/metrics/metrics/lodestar.ts b/packages/beacon-node/src/metrics/metrics/lodestar.ts index f15e195faa20..461f9c9e935b 100644 --- a/packages/beacon-node/src/metrics/metrics/lodestar.ts +++ b/packages/beacon-node/src/metrics/metrics/lodestar.ts @@ -1,6 +1,6 @@ import {EpochTransitionStep, StateCloneSource, StateHashTreeRootSource} from "@lodestar/state-transition"; import {BeaconState} from "@lodestar/types"; -import {BlockSource, BlobsSource} from "../../chain/blocks/types.js"; +import {BlobsSource, BlockSource} from "../../chain/blocks/types.js"; import {JobQueueItemType} from "../../chain/bls/index.js"; import {BlockErrorCode} from "../../chain/errors/index.js"; import {InsertOutcome} from "../../chain/opPools/types.js"; @@ -8,17 +8,17 @@ import {RegenCaller, RegenFnName} from "../../chain/regen/interface.js"; import {ReprocessStatus} from "../../chain/reprocess.js"; import {RejectReason} from "../../chain/seenCache/seenAttestationData.js"; import {BlockInputAvailabilitySource} from "../../chain/seenCache/seenGossipBlockInput.js"; +import {CacheItemType} from "../../chain/stateCache/types.js"; import {ExecutionPayloadStatus} from "../../execution/index.js"; import {GossipType} from "../../network/index.js"; import {CannotAcceptWorkReason, ReprocessRejectReason} from "../../network/processor/index.js"; import {BackfillSyncMethod} from "../../sync/backfill/backfill.js"; import {PendingBlockType} from "../../sync/index.js"; import {PeerSyncType, RangeSyncType} from "../../sync/utils/remoteSyncType.js"; +import {AllocSource} from "../../util/bufferPool.js"; import {LodestarMetadata} from "../options.js"; import {RegistryMetricCreator} from "../utils/registryMetricCreator.js"; import {OpSource} from "../validatorMonitor.js"; -import {CacheItemType} from "../../chain/stateCache/types.js"; -import {AllocSource} from "../../util/bufferPool.js"; export type LodestarMetrics = ReturnType; @@ -378,17 +378,6 @@ export function createLodestarMetrics( help: "Total count state.validators nodesPopulated is false on stfn for post state", }), - epochCache: { - finalizedPubkeyDuplicateInsert: register.gauge({ - name: "lodestar_epoch_cache_finalized_pubkey_duplicate_insert_total", - help: "Total count of duplicate insert of finalized pubkeys", - }), - newUnFinalizedPubkey: register.gauge({ - name: "lodestar_epoch_cache_new_unfinalized_pubkey_total", - help: "Total count of unfinalized pubkeys added", - }), - }, - // BLS verifier thread pool and queue bls: { diff --git a/packages/beacon-node/src/metrics/nodeJsMetrics.ts b/packages/beacon-node/src/metrics/nodeJsMetrics.ts index c565cfc07ba5..c448276e278a 100644 --- a/packages/beacon-node/src/metrics/nodeJsMetrics.ts +++ b/packages/beacon-node/src/metrics/nodeJsMetrics.ts @@ -1,5 +1,5 @@ -import {collectDefaultMetrics, Registry} from "prom-client"; import {gcStats} from "@chainsafe/prometheus-gc-stats"; +import {Registry, collectDefaultMetrics} from "prom-client"; export function collectNodeJSMetrics(register: Registry, prefix?: string): () => void { collectDefaultMetrics({ diff --git a/packages/beacon-node/src/metrics/server/http.ts b/packages/beacon-node/src/metrics/server/http.ts index e197dcfa2a25..5d4fa36998fb 100644 --- a/packages/beacon-node/src/metrics/server/http.ts +++ b/packages/beacon-node/src/metrics/server/http.ts @@ -1,9 +1,9 @@ import http from "node:http"; import {AddressInfo} from "node:net"; -import {Registry} from "prom-client"; import {Logger} from "@lodestar/utils"; -import {wrapError} from "../../util/wrapError.js"; +import {Registry} from "prom-client"; import {HttpActiveSocketsTracker} from "../../api/rest/activeSockets.js"; +import {wrapError} from "../../util/wrapError.js"; import {RegistryMetricCreator} from "../utils/registryMetricCreator.js"; export type HttpMetricsServerOpts = { diff --git a/packages/beacon-node/src/metrics/utils/avgMinMax.ts b/packages/beacon-node/src/metrics/utils/avgMinMax.ts index 709c83ee38d6..8bb5b196141e 100644 --- a/packages/beacon-node/src/metrics/utils/avgMinMax.ts +++ b/packages/beacon-node/src/metrics/utils/avgMinMax.ts @@ -1,5 +1,5 @@ -import {GaugeConfiguration} from "prom-client"; import {AvgMinMax as IAvgMinMax, LabelKeys, LabelsGeneric} from "@lodestar/utils"; +import {GaugeConfiguration} from "prom-client"; import {GaugeExtra} from "./gauge.js"; type GetValuesFn = () => number[]; diff --git a/packages/beacon-node/src/metrics/utils/gauge.ts b/packages/beacon-node/src/metrics/utils/gauge.ts index 1f527adfcb64..a4c5e9966759 100644 --- a/packages/beacon-node/src/metrics/utils/gauge.ts +++ b/packages/beacon-node/src/metrics/utils/gauge.ts @@ -1,5 +1,5 @@ -import {Gauge} from "prom-client"; import {CollectFn, Gauge as IGauge, LabelKeys, LabelsGeneric} from "@lodestar/utils"; +import {Gauge} from "prom-client"; /** * Extends the prom-client Gauge to be able to add multiple collect functions after instantiation diff --git a/packages/beacon-node/src/metrics/utils/registryMetricCreator.ts b/packages/beacon-node/src/metrics/utils/registryMetricCreator.ts index adec6f984702..30de36969456 100644 --- a/packages/beacon-node/src/metrics/utils/registryMetricCreator.ts +++ b/packages/beacon-node/src/metrics/utils/registryMetricCreator.ts @@ -1,4 +1,3 @@ -import {Gauge, Registry, Counter, Histogram} from "prom-client"; import { AvgMinMaxConfig, CounterConfig, @@ -14,6 +13,7 @@ import { NoLabels, StaticConfig, } from "@lodestar/utils"; +import {Counter, Gauge, Histogram, Registry} from "prom-client"; import {AvgMinMax} from "./avgMinMax.js"; import {GaugeExtra} from "./gauge.js"; diff --git a/packages/beacon-node/src/metrics/validatorMonitor.ts b/packages/beacon-node/src/metrics/validatorMonitor.ts index 14a210f62997..401d58af57ff 100644 --- a/packages/beacon-node/src/metrics/validatorMonitor.ts +++ b/packages/beacon-node/src/metrics/validatorMonitor.ts @@ -1,19 +1,19 @@ +import {ChainConfig, ChainForkConfig} from "@lodestar/config"; +import {ForkSeq, INTERVALS_PER_SLOT, MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH} from "@lodestar/params"; import { - computeEpochAtSlot, - parseAttesterFlags, CachedBeaconStateAllForks, CachedBeaconStateAltair, - parseParticipationFlags, + ParticipationFlags, + computeEpochAtSlot, computeStartSlotAtEpoch, getBlockRootAtSlot, - ParticipationFlags, + parseAttesterFlags, + parseParticipationFlags, } from "@lodestar/state-transition"; -import {LogData, LogHandler, LogLevel, Logger, MapDef, MapDefMax, toRootHex} from "@lodestar/utils"; import {BeaconBlock, RootHex, altair, deneb} from "@lodestar/types"; -import {ChainConfig, ChainForkConfig} from "@lodestar/config"; -import {ForkSeq, INTERVALS_PER_SLOT, MIN_ATTESTATION_INCLUSION_DELAY, SLOTS_PER_EPOCH} from "@lodestar/params"; import {Epoch, Slot, ValidatorIndex} from "@lodestar/types"; import {IndexedAttestation, SignedAggregateAndProof} from "@lodestar/types"; +import {LogData, LogHandler, LogLevel, Logger, MapDef, MapDefMax, toRootHex} from "@lodestar/utils"; import {GENESIS_SLOT} from "../constants/constants.js"; import {LodestarMetrics} from "./metrics/lodestar.js"; diff --git a/packages/beacon-node/src/monitoring/service.ts b/packages/beacon-node/src/monitoring/service.ts index f6a6a2352e02..930fe4a65224 100644 --- a/packages/beacon-node/src/monitoring/service.ts +++ b/packages/beacon-node/src/monitoring/service.ts @@ -1,11 +1,11 @@ -import {Registry} from "prom-client"; import {fetch} from "@lodestar/api"; import {ErrorAborted, Histogram, Logger, TimeoutError} from "@lodestar/utils"; +import {Registry} from "prom-client"; import {RegistryMetricCreator} from "../metrics/index.js"; -import {defaultMonitoringOptions, MonitoringOptions} from "./options.js"; import {createClientStats} from "./clientStats.js"; -import {ClientStats} from "./types.js"; +import {MonitoringOptions, defaultMonitoringOptions} from "./options.js"; import system from "./system.js"; +import {ClientStats} from "./types.js"; type MonitoringData = Record; diff --git a/packages/beacon-node/src/monitoring/system.ts b/packages/beacon-node/src/monitoring/system.ts index 83507443be01..4afcc6064b16 100644 --- a/packages/beacon-node/src/monitoring/system.ts +++ b/packages/beacon-node/src/monitoring/system.ts @@ -2,9 +2,9 @@ /* eslint-disable import/no-named-as-default-member */ import os from "node:os"; import path from "node:path"; +import {Logger} from "@lodestar/utils"; // We want to keep `system` export as it's more readable and easier to understand import system from "systeminformation"; -import {Logger} from "@lodestar/utils"; type MiscOs = "lin" | "win" | "mac" | "unk"; diff --git a/packages/beacon-node/src/network/core/networkCore.ts b/packages/beacon-node/src/network/core/networkCore.ts index d47fcabd4146..beda73b62a94 100644 --- a/packages/beacon-node/src/network/core/networkCore.ts +++ b/packages/beacon-node/src/network/core/networkCore.ts @@ -1,37 +1,37 @@ -import {Connection, PeerId} from "@libp2p/interface"; -import {multiaddr} from "@multiformats/multiaddr"; -import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types"; -import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.js"; import {ENR} from "@chainsafe/enr"; +import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/dist/src/score/peer-score.js"; +import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types"; +import {Connection, PeerId} from "@libp2p/interface"; import {routes} from "@lodestar/api"; import {BeaconConfig} from "@lodestar/config"; import type {LoggerNode} from "@lodestar/logger/node"; -import {Epoch, phase0} from "@lodestar/types"; -import {fromHex, withTimeout} from "@lodestar/utils"; import {ForkName} from "@lodestar/params"; import {ResponseIncoming} from "@lodestar/reqresp"; -import {Libp2p} from "../interface.js"; -import {PeerManager} from "../peers/peerManager.js"; -import {ReqRespBeaconNode} from "../reqresp/ReqRespBeaconNode.js"; -import {OutgoingRequestArgs, GetReqRespHandlerFn} from "../reqresp/types.js"; -import {Eth2Gossipsub, getCoreTopicsAtFork} from "../gossip/index.js"; -import {SyncnetsService} from "../subnets/syncnetsService.js"; +import {Epoch, phase0} from "@lodestar/types"; +import {fromHex, withTimeout} from "@lodestar/utils"; +import {multiaddr} from "@multiformats/multiaddr"; +import {formatNodePeer} from "../../api/impl/node/utils.js"; +import {RegistryMetricCreator} from "../../metrics/index.js"; +import {ClockEvent, IClock} from "../../util/clock.js"; +import {peerIdFromString, peerIdToString} from "../../util/peerId.js"; +import {Discv5Worker} from "../discv5/index.js"; +import {NetworkEventBus} from "../events.js"; import {FORK_EPOCH_LOOKAHEAD, getActiveForks} from "../forks.js"; -import {NetworkOptions} from "../options.js"; -import {CommitteeSubscription, IAttnetsService} from "../subnets/interface.js"; -import {MetadataController} from "../metadata.js"; +import {Eth2Gossipsub, getCoreTopicsAtFork} from "../gossip/index.js"; +import {Libp2p} from "../interface.js"; import {createNodeJsLibp2p} from "../libp2p/index.js"; -import {PeersData} from "../peers/peersData.js"; +import {MetadataController} from "../metadata.js"; +import {NetworkOptions} from "../options.js"; import {PeerAction, PeerRpcScoreStore, PeerScoreStats} from "../peers/index.js"; -import {getConnectionsMap} from "../util.js"; -import {IClock, ClockEvent} from "../../util/clock.js"; -import {formatNodePeer} from "../../api/impl/node/utils.js"; -import {NetworkEventBus} from "../events.js"; -import {Discv5Worker} from "../discv5/index.js"; +import {PeerManager} from "../peers/peerManager.js"; +import {PeersData} from "../peers/peersData.js"; +import {ReqRespBeaconNode} from "../reqresp/ReqRespBeaconNode.js"; +import {GetReqRespHandlerFn, OutgoingRequestArgs} from "../reqresp/types.js"; import {LocalStatusCache} from "../statusCache.js"; -import {RegistryMetricCreator} from "../../metrics/index.js"; -import {peerIdFromString, peerIdToString} from "../../util/peerId.js"; import {AttnetsService} from "../subnets/attnetsService.js"; +import {CommitteeSubscription, IAttnetsService} from "../subnets/interface.js"; +import {SyncnetsService} from "../subnets/syncnetsService.js"; +import {getConnectionsMap} from "../util.js"; import {NetworkCoreMetrics, createNetworkCoreMetrics} from "./metrics.js"; import {INetworkCore, MultiaddrStr, PeerIdStr} from "./types.js"; @@ -316,7 +316,7 @@ export class NetworkCore implements INetworkCore { } for (const fork of getActiveForks(this.config, this.clock.currentEpoch)) { - this.subscribeCoreTopicsAtFork(fork); + this.subscribeCoreTopicsAtFork(this.config, fork); } } @@ -325,7 +325,7 @@ export class NetworkCore implements INetworkCore { */ async unsubscribeGossipCoreTopics(): Promise { for (const fork of this.subscribedForks.values()) { - this.unsubscribeCoreTopicsAtFork(fork); + this.unsubscribeCoreTopicsAtFork(this.config, fork); } } @@ -456,7 +456,7 @@ export class NetworkCore implements INetworkCore { if (epoch === forkEpoch - FORK_EPOCH_LOOKAHEAD) { // Don't subscribe to new fork if the node is not subscribed to any topic if (await this.isSubscribedToGossipCoreTopics()) { - this.subscribeCoreTopicsAtFork(nextFork); + this.subscribeCoreTopicsAtFork(this.config, nextFork); this.logger.info("Subscribing gossip topics before fork", {nextFork}); } else { this.logger.info("Skipping subscribing gossip topics before fork", {nextFork}); @@ -475,7 +475,7 @@ export class NetworkCore implements INetworkCore { // After fork transition if (epoch === forkEpoch + FORK_EPOCH_LOOKAHEAD) { this.logger.info("Unsubscribing gossip topics from prev fork", {prevFork}); - this.unsubscribeCoreTopicsAtFork(prevFork); + this.unsubscribeCoreTopicsAtFork(this.config, prevFork); this.attnetsService.unsubscribeSubnetsFromPrevFork(prevFork); this.syncnetsService.unsubscribeSubnetsFromPrevFork(prevFork); } @@ -501,12 +501,12 @@ export class NetworkCore implements INetworkCore { } }; - private subscribeCoreTopicsAtFork(fork: ForkName): void { + private subscribeCoreTopicsAtFork(config: BeaconConfig, fork: ForkName): void { if (this.subscribedForks.has(fork)) return; this.subscribedForks.add(fork); const {subscribeAllSubnets, disableLightClientServer} = this.opts; - for (const topic of getCoreTopicsAtFork(fork, { + for (const topic of getCoreTopicsAtFork(config, fork, { subscribeAllSubnets, disableLightClientServer, })) { @@ -514,12 +514,12 @@ export class NetworkCore implements INetworkCore { } } - private unsubscribeCoreTopicsAtFork(fork: ForkName): void { + private unsubscribeCoreTopicsAtFork(config: BeaconConfig, fork: ForkName): void { if (!this.subscribedForks.has(fork)) return; this.subscribedForks.delete(fork); const {subscribeAllSubnets, disableLightClientServer} = this.opts; - for (const topic of getCoreTopicsAtFork(fork, { + for (const topic of getCoreTopicsAtFork(config, fork, { subscribeAllSubnets, disableLightClientServer, })) { diff --git a/packages/beacon-node/src/network/core/networkCoreWorker.ts b/packages/beacon-node/src/network/core/networkCoreWorker.ts index 5e4b057402d8..a5622bc6a5c1 100644 --- a/packages/beacon-node/src/network/core/networkCoreWorker.ts +++ b/packages/beacon-node/src/network/core/networkCoreWorker.ts @@ -11,11 +11,8 @@ import {AsyncIterableBridgeCaller, AsyncIterableBridgeHandler} from "../../util/ import {Clock} from "../../util/clock.js"; import {peerIdToString} from "../../util/peerId.js"; import {profileNodeJS, writeHeapSnapshot} from "../../util/profile.js"; -import {NetworkEventBus, NetworkEventData, networkEventDirection} from "../events.js"; import {wireEventsOnWorkerThread} from "../../util/workerEvents.js"; -import {getNetworkCoreWorkerMetrics} from "./metrics.js"; -import {NetworkWorkerApi, NetworkWorkerData} from "./types.js"; -import {NetworkCore} from "./networkCore.js"; +import {NetworkEventBus, NetworkEventData, networkEventDirection} from "../events.js"; import { NetworkWorkerThreadEventType, ReqRespBridgeEventBus, @@ -24,6 +21,9 @@ import { getReqRespBridgeRespEvents, reqRespBridgeEventDirection, } from "./events.js"; +import {getNetworkCoreWorkerMetrics} from "./metrics.js"; +import {NetworkCore} from "./networkCore.js"; +import {NetworkWorkerApi, NetworkWorkerData} from "./types.js"; // Cloned data from instantiation const workerData = worker.workerData as NetworkWorkerData; diff --git a/packages/beacon-node/src/network/core/types.ts b/packages/beacon-node/src/network/core/types.ts index 4eeaf96e1903..87feb9da9d21 100644 --- a/packages/beacon-node/src/network/core/types.ts +++ b/packages/beacon-node/src/network/core/types.ts @@ -1,13 +1,13 @@ import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score"; import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types"; import {routes} from "@lodestar/api"; +import {LoggerNodeOpts} from "@lodestar/logger/node"; import {ResponseIncoming} from "@lodestar/reqresp"; import {phase0} from "@lodestar/types"; -import {LoggerNodeOpts} from "@lodestar/logger/node"; import {NetworkOptions} from "../options.js"; -import {CommitteeSubscription} from "../subnets/interface.js"; import {PeerAction, PeerScoreStats} from "../peers/index.js"; import {OutgoingRequestArgs} from "../reqresp/types.js"; +import {CommitteeSubscription} from "../subnets/interface.js"; export type MultiaddrStr = string; export type PeerIdStr = string; diff --git a/packages/beacon-node/src/network/discv5/index.ts b/packages/beacon-node/src/network/discv5/index.ts index 745b3171c38d..b010ee1ac670 100644 --- a/packages/beacon-node/src/network/discv5/index.ts +++ b/packages/beacon-node/src/network/discv5/index.ts @@ -1,11 +1,11 @@ import EventEmitter from "node:events"; +import {ENR, ENRData, SignableENR, createPrivateKeyFromPeerId} from "@chainsafe/enr"; +import {Thread, Worker, spawn} from "@chainsafe/threads"; import {PeerId, Secp256k1PeerId} from "@libp2p/interface"; -import {StrictEventEmitter} from "strict-event-emitter-types"; import {exportToProtobuf} from "@libp2p/peer-id-factory"; -import {createPrivateKeyFromPeerId, ENR, ENRData, SignableENR} from "@chainsafe/enr"; -import {spawn, Thread, Worker} from "@chainsafe/threads"; -import {chainConfigFromJson, chainConfigToJson, BeaconConfig} from "@lodestar/config"; +import {BeaconConfig, chainConfigFromJson, chainConfigToJson} from "@lodestar/config"; import {LoggerNode} from "@lodestar/logger/node"; +import {StrictEventEmitter} from "strict-event-emitter-types"; import {NetworkCoreMetrics} from "../core/metrics.js"; import {Discv5WorkerApi, Discv5WorkerData, LodestarDiscv5Opts} from "./types.js"; diff --git a/packages/beacon-node/src/network/discv5/worker.ts b/packages/beacon-node/src/network/discv5/worker.ts index 8e96751d5fe7..49dfc9c2f35d 100644 --- a/packages/beacon-node/src/network/discv5/worker.ts +++ b/packages/beacon-node/src/network/discv5/worker.ts @@ -1,20 +1,20 @@ -import worker from "node:worker_threads"; -import path from "node:path"; import fs from "node:fs"; -import {createFromProtobuf} from "@libp2p/peer-id-factory"; -import {Multiaddr, multiaddr} from "@multiformats/multiaddr"; -import {expose} from "@chainsafe/threads/worker"; -import {Observable, Subject} from "@chainsafe/threads/observable"; +import path from "node:path"; +import worker from "node:worker_threads"; import {Discv5} from "@chainsafe/discv5"; -import {createPrivateKeyFromPeerId, ENR, ENRData, SignableENR, SignableENRData} from "@chainsafe/enr"; +import {ENR, ENRData, SignableENR, SignableENRData, createPrivateKeyFromPeerId} from "@chainsafe/enr"; +import {Observable, Subject} from "@chainsafe/threads/observable"; +import {expose} from "@chainsafe/threads/worker"; +import {createFromProtobuf} from "@libp2p/peer-id-factory"; import {createBeaconConfig} from "@lodestar/config"; import {getNodeLogger} from "@lodestar/logger/node"; import {Gauge} from "@lodestar/utils"; +import {Multiaddr, multiaddr} from "@multiformats/multiaddr"; import {RegistryMetricCreator} from "../../metrics/index.js"; import {collectNodeJSMetrics} from "../../metrics/nodeJsMetrics.js"; import {profileNodeJS, writeHeapSnapshot} from "../../util/profile.js"; import {Discv5WorkerApi, Discv5WorkerData} from "./types.js"; -import {enrRelevance, ENRRelevance} from "./utils.js"; +import {ENRRelevance, enrRelevance} from "./utils.js"; // This discv5 worker will start discv5 on initialization (there is no `start` function to call) // A consumer _should_ call `close` before terminating the worker to cleanly exit discv5 before destroying the thread diff --git a/packages/beacon-node/src/network/events.ts b/packages/beacon-node/src/network/events.ts index a95b52394163..ed3e7ec876ed 100644 --- a/packages/beacon-node/src/network/events.ts +++ b/packages/beacon-node/src/network/events.ts @@ -1,12 +1,12 @@ import {EventEmitter} from "node:events"; import {PeerId, TopicValidatorResult} from "@libp2p/interface"; -import {phase0, RootHex} from "@lodestar/types"; +import {RootHex, phase0} from "@lodestar/types"; import {BlockInput, NullBlockInput} from "../chain/blocks/types.js"; -import {StrictEventEmitterSingleArg} from "../util/strictEvents.js"; import {PeerIdStr} from "../util/peerId.js"; +import {StrictEventEmitterSingleArg} from "../util/strictEvents.js"; import {EventDirection} from "../util/workerEvents.js"; -import {RequestTypedContainer} from "./reqresp/ReqRespBeaconNode.js"; import {PendingGossipsubMessage} from "./processor/types.js"; +import {RequestTypedContainer} from "./reqresp/ReqRespBeaconNode.js"; export enum NetworkEvent { /** A relevant peer has connected or has been re-STATUS'd */ diff --git a/packages/beacon-node/src/network/forks.ts b/packages/beacon-node/src/network/forks.ts index 1c613f4cee94..cad4616c008b 100644 --- a/packages/beacon-node/src/network/forks.ts +++ b/packages/beacon-node/src/network/forks.ts @@ -1,5 +1,5 @@ -import {ForkName} from "@lodestar/params"; import {ChainForkConfig, ForkInfo} from "@lodestar/config"; +import {ForkName} from "@lodestar/params"; import {Epoch} from "@lodestar/types"; /** diff --git a/packages/beacon-node/src/network/gossip/encoding.ts b/packages/beacon-node/src/network/gossip/encoding.ts index f7f733fcd915..f6121bf8af91 100644 --- a/packages/beacon-node/src/network/gossip/encoding.ts +++ b/packages/beacon-node/src/network/gossip/encoding.ts @@ -1,13 +1,13 @@ -import {compress, uncompress} from "snappyjs"; -import xxhashFactory from "xxhash-wasm"; -import {Message} from "@libp2p/interface"; import {digest} from "@chainsafe/as-sha256"; import {RPC} from "@chainsafe/libp2p-gossipsub/message"; import {DataTransform} from "@chainsafe/libp2p-gossipsub/types"; -import {intToBytes} from "@lodestar/utils"; +import {Message} from "@libp2p/interface"; import {ForkName} from "@lodestar/params"; +import {intToBytes} from "@lodestar/utils"; +import {compress, uncompress} from "snappyjs"; +import xxhashFactory from "xxhash-wasm"; import {MESSAGE_DOMAIN_VALID_SNAPPY} from "./constants.js"; -import {getGossipSSZType, GossipTopicCache} from "./topic.js"; +import {GossipTopicCache, getGossipSSZType} from "./topic.js"; // Load WASM const xxhash = await xxhashFactory(); diff --git a/packages/beacon-node/src/network/gossip/gossipsub.ts b/packages/beacon-node/src/network/gossip/gossipsub.ts index 76e1330cd4a1..9f2b47e21c6f 100644 --- a/packages/beacon-node/src/network/gossip/gossipsub.ts +++ b/packages/beacon-node/src/network/gossip/gossipsub.ts @@ -1,29 +1,29 @@ import {GossipSub, GossipsubEvents} from "@chainsafe/libp2p-gossipsub"; -import {SignaturePolicy, TopicStr} from "@chainsafe/libp2p-gossipsub/types"; -import {PeerScoreParams} from "@chainsafe/libp2p-gossipsub/score"; import {MetricsRegister, TopicLabel, TopicStrToLabel} from "@chainsafe/libp2p-gossipsub/metrics"; +import {PeerScoreParams} from "@chainsafe/libp2p-gossipsub/score"; +import {SignaturePolicy, TopicStr} from "@chainsafe/libp2p-gossipsub/types"; import {BeaconConfig} from "@lodestar/config"; import {ATTESTATION_SUBNET_COUNT, ForkName, SLOTS_PER_EPOCH, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {Logger, Map2d, Map2dArr} from "@lodestar/utils"; -import {RegistryMetricCreator} from "../../metrics/index.js"; -import {PeersData} from "../peers/peersData.js"; -import {ClientKind} from "../peers/client.js"; import {GOSSIP_MAX_SIZE, GOSSIP_MAX_SIZE_BELLATRIX} from "../../constants/network.js"; -import {Libp2p} from "../interface.js"; -import {NetworkEvent, NetworkEventBus, NetworkEventData} from "../events.js"; +import {RegistryMetricCreator} from "../../metrics/index.js"; import {callInNextEventLoop} from "../../util/eventLoop.js"; -import {GossipTopic, GossipType} from "./interface.js"; -import {GossipTopicCache, stringifyGossipTopic, getCoreTopicsAtFork} from "./topic.js"; +import {NetworkEvent, NetworkEventBus, NetworkEventData} from "../events.js"; +import {Libp2p} from "../interface.js"; +import {ClientKind} from "../peers/client.js"; +import {PeersData} from "../peers/peersData.js"; import {DataTransformSnappy, fastMsgIdFn, msgIdFn, msgIdToStrFn} from "./encoding.js"; -import {createEth2GossipsubMetrics, Eth2GossipsubMetrics} from "./metrics.js"; +import {GossipTopic, GossipType} from "./interface.js"; +import {Eth2GossipsubMetrics, createEth2GossipsubMetrics} from "./metrics.js"; +import {GossipTopicCache, getCoreTopicsAtFork, stringifyGossipTopic} from "./topic.js"; import { - computeGossipPeerScoreParams, - gossipScoreThresholds, GOSSIP_D, GOSSIP_D_HIGH, GOSSIP_D_LOW, + computeGossipPeerScoreParams, + gossipScoreThresholds, } from "./scoringParameters.js"; /** As specified in https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md */ @@ -329,7 +329,7 @@ function getMetricsTopicStrToLabel(config: BeaconConfig, opts: {disableLightClie const metricsTopicStrToLabel = new Map(); for (const {name: fork} of config.forksAscendingEpochOrder) { - const topics = getCoreTopicsAtFork(fork, { + const topics = getCoreTopicsAtFork(config, fork, { subscribeAllSubnets: true, disableLightClientServer: opts.disableLightClientServer, }); diff --git a/packages/beacon-node/src/network/gossip/interface.ts b/packages/beacon-node/src/network/gossip/interface.ts index ff1bfa088c17..be7293524ce9 100644 --- a/packages/beacon-node/src/network/gossip/interface.ts +++ b/packages/beacon-node/src/network/gossip/interface.ts @@ -1,25 +1,25 @@ -import {Libp2p} from "libp2p"; -import {Message, TopicValidatorResult} from "@libp2p/interface"; import {PeerIdStr} from "@chainsafe/libp2p-gossipsub/types"; +import {Message, TopicValidatorResult} from "@libp2p/interface"; +import {BeaconConfig} from "@lodestar/config"; import {ForkName} from "@lodestar/params"; import { - altair, - capella, - deneb, + Attestation, LightClientFinalityUpdate, LightClientOptimisticUpdate, - phase0, + SignedAggregateAndProof, SignedBeaconBlock, Slot, - Attestation, - SignedAggregateAndProof, + altair, + capella, + deneb, + phase0, } from "@lodestar/types"; -import {BeaconConfig} from "@lodestar/config"; import {Logger} from "@lodestar/utils"; -import {IBeaconChain} from "../../chain/index.js"; -import {JobItemQueue} from "../../util/queue/index.js"; +import {Libp2p} from "libp2p"; import {AttestationError, AttestationErrorType} from "../../chain/errors/attestationError.js"; import {GossipActionError} from "../../chain/errors/gossipValidation.js"; +import {IBeaconChain} from "../../chain/index.js"; +import {JobItemQueue} from "../../util/queue/index.js"; export enum GossipType { beacon_block = "beacon_block", @@ -54,7 +54,7 @@ export interface IGossipTopic { export type GossipTopicTypeMap = { [GossipType.beacon_block]: {type: GossipType.beacon_block}; - [GossipType.blob_sidecar]: {type: GossipType.blob_sidecar; index: number}; + [GossipType.blob_sidecar]: {type: GossipType.blob_sidecar; subnet: number}; [GossipType.beacon_aggregate_and_proof]: {type: GossipType.beacon_aggregate_and_proof}; [GossipType.beacon_attestation]: {type: GossipType.beacon_attestation; subnet: number}; [GossipType.voluntary_exit]: {type: GossipType.voluntary_exit}; diff --git a/packages/beacon-node/src/network/gossip/scoringParameters.ts b/packages/beacon-node/src/network/gossip/scoringParameters.ts index 3ba32614afeb..890fd5acd251 100644 --- a/packages/beacon-node/src/network/gossip/scoringParameters.ts +++ b/packages/beacon-node/src/network/gossip/scoringParameters.ts @@ -1,12 +1,12 @@ import { - defaultTopicScoreParams, PeerScoreParams, - TopicScoreParams, PeerScoreThresholds, + TopicScoreParams, + defaultTopicScoreParams, } from "@chainsafe/libp2p-gossipsub/score"; -import {computeCommitteeCount} from "@lodestar/state-transition"; import {BeaconConfig} from "@lodestar/config"; import {ATTESTATION_SUBNET_COUNT, SLOTS_PER_EPOCH, TARGET_AGGREGATORS_PER_COMMITTEE} from "@lodestar/params"; +import {computeCommitteeCount} from "@lodestar/state-transition"; import {getActiveForks} from "../forks.js"; import {Eth2Context, Eth2GossipsubModules} from "./gossipsub.js"; import {GossipType} from "./interface.js"; diff --git a/packages/beacon-node/src/network/gossip/topic.ts b/packages/beacon-node/src/network/gossip/topic.ts index ed44c8314425..88ef4143f8ff 100644 --- a/packages/beacon-node/src/network/gossip/topic.ts +++ b/packages/beacon-node/src/network/gossip/topic.ts @@ -1,17 +1,16 @@ -import {ssz, Attestation, sszTypesFor} from "@lodestar/types"; -import {ForkDigestContext} from "@lodestar/config"; +import {ChainConfig, ForkDigestContext} from "@lodestar/config"; import { ATTESTATION_SUBNET_COUNT, ForkName, ForkSeq, SYNC_COMMITTEE_SUBNET_COUNT, isForkLightClient, - MAX_BLOBS_PER_BLOCK, } from "@lodestar/params"; +import {Attestation, ssz, sszTypesFor} from "@lodestar/types"; import {GossipAction, GossipActionError, GossipErrorCode} from "../../chain/errors/gossipValidation.js"; -import {GossipEncoding, GossipTopic, GossipType, GossipTopicTypeMap, SSZTypeOfGossipTopic} from "./interface.js"; import {DEFAULT_ENCODING} from "./constants.js"; +import {GossipEncoding, GossipTopic, GossipTopicTypeMap, GossipType, SSZTypeOfGossipTopic} from "./interface.js"; export interface IGossipTopicCache { getTopic(topicStr: string): GossipTopic; @@ -74,7 +73,7 @@ function stringifyGossipTopicType(topic: GossipTopic): string { case GossipType.sync_committee: return `${topic.type}_${topic.subnet}`; case GossipType.blob_sidecar: - return `${topic.type}_${topic.index}`; + return `${topic.type}_${topic.subnet}`; } } @@ -182,10 +181,10 @@ export function parseGossipTopic(forkDigestContext: ForkDigestContext, topicStr: } if (gossipTypeStr.startsWith(GossipType.blob_sidecar)) { - const indexStr = gossipTypeStr.slice(GossipType.blob_sidecar.length + 1); // +1 for '_' concatenating the topic name and the index - const index = parseInt(indexStr, 10); - if (Number.isNaN(index)) throw Error(`index ${indexStr} is not a number`); - return {type: GossipType.blob_sidecar, index, fork, encoding}; + const subnetStr = gossipTypeStr.slice(GossipType.blob_sidecar.length + 1); // +1 for '_' concatenating the topic name and the subnet + const subnet = parseInt(subnetStr, 10); + if (Number.isNaN(subnet)) throw Error(`subnet ${subnetStr} is not a number`); + return {type: GossipType.blob_sidecar, subnet, fork, encoding}; } throw Error(`Unknown gossip type ${gossipTypeStr}`); @@ -199,6 +198,7 @@ export function parseGossipTopic(forkDigestContext: ForkDigestContext, topicStr: * De-duplicate logic to pick fork topics between subscribeCoreTopicsAtFork and unsubscribeCoreTopicsAtFork */ export function getCoreTopicsAtFork( + config: ChainConfig, fork: ForkName, opts: {subscribeAllSubnets?: boolean; disableLightClientServer?: boolean} ): GossipTopicTypeMap[keyof GossipTopicTypeMap][] { @@ -211,10 +211,10 @@ export function getCoreTopicsAtFork( {type: GossipType.attester_slashing}, ]; - // After Deneb also track blob_sidecar_{index} + // After Deneb also track blob_sidecar_{subnet_id} if (ForkSeq[fork] >= ForkSeq.deneb) { - for (let index = 0; index < MAX_BLOBS_PER_BLOCK; index++) { - topics.push({type: GossipType.blob_sidecar, index}); + for (let subnet = 0; subnet < config.BLOB_SIDECAR_SUBNET_COUNT; subnet++) { + topics.push({type: GossipType.blob_sidecar, subnet}); } } diff --git a/packages/beacon-node/src/network/interface.ts b/packages/beacon-node/src/network/interface.ts index 0d48df42b31e..edcf35878420 100644 --- a/packages/beacon-node/src/network/interface.ts +++ b/packages/beacon-node/src/network/interface.ts @@ -1,40 +1,41 @@ -import {Libp2p as ILibp2p} from "libp2p"; +import {Identify} from "@chainsafe/libp2p-identify"; import { - Libp2pEvents, ComponentLogger, - NodeInfo, - ConnectionProtector, ConnectionGater, + ConnectionProtector, ContentRouting, - TypedEventTarget, + Libp2pEvents, Metrics, + NodeInfo, PeerId, PeerRouting, PeerStore, + TypedEventTarget, Upgrader, } from "@libp2p/interface"; import type {AddressManager, ConnectionManager, Registrar, TransportManager} from "@libp2p/interface-internal"; -import type {Datastore} from "interface-datastore"; -import {Identify} from "@chainsafe/libp2p-identify"; import { LightClientFinalityUpdate, LightClientOptimisticUpdate, + SignedAggregateAndProof, SignedBeaconBlock, Slot, SlotRootHex, + WithBytes, altair, capella, deneb, phase0, - SignedAggregateAndProof, - WithBytes, } from "@lodestar/types"; +import type {Datastore} from "interface-datastore"; +import {Libp2p as ILibp2p} from "libp2p"; import {PeerIdStr} from "../util/peerId.js"; -import {INetworkEventBus} from "./events.js"; +import {BlobSidecarsByRootRequest} from "../util/types.js"; import {INetworkCorePublic} from "./core/types.js"; +import {INetworkEventBus} from "./events.js"; import {GossipType} from "./gossip/interface.js"; -import {PendingGossipsubMessage} from "./processor/types.js"; import {PeerAction} from "./peers/index.js"; +import {PendingGossipsubMessage} from "./processor/types.js"; /** * The architecture of the network looks like so: @@ -66,7 +67,7 @@ export interface INetwork extends INetworkCorePublic { request: phase0.BeaconBlocksByRootRequest ): Promise[]>; sendBlobSidecarsByRange(peerId: PeerIdStr, request: deneb.BlobSidecarsByRangeRequest): Promise; - sendBlobSidecarsByRoot(peerId: PeerIdStr, request: deneb.BlobSidecarsByRootRequest): Promise; + sendBlobSidecarsByRoot(peerId: PeerIdStr, request: BlobSidecarsByRootRequest): Promise; // Gossip publishBeaconBlock(signedBlock: SignedBeaconBlock): Promise; diff --git a/packages/beacon-node/src/network/libp2p/index.ts b/packages/beacon-node/src/network/libp2p/index.ts index a0d58033cf2f..3191a63ac85c 100644 --- a/packages/beacon-node/src/network/libp2p/index.ts +++ b/packages/beacon-node/src/network/libp2p/index.ts @@ -1,18 +1,18 @@ -import {PeerId} from "@libp2p/interface"; -import {Registry} from "prom-client"; import {ENR} from "@chainsafe/enr"; // TODO: We should use this fork until https://github.com/libp2p/js-libp2p/pull/2387 import {identify} from "@chainsafe/libp2p-identify"; +import {noise} from "@chainsafe/libp2p-noise"; import {bootstrap} from "@libp2p/bootstrap"; +import {PeerId} from "@libp2p/interface"; import {mdns} from "@libp2p/mdns"; -import {createLibp2p} from "libp2p"; import {mplex} from "@libp2p/mplex"; import {prometheusMetrics} from "@libp2p/prometheus-metrics"; import {tcp} from "@libp2p/tcp"; -import {noise} from "@chainsafe/libp2p-noise"; -import {defaultNetworkOptions, NetworkOptions} from "../options.js"; -import {Eth2PeerDataStore} from "../peers/datastore.js"; +import {createLibp2p} from "libp2p"; +import {Registry} from "prom-client"; import {Libp2p, LodestarComponents} from "../interface.js"; +import {NetworkOptions, defaultNetworkOptions} from "../options.js"; +import {Eth2PeerDataStore} from "../peers/datastore.js"; export type NodeJsLibp2pOpts = { peerStoreDir?: string; diff --git a/packages/beacon-node/src/network/metadata.ts b/packages/beacon-node/src/network/metadata.ts index fab220c1ebf8..7b70775d63c6 100644 --- a/packages/beacon-node/src/network/metadata.ts +++ b/packages/beacon-node/src/network/metadata.ts @@ -1,8 +1,8 @@ import {BitArray} from "@chainsafe/ssz"; +import {BeaconConfig} from "@lodestar/config"; import {ForkSeq} from "@lodestar/params"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {altair, Epoch, phase0, ssz} from "@lodestar/types"; -import {BeaconConfig} from "@lodestar/config"; +import {Epoch, altair, phase0, ssz} from "@lodestar/types"; import {FAR_FUTURE_EPOCH} from "../constants/index.js"; import {getCurrentAndNextFork} from "./forks.js"; diff --git a/packages/beacon-node/src/network/network.ts b/packages/beacon-node/src/network/network.ts index 15414fcf9138..d8370fc22b5f 100644 --- a/packages/beacon-node/src/network/network.ts +++ b/packages/beacon-node/src/network/network.ts @@ -1,53 +1,54 @@ -import {PeerId} from "@libp2p/interface"; -import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types"; import {PeerScoreStatsDump} from "@chainsafe/libp2p-gossipsub/score"; +import {PublishOpts} from "@chainsafe/libp2p-gossipsub/types"; +import {PeerId} from "@libp2p/interface"; +import {routes} from "@lodestar/api"; import {BeaconConfig} from "@lodestar/config"; -import {sleep} from "@lodestar/utils"; import {LoggerNode} from "@lodestar/logger/node"; +import {ForkSeq} from "@lodestar/params"; +import {ResponseIncoming} from "@lodestar/reqresp"; import {computeStartSlotAtEpoch, computeTimeAtSlot} from "@lodestar/state-transition"; import { - phase0, - deneb, - altair, - Root, - capella, - SlotRootHex, - SignedBeaconBlock, LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, + Root, SignedAggregateAndProof, + SignedBeaconBlock, + SlotRootHex, WithBytes, + altair, + capella, + deneb, + phase0, } from "@lodestar/types"; -import {routes} from "@lodestar/api"; -import {ResponseIncoming} from "@lodestar/reqresp"; -import {ForkSeq, MAX_BLOBS_PER_BLOCK} from "@lodestar/params"; -import {Metrics, RegistryMetricCreator} from "../metrics/index.js"; +import {sleep} from "@lodestar/utils"; import {IBeaconChain} from "../chain/index.js"; import {IBeaconDb} from "../db/interface.js"; -import {PeerIdStr, peerIdToString} from "../util/peerId.js"; +import {Metrics, RegistryMetricCreator} from "../metrics/index.js"; import {IClock} from "../util/clock.js"; -import {NetworkOptions} from "./options.js"; -import {INetwork} from "./interface.js"; -import {ReqRespMethod} from "./reqresp/index.js"; +import {PeerIdStr, peerIdToString} from "../util/peerId.js"; +import {BlobSidecarsByRootRequest} from "../util/types.js"; +import {INetworkCore, NetworkCore, WorkerNetworkCore} from "./core/index.js"; +import {INetworkEventBus, NetworkEvent, NetworkEventBus, NetworkEventData} from "./events.js"; +import {getActiveForks} from "./forks.js"; import {GossipHandlers, GossipTopicMap, GossipType, GossipTypeMap} from "./gossip/index.js"; +import {getGossipSSZType, gossipTopicIgnoreDuplicatePublishError, stringifyGossipTopic} from "./gossip/topic.js"; +import {INetwork} from "./interface.js"; +import {NetworkOptions} from "./options.js"; import {PeerAction, PeerScoreStats} from "./peers/index.js"; -import {INetworkEventBus, NetworkEvent, NetworkEventBus, NetworkEventData} from "./events.js"; -import {CommitteeSubscription} from "./subnets/index.js"; -import {isPublishToZeroPeersError} from "./util.js"; +import {AggregatorTracker} from "./processor/aggregatorTracker.js"; import {NetworkProcessor, PendingGossipsubMessage} from "./processor/index.js"; -import {INetworkCore, NetworkCore, WorkerNetworkCore} from "./core/index.js"; +import {ReqRespMethod} from "./reqresp/index.js"; +import {GetReqRespHandlerFn, Version, requestSszTypeByMethod, responseSszTypeByMethod} from "./reqresp/types.js"; import { collectExactOneTyped, collectMaxResponseTyped, collectMaxResponseTypedWithBytes, } from "./reqresp/utils/collect.js"; -import {GetReqRespHandlerFn, Version, requestSszTypeByMethod, responseSszTypeByMethod} from "./reqresp/types.js"; import {collectSequentialBlocksInRange} from "./reqresp/utils/collectSequentialBlocksInRange.js"; -import {getGossipSSZType, gossipTopicIgnoreDuplicatePublishError, stringifyGossipTopic} from "./gossip/topic.js"; -import {AggregatorTracker} from "./processor/aggregatorTracker.js"; -import {getActiveForks} from "./forks.js"; +import {CommitteeSubscription} from "./subnets/index.js"; +import {isPublishToZeroPeersError} from "./util.js"; type NetworkModules = { opts: NetworkOptions; @@ -311,9 +312,9 @@ export class Network implements INetwork { async publishBlobSidecar(blobSidecar: deneb.BlobSidecar): Promise { const slot = blobSidecar.signedBlockHeader.message.slot; const fork = this.config.getForkName(slot); - const index = blobSidecar.index; + const subnet = blobSidecar.index; - return this.publishGossip({type: GossipType.blob_sidecar, fork, index}, blobSidecar, { + return this.publishGossip({type: GossipType.blob_sidecar, fork, subnet}, blobSidecar, { ignoreDuplicatePublishError: true, }); } @@ -502,15 +503,12 @@ export class Network implements INetwork { return collectMaxResponseTyped( this.sendReqRespRequest(peerId, ReqRespMethod.BlobSidecarsByRange, [Version.V1], request), // request's count represent the slots, so the actual max count received could be slots * blobs per slot - request.count * MAX_BLOBS_PER_BLOCK, + request.count * this.config.MAX_BLOBS_PER_BLOCK, responseSszTypeByMethod[ReqRespMethod.BlobSidecarsByRange] ); } - async sendBlobSidecarsByRoot( - peerId: PeerIdStr, - request: deneb.BlobSidecarsByRootRequest - ): Promise { + async sendBlobSidecarsByRoot(peerId: PeerIdStr, request: BlobSidecarsByRootRequest): Promise { return collectMaxResponseTyped( this.sendReqRespRequest(peerId, ReqRespMethod.BlobSidecarsByRoot, [Version.V1], request), request.length, @@ -524,7 +522,7 @@ export class Network implements INetwork { versions: number[], request: Req ): AsyncIterable { - const requestType = requestSszTypeByMethod[method]; + const requestType = requestSszTypeByMethod(this.config)[method]; const requestData = requestType ? requestType.serialize(request as never) : new Uint8Array(); // ReqResp outgoing request, emit from main thread to worker diff --git a/packages/beacon-node/src/network/options.ts b/packages/beacon-node/src/network/options.ts index ebb321584d12..1420be1d58fb 100644 --- a/packages/beacon-node/src/network/options.ts +++ b/packages/beacon-node/src/network/options.ts @@ -1,7 +1,7 @@ import {Eth2GossipsubOpts} from "./gossip/gossipsub.js"; import {PeerManagerOpts, PeerRpcScoreOpts} from "./peers/index.js"; -import {ReqRespBeaconNodeOpts} from "./reqresp/ReqRespBeaconNode.js"; import {NetworkProcessorOpts} from "./processor/index.js"; +import {ReqRespBeaconNodeOpts} from "./reqresp/ReqRespBeaconNode.js"; import {SubnetsServiceOpts} from "./subnets/interface.js"; // Since Network is eventually intended to be run in a separate thread, ensure that all options are cloneable using structuredClone diff --git a/packages/beacon-node/src/network/peers/datastore.ts b/packages/beacon-node/src/network/peers/datastore.ts index 88a7a6f5f2d6..ba5cae92c9a9 100644 --- a/packages/beacon-node/src/network/peers/datastore.ts +++ b/packages/beacon-node/src/network/peers/datastore.ts @@ -1,6 +1,6 @@ import {BaseDatastore} from "datastore-core"; import {LevelDatastore} from "datastore-level"; -import {Key, KeyQuery, Query, Pair} from "interface-datastore"; +import {Key, KeyQuery, Pair, Query} from "interface-datastore"; type MemoryItem = { lastAccessedMs: number; diff --git a/packages/beacon-node/src/network/peers/discover.ts b/packages/beacon-node/src/network/peers/discover.ts index 2b03656064e4..e658fd6378bf 100644 --- a/packages/beacon-node/src/network/peers/discover.ts +++ b/packages/beacon-node/src/network/peers/discover.ts @@ -1,18 +1,18 @@ -import {Multiaddr} from "@multiformats/multiaddr"; -import type {PeerId, PeerInfo} from "@libp2p/interface"; import {ENR} from "@chainsafe/enr"; +import type {PeerId, PeerInfo} from "@libp2p/interface"; import {BeaconConfig} from "@lodestar/config"; -import {pruneSetToMax, sleep} from "@lodestar/utils"; -import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {LoggerNode} from "@lodestar/logger/node"; +import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; +import {pruneSetToMax, sleep} from "@lodestar/utils"; +import {Multiaddr} from "@multiformats/multiaddr"; import {NetworkCoreMetrics} from "../core/metrics.js"; +import {Discv5Worker} from "../discv5/index.js"; +import {LodestarDiscv5Opts} from "../discv5/types.js"; import {Libp2p} from "../interface.js"; import {ENRKey, SubnetType} from "../metadata.js"; import {getConnectionsMap, prettyPrintPeerId} from "../util.js"; -import {Discv5Worker} from "../discv5/index.js"; -import {LodestarDiscv5Opts} from "../discv5/types.js"; -import {deserializeEnrSubnets, zeroAttnets, zeroSyncnets} from "./utils/enrSubnetsDeserialize.js"; import {IPeerRpcScoreStore, ScoreState} from "./score/index.js"; +import {deserializeEnrSubnets, zeroAttnets, zeroSyncnets} from "./utils/enrSubnetsDeserialize.js"; /** Max number of cached ENRs after discovering a good peer */ const MAX_CACHED_ENRS = 100; diff --git a/packages/beacon-node/src/network/peers/peerManager.ts b/packages/beacon-node/src/network/peers/peerManager.ts index b8742789d4fb..b8787bcc73a7 100644 --- a/packages/beacon-node/src/network/peers/peerManager.ts +++ b/packages/beacon-node/src/network/peers/peerManager.ts @@ -1,33 +1,33 @@ -import {Connection, PeerId} from "@libp2p/interface"; import {BitArray} from "@chainsafe/ssz"; -import {SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; +import {Connection, PeerId} from "@libp2p/interface"; import {BeaconConfig} from "@lodestar/config"; +import {LoggerNode} from "@lodestar/logger/node"; +import {SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {Metadata, altair, phase0} from "@lodestar/types"; import {withTimeout} from "@lodestar/utils"; -import {LoggerNode} from "@lodestar/logger/node"; -import {GoodByeReasonCode, GOODBYE_KNOWN_CODES, Libp2pEvent} from "../../constants/index.js"; +import {GOODBYE_KNOWN_CODES, GoodByeReasonCode, Libp2pEvent} from "../../constants/index.js"; import {IClock} from "../../util/clock.js"; -import {NetworkEvent, INetworkEventBus, NetworkEventData} from "../events.js"; +import {NetworkCoreMetrics} from "../core/metrics.js"; +import {LodestarDiscv5Opts} from "../discv5/types.js"; +import {INetworkEventBus, NetworkEvent, NetworkEventData} from "../events.js"; +import {Eth2Gossipsub} from "../gossip/gossipsub.js"; import {Libp2p} from "../interface.js"; -import {ReqRespMethod} from "../reqresp/ReqRespBeaconNode.js"; -import {getConnection, getConnectionsMap, prettyPrintPeerId} from "../util.js"; -import {SubnetsService} from "../subnets/index.js"; import {SubnetType} from "../metadata.js"; -import {Eth2Gossipsub} from "../gossip/gossipsub.js"; +import {ReqRespMethod} from "../reqresp/ReqRespBeaconNode.js"; import {StatusCache} from "../statusCache.js"; -import {NetworkCoreMetrics} from "../core/metrics.js"; -import {LodestarDiscv5Opts} from "../discv5/types.js"; +import {SubnetsService} from "../subnets/index.js"; +import {getConnection, getConnectionsMap, prettyPrintPeerId} from "../util.js"; +import {ClientKind, getKnownClientFromAgentVersion} from "./client.js"; import {PeerDiscovery, SubnetDiscvQueryMs} from "./discover.js"; -import {PeersData, PeerData} from "./peersData.js"; -import {getKnownClientFromAgentVersion, ClientKind} from "./client.js"; +import {PeerData, PeersData} from "./peersData.js"; +import {IPeerRpcScoreStore, PeerAction, PeerScoreStats, ScoreState, updateGossipsubScores} from "./score/index.js"; import { + assertPeerRelevance, getConnectedPeerIds, hasSomeConnectedPeer, - assertPeerRelevance, prioritizePeers, renderIrrelevantPeerType, } from "./utils/index.js"; -import {IPeerRpcScoreStore, PeerAction, PeerScoreStats, ScoreState, updateGossipsubScores} from "./score/index.js"; /** heartbeat performs regular updates such as updating reputations and performing discovery requests */ const HEARTBEAT_INTERVAL_MS = 30 * 1000; diff --git a/packages/beacon-node/src/network/peers/peersData.ts b/packages/beacon-node/src/network/peers/peersData.ts index 4f96548c73e4..1a2619f202cd 100644 --- a/packages/beacon-node/src/network/peers/peersData.ts +++ b/packages/beacon-node/src/network/peers/peersData.ts @@ -1,6 +1,6 @@ import {PeerId} from "@libp2p/interface"; -import {altair} from "@lodestar/types"; import {Encoding} from "@lodestar/reqresp"; +import {altair} from "@lodestar/types"; import {ClientKind} from "./client.js"; type PeerIdStr = string; diff --git a/packages/beacon-node/src/network/peers/utils/enrSubnetsDeserialize.ts b/packages/beacon-node/src/network/peers/utils/enrSubnetsDeserialize.ts index 0a26cce9b215..a330a8dca3c8 100644 --- a/packages/beacon-node/src/network/peers/utils/enrSubnetsDeserialize.ts +++ b/packages/beacon-node/src/network/peers/utils/enrSubnetsDeserialize.ts @@ -1,6 +1,6 @@ import {getUint8ByteToBitBooleanArray} from "@chainsafe/ssz"; -import {newFilledArray} from "@lodestar/state-transition"; import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; +import {newFilledArray} from "@lodestar/state-transition"; export const zeroAttnets = newFilledArray(ATTESTATION_SUBNET_COUNT, false); export const zeroSyncnets = newFilledArray(SYNC_COMMITTEE_SUBNET_COUNT, false); diff --git a/packages/beacon-node/src/network/peers/utils/prioritizePeers.ts b/packages/beacon-node/src/network/peers/utils/prioritizePeers.ts index b6fe4cb6bc77..545d8a6ca8b0 100644 --- a/packages/beacon-node/src/network/peers/utils/prioritizePeers.ts +++ b/packages/beacon-node/src/network/peers/utils/prioritizePeers.ts @@ -1,7 +1,7 @@ -import {Direction, PeerId} from "@libp2p/interface"; import {BitArray} from "@chainsafe/ssz"; -import {altair, phase0} from "@lodestar/types"; +import {Direction, PeerId} from "@libp2p/interface"; import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; +import {altair, phase0} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; import {shuffle} from "../../../util/shuffle.js"; import {sortBy} from "../../../util/sortBy.js"; diff --git a/packages/beacon-node/src/network/processor/extractSlotRootFns.ts b/packages/beacon-node/src/network/processor/extractSlotRootFns.ts index d31cb3e2d7f9..57a4861b4cb8 100644 --- a/packages/beacon-node/src/network/processor/extractSlotRootFns.ts +++ b/packages/beacon-node/src/network/processor/extractSlotRootFns.ts @@ -3,8 +3,8 @@ import { getBlockRootFromAttestationSerialized, getBlockRootFromSignedAggregateAndProofSerialized, getSlotFromAttestationSerialized, - getSlotFromSignedAggregateAndProofSerialized, getSlotFromBlobSidecarSerialized, + getSlotFromSignedAggregateAndProofSerialized, getSlotFromSignedBeaconBlockSerialized, } from "../../util/sszBytes.js"; import {GossipType} from "../gossip/index.js"; diff --git a/packages/beacon-node/src/network/processor/gossipHandlers.ts b/packages/beacon-node/src/network/processor/gossipHandlers.ts index dab3af0df8ba..3fb7b06e700a 100644 --- a/packages/beacon-node/src/network/processor/gossipHandlers.ts +++ b/packages/beacon-node/src/network/processor/gossipHandlers.ts @@ -1,59 +1,59 @@ +import {routes} from "@lodestar/api"; import {BeaconConfig, ChainForkConfig} from "@lodestar/config"; -import {LogLevel, Logger, prettyBytes, toRootHex} from "@lodestar/utils"; -import {Root, Slot, ssz, deneb, UintNum64, SignedBeaconBlock, sszTypesFor} from "@lodestar/types"; import {ForkName, ForkSeq} from "@lodestar/params"; -import {routes} from "@lodestar/api"; import {computeTimeAtSlot} from "@lodestar/state-transition"; -import {Metrics} from "../../metrics/index.js"; -import {OpSource} from "../../metrics/validatorMonitor.js"; +import {Root, SignedBeaconBlock, Slot, UintNum64, deneb, ssz, sszTypesFor} from "@lodestar/types"; +import {LogLevel, Logger, prettyBytes, toRootHex} from "@lodestar/utils"; +import { + BlobSidecarValidation, + BlockInput, + BlockInputType, + GossipedInputType, + NullBlockInput, +} from "../../chain/blocks/types.js"; import { AttestationError, AttestationErrorCode, + BlobSidecarErrorCode, + BlobSidecarGossipError, BlockError, BlockErrorCode, BlockGossipError, - BlobSidecarErrorCode, - BlobSidecarGossipError, GossipAction, GossipActionError, SyncCommitteeError, } from "../../chain/errors/index.js"; +import {IBeaconChain} from "../../chain/interface.js"; +import {validateGossipBlobSidecar} from "../../chain/validation/blobSidecar.js"; import { - BatchGossipHandlers, - SequentialGossipHandlers, - GossipHandlerParamGeneric, - GossipHandlers, - GossipType, -} from "../gossip/interface.js"; -import { + AggregateAndProofValidationResult, + GossipAttestation, validateGossipAggregateAndProof, + validateGossipAttestationsSameAttData, validateGossipAttesterSlashing, validateGossipBlock, + validateGossipBlsToExecutionChange, validateGossipProposerSlashing, validateGossipSyncCommittee, - validateSyncCommitteeGossipContributionAndProof, validateGossipVoluntaryExit, - validateGossipBlsToExecutionChange, - AggregateAndProofValidationResult, - validateGossipAttestationsSameAttData, - GossipAttestation, + validateSyncCommitteeGossipContributionAndProof, } from "../../chain/validation/index.js"; -import {NetworkEvent, NetworkEventBus} from "../events.js"; -import {PeerAction} from "../peers/index.js"; import {validateLightClientFinalityUpdate} from "../../chain/validation/lightClientFinalityUpdate.js"; import {validateLightClientOptimisticUpdate} from "../../chain/validation/lightClientOptimisticUpdate.js"; -import {validateGossipBlobSidecar} from "../../chain/validation/blobSidecar.js"; +import {Metrics} from "../../metrics/index.js"; +import {OpSource} from "../../metrics/validatorMonitor.js"; +import {INetworkCore} from "../core/index.js"; +import {NetworkEvent, NetworkEventBus} from "../events.js"; import { - BlockInput, - GossipedInputType, - BlobSidecarValidation, - BlockInputType, - NullBlockInput, -} from "../../chain/blocks/types.js"; + BatchGossipHandlers, + GossipHandlerParamGeneric, + GossipHandlers, + GossipType, + SequentialGossipHandlers, +} from "../gossip/interface.js"; import {sszDeserialize} from "../gossip/topic.js"; -import {INetworkCore} from "../core/index.js"; import {INetwork} from "../interface.js"; -import {IBeaconChain} from "../../chain/interface.js"; +import {PeerAction} from "../peers/index.js"; import {AggregatorTracker} from "./aggregatorTracker.js"; /** @@ -179,7 +179,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand async function validateBeaconBlob( blobSidecar: deneb.BlobSidecar, blobBytes: Uint8Array, - gossipIndex: number, + subnet: number, peerIdStr: string, seenTimestampSec: number ): Promise { @@ -202,7 +202,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand ); try { - await validateGossipBlobSidecar(chain, blobSidecar, gossipIndex); + await validateGossipBlobSidecar(chain, blobSidecar, subnet); const recvToValidation = Date.now() / 1000 - seenTimestampSec; const validationTime = recvToValidation - recvToValLatency; @@ -212,10 +212,10 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand logger.debug("Received gossip blob", { slot: slot, root: blockHex, - curentSlot: chain.clock.currentSlot, + currentSlot: chain.clock.currentSlot, peerId: peerIdStr, delaySec, - gossipIndex, + subnet, ...blockInputMeta, recvToValLatency, recvToValidation, @@ -253,6 +253,9 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand // if blobs are not yet fully available start an aggressive blob pull if (blockInput.type === BlockInputType.dataPromise) { events.emit(NetworkEvent.unknownBlockInput, {blockInput, peer: peerIdStr}); + } else if (blockInput.type === BlockInputType.availableData) { + metrics?.blockInputFetchStats.totalDataAvailableBlockInputs.inc(); + metrics?.blockInputFetchStats.totalDataAvailableBlockInputBlobs.inc(blockInput.blockData.blobs.length); } chain @@ -360,7 +363,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand const blockInput = await validateBeaconBlob( blobSidecar, serializedData, - topic.index, + topic.subnet, peerIdStr, seenTimestampSec ); diff --git a/packages/beacon-node/src/network/processor/gossipQueues/index.ts b/packages/beacon-node/src/network/processor/gossipQueues/index.ts index dfa5b0dd1973..b76ebe2d875d 100644 --- a/packages/beacon-node/src/network/processor/gossipQueues/index.ts +++ b/packages/beacon-node/src/network/processor/gossipQueues/index.ts @@ -1,10 +1,10 @@ import {mapValues} from "@lodestar/utils"; +import {getGossipAttestationIndex} from "../../../util/sszBytes.js"; import {BatchGossipType, GossipType, SequentialGossipType} from "../../gossip/interface.js"; import {PendingGossipsubMessage} from "../types.js"; -import {getGossipAttestationIndex} from "../../../util/sszBytes.js"; +import {IndexedGossipQueueMinSize} from "./indexed.js"; import {LinearGossipQueue} from "./linear.js"; import {DropType, GossipQueue, GossipQueueOpts, QueueType, isIndexedGossipQueueMinSizeOpts} from "./types.js"; -import {IndexedGossipQueueMinSize} from "./indexed.js"; /** * In normal condition, the higher this value the more efficient the signature verification. diff --git a/packages/beacon-node/src/network/processor/gossipQueues/linear.ts b/packages/beacon-node/src/network/processor/gossipQueues/linear.ts index 57a29054d417..f8a06c0d4622 100644 --- a/packages/beacon-node/src/network/processor/gossipQueues/linear.ts +++ b/packages/beacon-node/src/network/processor/gossipQueues/linear.ts @@ -1,5 +1,5 @@ import {LinkedList} from "../../../util/array.js"; -import {LinearGossipQueueOpts, DropType, GossipQueue, QueueType} from "./types.js"; +import {DropType, GossipQueue, LinearGossipQueueOpts, QueueType} from "./types.js"; // Having a drop ratio of 1 will empty the queue which is too severe // Worse case drop 95% of the queue diff --git a/packages/beacon-node/src/network/processor/gossipValidatorFn.ts b/packages/beacon-node/src/network/processor/gossipValidatorFn.ts index e5b276e7c707..6fda29bf4ac4 100644 --- a/packages/beacon-node/src/network/processor/gossipValidatorFn.ts +++ b/packages/beacon-node/src/network/processor/gossipValidatorFn.ts @@ -1,16 +1,16 @@ import {TopicValidatorResult} from "@libp2p/interface"; import {ChainForkConfig} from "@lodestar/config"; import {Logger} from "@lodestar/utils"; +import {AttestationError, GossipAction, GossipActionError} from "../../chain/errors/index.js"; import {Metrics} from "../../metrics/index.js"; import { - GossipValidatorFn, - GossipHandlers, - GossipHandlerFn, - GossipValidatorBatchFn, BatchGossipHandlerFn, + GossipHandlerFn, + GossipHandlers, GossipMessageInfo, + GossipValidatorBatchFn, + GossipValidatorFn, } from "../gossip/interface.js"; -import {GossipActionError, GossipAction, AttestationError} from "../../chain/errors/index.js"; export type ValidatorFnModules = { config: ChainForkConfig; diff --git a/packages/beacon-node/src/network/processor/index.ts b/packages/beacon-node/src/network/processor/index.ts index ec0edf54644f..4bfc4263adc8 100644 --- a/packages/beacon-node/src/network/processor/index.ts +++ b/packages/beacon-node/src/network/processor/index.ts @@ -1,14 +1,15 @@ -import {Logger, MapDef, mapValues, sleep} from "@lodestar/utils"; -import {RootHex, Slot, SlotRootHex} from "@lodestar/types"; import {routes} from "@lodestar/api"; -import {pruneSetToMax} from "@lodestar/utils"; import {ForkSeq} from "@lodestar/params"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {IBeaconChain} from "../../chain/interface.js"; +import {RootHex, Slot, SlotRootHex} from "@lodestar/types"; +import {Logger, MapDef, mapValues, sleep} from "@lodestar/utils"; +import {pruneSetToMax} from "@lodestar/utils"; import {GossipErrorCode} from "../../chain/errors/gossipValidation.js"; -import {Metrics} from "../../metrics/metrics.js"; +import {IBeaconChain} from "../../chain/interface.js"; import {IBeaconDb} from "../../db/interface.js"; +import {Metrics} from "../../metrics/metrics.js"; import {ClockEvent} from "../../util/clock.js"; +import {callInNextEventLoop} from "../../util/eventLoop.js"; import {NetworkEvent, NetworkEventBus} from "../events.js"; import { GossipHandlers, @@ -18,12 +19,11 @@ import { GossipValidatorFn, } from "../gossip/interface.js"; import {PeerIdStr} from "../peers/index.js"; -import {callInNextEventLoop} from "../../util/eventLoop.js"; -import {createGossipQueues} from "./gossipQueues/index.js"; -import {PendingGossipsubMessage} from "./types.js"; -import {ValidatorFnsModules, GossipHandlerOpts, getGossipHandlers} from "./gossipHandlers.js"; import {createExtractBlockSlotRootFns} from "./extractSlotRootFns.js"; +import {GossipHandlerOpts, ValidatorFnsModules, getGossipHandlers} from "./gossipHandlers.js"; +import {createGossipQueues} from "./gossipQueues/index.js"; import {ValidatorFnModules, getGossipValidatorBatchFn, getGossipValidatorFn} from "./gossipValidatorFn.js"; +import {PendingGossipsubMessage} from "./types.js"; export * from "./types.js"; diff --git a/packages/beacon-node/src/network/processor/types.ts b/packages/beacon-node/src/network/processor/types.ts index 386b9e8afc37..ec78116bc766 100644 --- a/packages/beacon-node/src/network/processor/types.ts +++ b/packages/beacon-node/src/network/processor/types.ts @@ -1,7 +1,7 @@ import {Message} from "@libp2p/interface"; import {Slot, SlotOptionalRoot} from "@lodestar/types"; -import {GossipTopic, GossipType} from "../gossip/index.js"; import {PeerIdStr} from "../../util/peerId.js"; +import {GossipTopic, GossipType} from "../gossip/index.js"; export type GossipAttestationsWork = { messages: PendingGossipsubMessage[]; diff --git a/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts b/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts index d34b379f4ccd..96b5c6c0a776 100644 --- a/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts +++ b/packages/beacon-node/src/network/reqresp/ReqRespBeaconNode.ts @@ -1,5 +1,4 @@ import {PeerId} from "@libp2p/interface"; -import {Libp2p} from "libp2p"; import {BeaconConfig} from "@lodestar/config"; import {ForkName, ForkSeq} from "@lodestar/params"; import { @@ -15,13 +14,15 @@ import { } from "@lodestar/reqresp"; import {Metadata, phase0, ssz} from "@lodestar/types"; import {Logger} from "@lodestar/utils"; +import {Libp2p} from "libp2p"; +import {callInNextEventLoop} from "../../util/eventLoop.js"; +import {NetworkCoreMetrics} from "../core/metrics.js"; import {INetworkEventBus, NetworkEvent} from "../events.js"; import {MetadataController} from "../metadata.js"; import {PeersData} from "../peers/peersData.js"; import {IPeerRpcScoreStore, PeerAction} from "../peers/score/index.js"; -import {NetworkCoreMetrics} from "../core/metrics.js"; import {StatusCache} from "../statusCache.js"; -import {callInNextEventLoop} from "../../util/eventLoop.js"; +import * as protocols from "./protocols.js"; import {onOutgoingReqRespError} from "./score.js"; import { GetReqRespHandlerFn, @@ -32,7 +33,6 @@ import { requestSszTypeByMethod, responseSszTypeByMethod, } from "./types.js"; -import * as protocols from "./protocols.js"; import {collectExactOneTyped} from "./utils/collect.js"; export {getReqRespHandlers} from "./handlers/index.js"; @@ -156,7 +156,9 @@ export class ReqRespBeaconNode extends ReqResp { // Overwrite placeholder requestData from main thread with correct sequenceNumber if (method === ReqRespMethod.Ping) { - requestData = requestSszTypeByMethod[ReqRespMethod.Ping].serialize(this.metadataController.seqNumber); + requestData = requestSszTypeByMethod(this.config)[ReqRespMethod.Ping].serialize( + this.metadataController.seqNumber + ); } // ReqResp outgoing request, emit from main thread to worker @@ -205,7 +207,7 @@ export class ReqRespBeaconNode extends ReqResp { versions: number[], request: Req ): AsyncIterable { - const requestType = requestSszTypeByMethod[method]; + const requestType = requestSszTypeByMethod(this.config)[method]; const requestData = requestType ? requestType.serialize(request as never) : new Uint8Array(); return this.sendRequestWithoutEncoding(peerId, method, versions, requestData); } diff --git a/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts b/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts index 041f1c59cc0a..d19a7867d873 100644 --- a/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts +++ b/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRange.ts @@ -1,9 +1,9 @@ import {ChainForkConfig} from "@lodestar/config"; -import {deneb, Epoch, phase0, SignedBeaconBlock, Slot, WithBytes} from "@lodestar/types"; import {ForkSeq} from "@lodestar/params"; import {computeEpochAtSlot} from "@lodestar/state-transition"; +import {Epoch, SignedBeaconBlock, Slot, WithBytes, deneb, phase0} from "@lodestar/types"; -import {BlobsSource, BlockInput, BlockSource, getBlockInput, BlockInputDataBlobs} from "../../chain/blocks/types.js"; +import {BlobsSource, BlockInput, BlockInputDataBlobs, BlockSource, getBlockInput} from "../../chain/blocks/types.js"; import {PeerIdStr} from "../../util/peerId.js"; import {INetwork} from "../interface.js"; diff --git a/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRoot.ts b/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRoot.ts index 3d121156d8e6..3bbe00bfc56b 100644 --- a/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRoot.ts +++ b/packages/beacon-node/src/network/reqresp/beaconBlocksMaybeBlobsByRoot.ts @@ -1,23 +1,32 @@ +import {toHexString} from "@chainsafe/ssz"; import {ChainForkConfig} from "@lodestar/config"; -import {phase0, deneb, SignedBeaconBlock} from "@lodestar/types"; -import {ForkSeq} from "@lodestar/params"; +import {ForkName, ForkSeq} from "@lodestar/params"; +import {signedBlockToSignedHeader} from "@lodestar/state-transition"; +import {RootHex, SignedBeaconBlock, deneb, phase0} from "@lodestar/types"; +import {BlobAndProof} from "@lodestar/types/deneb"; import {fromHex} from "@lodestar/utils"; import { + BlobsSource, BlockInput, + BlockInputDataBlobs, BlockInputType, BlockSource, - getBlockInputBlobs, - getBlockInput, NullBlockInput, - BlobsSource, - BlockInputDataBlobs, + getBlockInput, + getBlockInputBlobs, } from "../../chain/blocks/types.js"; -import {PeerIdStr} from "../../util/peerId.js"; -import {INetwork} from "../interface.js"; import {BlockInputAvailabilitySource} from "../../chain/seenCache/seenGossipBlockInput.js"; +import {IExecutionEngine} from "../../execution/index.js"; import {Metrics} from "../../metrics/index.js"; +import {computeInclusionProof, kzgCommitmentToVersionedHash} from "../../util/blobs.js"; +import {PeerIdStr} from "../../util/peerId.js"; +import {INetwork} from "../interface.js"; import {matchBlockWithBlobs} from "./beaconBlocksMaybeBlobsByRange.js"; +// keep 1 epoch of stuff, assmume 16 blobs +const MAX_ENGINE_GETBLOBS_CACHE = 32 * 16; +const MAX_UNAVAILABLE_RETRY_CACHE = 32; + export async function beaconBlocksMaybeBlobsByRoot( config: ChainForkConfig, network: INetwork, @@ -35,6 +44,7 @@ export async function beaconBlocksMaybeBlobsByRoot( if (ForkSeq[fork] >= ForkSeq.deneb) { const blobKzgCommitmentsLen = (block.data.message.body as deneb.BeaconBlockBody).blobKzgCommitments.length; for (let index = 0; index < blobKzgCommitmentsLen; index++) { + // try see if the blob is available locally blobIdentifiers.push({blockRoot, index}); } } @@ -57,8 +67,14 @@ export async function unavailableBeaconBlobsByRoot( network: INetwork, peerId: PeerIdStr, unavailableBlockInput: BlockInput | NullBlockInput, - metrics: Metrics | null + opts: { + metrics: Metrics | null; + executionEngine: IExecutionEngine; + engineGetBlobsCache?: Map; + blockInputsRetryTrackerCache?: Set; + } ): Promise { + const {executionEngine, metrics, engineGetBlobsCache, blockInputsRetryTrackerCache} = opts; if (unavailableBlockInput.block !== null && unavailableBlockInput.type !== BlockInputType.dataPromise) { return unavailableBlockInput; } @@ -81,26 +97,150 @@ export async function unavailableBeaconBlobsByRoot( } // resolve missing blobs - const blobIdentifiers: deneb.BlobIdentifier[] = []; const slot = block.message.slot; + const fork = config.getForkName(slot); const blockRoot = config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block.message); + const blockRootHex = toHexString(blockRoot); + + const blockTriedBefore = blockInputsRetryTrackerCache?.has(blockRootHex) === true; + if (blockTriedBefore) { + metrics?.blockInputFetchStats.totalDataPromiseBlockInputsReTried.inc(); + } else { + metrics?.blockInputFetchStats.totalDataPromiseBlockInputsTried.inc(); + blockInputsRetryTrackerCache?.add(blockRootHex); + } const blobKzgCommitmentsLen = (block.message.body as deneb.BeaconBlockBody).blobKzgCommitments.length; + const signedBlockHeader = signedBlockToSignedHeader(config, block); + + const engineReqIdentifiers: (deneb.BlobIdentifier & { + kzgCommitment: deneb.KZGCommitment; + versionedHash: Uint8Array; + })[] = []; + const networkReqIdentifiers: deneb.BlobIdentifier[] = []; + + let getBlobsUseful = false; for (let index = 0; index < blobKzgCommitmentsLen; index++) { - if (blobsCache.has(index) === false) blobIdentifiers.push({blockRoot, index}); + if (blobsCache.has(index) === false) { + const kzgCommitment = (block.message.body as deneb.BeaconBlockBody).blobKzgCommitments[index]; + const versionedHash = kzgCommitmentToVersionedHash(kzgCommitment); + + // check if the getblobs cache has the data if block not been queried before + if (engineGetBlobsCache?.has(toHexString(versionedHash)) === true && !blockTriedBefore) { + const catchedBlobAndProof = engineGetBlobsCache.get(toHexString(versionedHash)) ?? null; + if (catchedBlobAndProof === null) { + metrics?.blockInputFetchStats.dataPromiseBlobsFoundInGetBlobsCacheNull.inc(); + networkReqIdentifiers.push({blockRoot, index}); + } else { + metrics?.blockInputFetchStats.dataPromiseBlobsFoundInGetBlobsCacheNotNull.inc(); + // compute TODO: also add inclusion proof cache + const {blob, proof: kzgProof} = catchedBlobAndProof; + const kzgCommitmentInclusionProof = computeInclusionProof(fork, block.message.body, index); + const blobSidecar = {index, blob, kzgCommitment, kzgProof, signedBlockHeader, kzgCommitmentInclusionProof}; + blobsCache.set(blobSidecar.index, {blobSidecar, blobBytes: null}); + } + } else if (blockTriedBefore) { + // only retry it from network + networkReqIdentifiers.push({blockRoot, index}); + } else { + // see if we can pull from EL + metrics?.blockInputFetchStats.dataPromiseBlobsNotAvailableInGetBlobsCache.inc(); + engineReqIdentifiers.push({blockRoot, index, versionedHash, kzgCommitment}); + } + } else { + metrics?.blockInputFetchStats.dataPromiseBlobsAlreadyAvailable.inc(); + } } - let allBlobSidecars: deneb.BlobSidecar[]; - if (blobIdentifiers.length > 0) { - allBlobSidecars = await network.sendBlobSidecarsByRoot(peerId, blobIdentifiers); + const versionedHashes = engineReqIdentifiers.map((bi) => bi.versionedHash); + metrics?.blockInputFetchStats.dataPromiseBlobsEngineGetBlobsApiRequests.inc(versionedHashes.length); + + const blobAndProofs = await executionEngine.getBlobs(ForkName.deneb, versionedHashes).catch((_e) => { + metrics?.blockInputFetchStats.dataPromiseBlobsEngineApiGetBlobsErroredNull.inc(versionedHashes.length); + return versionedHashes.map((_vh) => null); + }); + + for (let j = 0; j < versionedHashes.length; j++) { + const blobAndProof = blobAndProofs[j] ?? null; + // save to cache for future reference + engineGetBlobsCache?.set(toHexString(versionedHashes[j]), blobAndProof); + if (blobAndProof !== null) { + metrics?.blockInputFetchStats.dataPromiseBlobsEngineGetBlobsApiNotNull.inc(); + + // if we already got it by now, save the compute + if (blobsCache.has(engineReqIdentifiers[j].index) === false) { + metrics?.blockInputFetchStats.dataPromiseBlobsEngineApiGetBlobsUseful.inc(); + getBlobsUseful = true; + const {blob, proof: kzgProof} = blobAndProof; + const {kzgCommitment, index} = engineReqIdentifiers[j]; + const kzgCommitmentInclusionProof = computeInclusionProof(fork, block.message.body, index); + const blobSidecar = {index, blob, kzgCommitment, kzgProof, signedBlockHeader, kzgCommitmentInclusionProof}; + // add them in cache so that its reflected in all the blockInputs that carry this + // for e.g. a blockInput that might be awaiting blobs promise fullfillment in + // verifyBlocksDataAvailability + blobsCache.set(blobSidecar.index, {blobSidecar, blobBytes: null}); + } else { + metrics?.blockInputFetchStats.dataPromiseBlobsDelayedGossipAvailable.inc(); + metrics?.blockInputFetchStats.dataPromiseBlobsDeplayedGossipAvailableSavedGetBlobsCompute.inc(); + } + } + // may be blobsidecar arrived in the timespan of making the request + else { + metrics?.blockInputFetchStats.dataPromiseBlobsEngineGetBlobsApiNull.inc(); + if (blobsCache.has(engineReqIdentifiers[j].index) === false) { + const {blockRoot, index} = engineReqIdentifiers[j]; + networkReqIdentifiers.push({blockRoot, index}); + } else { + metrics?.blockInputFetchStats.dataPromiseBlobsDelayedGossipAvailable.inc(); + } + } + } + + if (engineGetBlobsCache !== undefined) { + // prune out engineGetBlobsCache + let pruneLength = Math.max(0, engineGetBlobsCache?.size - MAX_ENGINE_GETBLOBS_CACHE); + for (const key of engineGetBlobsCache.keys()) { + if (pruneLength <= 0) break; + engineGetBlobsCache.delete(key); + pruneLength--; + metrics?.blockInputFetchStats.getBlobsCachePruned.inc(); + } + metrics?.blockInputFetchStats.getBlobsCacheSize.set(engineGetBlobsCache.size); + } + if (blockInputsRetryTrackerCache !== undefined) { + // prune out engineGetBlobsCache + let pruneLength = Math.max(0, blockInputsRetryTrackerCache?.size - MAX_UNAVAILABLE_RETRY_CACHE); + for (const key of blockInputsRetryTrackerCache.keys()) { + if (pruneLength <= 0) break; + blockInputsRetryTrackerCache.delete(key); + pruneLength--; + metrics?.blockInputFetchStats.dataPromiseBlockInputRetryTrackerCachePruned.inc(); + } + metrics?.blockInputFetchStats.dataPromiseBlockInputRetryTrackerCacheSize.set(blockInputsRetryTrackerCache.size); + } + + // if clients expect sorted identifiers + networkReqIdentifiers.sort((a, b) => a.index - b.index); + let networkResBlobSidecars: deneb.BlobSidecar[]; + metrics?.blockInputFetchStats.dataPromiseBlobsFinallyQueriedFromNetwork.inc(networkReqIdentifiers.length); + if (blockTriedBefore) { + metrics?.blockInputFetchStats.dataPromiseBlobsRetriedFromNetwork.inc(networkReqIdentifiers.length); + } + + if (networkReqIdentifiers.length > 0) { + networkResBlobSidecars = await network.sendBlobSidecarsByRoot(peerId, networkReqIdentifiers); + metrics?.blockInputFetchStats.dataPromiseBlobsFinallyAvailableFromNetwork.inc(networkResBlobSidecars.length); + if (blockTriedBefore) { + metrics?.blockInputFetchStats.dataPromiseBlobsRetriedAvailableFromNetwork.inc(networkResBlobSidecars.length); + } } else { - allBlobSidecars = []; + networkResBlobSidecars = []; } // add them in cache so that its reflected in all the blockInputs that carry this // for e.g. a blockInput that might be awaiting blobs promise fullfillment in // verifyBlocksDataAvailability - for (const blobSidecar of allBlobSidecars) { + for (const blobSidecar of networkResBlobSidecars) { blobsCache.set(blobSidecar.index, {blobSidecar, blobBytes: null}); } @@ -114,5 +254,14 @@ export async function unavailableBeaconBlobsByRoot( const blockData = {fork: cachedData.fork, ...allBlobs, blobsSource: BlobsSource.byRoot} as BlockInputDataBlobs; resolveAvailability(blockData); metrics?.syncUnknownBlock.resolveAvailabilitySource.inc({source: BlockInputAvailabilitySource.UNKNOWN_SYNC}); + + metrics?.blockInputFetchStats.totalDataAvailableBlockInputs.inc(); + if (getBlobsUseful) { + metrics?.blockInputFetchStats.totalDataPromiseBlockInputsAvailableUsingGetBlobs.inc(); + } + if (blockTriedBefore) { + metrics?.blockInputFetchStats.totalDataPromiseBlockInputsRetriedAvailableFromNetwork.inc(); + } + return getBlockInput.availableData(config, block, BlockSource.byRoot, blockBytes, blockData); } diff --git a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts index d1046db9651d..e8c19fb49628 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/beaconBlocksByRange.ts @@ -1,5 +1,5 @@ import {GENESIS_SLOT, MAX_REQUEST_BLOCKS} from "@lodestar/params"; -import {ResponseError, ResponseOutgoing, RespStatus} from "@lodestar/reqresp"; +import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; import {deneb, phase0} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; import {IBeaconChain} from "../../../chain/index.js"; diff --git a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts index e3655cd90c6f..9cac846fdb61 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRange.ts @@ -1,6 +1,6 @@ -import {GENESIS_SLOT, MAX_REQUEST_BLOCKS_DENEB, BLOBSIDECAR_FIXED_SIZE} from "@lodestar/params"; -import {ResponseError, ResponseOutgoing, RespStatus} from "@lodestar/reqresp"; -import {deneb, Slot} from "@lodestar/types"; +import {BLOBSIDECAR_FIXED_SIZE, GENESIS_SLOT, MAX_REQUEST_BLOCKS_DENEB} from "@lodestar/params"; +import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; +import {Slot, deneb} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; import {IBeaconChain} from "../../../chain/index.js"; import {IBeaconDb} from "../../../db/index.js"; diff --git a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRoot.ts b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRoot.ts index 144d470d7199..951a39cff564 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRoot.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/blobSidecarsByRoot.ts @@ -1,13 +1,14 @@ -import {ResponseError, ResponseOutgoing, RespStatus} from "@lodestar/reqresp"; import {BLOBSIDECAR_FIXED_SIZE} from "@lodestar/params"; -import {deneb, RootHex} from "@lodestar/types"; +import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; +import {RootHex} from "@lodestar/types"; import {fromHex, toRootHex} from "@lodestar/utils"; import {IBeaconChain} from "../../../chain/index.js"; import {IBeaconDb} from "../../../db/index.js"; import {BLOB_SIDECARS_IN_WRAPPER_INDEX} from "../../../db/repositories/blobSidecars.js"; +import {BlobSidecarsByRootRequest} from "../../../util/types.js"; export async function* onBlobSidecarsByRoot( - requestBody: deneb.BlobSidecarsByRootRequest, + requestBody: BlobSidecarsByRootRequest, chain: IBeaconChain, db: IBeaconDb ): AsyncIterable { diff --git a/packages/beacon-node/src/network/reqresp/handlers/index.ts b/packages/beacon-node/src/network/reqresp/handlers/index.ts index 50b8cc870844..83f6620dbbd4 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/index.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/index.ts @@ -1,12 +1,13 @@ -import {ssz} from "@lodestar/types"; import {ProtocolHandler} from "@lodestar/reqresp"; +import {ssz} from "@lodestar/types"; import {IBeaconChain} from "../../../chain/index.js"; import {IBeaconDb} from "../../../db/index.js"; +import {BlobSidecarsByRootRequestType} from "../../../util/types.js"; import {GetReqRespHandlerFn, ReqRespMethod} from "../types.js"; import {onBeaconBlocksByRange} from "./beaconBlocksByRange.js"; import {onBeaconBlocksByRoot} from "./beaconBlocksByRoot.js"; -import {onBlobSidecarsByRoot} from "./blobSidecarsByRoot.js"; import {onBlobSidecarsByRange} from "./blobSidecarsByRange.js"; +import {onBlobSidecarsByRoot} from "./blobSidecarsByRoot.js"; import {onLightClientBootstrap} from "./lightClientBootstrap.js"; import {onLightClientFinalityUpdate} from "./lightClientFinalityUpdate.js"; import {onLightClientOptimisticUpdate} from "./lightClientOptimisticUpdate.js"; @@ -37,7 +38,7 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh return onBeaconBlocksByRoot(body, chain, db); }, [ReqRespMethod.BlobSidecarsByRoot]: (req) => { - const body = ssz.deneb.BlobSidecarsByRootRequest.deserialize(req.data); + const body = BlobSidecarsByRootRequestType(chain.config).deserialize(req.data); return onBlobSidecarsByRoot(body, chain, db); }, [ReqRespMethod.BlobSidecarsByRange]: (req) => { diff --git a/packages/beacon-node/src/network/reqresp/handlers/lightClientBootstrap.ts b/packages/beacon-node/src/network/reqresp/handlers/lightClientBootstrap.ts index 3b50304eb50c..ae5b5abf1f80 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/lightClientBootstrap.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/lightClientBootstrap.ts @@ -1,14 +1,14 @@ import { - RespStatus, - ResponseError, LightClientServerError, LightClientServerErrorCode, + RespStatus, + ResponseError, ResponseOutgoing, } from "@lodestar/reqresp"; import {Root} from "@lodestar/types"; import {IBeaconChain} from "../../../chain/index.js"; -import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; import {assertLightClientServer} from "../../../node/utils/lightclient.js"; +import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; export async function* onLightClientBootstrap(requestBody: Root, chain: IBeaconChain): AsyncIterable { assertLightClientServer(chain.lightClientServer); diff --git a/packages/beacon-node/src/network/reqresp/handlers/lightClientFinalityUpdate.ts b/packages/beacon-node/src/network/reqresp/handlers/lightClientFinalityUpdate.ts index 4764c6f198f7..26eec4585d79 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/lightClientFinalityUpdate.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/lightClientFinalityUpdate.ts @@ -1,7 +1,7 @@ -import {ResponseOutgoing, RespStatus, ResponseError} from "@lodestar/reqresp"; +import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; import {IBeaconChain} from "../../../chain/index.js"; -import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; import {assertLightClientServer} from "../../../node/utils/lightclient.js"; +import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; export async function* onLightClientFinalityUpdate(chain: IBeaconChain): AsyncIterable { assertLightClientServer(chain.lightClientServer); diff --git a/packages/beacon-node/src/network/reqresp/handlers/lightClientOptimisticUpdate.ts b/packages/beacon-node/src/network/reqresp/handlers/lightClientOptimisticUpdate.ts index 4c030a8e4174..e8cdb73ee05a 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/lightClientOptimisticUpdate.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/lightClientOptimisticUpdate.ts @@ -1,7 +1,7 @@ -import {ResponseOutgoing, ResponseError, RespStatus} from "@lodestar/reqresp"; +import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; import {IBeaconChain} from "../../../chain/index.js"; -import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; import {assertLightClientServer} from "../../../node/utils/lightclient.js"; +import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; export async function* onLightClientOptimisticUpdate(chain: IBeaconChain): AsyncIterable { assertLightClientServer(chain.lightClientServer); diff --git a/packages/beacon-node/src/network/reqresp/handlers/lightClientUpdatesByRange.ts b/packages/beacon-node/src/network/reqresp/handlers/lightClientUpdatesByRange.ts index 89466eca6c21..53b701d448cd 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/lightClientUpdatesByRange.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/lightClientUpdatesByRange.ts @@ -1,15 +1,15 @@ -import {altair} from "@lodestar/types"; import {MAX_REQUEST_LIGHT_CLIENT_UPDATES} from "@lodestar/params"; import { - ResponseOutgoing, LightClientServerError, LightClientServerErrorCode, - ResponseError, RespStatus, + ResponseError, + ResponseOutgoing, } from "@lodestar/reqresp"; +import {altair} from "@lodestar/types"; import {IBeaconChain} from "../../../chain/index.js"; -import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; import {assertLightClientServer} from "../../../node/utils/lightclient.js"; +import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; export async function* onLightClientUpdatesByRange( requestBody: altair.LightClientUpdatesByRange, diff --git a/packages/beacon-node/src/network/reqresp/handlers/status.ts b/packages/beacon-node/src/network/reqresp/handlers/status.ts index e46c1a268b06..22c342177334 100644 --- a/packages/beacon-node/src/network/reqresp/handlers/status.ts +++ b/packages/beacon-node/src/network/reqresp/handlers/status.ts @@ -1,6 +1,6 @@ +import {ForkName} from "@lodestar/params"; import {ResponseOutgoing} from "@lodestar/reqresp"; import {ssz} from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; import {IBeaconChain} from "../../../chain/index.js"; export async function* onStatus(chain: IBeaconChain): AsyncIterable { diff --git a/packages/beacon-node/src/network/reqresp/protocols.ts b/packages/beacon-node/src/network/reqresp/protocols.ts index e63df4b1341b..b254db022101 100644 --- a/packages/beacon-node/src/network/reqresp/protocols.ts +++ b/packages/beacon-node/src/network/reqresp/protocols.ts @@ -1,7 +1,7 @@ +import {BeaconConfig, ForkDigestContext} from "@lodestar/config"; import {ContextBytesFactory, ContextBytesType, Encoding} from "@lodestar/reqresp"; -import {ForkDigestContext} from "@lodestar/config"; -import {ProtocolNoHandler, ReqRespMethod, Version, requestSszTypeByMethod, responseSszTypeByMethod} from "./types.js"; import {rateLimitQuotas} from "./rateLimit.js"; +import {ProtocolNoHandler, ReqRespMethod, Version, requestSszTypeByMethod, responseSszTypeByMethod} from "./types.js"; export const Goodbye = toProtocol({ method: ReqRespMethod.Goodbye, @@ -100,13 +100,13 @@ type ProtocolSummary = { }; function toProtocol(protocol: ProtocolSummary) { - return (config: ForkDigestContext): ProtocolNoHandler => ({ + return (config: BeaconConfig): ProtocolNoHandler => ({ method: protocol.method, version: protocol.version, encoding: Encoding.SSZ_SNAPPY, contextBytes: toContextBytes(protocol.contextBytesType, config), - inboundRateLimits: rateLimitQuotas[protocol.method], - requestSizes: requestSszTypeByMethod[protocol.method], + inboundRateLimits: rateLimitQuotas(config)[protocol.method], + requestSizes: requestSszTypeByMethod(config)[protocol.method], responseSizes: (fork) => responseSszTypeByMethod[protocol.method](fork, protocol.version), }); } diff --git a/packages/beacon-node/src/network/reqresp/rateLimit.ts b/packages/beacon-node/src/network/reqresp/rateLimit.ts index b6dacd6ba8e5..771d01f6c339 100644 --- a/packages/beacon-node/src/network/reqresp/rateLimit.ts +++ b/packages/beacon-node/src/network/reqresp/rateLimit.ts @@ -1,14 +1,10 @@ -import { - MAX_REQUEST_BLOCKS, - MAX_REQUEST_LIGHT_CLIENT_UPDATES, - MAX_BLOBS_PER_BLOCK, - MAX_REQUEST_BLOB_SIDECARS, -} from "@lodestar/params"; +import {ChainConfig} from "@lodestar/config"; +import {MAX_REQUEST_BLOCKS, MAX_REQUEST_LIGHT_CLIENT_UPDATES} from "@lodestar/params"; import {InboundRateLimitQuota} from "@lodestar/reqresp"; import {ReqRespMethod, RequestBodyByMethod} from "./types.js"; import {requestSszTypeByMethod} from "./types.js"; -export const rateLimitQuotas: Record = { +export const rateLimitQuotas: (config: ChainConfig) => Record = (config) => ({ [ReqRespMethod.Status]: { // Rationale: https://github.com/sigp/lighthouse/blob/bf533c8e42cc73c35730e285c21df8add0195369/beacon_node/lighthouse_network/src/rpc/mod.rs#L118-L130 byPeer: {quota: 5, quotaTimeMs: 15_000}, @@ -29,22 +25,22 @@ export const rateLimitQuotas: Record = { [ReqRespMethod.BeaconBlocksByRange]: { // Rationale: https://github.com/sigp/lighthouse/blob/bf533c8e42cc73c35730e285c21df8add0195369/beacon_node/lighthouse_network/src/rpc/mod.rs#L118-L130 byPeer: {quota: MAX_REQUEST_BLOCKS, quotaTimeMs: 10_000}, - getRequestCount: getRequestCountFn(ReqRespMethod.BeaconBlocksByRange, (req) => req.count), + getRequestCount: getRequestCountFn(config, ReqRespMethod.BeaconBlocksByRange, (req) => req.count), }, [ReqRespMethod.BeaconBlocksByRoot]: { // Rationale: https://github.com/sigp/lighthouse/blob/bf533c8e42cc73c35730e285c21df8add0195369/beacon_node/lighthouse_network/src/rpc/mod.rs#L118-L130 byPeer: {quota: 128, quotaTimeMs: 10_000}, - getRequestCount: getRequestCountFn(ReqRespMethod.BeaconBlocksByRoot, (req) => req.length), + getRequestCount: getRequestCountFn(config, ReqRespMethod.BeaconBlocksByRoot, (req) => req.length), }, [ReqRespMethod.BlobSidecarsByRange]: { // Rationale: MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK - byPeer: {quota: MAX_REQUEST_BLOB_SIDECARS, quotaTimeMs: 10_000}, - getRequestCount: getRequestCountFn(ReqRespMethod.BlobSidecarsByRange, (req) => req.count), + byPeer: {quota: config.MAX_REQUEST_BLOB_SIDECARS, quotaTimeMs: 10_000}, + getRequestCount: getRequestCountFn(config, ReqRespMethod.BlobSidecarsByRange, (req) => req.count), }, [ReqRespMethod.BlobSidecarsByRoot]: { // Rationale: quota of BeaconBlocksByRoot * MAX_BLOBS_PER_BLOCK - byPeer: {quota: 128 * MAX_BLOBS_PER_BLOCK, quotaTimeMs: 10_000}, - getRequestCount: getRequestCountFn(ReqRespMethod.BlobSidecarsByRoot, (req) => req.length), + byPeer: {quota: config.MAX_REQUEST_BLOB_SIDECARS, quotaTimeMs: 10_000}, + getRequestCount: getRequestCountFn(config, ReqRespMethod.BlobSidecarsByRoot, (req) => req.length), }, [ReqRespMethod.LightClientBootstrap]: { // As similar in the nature of `Status` protocol so we use the same rate limits. @@ -53,7 +49,7 @@ export const rateLimitQuotas: Record = { [ReqRespMethod.LightClientUpdatesByRange]: { // Same rationale as for BeaconBlocksByRange byPeer: {quota: MAX_REQUEST_LIGHT_CLIENT_UPDATES, quotaTimeMs: 10_000}, - getRequestCount: getRequestCountFn(ReqRespMethod.LightClientUpdatesByRange, (req) => req.count), + getRequestCount: getRequestCountFn(config, ReqRespMethod.LightClientUpdatesByRange, (req) => req.count), }, [ReqRespMethod.LightClientFinalityUpdate]: { // Finality updates should not be requested more than once per epoch. @@ -65,14 +61,15 @@ export const rateLimitQuotas: Record = { // Allow 2 per slot and a very safe bound until there's more testing of real usage. byPeer: {quota: 2, quotaTimeMs: 12_000}, }, -}; +}); // Helper to produce a getRequestCount function function getRequestCountFn( + config: ChainConfig, method: T, fn: (req: RequestBodyByMethod[T]) => number ): (reqData: Uint8Array) => number { - const type = requestSszTypeByMethod[method]; + const type = requestSszTypeByMethod(config)[method]; return (reqData: Uint8Array) => { try { return (type && fn(type.deserialize(reqData))) ?? 1; diff --git a/packages/beacon-node/src/network/reqresp/types.ts b/packages/beacon-node/src/network/reqresp/types.ts index 96ae1558ec07..b7c18ebdfeb5 100644 --- a/packages/beacon-node/src/network/reqresp/types.ts +++ b/packages/beacon-node/src/network/reqresp/types.ts @@ -1,4 +1,5 @@ import {Type} from "@chainsafe/ssz"; +import {ChainConfig} from "@lodestar/config"; import {ForkLightClient, ForkName, isForkLightClient} from "@lodestar/params"; import {Protocol, ProtocolHandler, ReqRespRequest} from "@lodestar/reqresp"; import { @@ -15,6 +16,7 @@ import { ssz, sszTypesFor, } from "@lodestar/types"; +import {BlobSidecarsByRootRequest, BlobSidecarsByRootRequestType} from "../../util/types.js"; export type ProtocolNoHandler = Omit; @@ -44,7 +46,7 @@ export type RequestBodyByMethod = { [ReqRespMethod.BeaconBlocksByRange]: phase0.BeaconBlocksByRangeRequest; [ReqRespMethod.BeaconBlocksByRoot]: phase0.BeaconBlocksByRootRequest; [ReqRespMethod.BlobSidecarsByRange]: deneb.BlobSidecarsByRangeRequest; - [ReqRespMethod.BlobSidecarsByRoot]: deneb.BlobSidecarsByRootRequest; + [ReqRespMethod.BlobSidecarsByRoot]: BlobSidecarsByRootRequest; [ReqRespMethod.LightClientBootstrap]: Root; [ReqRespMethod.LightClientUpdatesByRange]: altair.LightClientUpdatesByRange; [ReqRespMethod.LightClientFinalityUpdate]: null; @@ -68,9 +70,9 @@ type ResponseBodyByMethod = { }; /** Request SSZ type for each method and ForkName */ -export const requestSszTypeByMethod: { +export const requestSszTypeByMethod: (config: ChainConfig) => { [K in ReqRespMethod]: RequestBodyByMethod[K] extends null ? null : Type; -} = { +} = (config) => ({ [ReqRespMethod.Status]: ssz.phase0.Status, [ReqRespMethod.Goodbye]: ssz.phase0.Goodbye, [ReqRespMethod.Ping]: ssz.phase0.Ping, @@ -78,12 +80,12 @@ export const requestSszTypeByMethod: { [ReqRespMethod.BeaconBlocksByRange]: ssz.phase0.BeaconBlocksByRangeRequest, [ReqRespMethod.BeaconBlocksByRoot]: ssz.phase0.BeaconBlocksByRootRequest, [ReqRespMethod.BlobSidecarsByRange]: ssz.deneb.BlobSidecarsByRangeRequest, - [ReqRespMethod.BlobSidecarsByRoot]: ssz.deneb.BlobSidecarsByRootRequest, + [ReqRespMethod.BlobSidecarsByRoot]: BlobSidecarsByRootRequestType(config), [ReqRespMethod.LightClientBootstrap]: ssz.Root, [ReqRespMethod.LightClientUpdatesByRange]: ssz.altair.LightClientUpdatesByRange, [ReqRespMethod.LightClientFinalityUpdate]: null, [ReqRespMethod.LightClientOptimisticUpdate]: null, -}; +}); export type ResponseTypeGetter = (fork: ForkName, version: number) => Type; diff --git a/packages/beacon-node/src/network/reqresp/utils/collect.ts b/packages/beacon-node/src/network/reqresp/utils/collect.ts index 9818b1921f8e..f79ea2abba07 100644 --- a/packages/beacon-node/src/network/reqresp/utils/collect.ts +++ b/packages/beacon-node/src/network/reqresp/utils/collect.ts @@ -1,5 +1,5 @@ import {Type} from "@chainsafe/ssz"; -import {ResponseIncoming, RequestErrorCode, RequestError} from "@lodestar/reqresp"; +import {RequestError, RequestErrorCode, ResponseIncoming} from "@lodestar/reqresp"; import {WithBytes} from "@lodestar/types"; import {ResponseTypeGetter} from "../types.js"; diff --git a/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts b/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts index 2709cb3f64a9..2e2bcf772d76 100644 --- a/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +++ b/packages/beacon-node/src/network/reqresp/utils/collectSequentialBlocksInRange.ts @@ -1,6 +1,6 @@ import {ResponseIncoming} from "@lodestar/reqresp"; +import {SignedBeaconBlock, WithBytes, phase0} from "@lodestar/types"; import {LodestarError} from "@lodestar/utils"; -import {phase0, SignedBeaconBlock, WithBytes} from "@lodestar/types"; import {ReqRespMethod, responseSszTypeByMethod} from "../types.js"; import {sszDeserializeResponse} from "./collect.js"; diff --git a/packages/beacon-node/src/network/subnets/attnetsService.ts b/packages/beacon-node/src/network/subnets/attnetsService.ts index 5044bac059cd..ed2f94bd56d8 100644 --- a/packages/beacon-node/src/network/subnets/attnetsService.ts +++ b/packages/beacon-node/src/network/subnets/attnetsService.ts @@ -1,3 +1,4 @@ +import {BeaconConfig} from "@lodestar/config"; import { ATTESTATION_SUBNET_COUNT, EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION, @@ -6,16 +7,15 @@ import { } from "@lodestar/params"; import {Epoch, Slot, ssz} from "@lodestar/types"; import {Logger, MapDef} from "@lodestar/utils"; -import {BeaconConfig} from "@lodestar/config"; import {ClockEvent, IClock} from "../../util/clock.js"; -import {GossipType} from "../gossip/index.js"; -import {MetadataController} from "../metadata.js"; -import {SubnetMap, RequestedSubnet} from "../peers/utils/index.js"; -import {getActiveForks} from "../forks.js"; import {NetworkCoreMetrics} from "../core/metrics.js"; -import {stringifyGossipTopic} from "../gossip/topic.js"; +import {getActiveForks} from "../forks.js"; +import {GossipType} from "../gossip/index.js"; import {GOSSIP_D_LOW} from "../gossip/scoringParameters.js"; -import {IAttnetsService, CommitteeSubscription, SubnetsServiceOpts, GossipSubscriber, NodeId} from "./interface.js"; +import {stringifyGossipTopic} from "../gossip/topic.js"; +import {MetadataController} from "../metadata.js"; +import {RequestedSubnet, SubnetMap} from "../peers/utils/index.js"; +import {CommitteeSubscription, GossipSubscriber, IAttnetsService, NodeId, SubnetsServiceOpts} from "./interface.js"; import {computeSubscribedSubnet} from "./util.js"; const gossipType = GossipType.beacon_attestation; diff --git a/packages/beacon-node/src/network/subnets/interface.ts b/packages/beacon-node/src/network/subnets/interface.ts index 1d036bf9831d..e3b1e2513818 100644 --- a/packages/beacon-node/src/network/subnets/interface.ts +++ b/packages/beacon-node/src/network/subnets/interface.ts @@ -1,7 +1,7 @@ import {ForkName} from "@lodestar/params"; import {Bytes32, Slot, ValidatorIndex} from "@lodestar/types"; -import {RequestedSubnet} from "../peers/utils/index.js"; import {GossipTopic} from "../gossip/interface.js"; +import {RequestedSubnet} from "../peers/utils/index.js"; /** Generic CommitteeSubscription for both beacon attnets subs and syncnets subs */ export type CommitteeSubscription = { diff --git a/packages/beacon-node/src/network/subnets/syncnetsService.ts b/packages/beacon-node/src/network/subnets/syncnetsService.ts index c61b1060899a..8dee6243b39f 100644 --- a/packages/beacon-node/src/network/subnets/syncnetsService.ts +++ b/packages/beacon-node/src/network/subnets/syncnetsService.ts @@ -1,14 +1,14 @@ -import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {BeaconConfig} from "@lodestar/config"; import {ForkName, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; +import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {Epoch, ssz} from "@lodestar/types"; import {Logger} from "@lodestar/utils"; import {ClockEvent, IClock} from "../../util/clock.js"; +import {NetworkCoreMetrics} from "../core/metrics.js"; import {getActiveForks} from "../forks.js"; import {GossipType} from "../gossip/index.js"; import {MetadataController} from "../metadata.js"; import {RequestedSubnet, SubnetMap} from "../peers/utils/index.js"; -import {NetworkCoreMetrics} from "../core/metrics.js"; import {CommitteeSubscription, GossipSubscriber, SubnetsService, SubnetsServiceOpts} from "./interface.js"; const gossipType = GossipType.sync_committee; diff --git a/packages/beacon-node/src/node/nodejs.ts b/packages/beacon-node/src/node/nodejs.ts index 701ab0fde070..ec3a0ef66a5a 100644 --- a/packages/beacon-node/src/node/nodejs.ts +++ b/packages/beacon-node/src/node/nodejs.ts @@ -2,28 +2,28 @@ import {setMaxListeners} from "node:events"; import {Registry} from "prom-client"; import {PeerId} from "@libp2p/interface"; +import {BeaconApiMethods} from "@lodestar/api/beacon/server"; import {BeaconConfig} from "@lodestar/config"; -import {phase0} from "@lodestar/types"; -import {sleep} from "@lodestar/utils"; import type {LoggerNode} from "@lodestar/logger/node"; -import {BeaconApiMethods} from "@lodestar/api/beacon/server"; import {BeaconStateAllForks} from "@lodestar/state-transition"; +import {phase0} from "@lodestar/types"; +import {sleep} from "@lodestar/utils"; import {ProcessShutdownCallback} from "@lodestar/validator"; +import {BeaconRestApiServer, getApi} from "../api/index.js"; +import {HistoricalStateRegen} from "../chain/historicalState/index.js"; +import {BeaconChain, IBeaconChain, initBeaconMetrics} from "../chain/index.js"; import {IBeaconDb} from "../db/index.js"; +import {initializeEth1ForBlockProduction} from "../eth1/index.js"; +import {initializeExecutionBuilder, initializeExecutionEngine} from "../execution/index.js"; +import {HttpMetricsServer, Metrics, createMetrics, getHttpMetricsServer} from "../metrics/index.js"; +import {MonitoringService} from "../monitoring/index.js"; import {Network, getReqRespHandlers} from "../network/index.js"; -import {BeaconSync, IBeaconSync} from "../sync/index.js"; import {BackfillSync} from "../sync/backfill/index.js"; -import {BeaconChain, IBeaconChain, initBeaconMetrics} from "../chain/index.js"; -import {createMetrics, Metrics, HttpMetricsServer, getHttpMetricsServer} from "../metrics/index.js"; -import {MonitoringService} from "../monitoring/index.js"; -import {getApi, BeaconRestApiServer} from "../api/index.js"; -import {initializeExecutionEngine, initializeExecutionBuilder} from "../execution/index.js"; -import {initializeEth1ForBlockProduction} from "../eth1/index.js"; -import {initCKZG, loadEthereumTrustedSetup, TrustedFileMode} from "../util/kzg.js"; -import {HistoricalStateRegen} from "../chain/historicalState/index.js"; -import {IBeaconNodeOptions} from "./options.js"; +import {BeaconSync, IBeaconSync} from "../sync/index.js"; +import {TrustedFileMode, initCKZG, loadEthereumTrustedSetup} from "../util/kzg.js"; import {runNodeNotifier} from "./notifier.js"; +import {IBeaconNodeOptions} from "./options.js"; export * from "./options.js"; diff --git a/packages/beacon-node/src/node/notifier.ts b/packages/beacon-node/src/node/notifier.ts index 20a359a45c49..cd316516259b 100644 --- a/packages/beacon-node/src/node/notifier.ts +++ b/packages/beacon-node/src/node/notifier.ts @@ -1,12 +1,12 @@ import {BeaconConfig} from "@lodestar/config"; -import {Epoch} from "@lodestar/types"; -import {CachedBeaconStateAllForks, computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {ProtoBlock, ExecutionStatus} from "@lodestar/fork-choice"; -import {ErrorAborted, Logger, sleep, prettyBytes, prettyBytesShort} from "@lodestar/utils"; +import {ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice"; import {EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {CachedBeaconStateAllForks, computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {computeEpochAtSlot, isExecutionCachedStateType, isMergeTransitionComplete} from "@lodestar/state-transition"; -import {ExecutionEngineState} from "../execution/index.js"; +import {Epoch} from "@lodestar/types"; +import {ErrorAborted, Logger, prettyBytes, prettyBytesShort, sleep} from "@lodestar/utils"; import {IBeaconChain} from "../chain/index.js"; +import {ExecutionEngineState} from "../execution/index.js"; import {INetwork} from "../network/index.js"; import {IBeaconSync, SyncState} from "../sync/index.js"; import {prettyTimeDiffSec} from "../util/time.js"; @@ -54,12 +54,12 @@ export async function runNodeNotifier(modules: NodeNotifierModules): Promise= config.BELLATRIX_FORK_EPOCH && - computeStartSlotAtEpoch(clockEpoch) === clockSlot && - chain.executionEngine.state === ExecutionEngineState.OFFLINE - ) { - logger.warn("Execution client is offline"); + if (clockEpoch >= config.BELLATRIX_FORK_EPOCH && computeStartSlotAtEpoch(clockEpoch) === clockSlot) { + if (chain.executionEngine.state === ExecutionEngineState.OFFLINE) { + logger.warn("Execution client is offline"); + } else if (chain.executionEngine.state === ExecutionEngineState.AUTH_FAILED) { + logger.error("Execution client authentication failed. Verify if the JWT secret matches on both clients"); + } } const headInfo = chain.forkChoice.getHead(); diff --git a/packages/beacon-node/src/node/options.ts b/packages/beacon-node/src/node/options.ts index e587e58ec127..1a440bfd4981 100644 --- a/packages/beacon-node/src/node/options.ts +++ b/packages/beacon-node/src/node/options.ts @@ -1,19 +1,19 @@ -import {defaultApiOptions, ApiOptions} from "../api/options.js"; -import {defaultChainOptions, IChainOptions, StateArchiveMode, DEFAULT_STATE_ARCHIVE_MODE} from "../chain/options.js"; -import {defaultDbOptions, DatabaseOptions} from "../db/options.js"; -import {defaultEth1Options, Eth1Options} from "../eth1/options.js"; -import {defaultMetricsOptions, MetricsOptions} from "../metrics/options.js"; -import {defaultMonitoringOptions, MonitoringOptions} from "../monitoring/options.js"; -import {defaultNetworkOptions, NetworkOptions} from "../network/options.js"; -import {defaultSyncOptions, SyncOptions} from "../sync/options.js"; +import {ApiOptions, defaultApiOptions} from "../api/options.js"; +import {DEFAULT_STATE_ARCHIVE_MODE, IChainOptions, StateArchiveMode, defaultChainOptions} from "../chain/options.js"; +import {DatabaseOptions, defaultDbOptions} from "../db/options.js"; +import {Eth1Options, defaultEth1Options} from "../eth1/options.js"; import { - defaultExecutionEngineOpts, - defaultExecutionEngineHttpOpts, - ExecutionEngineOpts, ExecutionBuilderOpts, - defaultExecutionBuilderOpts, + ExecutionEngineOpts, defaultExecutionBuilderHttpOpts, + defaultExecutionBuilderOpts, + defaultExecutionEngineHttpOpts, + defaultExecutionEngineOpts, } from "../execution/index.js"; +import {MetricsOptions, defaultMetricsOptions} from "../metrics/options.js"; +import {MonitoringOptions, defaultMonitoringOptions} from "../monitoring/options.js"; +import {NetworkOptions, defaultNetworkOptions} from "../network/options.js"; +import {SyncOptions, defaultSyncOptions} from "../sync/options.js"; // Re-export so the CLI doesn't need to depend on lodestar-api export {allNamespaces} from "../api/rest/index.js"; diff --git a/packages/beacon-node/src/node/utils/interop/deposits.ts b/packages/beacon-node/src/node/utils/interop/deposits.ts index 6cce7e883b84..21f78a6ec2be 100644 --- a/packages/beacon-node/src/node/utils/interop/deposits.ts +++ b/packages/beacon-node/src/node/utils/interop/deposits.ts @@ -1,14 +1,14 @@ import {digest} from "@chainsafe/as-sha256"; -import {toGindex, Tree} from "@chainsafe/persistent-merkle-tree"; -import {phase0, ssz} from "@lodestar/types"; +import {Tree, toGindex} from "@chainsafe/persistent-merkle-tree"; import {ChainConfig} from "@lodestar/config"; -import {computeDomain, computeSigningRoot, interopSecretKeys, ZERO_HASH} from "@lodestar/state-transition"; import { BLS_WITHDRAWAL_PREFIX, - ETH1_ADDRESS_WITHDRAWAL_PREFIX, DOMAIN_DEPOSIT, + ETH1_ADDRESS_WITHDRAWAL_PREFIX, MAX_EFFECTIVE_BALANCE, } from "@lodestar/params"; +import {ZERO_HASH, computeDomain, computeSigningRoot, interopSecretKeys} from "@lodestar/state-transition"; +import {phase0, ssz} from "@lodestar/types"; import {DepositTree} from "../../../db/repositories/depositDataRoot.js"; /** diff --git a/packages/beacon-node/src/node/utils/interop/state.ts b/packages/beacon-node/src/node/utils/interop/state.ts index fe26afef2013..ef88fb956e05 100644 --- a/packages/beacon-node/src/node/utils/interop/state.ts +++ b/packages/beacon-node/src/node/utils/interop/state.ts @@ -1,8 +1,8 @@ -import {Bytes32, phase0, ssz, sszTypesFor, TimeSeconds} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {ForkName, GENESIS_SLOT} from "@lodestar/params"; import {BeaconStateAllForks, initializeBeaconStateFromEth1} from "@lodestar/state-transition"; import {createEmptyEpochCacheImmutableData} from "@lodestar/state-transition"; -import {ForkName, GENESIS_SLOT} from "@lodestar/params"; +import {Bytes32, TimeSeconds, phase0, ssz, sszTypesFor} from "@lodestar/types"; import {DepositTree} from "../../../db/repositories/depositDataRoot.js"; diff --git a/packages/beacon-node/src/node/utils/state.ts b/packages/beacon-node/src/node/utils/state.ts index 05da7042eef4..ac0ff8101fb6 100644 --- a/packages/beacon-node/src/node/utils/state.ts +++ b/packages/beacon-node/src/node/utils/state.ts @@ -3,7 +3,7 @@ import {BeaconStateAllForks} from "@lodestar/state-transition"; import {phase0, ssz} from "@lodestar/types"; import {IBeaconDb} from "../../db/index.js"; import {interopDeposits} from "./interop/deposits.js"; -import {getInteropState, InteropStateOpts} from "./interop/state.js"; +import {InteropStateOpts, getInteropState} from "./interop/state.js"; /** * Builds state for `dev` command, for sim testing and some other tests diff --git a/packages/beacon-node/src/sync/backfill/backfill.ts b/packages/beacon-node/src/sync/backfill/backfill.ts index 9612cf23b615..4fedb9d1fd5b 100644 --- a/packages/beacon-node/src/sync/backfill/backfill.ts +++ b/packages/beacon-node/src/sync/backfill/backfill.ts @@ -1,22 +1,22 @@ import {EventEmitter} from "node:events"; -import {StrictEventEmitter} from "strict-event-emitter-types"; -import {BeaconStateAllForks, blockToHeader, computeAnchorCheckpoint} from "@lodestar/state-transition"; import {BeaconConfig, ChainForkConfig} from "@lodestar/config"; -import {phase0, Root, SignedBeaconBlock, Slot, ssz} from "@lodestar/types"; +import {BeaconStateAllForks, blockToHeader, computeAnchorCheckpoint} from "@lodestar/state-transition"; +import {Root, SignedBeaconBlock, Slot, phase0, ssz} from "@lodestar/types"; import {ErrorAborted, Logger, sleep, toRootHex} from "@lodestar/utils"; +import {StrictEventEmitter} from "strict-event-emitter-types"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {IBeaconChain} from "../../chain/index.js"; import {GENESIS_SLOT, ZERO_HASH} from "../../constants/index.js"; import {IBeaconDb} from "../../db/index.js"; +import {Metrics} from "../../metrics/metrics.js"; import {INetwork, NetworkEvent, NetworkEventData, PeerAction} from "../../network/index.js"; +import {byteArrayEquals} from "../../util/bytes.js"; import {ItTrigger} from "../../util/itTrigger.js"; import {PeerIdStr} from "../../util/peerId.js"; import {shuffleOne} from "../../util/shuffle.js"; -import {Metrics} from "../../metrics/metrics.js"; -import {byteArrayEquals} from "../../util/bytes.js"; -import {verifyBlockProposerSignature, verifyBlockSequence, BackfillBlockHeader, BackfillBlock} from "./verify.js"; import {BackfillSyncError, BackfillSyncErrorCode} from "./errors.js"; +import {BackfillBlock, BackfillBlockHeader, verifyBlockProposerSignature, verifyBlockSequence} from "./verify.js"; /** * Timeout in ms to take a break from reading a backfillBatchSize from db, as just yielding * to sync loop gives hardly any. diff --git a/packages/beacon-node/src/sync/backfill/errors.ts b/packages/beacon-node/src/sync/backfill/errors.ts index e62c90407ed5..530507f99f36 100644 --- a/packages/beacon-node/src/sync/backfill/errors.ts +++ b/packages/beacon-node/src/sync/backfill/errors.ts @@ -1,6 +1,6 @@ import {PeerId} from "@libp2p/interface"; -import {LodestarError} from "@lodestar/utils"; import {Root} from "@lodestar/types"; +import {LodestarError} from "@lodestar/utils"; export enum BackfillSyncErrorCode { /** fetched block doesn't connect to anchor block */ diff --git a/packages/beacon-node/src/sync/backfill/verify.ts b/packages/beacon-node/src/sync/backfill/verify.ts index 715cc6621253..9150e17b3e8c 100644 --- a/packages/beacon-node/src/sync/backfill/verify.ts +++ b/packages/beacon-node/src/sync/backfill/verify.ts @@ -1,7 +1,7 @@ -import {CachedBeaconStateAllForks, ISignatureSet, getBlockProposerSignatureSet} from "@lodestar/state-transition"; import {BeaconConfig} from "@lodestar/config"; -import {Root, ssz, Slot, SignedBeaconBlock, WithBytes} from "@lodestar/types"; import {GENESIS_SLOT} from "@lodestar/params"; +import {CachedBeaconStateAllForks, ISignatureSet, getBlockProposerSignatureSet} from "@lodestar/state-transition"; +import {Root, SignedBeaconBlock, Slot, WithBytes, ssz} from "@lodestar/types"; import {IBlsVerifier} from "../../chain/bls/index.js"; import {BackfillSyncError, BackfillSyncErrorCode} from "./errors.js"; diff --git a/packages/beacon-node/src/sync/interface.ts b/packages/beacon-node/src/sync/interface.ts index c1e83cb476fb..88d7138656f3 100644 --- a/packages/beacon-node/src/sync/interface.ts +++ b/packages/beacon-node/src/sync/interface.ts @@ -1,12 +1,12 @@ -import {Logger} from "@lodestar/utils"; -import {RootHex, Slot, phase0} from "@lodestar/types"; -import {BeaconConfig} from "@lodestar/config"; import {routes} from "@lodestar/api"; +import {BeaconConfig} from "@lodestar/config"; +import {RootHex, Slot, phase0} from "@lodestar/types"; +import {Logger} from "@lodestar/utils"; import {BlockInput, BlockInputType, NullBlockInput} from "../chain/blocks/types.js"; -import {INetwork} from "../network/index.js"; import {IBeaconChain} from "../chain/index.js"; -import {Metrics} from "../metrics/index.js"; import {IBeaconDb} from "../db/index.js"; +import {Metrics} from "../metrics/index.js"; +import {INetwork} from "../network/index.js"; import {SyncChainDebugState} from "./range/chain.js"; export type {SyncChainDebugState}; diff --git a/packages/beacon-node/src/sync/range/batch.ts b/packages/beacon-node/src/sync/range/batch.ts index e3e81bc57143..a78febbc5c7f 100644 --- a/packages/beacon-node/src/sync/range/batch.ts +++ b/packages/beacon-node/src/sync/range/batch.ts @@ -1,10 +1,10 @@ -import {Epoch, phase0, RootHex} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {Epoch, RootHex, phase0} from "@lodestar/types"; import {LodestarError} from "@lodestar/utils"; -import {MAX_BATCH_DOWNLOAD_ATTEMPTS, MAX_BATCH_PROCESSING_ATTEMPTS} from "../constants.js"; -import {PeerIdStr} from "../../util/peerId.js"; import {BlockInput} from "../../chain/blocks/types.js"; import {BlockError, BlockErrorCode} from "../../chain/errors/index.js"; +import {PeerIdStr} from "../../util/peerId.js"; +import {MAX_BATCH_DOWNLOAD_ATTEMPTS, MAX_BATCH_PROCESSING_ATTEMPTS} from "../constants.js"; import {getBatchSlotRange, hashBlocks} from "./utils/index.js"; /** diff --git a/packages/beacon-node/src/sync/range/chain.ts b/packages/beacon-node/src/sync/range/chain.ts index 0a2fc1a3f7c3..2a8d76d99785 100644 --- a/packages/beacon-node/src/sync/range/chain.ts +++ b/packages/beacon-node/src/sync/range/chain.ts @@ -1,24 +1,24 @@ +import {ChainForkConfig} from "@lodestar/config"; import {Epoch, Root, Slot, phase0} from "@lodestar/types"; import {ErrorAborted, Logger, toRootHex} from "@lodestar/utils"; -import {ChainForkConfig} from "@lodestar/config"; import {BlockInput, BlockInputType} from "../../chain/blocks/types.js"; import {PeerAction} from "../../network/index.js"; import {ItTrigger} from "../../util/itTrigger.js"; import {PeerIdStr} from "../../util/peerId.js"; import {wrapError} from "../../util/wrapError.js"; -import {RangeSyncType} from "../utils/remoteSyncType.js"; import {BATCH_BUFFER_SIZE, EPOCHS_PER_BATCH} from "../constants.js"; +import {RangeSyncType} from "../utils/remoteSyncType.js"; import {Batch, BatchError, BatchErrorCode, BatchMetadata, BatchStatus} from "./batch.js"; import { - validateBatchesStatus, - getNextBatchToProcess, - toBeDownloadedStartEpoch, - toArr, ChainPeersBalancer, - computeMostCommonTarget, batchStartEpochIsAfterSlot, - isSyncChainDone, + computeMostCommonTarget, getBatchSlotRange, + getNextBatchToProcess, + isSyncChainDone, + toArr, + toBeDownloadedStartEpoch, + validateBatchesStatus, } from "./utils/index.js"; export type SyncChainModules = { diff --git a/packages/beacon-node/src/sync/range/range.ts b/packages/beacon-node/src/sync/range/range.ts index 51e3a5d0f182..8284abd09955 100644 --- a/packages/beacon-node/src/sync/range/range.ts +++ b/packages/beacon-node/src/sync/range/range.ts @@ -1,18 +1,18 @@ import {EventEmitter} from "node:events"; -import {StrictEventEmitter} from "strict-event-emitter-types"; -import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {BeaconConfig} from "@lodestar/config"; +import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {Epoch, phase0} from "@lodestar/types"; import {Logger, toRootHex} from "@lodestar/utils"; +import {StrictEventEmitter} from "strict-event-emitter-types"; +import {AttestationImportOpt, ImportBlockOpts} from "../../chain/blocks/index.js"; import {IBeaconChain} from "../../chain/index.js"; -import {INetwork} from "../../network/index.js"; import {Metrics} from "../../metrics/index.js"; -import {RangeSyncType, rangeSyncTypes, getRangeSyncTarget} from "../utils/remoteSyncType.js"; -import {PeerIdStr} from "../../util/peerId.js"; -import {ImportBlockOpts, AttestationImportOpt} from "../../chain/blocks/index.js"; +import {INetwork} from "../../network/index.js"; import {beaconBlocksMaybeBlobsByRange} from "../../network/reqresp/beaconBlocksMaybeBlobsByRange.js"; +import {PeerIdStr} from "../../util/peerId.js"; +import {RangeSyncType, getRangeSyncTarget, rangeSyncTypes} from "../utils/remoteSyncType.js"; +import {ChainTarget, SyncChain, SyncChainDebugState, SyncChainFns} from "./chain.js"; import {updateChains} from "./utils/index.js"; -import {ChainTarget, SyncChainFns, SyncChain, SyncChainDebugState} from "./chain.js"; export enum RangeSyncEvent { completedChain = "RangeSync-completedChain", diff --git a/packages/beacon-node/src/sync/range/utils/hashBlocks.ts b/packages/beacon-node/src/sync/range/utils/hashBlocks.ts index 986d023d9ca1..9d983fc7278e 100644 --- a/packages/beacon-node/src/sync/range/utils/hashBlocks.ts +++ b/packages/beacon-node/src/sync/range/utils/hashBlocks.ts @@ -1,5 +1,5 @@ -import {RootHex} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {RootHex} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {BlockInput} from "../../../chain/blocks/types.js"; diff --git a/packages/beacon-node/src/sync/sync.ts b/packages/beacon-node/src/sync/sync.ts index 94eea73e1ef8..1a4121f4b9f1 100644 --- a/packages/beacon-node/src/sync/sync.ts +++ b/packages/beacon-node/src/sync/sync.ts @@ -1,20 +1,20 @@ -import {Logger} from "@lodestar/utils"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {Slot} from "@lodestar/types"; -import {INetwork, NetworkEvent, NetworkEventData} from "../network/index.js"; -import {isOptimisticBlock} from "../util/forkChoice.js"; -import {Metrics} from "../metrics/index.js"; +import {Logger} from "@lodestar/utils"; import {IBeaconChain} from "../chain/index.js"; -import {ClockEvent} from "../util/clock.js"; import {GENESIS_SLOT} from "../constants/constants.js"; import {ExecutionEngineState} from "../execution/index.js"; -import {IBeaconSync, SyncModules, SyncingStatus} from "./interface.js"; -import {RangeSync, RangeSyncStatus, RangeSyncEvent} from "./range/range.js"; -import {getPeerSyncType, PeerSyncType, peerSyncTypes} from "./utils/remoteSyncType.js"; +import {Metrics} from "../metrics/index.js"; +import {INetwork, NetworkEvent, NetworkEventData} from "../network/index.js"; +import {ClockEvent} from "../util/clock.js"; +import {isOptimisticBlock} from "../util/forkChoice.js"; import {MIN_EPOCH_TO_START_GOSSIP} from "./constants.js"; -import {SyncState, SyncChainDebugState, syncStateMetric} from "./interface.js"; +import {IBeaconSync, SyncModules, SyncingStatus} from "./interface.js"; +import {SyncChainDebugState, SyncState, syncStateMetric} from "./interface.js"; import {SyncOptions} from "./options.js"; +import {RangeSync, RangeSyncEvent, RangeSyncStatus} from "./range/range.js"; import {UnknownBlockSync} from "./unknownBlock.js"; +import {PeerSyncType, getPeerSyncType, peerSyncTypes} from "./utils/remoteSyncType.js"; export class BeaconSync implements IBeaconSync { private readonly logger: Logger; diff --git a/packages/beacon-node/src/sync/unknownBlock.ts b/packages/beacon-node/src/sync/unknownBlock.ts index 003b035a898d..f1fa44750f4b 100644 --- a/packages/beacon-node/src/sync/unknownBlock.ts +++ b/packages/beacon-node/src/sync/unknownBlock.ts @@ -1,24 +1,25 @@ import {ChainForkConfig} from "@lodestar/config"; -import {Logger, fromHex, pruneSetToMax, toRootHex} from "@lodestar/utils"; -import {Root, RootHex, deneb} from "@lodestar/types"; import {INTERVALS_PER_SLOT} from "@lodestar/params"; +import {Root, RootHex, deneb} from "@lodestar/types"; +import {BlobAndProof} from "@lodestar/types/deneb"; +import {Logger, fromHex, pruneSetToMax, toRootHex} from "@lodestar/utils"; import {sleep} from "@lodestar/utils"; -import {INetwork, NetworkEvent, NetworkEventData, PeerAction} from "../network/index.js"; -import {PeerIdStr} from "../util/peerId.js"; -import {IBeaconChain} from "../chain/index.js"; import {BlockInput, BlockInputType, NullBlockInput} from "../chain/blocks/types.js"; -import {Metrics} from "../metrics/index.js"; -import {shuffle} from "../util/shuffle.js"; -import {byteArrayEquals} from "../util/bytes.js"; import {BlockError, BlockErrorCode} from "../chain/errors/index.js"; +import {IBeaconChain} from "../chain/index.js"; +import {Metrics} from "../metrics/index.js"; +import {INetwork, NetworkEvent, NetworkEventData, PeerAction} from "../network/index.js"; import { beaconBlocksMaybeBlobsByRoot, unavailableBeaconBlobsByRoot, } from "../network/reqresp/beaconBlocksMaybeBlobsByRoot.js"; +import {byteArrayEquals} from "../util/bytes.js"; +import {PeerIdStr} from "../util/peerId.js"; +import {shuffle} from "../util/shuffle.js"; import {Result, wrapError} from "../util/wrapError.js"; import {PendingBlock, PendingBlockStatus, PendingBlockType} from "./interface.js"; -import {getDescendantBlocks, getAllDescendantBlocks, getUnknownAndAncestorBlocks} from "./utils/pendingBlocksTree.js"; import {SyncOptions} from "./options.js"; +import {getAllDescendantBlocks, getDescendantBlocks, getUnknownAndAncestorBlocks} from "./utils/pendingBlocksTree.js"; const MAX_ATTEMPTS_PER_BLOCK = 5; const MAX_KNOWN_BAD_BLOCKS = 500; @@ -34,6 +35,9 @@ export class UnknownBlockSync { private readonly maxPendingBlocks; private subscribedToNetworkEvents = false; + private engineGetBlobsCache = new Map(); + private blockInputsRetryTrackerCache = new Set(); + constructor( private readonly config: ChainForkConfig, private readonly network: INetwork, @@ -532,13 +536,12 @@ export class UnknownBlockSync { for (let i = 0; i < MAX_ATTEMPTS_PER_BLOCK; i++) { const peer = shuffledPeers[i % shuffledPeers.length]; try { - const blockInput = await unavailableBeaconBlobsByRoot( - this.config, - this.network, - peer, - unavailableBlockInput, - this.metrics - ); + const blockInput = await unavailableBeaconBlobsByRoot(this.config, this.network, peer, unavailableBlockInput, { + metrics: this.metrics, + executionEngine: this.chain.executionEngine, + engineGetBlobsCache: this.engineGetBlobsCache, + blockInputsRetryTrackerCache: this.blockInputsRetryTrackerCache, + }); // Peer does not have the block, try with next peer if (blockInput === undefined) { diff --git a/packages/beacon-node/src/sync/utils/pendingBlocksTree.ts b/packages/beacon-node/src/sync/utils/pendingBlocksTree.ts index 0feb15862408..deefba91f366 100644 --- a/packages/beacon-node/src/sync/utils/pendingBlocksTree.ts +++ b/packages/beacon-node/src/sync/utils/pendingBlocksTree.ts @@ -1,5 +1,6 @@ import {RootHex} from "@lodestar/types"; import {MapDef} from "@lodestar/utils"; +import {BlockInputType} from "../../chain/blocks/types.js"; import { DownloadedBlock, PendingBlock, @@ -7,7 +8,6 @@ import { UnknownAndAncestorBlocks, UnknownBlock, } from "../interface.js"; -import {BlockInputType} from "../../chain/blocks/types.js"; export function getAllDescendantBlocks(blockRootHex: RootHex, blocks: Map): PendingBlock[] { // Do one pass over all blocks to index by parent diff --git a/packages/beacon-node/src/sync/utils/remoteSyncType.ts b/packages/beacon-node/src/sync/utils/remoteSyncType.ts index 247269ab409a..16f1481a2a83 100644 --- a/packages/beacon-node/src/sync/utils/remoteSyncType.ts +++ b/packages/beacon-node/src/sync/utils/remoteSyncType.ts @@ -1,6 +1,6 @@ import {IForkChoice} from "@lodestar/fork-choice"; import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {phase0, Slot} from "@lodestar/types"; +import {Slot, phase0} from "@lodestar/types"; import {ChainTarget} from "../range/utils/index.js"; /** The type of peer relative to our current state */ diff --git a/packages/beacon-node/src/util/blobs.ts b/packages/beacon-node/src/util/blobs.ts index fcc31092464f..56f1ab21aae9 100644 --- a/packages/beacon-node/src/util/blobs.ts +++ b/packages/beacon-node/src/util/blobs.ts @@ -1,9 +1,9 @@ import {digest as sha256Digest} from "@chainsafe/as-sha256"; import {Tree} from "@chainsafe/persistent-merkle-tree"; -import {VERSIONED_HASH_VERSION_KZG, KZG_COMMITMENT_GINDEX0, ForkName, ForkAll} from "@lodestar/params"; -import {deneb, ssz, BeaconBlockBody, SignedBeaconBlock, SSZTypesFor} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {ForkAll, ForkName, KZG_COMMITMENT_GINDEX0, VERSIONED_HASH_VERSION_KZG} from "@lodestar/params"; import {signedBlockToSignedHeader} from "@lodestar/state-transition"; +import {BeaconBlockBody, SSZTypesFor, SignedBeaconBlock, deneb, ssz} from "@lodestar/types"; type VersionHash = Uint8Array; diff --git a/packages/beacon-node/src/util/clock.ts b/packages/beacon-node/src/util/clock.ts index 197d17f38281..36eb6f6f7f2c 100644 --- a/packages/beacon-node/src/util/clock.ts +++ b/packages/beacon-node/src/util/clock.ts @@ -1,9 +1,9 @@ import EventEmitter from "node:events"; -import type {StrictEventEmitter} from "strict-event-emitter-types"; -import type {Epoch, Slot} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; -import {ErrorAborted} from "@lodestar/utils"; import {computeEpochAtSlot, computeTimeAtSlot, getCurrentSlot} from "@lodestar/state-transition"; +import type {Epoch, Slot} from "@lodestar/types"; +import {ErrorAborted} from "@lodestar/utils"; +import type {StrictEventEmitter} from "strict-event-emitter-types"; import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../constants/constants.js"; export enum ClockEvent { diff --git a/packages/beacon-node/src/util/graffiti.ts b/packages/beacon-node/src/util/graffiti.ts index 9a4bc3d9689b..ff23145d7295 100644 --- a/packages/beacon-node/src/util/graffiti.ts +++ b/packages/beacon-node/src/util/graffiti.ts @@ -8,6 +8,15 @@ export function toGraffitiBuffer(graffiti: string): Buffer { return Buffer.concat([Buffer.from(graffiti, "utf8"), Buffer.alloc(GRAFFITI_SIZE, 0)], GRAFFITI_SIZE); } +/** + * Converts a graffiti from 32 bytes buffer back to a UTF-8 string + */ +export function fromGraffitiBuffer(graffiti: Uint8Array): string { + return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength) + .toString("utf8") + .replaceAll("\u0000", ""); +} + export function getDefaultGraffiti( consensusClientVersion: ClientVersion, executionClientVersion: ClientVersion | null | undefined, diff --git a/packages/beacon-node/src/util/kzg.ts b/packages/beacon-node/src/util/kzg.ts index 42224d1ebaa6..696eeae73370 100644 --- a/packages/beacon-node/src/util/kzg.ts +++ b/packages/beacon-node/src/util/kzg.ts @@ -1,7 +1,7 @@ -import path from "node:path"; import fs from "node:fs"; +import path from "node:path"; import {fileURLToPath} from "node:url"; -import {fromHex, toHex} from "@lodestar/utils"; +import {fromHex, strip0xPrefix, toHex} from "@lodestar/utils"; // "c-kzg" has hardcoded the mainnet value, do not use params export const FIELD_ELEMENTS_PER_BLOB_MAINNET = 4096; @@ -154,10 +154,3 @@ export function trustedSetupJsonToTxt(data: TrustedSetupJSON): TrustedSetupTXT { ...data.setup_G2.map(strip0xPrefix), ].join("\n"); } - -function strip0xPrefix(hex: string): string { - if (hex.startsWith("0x")) { - return hex.slice(2); - } - return hex; -} diff --git a/packages/beacon-node/src/util/multifork.ts b/packages/beacon-node/src/util/multifork.ts index 0a00677afadf..952498c5a4d1 100644 --- a/packages/beacon-node/src/util/multifork.ts +++ b/packages/beacon-node/src/util/multifork.ts @@ -1,7 +1,7 @@ import {ChainForkConfig} from "@lodestar/config"; +import {ForkAll, ForkLightClient} from "@lodestar/params"; import {SSZTypesFor, Slot} from "@lodestar/types"; import {bytesToInt} from "@lodestar/utils"; -import {ForkAll, ForkLightClient} from "@lodestar/params"; import {getSlotFromSignedBeaconBlockSerialized} from "./sszBytes.js"; /** diff --git a/packages/beacon-node/src/util/peerId.ts b/packages/beacon-node/src/util/peerId.ts index 2afb9bed390e..6fee7db855da 100644 --- a/packages/beacon-node/src/util/peerId.ts +++ b/packages/beacon-node/src/util/peerId.ts @@ -1,6 +1,6 @@ import {PeerId} from "@libp2p/interface"; -import {base58btc} from "multiformats/bases/base58"; import {peerIdFromString} from "@libp2p/peer-id"; +import {base58btc} from "multiformats/bases/base58"; // Ensure consistent serialization of PeerId to string diff --git a/packages/beacon-node/src/util/queue/fnQueue.ts b/packages/beacon-node/src/util/queue/fnQueue.ts index 80e179f8e8f3..1e4f68b7b9b6 100644 --- a/packages/beacon-node/src/util/queue/fnQueue.ts +++ b/packages/beacon-node/src/util/queue/fnQueue.ts @@ -1,5 +1,5 @@ import {JobItemQueue} from "./itemQueue.js"; -import {QueueMetrics, JobQueueOpts} from "./options.js"; +import {JobQueueOpts, QueueMetrics} from "./options.js"; // biome-ignore lint/suspicious/noExplicitAny: type Fn = (...args: any) => Promise; diff --git a/packages/beacon-node/src/util/queue/itemQueue.ts b/packages/beacon-node/src/util/queue/itemQueue.ts index f380a15f5eaf..8713340ec9a4 100644 --- a/packages/beacon-node/src/util/queue/itemQueue.ts +++ b/packages/beacon-node/src/util/queue/itemQueue.ts @@ -1,7 +1,7 @@ -import {LinkedList} from "../array.js"; import {callInNextEventLoop, nextEventLoop} from "../../util/eventLoop.js"; +import {LinkedList} from "../array.js"; import {QueueError, QueueErrorCode} from "./errors.js"; -import {defaultQueueOpts, QueueMetrics, JobQueueOpts, QueueType} from "./options.js"; +import {JobQueueOpts, QueueMetrics, QueueType, defaultQueueOpts} from "./options.js"; /** * JobQueue that stores arguments in the job array instead of closures. diff --git a/packages/beacon-node/src/util/sszBytes.ts b/packages/beacon-node/src/util/sszBytes.ts index c27df1a0fbf3..cb80d5d1bb4b 100644 --- a/packages/beacon-node/src/util/sszBytes.ts +++ b/packages/beacon-node/src/util/sszBytes.ts @@ -1,5 +1,4 @@ import {BitArray, deserializeUint8ArrayBitListFromBytes} from "@chainsafe/ssz"; -import {BLSSignature, RootHex, Slot} from "@lodestar/types"; import { BYTES_PER_FIELD_ELEMENT, FIELD_ELEMENTS_PER_BLOB, @@ -7,6 +6,7 @@ import { ForkSeq, MAX_COMMITTEES_PER_SLOT, } from "@lodestar/params"; +import {BLSSignature, RootHex, Slot} from "@lodestar/types"; export type BlockRootHex = RootHex; // pre-electra, AttestationData is used to cache attestations diff --git a/packages/beacon-node/src/util/types.ts b/packages/beacon-node/src/util/types.ts index 545a706c7511..5b9c7a784277 100644 --- a/packages/beacon-node/src/util/types.ts +++ b/packages/beacon-node/src/util/types.ts @@ -1,4 +1,5 @@ -import {ContainerType, ValueOf} from "@chainsafe/ssz"; +import {ContainerType, ListCompositeType, ValueOf} from "@chainsafe/ssz"; +import {ChainConfig} from "@lodestar/config"; import {ssz} from "@lodestar/types"; // Misc SSZ types used only in the beacon-node package, no need to upstream to types @@ -12,3 +13,7 @@ export const signedBLSToExecutionChangeVersionedType = new ContainerType( {jsonCase: "eth2", typeName: "SignedBLSToExecutionChangeVersionedType"} ); export type SignedBLSToExecutionChangeVersioned = ValueOf; + +export const BlobSidecarsByRootRequestType = (config: ChainConfig) => + new ListCompositeType(ssz.deneb.BlobIdentifier, config.MAX_REQUEST_BLOB_SIDECARS); +export type BlobSidecarsByRootRequest = ValueOf>; diff --git a/packages/beacon-node/test/e2e/api/impl/beacon/block/endpoint.test.ts b/packages/beacon-node/test/e2e/api/impl/beacon/block/endpoint.test.ts index b8939b54c294..16a3dd0c80b0 100644 --- a/packages/beacon-node/test/e2e/api/impl/beacon/block/endpoint.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/beacon/block/endpoint.test.ts @@ -1,6 +1,6 @@ -import {describe, beforeAll, afterAll, it, expect, vi} from "vitest"; -import {createBeaconConfig} from "@lodestar/config"; import {ApiClient, WireFormat, getClient} from "@lodestar/api"; +import {createBeaconConfig} from "@lodestar/config"; +import {ForkName} from "@lodestar/params"; import { SignedBeaconBlock, SignedBlindedBeaconBlock, @@ -8,11 +8,11 @@ import { isExecutionPayload, isExecutionPayloadHeader, } from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; -import {LogLevel, testLogger} from "../../../../../utils/logger.js"; -import {getDevBeaconNode} from "../../../../../utils/node/beacon.js"; +import {afterAll, beforeAll, describe, expect, it, vi} from "vitest"; import {BeaconNode} from "../../../../../../src/node/nodejs.js"; import {getConfig} from "../../../../../utils/config.js"; +import {LogLevel, testLogger} from "../../../../../utils/logger.js"; +import {getDevBeaconNode} from "../../../../../utils/node/beacon.js"; describe("beacon block api", () => { vi.setConfig({testTimeout: 60_000, hookTimeout: 60_000}); diff --git a/packages/beacon-node/test/e2e/api/impl/beacon/node/endpoints.test.ts b/packages/beacon-node/test/e2e/api/impl/beacon/node/endpoints.test.ts index 6dc01870a844..18747fd2f735 100644 --- a/packages/beacon-node/test/e2e/api/impl/beacon/node/endpoints.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/beacon/node/endpoints.test.ts @@ -1,12 +1,12 @@ -import {describe, beforeAll, afterAll, it, expect, vi} from "vitest"; -import {createBeaconConfig} from "@lodestar/config"; -import {chainConfig as chainConfigDef} from "@lodestar/config/default"; import {routes} from "@lodestar/api"; import {ApiClient, getClient} from "@lodestar/api/beacon"; +import {createBeaconConfig} from "@lodestar/config"; +import {chainConfig as chainConfigDef} from "@lodestar/config/default"; import {sleep} from "@lodestar/utils"; +import {afterAll, beforeAll, describe, expect, it, vi} from "vitest"; +import {BeaconNode} from "../../../../../../src/node/nodejs.js"; import {LogLevel, testLogger} from "../../../../../utils/logger.js"; import {getDevBeaconNode} from "../../../../../utils/node/beacon.js"; -import {BeaconNode} from "../../../../../../src/node/nodejs.js"; import {getAndInitDevValidators} from "../../../../../utils/node/validator.js"; describe("beacon node api", () => { diff --git a/packages/beacon-node/test/e2e/api/impl/beacon/state/endpoint.test.ts b/packages/beacon-node/test/e2e/api/impl/beacon/state/endpoint.test.ts index d8c87a3ba6b8..1b2c6b902f20 100644 --- a/packages/beacon-node/test/e2e/api/impl/beacon/state/endpoint.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/beacon/state/endpoint.test.ts @@ -1,12 +1,12 @@ -import {describe, beforeAll, afterAll, it, expect} from "vitest"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {ApiClient, getClient} from "@lodestar/api"; import {createBeaconConfig} from "@lodestar/config"; import {chainConfig as chainConfigDef} from "@lodestar/config/default"; -import {ApiClient, getClient} from "@lodestar/api"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {computeCommitteeCount} from "@lodestar/state-transition"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; +import {BeaconNode} from "../../../../../../src/node/nodejs.js"; import {LogLevel, testLogger} from "../../../../../utils/logger.js"; import {getDevBeaconNode} from "../../../../../utils/node/beacon.js"; -import {BeaconNode} from "../../../../../../src/node/nodejs.js"; describe("beacon state api", () => { const restPort = 9596; diff --git a/packages/beacon-node/test/e2e/api/impl/config.test.ts b/packages/beacon-node/test/e2e/api/impl/config.test.ts index 3ffdbc4beb21..078e210cb0cc 100644 --- a/packages/beacon-node/test/e2e/api/impl/config.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/config.test.ts @@ -1,17 +1,15 @@ -import {describe, it} from "vitest"; import {fetch} from "@lodestar/api"; -import {ForkName, activePreset} from "@lodestar/params"; import {chainConfig} from "@lodestar/config/default"; -import {ethereumConsensusSpecsTests} from "../../../spec/specTestVersioning.js"; +import {ForkName, activePreset} from "@lodestar/params"; +import {describe, it} from "vitest"; import {specConstants} from "../../../../src/api/impl/config/constants.js"; +import {ethereumConsensusSpecsTests} from "../../../spec/specTestVersioning.js"; const CONSTANT_NAMES_SKIP_LIST = new Set([ // This constant is an array, so it's skipped due to not being just a string. // This constant can also be derived from existing constants so it's not critical. // PARTICIPATION_FLAG_WEIGHTS = [TIMELY_SOURCE_WEIGHT, TIMELY_TARGET_WEIGHT, TIMELY_HEAD_WEIGHT] "PARTICIPATION_FLAG_WEIGHTS", - // TODO DENEB: Configure the blob subnets in a followup PR - "BLOB_SIDECAR_SUBNET_COUNT", ]); describe("api / impl / config", () => { @@ -60,7 +58,7 @@ async function downloadRemoteConstants(commit: string): Promise { const constantNames: string[] = []; for (const spec of await Promise.all(downloadedSpecs)) { - const matches = spec.matchAll(/\|\s`*([A-Z_]+)`\s\|/g); + const matches = spec.matchAll(/\|\s`*([A-Z_]+)`\s+\|/g); for (const match of matches) { constantNames.push(match[1]); } diff --git a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts index effbed19fc2c..a836024aab01 100644 --- a/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts +++ b/packages/beacon-node/test/e2e/api/impl/lightclient/endpoint.test.ts @@ -1,17 +1,17 @@ -import {describe, it, beforeEach, afterEach, expect} from "vitest"; import {aggregateSerializedPublicKeys} from "@chainsafe/blst"; -import {createBeaconConfig, ChainConfig} from "@lodestar/config"; +import {HttpHeader, getClient, routes} from "@lodestar/api"; +import {ChainConfig, createBeaconConfig} from "@lodestar/config"; import {chainConfig as chainConfigDef} from "@lodestar/config/default"; -import {getClient, HttpHeader, routes} from "@lodestar/api"; -import {sleep} from "@lodestar/utils"; import {ForkName, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; -import {Validator} from "@lodestar/validator"; import {phase0, ssz} from "@lodestar/types"; -import {LogLevel, testLogger, TestLoggerOpts} from "../../../../utils/logger.js"; -import {getDevBeaconNode} from "../../../../utils/node/beacon.js"; -import {getAndInitDevValidators} from "../../../../utils/node/validator.js"; +import {sleep} from "@lodestar/utils"; +import {Validator} from "@lodestar/validator"; +import {afterEach, beforeEach, describe, expect, it} from "vitest"; import {BeaconNode} from "../../../../../src/node/nodejs.js"; import {waitForEvent} from "../../../../utils/events/resolver.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../../../utils/logger.js"; +import {getDevBeaconNode} from "../../../../utils/node/beacon.js"; +import {getAndInitDevValidators} from "../../../../utils/node/validator.js"; describe("lightclient api", () => { const SECONDS_PER_SLOT = 1; diff --git a/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts b/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts index bc847b47e9a9..7501460779f3 100644 --- a/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts +++ b/packages/beacon-node/test/e2e/api/lodestar/lodestar.test.ts @@ -1,14 +1,14 @@ -import {describe, it, afterEach, expect, vi} from "vitest"; -import {createBeaconConfig, ChainConfig} from "@lodestar/config"; +import {getClient} from "@lodestar/api"; +import {ChainConfig, createBeaconConfig} from "@lodestar/config"; import {chainConfig as chainConfigDef} from "@lodestar/config/default"; -import {phase0} from "@lodestar/types"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {getClient} from "@lodestar/api"; -import {LogLevel, testLogger, TestLoggerOpts} from "../../../utils/logger.js"; -import {getDevBeaconNode} from "../../../utils/node/beacon.js"; -import {waitForEvent} from "../../../utils/events/resolver.js"; -import {ClockEvent} from "../../../../src/util/clock.js"; +import {phase0} from "@lodestar/types"; +import {afterEach, describe, expect, it, vi} from "vitest"; import {BeaconNode} from "../../../../src/index.js"; +import {ClockEvent} from "../../../../src/util/clock.js"; +import {waitForEvent} from "../../../utils/events/resolver.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../../utils/logger.js"; +import {getDevBeaconNode} from "../../../utils/node/beacon.js"; describe("api / impl / validator", () => { vi.setConfig({testTimeout: 60_000}); diff --git a/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts b/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts index a544b3231e87..f8c3a47fb824 100644 --- a/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts +++ b/packages/beacon-node/test/e2e/chain/bls/multithread.test.ts @@ -1,9 +1,9 @@ -import {describe, it, beforeAll, expect, beforeEach, afterEach} from "vitest"; import {PublicKey, SecretKey} from "@chainsafe/blst"; import {ISignatureSet, SignatureSetType} from "@lodestar/state-transition"; +import {afterEach, beforeAll, beforeEach, describe, expect, it} from "vitest"; +import {VerifySignatureOpts} from "../../../../src/chain/bls/interface.js"; import {BlsMultiThreadWorkerPool} from "../../../../src/chain/bls/multithread/index.js"; import {testLogger} from "../../../utils/logger.js"; -import {VerifySignatureOpts} from "../../../../src/chain/bls/interface.js"; describe("chain / bls / multithread queue", () => { const logger = testLogger(); diff --git a/packages/beacon-node/test/e2e/chain/lightclient.test.ts b/packages/beacon-node/test/e2e/chain/lightclient.test.ts index ed698f2844a1..2fc983b8d488 100644 --- a/packages/beacon-node/test/e2e/chain/lightclient.test.ts +++ b/packages/beacon-node/test/e2e/chain/lightclient.test.ts @@ -1,18 +1,18 @@ -import {describe, it, expect, afterEach, vi} from "vitest"; -import {JsonPath, toHexString, fromHexString} from "@chainsafe/ssz"; import {CompactMultiProof, computeDescriptor} from "@chainsafe/persistent-merkle-tree"; +import {JsonPath, fromHexString, toHexString} from "@chainsafe/ssz"; +import {ApiClient, getClient, routes} from "@lodestar/api"; import {ChainConfig} from "@lodestar/config"; -import {ssz, altair} from "@lodestar/types"; +import {Lightclient} from "@lodestar/light-client"; +import {LightClientRestTransport} from "@lodestar/light-client/transport"; import {TimestampFormatCode} from "@lodestar/logger"; import {EPOCHS_PER_SYNC_COMMITTEE_PERIOD, SLOTS_PER_EPOCH} from "@lodestar/params"; -import {Lightclient} from "@lodestar/light-client"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {LightClientRestTransport} from "@lodestar/light-client/transport"; -import {ApiClient, getClient, routes} from "@lodestar/api"; -import {testLogger, LogLevel, TestLoggerOpts} from "../../utils/logger.js"; +import {altair, ssz} from "@lodestar/types"; +import {afterEach, describe, expect, it, vi} from "vitest"; +import {HeadEventData} from "../../../src/chain/index.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../utils/logger.js"; import {getDevBeaconNode} from "../../utils/node/beacon.js"; import {getAndInitDevValidators} from "../../utils/node/validator.js"; -import {HeadEventData} from "../../../src/chain/index.js"; describe("chain / lightclient", () => { vi.setConfig({testTimeout: 600_000}); diff --git a/packages/beacon-node/test/e2e/chain/proposerBoostReorg.test.ts b/packages/beacon-node/test/e2e/chain/proposerBoostReorg.test.ts index fd6af72ad6cb..70f2d87e2456 100644 --- a/packages/beacon-node/test/e2e/chain/proposerBoostReorg.test.ts +++ b/packages/beacon-node/test/e2e/chain/proposerBoostReorg.test.ts @@ -1,16 +1,16 @@ -import {describe, it, afterEach, expect, vi} from "vitest"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {TimestampFormatCode} from "@lodestar/logger"; +import {routes} from "@lodestar/api"; import {ChainConfig} from "@lodestar/config"; +import {TimestampFormatCode} from "@lodestar/logger"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {RootHex, Slot} from "@lodestar/types"; -import {routes} from "@lodestar/api"; import {toHexString} from "@lodestar/utils"; +import {afterEach, describe, expect, it, vi} from "vitest"; +import {ReorgEventData} from "../../../src/chain/emitter.js"; +import {TimelinessForkChoice} from "../../mocks/fork-choice/timeliness.js"; +import {waitForEvent} from "../../utils/events/resolver.js"; import {LogLevel, TestLoggerOpts, testLogger} from "../../utils/logger.js"; import {getDevBeaconNode} from "../../utils/node/beacon.js"; -import {TimelinessForkChoice} from "../../mocks/fork-choice/timeliness.js"; import {getAndInitDevValidators} from "../../utils/node/validator.js"; -import {waitForEvent} from "../../utils/events/resolver.js"; -import {ReorgEventData} from "../../../src/chain/emitter.js"; describe("proposer boost reorg", () => { vi.setConfig({testTimeout: 60000}); diff --git a/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts b/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts index fcac715e1719..875e3fe13b03 100644 --- a/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts +++ b/packages/beacon-node/test/e2e/chain/stateCache/nHistoricalStates.test.ts @@ -1,18 +1,18 @@ -import {describe, it, afterEach, expect, vi} from "vitest"; -import {Gauge, Histogram} from "prom-client"; +import {routes} from "@lodestar/api"; import {ChainConfig} from "@lodestar/config"; -import {Slot, phase0} from "@lodestar/types"; import {TimestampFormatCode} from "@lodestar/logger"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {routes} from "@lodestar/api"; -import {LogLevel, TestLoggerOpts, testLogger} from "../../../utils/logger.js"; -import {getDevBeaconNode} from "../../../utils/node/beacon.js"; -import {getAndInitDevValidators} from "../../../utils/node/validator.js"; -import {waitForEvent} from "../../../utils/events/resolver.js"; +import {Slot, phase0} from "@lodestar/types"; +import {Gauge, Histogram} from "prom-client"; +import {afterEach, describe, expect, it, vi} from "vitest"; import {ChainEvent, ReorgEventData} from "../../../../src/chain/emitter.js"; -import {connect, onPeerConnect} from "../../../utils/network.js"; import {CacheItemType} from "../../../../src/chain/stateCache/types.js"; import {ReorgedForkChoice} from "../../../mocks/fork-choice/reorg.js"; +import {waitForEvent} from "../../../utils/events/resolver.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../../utils/logger.js"; +import {connect, onPeerConnect} from "../../../utils/network.js"; +import {getDevBeaconNode} from "../../../utils/node/beacon.js"; +import {getAndInitDevValidators} from "../../../utils/node/validator.js"; /** * Test different reorg scenarios to make sure the StateCache implementations are correct. diff --git a/packages/beacon-node/test/e2e/db/api/beacon/repositories/blockArchive.test.ts b/packages/beacon-node/test/e2e/db/api/beacon/repositories/blockArchive.test.ts index 3c7a37e52a8b..a08be8922d2a 100644 --- a/packages/beacon-node/test/e2e/db/api/beacon/repositories/blockArchive.test.ts +++ b/packages/beacon-node/test/e2e/db/api/beacon/repositories/blockArchive.test.ts @@ -1,6 +1,6 @@ -import {beforeAll, afterAll, describe, it, expect} from "vitest"; import {config} from "@lodestar/config/default"; import {ssz} from "@lodestar/types"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; import {BeaconDb} from "../../../../../../src/db/index.js"; import {startTmpBeaconDb} from "../../../../../utils/db.js"; diff --git a/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts b/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts index 949d0104d641..c83a2896530c 100644 --- a/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts +++ b/packages/beacon-node/test/e2e/doppelganger/doppelganger.test.ts @@ -1,18 +1,18 @@ -import {describe, afterEach, it, expect} from "vitest"; import {fromHexString} from "@chainsafe/ssz"; import {routes} from "@lodestar/api/beacon"; -import {BLSPubkey, Epoch, phase0, Slot, ssz} from "@lodestar/types"; import {ChainConfig} from "@lodestar/config"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {BLSPubkey, Epoch, Slot, phase0, ssz} from "@lodestar/types"; import {Validator} from "@lodestar/validator"; import {PubkeyHex} from "@lodestar/validator/src/types"; -import {getAndInitDevValidators} from "../../utils/node/validator.js"; +import {afterEach, describe, expect, it} from "vitest"; +import {BeaconNode} from "../../../src/node/index.js"; import {ClockEvent} from "../../../src/util/clock.js"; +import {waitForEvent} from "../../utils/events/resolver.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../utils/logger.js"; import {connect} from "../../utils/network.js"; -import {testLogger, LogLevel, TestLoggerOpts} from "../../utils/logger.js"; import {getDevBeaconNode} from "../../utils/node/beacon.js"; -import {waitForEvent} from "../../utils/events/resolver.js"; -import {BeaconNode} from "../../../src/node/index.js"; +import {getAndInitDevValidators} from "../../utils/node/validator.js"; // TODO: Reconsider this tests latter. // Doppelganger testing can be split in two items: diff --git a/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts b/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts index 21cadeb55d2c..f72be5ed3e94 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1ForBlockProduction.test.ts @@ -1,18 +1,18 @@ -import {describe, it, beforeAll, afterAll, expect} from "vitest"; import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {sleep} from "@lodestar/utils"; import {LevelDbController} from "@lodestar/db"; +import {sleep} from "@lodestar/utils"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; import {ssz} from "@lodestar/types"; +import {BeaconDb} from "../../../src/db/index.js"; import {Eth1ForBlockProduction} from "../../../src/eth1/index.js"; import {Eth1Options} from "../../../src/eth1/options.js"; -import {getTestnetConfig, medallaTestnetConfig} from "../../utils/testnet.js"; -import {testLogger} from "../../utils/logger.js"; -import {BeaconDb} from "../../../src/db/index.js"; -import {generateState} from "../../utils/state.js"; import {Eth1Provider} from "../../../src/eth1/provider/eth1Provider.js"; import {getGoerliRpcUrl} from "../../testParams.js"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {testLogger} from "../../utils/logger.js"; +import {generateState} from "../../utils/state.js"; +import {getTestnetConfig, medallaTestnetConfig} from "../../utils/testnet.js"; const dbLocation = "./.__testdb"; diff --git a/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts b/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts index 9423bb716b3f..79ff059e2b82 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1MergeBlockTracker.test.ts @@ -1,14 +1,14 @@ -import {describe, it, beforeAll, expect, beforeEach, afterEach} from "vitest"; import {fromHexString} from "@chainsafe/ssz"; import {ChainConfig} from "@lodestar/config"; import {sleep} from "@lodestar/utils"; -import {Eth1Provider, IEth1Provider} from "../../../src/index.js"; +import {afterEach, beforeAll, beforeEach, describe, expect, it} from "vitest"; +import {ZERO_HASH} from "../../../src/constants/index.js"; import {Eth1MergeBlockTracker, StatusCode} from "../../../src/eth1/eth1MergeBlockTracker.js"; import {Eth1Options} from "../../../src/eth1/options.js"; -import {testLogger} from "../../utils/logger.js"; import {quantityToBigint} from "../../../src/eth1/provider/utils.js"; -import {ZERO_HASH} from "../../../src/constants/index.js"; +import {Eth1Provider, IEth1Provider} from "../../../src/index.js"; import {getGoerliRpcUrl} from "../../testParams.js"; +import {testLogger} from "../../utils/logger.js"; // This test is constantly failing. We must unblock PR so this issue is a TODO to debug it and re-enable latter. // It's OKAY to disable temporarily since this functionality is tested indirectly by the sim merge tests. diff --git a/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts b/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts index 606845f40337..d571a695c648 100644 --- a/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts +++ b/packages/beacon-node/test/e2e/eth1/eth1Provider.test.ts @@ -1,11 +1,11 @@ -import {describe, it, expect, beforeEach, afterEach} from "vitest"; import {fromHexString} from "@chainsafe/ssz"; +import {afterEach, beforeEach, describe, expect, it} from "vitest"; +import {Eth1Block} from "../../../src/eth1/interface.js"; import {Eth1Options} from "../../../src/eth1/options.js"; -import {getTestnetConfig} from "../../utils/testnet.js"; -import {goerliTestnetDepositEvents} from "../../utils/testnet.js"; import {Eth1Provider, parseEth1Block} from "../../../src/eth1/provider/eth1Provider.js"; -import {Eth1Block} from "../../../src/eth1/interface.js"; import {getGoerliRpcUrl} from "../../testParams.js"; +import {getTestnetConfig} from "../../utils/testnet.js"; +import {goerliTestnetDepositEvents} from "../../utils/testnet.js"; // https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("eth1 / Eth1Provider", () => { diff --git a/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts b/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts index 91131a89f379..ee2476549737 100644 --- a/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts +++ b/packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts @@ -1,11 +1,11 @@ import crypto from "node:crypto"; import http from "node:http"; -import {describe, it, expect, afterEach, vi} from "vitest"; import {FetchError} from "@lodestar/api"; import {sleep} from "@lodestar/utils"; +import {afterEach, describe, expect, it, vi} from "vitest"; +import {RpcPayload} from "../../../src/eth1/interface.js"; import {JsonRpcHttpClient} from "../../../src/eth1/provider/jsonRpcHttpClient.js"; import {getGoerliRpcUrl} from "../../testParams.js"; -import {RpcPayload} from "../../../src/eth1/interface.js"; describe("eth1 / jsonRpcHttpClient", () => { vi.setConfig({testTimeout: 10_000}); diff --git a/packages/beacon-node/test/e2e/eth1/stream.test.ts b/packages/beacon-node/test/e2e/eth1/stream.test.ts index ce65d4353f0e..1ec20608cfd7 100644 --- a/packages/beacon-node/test/e2e/eth1/stream.test.ts +++ b/packages/beacon-node/test/e2e/eth1/stream.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect, beforeEach, afterEach} from "vitest"; -import {getTestnetConfig, medallaTestnetConfig} from "../../utils/testnet.js"; -import {getDepositsStream, getDepositsAndBlockStreamForGenesis} from "../../../src/eth1/stream.js"; +import {afterEach, beforeEach, describe, expect, it} from "vitest"; +import {Eth1Options} from "../../../src/eth1/options.js"; import {Eth1Provider} from "../../../src/eth1/provider/eth1Provider.js"; +import {getDepositsAndBlockStreamForGenesis, getDepositsStream} from "../../../src/eth1/stream.js"; import {getGoerliRpcUrl} from "../../testParams.js"; -import {Eth1Options} from "../../../src/eth1/options.js"; +import {getTestnetConfig, medallaTestnetConfig} from "../../utils/testnet.js"; // https://github.com/ChainSafe/lodestar/issues/5967 describe.skip("Eth1 streams", () => { diff --git a/packages/beacon-node/test/e2e/interop/genesisState.test.ts b/packages/beacon-node/test/e2e/interop/genesisState.test.ts index 739319a4257c..91d67fae91ce 100644 --- a/packages/beacon-node/test/e2e/interop/genesisState.test.ts +++ b/packages/beacon-node/test/e2e/interop/genesisState.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect} from "vitest"; import {toHexString} from "@chainsafe/ssz"; import {config} from "@lodestar/config/default"; import {ssz} from "@lodestar/types"; -import {initDevState} from "../../../src/node/utils/state.js"; +import {describe, expect, it} from "vitest"; import {interopDeposits} from "../../../src/node/utils/interop/deposits.js"; +import {initDevState} from "../../../src/node/utils/state.js"; describe("interop / initDevState", () => { it("Create interop deposits", () => { diff --git a/packages/beacon-node/test/e2e/network/gossipsub.test.ts b/packages/beacon-node/test/e2e/network/gossipsub.test.ts index 29a745455561..e63b26d026db 100644 --- a/packages/beacon-node/test/e2e/network/gossipsub.test.ts +++ b/packages/beacon-node/test/e2e/network/gossipsub.test.ts @@ -1,12 +1,12 @@ -import {describe, it, expect, afterEach, vi} from "vitest"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {sleep} from "@lodestar/utils"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {ssz} from "@lodestar/types"; +import {sleep} from "@lodestar/utils"; +import {afterEach, describe, expect, it, vi} from "vitest"; +import {GossipHandlerParamGeneric, GossipHandlers, GossipType} from "../../../src/network/gossip/index.js"; import {Network} from "../../../src/network/index.js"; -import {GossipType, GossipHandlers, GossipHandlerParamGeneric} from "../../../src/network/gossip/index.js"; -import {getNetworkForTest} from "../../utils/networkWithMockDb.js"; import {connect, onPeerConnect} from "../../utils/network.js"; +import {getNetworkForTest} from "../../utils/networkWithMockDb.js"; describe("gossipsub / main thread", () => { vi.setConfig({testTimeout: 3000}); diff --git a/packages/beacon-node/test/e2e/network/mdns.test.ts b/packages/beacon-node/test/e2e/network/mdns.test.ts index f8b55d8afae7..f1df1f1e94d6 100644 --- a/packages/beacon-node/test/e2e/network/mdns.test.ts +++ b/packages/beacon-node/test/e2e/network/mdns.test.ts @@ -1,21 +1,21 @@ -import {describe, it, afterEach, beforeEach, expect, vi} from "vitest"; +import {SignableENR} from "@chainsafe/enr"; import {PeerId} from "@libp2p/interface"; -import {multiaddr} from "@multiformats/multiaddr"; import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; -import {SignableENR} from "@chainsafe/enr"; import {createBeaconConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; -import {ssz} from "@lodestar/types"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; +import {multiaddr} from "@multiformats/multiaddr"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import {GossipHandlers} from "../../../src/network/gossip/index.js"; +import {Network, NetworkInitModules, getReqRespHandlers} from "../../../src/network/index.js"; +import {NetworkOptions, defaultNetworkOptions} from "../../../src/network/options.js"; import {getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; import {getMockedBeaconDb} from "../../mocks/mockedBeaconDb.js"; -import {Network, NetworkInitModules, getReqRespHandlers} from "../../../src/network/index.js"; -import {defaultNetworkOptions, NetworkOptions} from "../../../src/network/options.js"; +import {memoOnce} from "../../utils/cache.js"; +import {testLogger} from "../../utils/logger.js"; import {createNetworkModules, onPeerConnect} from "../../utils/network.js"; import {generateState, zeroProtoBlock} from "../../utils/state.js"; -import {testLogger} from "../../utils/logger.js"; -import {GossipHandlers} from "../../../src/network/gossip/index.js"; -import {memoOnce} from "../../utils/cache.js"; let port = 9000; const mu = "/ip4/127.0.0.1/tcp/0"; diff --git a/packages/beacon-node/test/e2e/network/network.test.ts b/packages/beacon-node/test/e2e/network/network.test.ts index 2435b005efa1..fee80d6f48b5 100644 --- a/packages/beacon-node/test/e2e/network/network.test.ts +++ b/packages/beacon-node/test/e2e/network/network.test.ts @@ -1,10 +1,10 @@ -import {describe, it, expect, afterEach, beforeEach, vi} from "vitest"; import {PeerId} from "@libp2p/interface"; import {config} from "@lodestar/config/default"; import {phase0} from "@lodestar/types"; import {sleep} from "@lodestar/utils"; -import {Network, NetworkEvent, ReqRespMethod} from "../../../src/network/index.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {GoodByeReasonCode} from "../../../src/constants/index.js"; +import {Network, NetworkEvent, ReqRespMethod} from "../../../src/network/index.js"; import {connect, disconnect, onPeerConnect, onPeerDisconnect} from "../../utils/network.js"; import {getNetworkForTest} from "../../utils/networkWithMockDb.js"; import {getValidPeerId} from "../../utils/peer.js"; diff --git a/packages/beacon-node/test/e2e/network/onWorker/dataSerialization.test.ts b/packages/beacon-node/test/e2e/network/onWorker/dataSerialization.test.ts index 12d9e393af09..e4056ca9671e 100644 --- a/packages/beacon-node/test/e2e/network/onWorker/dataSerialization.test.ts +++ b/packages/beacon-node/test/e2e/network/onWorker/dataSerialization.test.ts @@ -1,12 +1,20 @@ -import {describe, it, beforeAll, afterAll, expect} from "vitest"; -import {TopicValidatorResult} from "@libp2p/interface"; import {BitArray} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; +import {TopicValidatorResult} from "@libp2p/interface"; import {routes} from "@lodestar/api"; import {ForkName} from "@lodestar/params"; -import {getValidPeerId, validPeerIdStr} from "../../../utils/peer.js"; +import {ssz} from "@lodestar/types"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; +import { + BlockInput, + BlockInputDataBlobs, + BlockInputType, + BlockSource, + CachedData, +} from "../../../../src/chain/blocks/types.js"; +import {ZERO_HASH, ZERO_HASH_HEX} from "../../../../src/constants/constants.js"; import {ReqRespBridgeEventData} from "../../../../src/network/core/events.js"; import {ReqRespBridgeEvent} from "../../../../src/network/core/events.js"; +import {NetworkWorkerApi} from "../../../../src/network/core/index.js"; import { GossipType, NetworkEvent, @@ -15,18 +23,10 @@ import { ReqRespMethod, networkEventDirection, } from "../../../../src/network/index.js"; -import { - BlockInputType, - BlockSource, - BlockInput, - BlockInputDataBlobs, - CachedData, -} from "../../../../src/chain/blocks/types.js"; -import {ZERO_HASH, ZERO_HASH_HEX} from "../../../../src/constants/constants.js"; +import {CommitteeSubscription} from "../../../../src/network/subnets/interface.js"; import {IteratorEventType} from "../../../../src/util/asyncIterableToEvents.js"; -import {NetworkWorkerApi} from "../../../../src/network/core/index.js"; import {EventDirection} from "../../../../src/util/workerEvents.js"; -import {CommitteeSubscription} from "../../../../src/network/subnets/interface.js"; +import {getValidPeerId, validPeerIdStr} from "../../../utils/peer.js"; import {EchoWorker, getEchoWorker} from "./workerEchoHandler.js"; describe("data serialization through worker boundary", () => { diff --git a/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts b/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts index b2c0f6b56aa0..f4b5df8189a0 100644 --- a/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts +++ b/packages/beacon-node/test/e2e/network/onWorker/workerEchoHandler.ts @@ -1,5 +1,5 @@ import workerThreads from "node:worker_threads"; -import {spawn, Worker} from "@chainsafe/threads"; +import {Worker, spawn} from "@chainsafe/threads"; export type EchoWorker = { send(data: T): Promise; diff --git a/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts b/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts index d0b94399c01d..e0b1e6b357fc 100644 --- a/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts +++ b/packages/beacon-node/test/e2e/network/peers/peerManager.test.ts @@ -1,24 +1,24 @@ -import {describe, it, afterEach, expect, vi} from "vitest"; +import {BitArray} from "@chainsafe/ssz"; import {Connection} from "@libp2p/interface"; import {CustomEvent} from "@libp2p/interface"; -import {BitArray} from "@chainsafe/ssz"; +import {createBeaconConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; import {altair, phase0, ssz} from "@lodestar/types"; import {sleep} from "@lodestar/utils"; -import {createBeaconConfig} from "@lodestar/config"; -import {ReqRespMethod} from "../../../../src/network/reqresp/ReqRespBeaconNode.js"; -import {PeerRpcScoreStore, PeerManager, IReqRespBeaconNodePeerManager} from "../../../../src/network/peers/index.js"; -import {Eth2Gossipsub, getConnectionsMap, NetworkEvent, NetworkEventBus} from "../../../../src/network/index.js"; +import {afterEach, describe, expect, it, vi} from "vitest"; +import {Eth2Gossipsub, NetworkEvent, NetworkEventBus, getConnectionsMap} from "../../../../src/network/index.js"; +import {IReqRespBeaconNodePeerManager, PeerManager, PeerRpcScoreStore} from "../../../../src/network/peers/index.js"; import {PeersData} from "../../../../src/network/peers/peersData.js"; -import {createNode} from "../../../utils/network.js"; -import {getAttnets, getSyncnets} from "../../../utils/network.js"; -import {generateState} from "../../../utils/state.js"; +import {ReqRespMethod} from "../../../../src/network/reqresp/ReqRespBeaconNode.js"; +import {LocalStatusCache} from "../../../../src/network/statusCache.js"; +import {IAttnetsService} from "../../../../src/network/subnets/index.js"; +import {Clock} from "../../../../src/util/clock.js"; import {waitForEvent} from "../../../utils/events/resolver.js"; import {testLogger} from "../../../utils/logger.js"; +import {createNode} from "../../../utils/network.js"; +import {getAttnets, getSyncnets} from "../../../utils/network.js"; import {getValidPeerId} from "../../../utils/peer.js"; -import {IAttnetsService} from "../../../../src/network/subnets/index.js"; -import {Clock} from "../../../../src/util/clock.js"; -import {LocalStatusCache} from "../../../../src/network/statusCache.js"; +import {generateState} from "../../../utils/state.js"; const logger = testLogger("peerManager"); diff --git a/packages/beacon-node/test/e2e/network/reqresp.test.ts b/packages/beacon-node/test/e2e/network/reqresp.test.ts index b7ab190166e7..854a2a2482ff 100644 --- a/packages/beacon-node/test/e2e/network/reqresp.test.ts +++ b/packages/beacon-node/test/e2e/network/reqresp.test.ts @@ -1,17 +1,17 @@ -import {describe, it, expect, afterEach, beforeEach, vi} from "vitest"; -import {createChainForkConfig, ChainForkConfig} from "@lodestar/config"; +import {ChainForkConfig, createChainForkConfig} from "@lodestar/config"; import {chainConfig} from "@lodestar/config/default"; import {ForkName} from "@lodestar/params"; import {RequestError, RequestErrorCode, ResponseOutgoing} from "@lodestar/reqresp"; -import {altair, phase0, Root, SignedBeaconBlock, ssz} from "@lodestar/types"; +import {Root, SignedBeaconBlock, altair, phase0, ssz} from "@lodestar/types"; import {sleep as _sleep} from "@lodestar/utils"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {Network, ReqRespBeaconNodeOpts} from "../../../src/network/index.js"; +import {GetReqRespHandlerFn, ReqRespMethod} from "../../../src/network/reqresp/types.js"; +import {PeerIdStr} from "../../../src/util/peerId.js"; +import {arrToSource} from "../../unit/network/reqresp/utils.js"; import {expectRejectedWithLodestarError} from "../../utils/errors.js"; import {connect, getPeerIdOf, onPeerConnect} from "../../utils/network.js"; import {getNetworkForTest} from "../../utils/networkWithMockDb.js"; -import {arrToSource} from "../../unit/network/reqresp/utils.js"; -import {GetReqRespHandlerFn, ReqRespMethod} from "../../../src/network/reqresp/types.js"; -import {PeerIdStr} from "../../../src/util/peerId.js"; /* eslint-disable require-yield, @typescript-eslint/naming-convention */ diff --git a/packages/beacon-node/test/e2e/network/reqrespEncode.test.ts b/packages/beacon-node/test/e2e/network/reqrespEncode.test.ts index ae916bdd0ab7..4634870c40fe 100644 --- a/packages/beacon-node/test/e2e/network/reqrespEncode.test.ts +++ b/packages/beacon-node/test/e2e/network/reqrespEncode.test.ts @@ -1,26 +1,26 @@ -import {describe, it, afterEach, expect} from "vitest"; -import all from "it-all"; -import {Libp2p, createLibp2p} from "libp2p"; -import {tcp} from "@libp2p/tcp"; -import {mplex} from "@libp2p/mplex"; -import {Multiaddr, multiaddr} from "@multiformats/multiaddr"; import {noise} from "@chainsafe/libp2p-noise"; -import {ssz} from "@lodestar/types"; +import {mplex} from "@libp2p/mplex"; +import {tcp} from "@libp2p/tcp"; import {createBeaconConfig} from "@lodestar/config"; import {ForkName} from "@lodestar/params"; +import {ssz} from "@lodestar/types"; import {fromHex, sleep, toHex} from "@lodestar/utils"; +import {Multiaddr, multiaddr} from "@multiformats/multiaddr"; +import all from "it-all"; +import {Libp2p, createLibp2p} from "libp2p"; +import {afterEach, describe, expect, it} from "vitest"; +import {ZERO_HASH} from "../../../src/constants/constants.js"; import { NetworkEventBus, PeerRpcScoreStore, ReqRespBeaconNode, ReqRespBeaconNodeModules, } from "../../../src/network/index.js"; -import {PeersData} from "../../../src/network/peers/peersData.js"; -import {ZERO_HASH} from "../../../src/constants/constants.js"; import {MetadataController} from "../../../src/network/metadata.js"; -import {testLogger} from "../../utils/logger.js"; +import {PeersData} from "../../../src/network/peers/peersData.js"; import {GetReqRespHandlerFn} from "../../../src/network/reqresp/types.js"; import {LocalStatusCache} from "../../../src/network/statusCache.js"; +import {testLogger} from "../../utils/logger.js"; /* eslint-disable require-yield */ diff --git a/packages/beacon-node/test/e2e/sync/finalizedSync.test.ts b/packages/beacon-node/test/e2e/sync/finalizedSync.test.ts index ba98f2a1facd..38e3f59adf54 100644 --- a/packages/beacon-node/test/e2e/sync/finalizedSync.test.ts +++ b/packages/beacon-node/test/e2e/sync/finalizedSync.test.ts @@ -1,18 +1,18 @@ -import {describe, it, afterEach, vi} from "vitest"; -import {assert} from "chai"; import {fromHexString} from "@chainsafe/ssz"; +import {routes} from "@lodestar/api"; +import {EventData, EventType} from "@lodestar/api/lib/beacon/routes/events.js"; import {ChainConfig} from "@lodestar/config"; -import {phase0} from "@lodestar/types"; import {TimestampFormatCode} from "@lodestar/logger"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {routes} from "@lodestar/api"; -import {EventData, EventType} from "@lodestar/api/lib/beacon/routes/events.js"; -import {getDevBeaconNode} from "../../utils/node/beacon.js"; -import {waitForEvent} from "../../utils/events/resolver.js"; -import {getAndInitDevValidators} from "../../utils/node/validator.js"; +import {phase0} from "@lodestar/types"; +import {assert} from "chai"; +import {afterEach, describe, it, vi} from "vitest"; import {ChainEvent} from "../../../src/chain/index.js"; +import {waitForEvent} from "../../utils/events/resolver.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../utils/logger.js"; import {connect, onPeerConnect} from "../../utils/network.js"; -import {testLogger, LogLevel, TestLoggerOpts} from "../../utils/logger.js"; +import {getDevBeaconNode} from "../../utils/node/beacon.js"; +import {getAndInitDevValidators} from "../../utils/node/validator.js"; describe("sync / finalized sync", () => { // chain is finalized at slot 32, plus 4 slots for genesis delay => ~72s it should sync pretty fast diff --git a/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts b/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts index 290213d2b1ee..28ec0871b275 100644 --- a/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts +++ b/packages/beacon-node/test/e2e/sync/unknownBlockSync.test.ts @@ -1,21 +1,21 @@ -import {describe, it, afterEach, vi} from "vitest"; import {fromHexString} from "@chainsafe/ssz"; +import {routes} from "@lodestar/api"; +import {EventData, EventType} from "@lodestar/api/lib/beacon/routes/events.js"; import {ChainConfig} from "@lodestar/config"; -import {phase0} from "@lodestar/types"; import {config} from "@lodestar/config/default"; import {TimestampFormatCode} from "@lodestar/logger"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {routes} from "@lodestar/api"; -import {EventData, EventType} from "@lodestar/api/lib/beacon/routes/events.js"; -import {getDevBeaconNode} from "../../utils/node/beacon.js"; -import {waitForEvent} from "../../utils/events/resolver.js"; -import {getAndInitDevValidators} from "../../utils/node/validator.js"; +import {phase0} from "@lodestar/types"; +import {afterEach, describe, it, vi} from "vitest"; +import {BlockSource, getBlockInput} from "../../../src/chain/blocks/types.js"; +import {BlockError, BlockErrorCode} from "../../../src/chain/errors/index.js"; import {ChainEvent} from "../../../src/chain/index.js"; import {NetworkEvent} from "../../../src/network/index.js"; +import {waitForEvent} from "../../utils/events/resolver.js"; +import {LogLevel, TestLoggerOpts, testLogger} from "../../utils/logger.js"; import {connect, onPeerConnect} from "../../utils/network.js"; -import {testLogger, LogLevel, TestLoggerOpts} from "../../utils/logger.js"; -import {BlockError, BlockErrorCode} from "../../../src/chain/errors/index.js"; -import {BlockSource, getBlockInput} from "../../../src/chain/blocks/types.js"; +import {getDevBeaconNode} from "../../utils/node/beacon.js"; +import {getAndInitDevValidators} from "../../utils/node/validator.js"; describe("sync / unknown block sync", () => { vi.setConfig({testTimeout: 40_000}); diff --git a/packages/beacon-node/test/globalSetup.ts b/packages/beacon-node/test/globalSetup.ts index f41a7f249b9b..784633baf2c4 100644 --- a/packages/beacon-node/test/globalSetup.ts +++ b/packages/beacon-node/test/globalSetup.ts @@ -1,4 +1,4 @@ -import {setActivePreset, PresetName} from "@lodestar/params/setPreset"; +import {PresetName, setActivePreset} from "@lodestar/params/setPreset"; export async function setup(): Promise { process.env.NODE_ENV = "test"; diff --git a/packages/beacon-node/test/memory/unfinalizedPubkey2Index.ts b/packages/beacon-node/test/memory/unfinalizedPubkey2Index.ts deleted file mode 100644 index 1a317a7fe9d3..000000000000 --- a/packages/beacon-node/test/memory/unfinalizedPubkey2Index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import crypto from "node:crypto"; -// biome-ignore lint/suspicious/noShadowRestrictedNames: We explicitly want `Map` name to be imported -import {Map} from "immutable"; -import {ValidatorIndex} from "@lodestar/types"; -import {toMemoryEfficientHexStr} from "@lodestar/state-transition/src/cache/pubkeyCache.js"; -import {testRunnerMemory} from "./testRunnerMemory.js"; - -// Results in MacOS Nov 2023 -// -// UnfinalizedPubkey2Index 1000 keys - 274956.5 bytes / instance -// UnfinalizedPubkey2Index 10000 keys - 2591129.3 bytes / instance -// UnfinalizedPubkey2Index 100000 keys - 27261443.4 bytes / instance - -testRunnerMemoryBpi([ - { - id: "UnfinalizedPubkey2Index 1000 keys", - getInstance: () => getRandomMap(1000, () => toMemoryEfficientHexStr(crypto.randomBytes(48))), - }, - { - id: "UnfinalizedPubkey2Index 10000 keys", - getInstance: () => getRandomMap(10000, () => toMemoryEfficientHexStr(crypto.randomBytes(48))), - }, - { - id: "UnfinalizedPubkey2Index 100000 keys", - getInstance: () => getRandomMap(100000, () => toMemoryEfficientHexStr(crypto.randomBytes(48))), - }, -]); - -function getRandomMap(n: number, getKey: (i: number) => string): Map { - const map = Map(); - - return map.withMutations((m) => { - for (let i = 0; i < n; i++) { - m.set(getKey(i), i); - } - }); -} - -/** - * Test bytes per instance in different representations of raw binary data - */ -function testRunnerMemoryBpi(testCases: {getInstance: (bytes: number) => unknown; id: string}[]): void { - const longestId = Math.max(...testCases.map(({id}) => id.length)); - - for (const {id, getInstance} of testCases) { - const bpi = testRunnerMemory({ - getInstance, - convergeFactor: 1 / 100, - sampleEvery: 5, - }); - - console.log(`${id.padEnd(longestId)} - ${bpi.toFixed(1)} bytes / instance`); - } -} diff --git a/packages/beacon-node/test/mocks/clock.ts b/packages/beacon-node/test/mocks/clock.ts index 6f09bd292491..dc06fcd6922a 100644 --- a/packages/beacon-node/test/mocks/clock.ts +++ b/packages/beacon-node/test/mocks/clock.ts @@ -1,7 +1,7 @@ import EventEmitter from "node:events"; -import {Mocked, vi} from "vitest"; import {computeEpochAtSlot} from "@lodestar/state-transition"; import {Epoch, Slot} from "@lodestar/types"; +import {Mocked, vi} from "vitest"; import {IClock} from "../../src/util/clock.js"; /** diff --git a/packages/beacon-node/test/mocks/loggerMock.ts b/packages/beacon-node/test/mocks/loggerMock.ts index ee25ede93475..99984ba87e9f 100644 --- a/packages/beacon-node/test/mocks/loggerMock.ts +++ b/packages/beacon-node/test/mocks/loggerMock.ts @@ -1,5 +1,5 @@ -import {vi, Mocked} from "vitest"; import {Logger} from "@lodestar/logger"; +import {Mocked, vi} from "vitest"; export type MockedLogger = Mocked; diff --git a/packages/beacon-node/test/mocks/mockedBeaconChain.ts b/packages/beacon-node/test/mocks/mockedBeaconChain.ts index a69efc55836c..36d6fb27c53a 100644 --- a/packages/beacon-node/test/mocks/mockedBeaconChain.ts +++ b/packages/beacon-node/test/mocks/mockedBeaconChain.ts @@ -1,22 +1,22 @@ -import {vi, Mocked, Mock} from "vitest"; import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; -import {config as defaultConfig} from "@lodestar/config/default"; import {ChainForkConfig} from "@lodestar/config"; -import {ForkChoice, ProtoBlock, EpochDifference} from "@lodestar/fork-choice"; +import {config as defaultConfig} from "@lodestar/config/default"; +import {EpochDifference, ForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {Logger} from "@lodestar/utils"; +import {Mock, Mocked, vi} from "vitest"; +import {BeaconProposerCache} from "../../src/chain/beaconProposerCache.js"; import {BeaconChain} from "../../src/chain/chain.js"; import {ChainEventEmitter} from "../../src/chain/emitter.js"; -import {ExecutionEngineHttp} from "../../src/execution/engine/index.js"; -import {ExecutionBuilderHttp} from "../../src/execution/builder/http.js"; -import {Eth1ForBlockProduction} from "../../src/eth1/index.js"; -import {OpPool, AggregatedAttestationPool} from "../../src/chain/opPools/index.js"; -import {BeaconProposerCache} from "../../src/chain/beaconProposerCache.js"; import {LightClientServer} from "../../src/chain/lightClient/index.js"; -import {Clock} from "../../src/util/clock.js"; +import {AggregatedAttestationPool, OpPool, SyncContributionAndProofPool} from "../../src/chain/opPools/index.js"; import {QueuedStateRegenerator} from "../../src/chain/regen/index.js"; import {ShufflingCache} from "../../src/chain/shufflingCache.js"; -import {getMockedLogger} from "./loggerMock.js"; +import {Eth1ForBlockProduction} from "../../src/eth1/index.js"; +import {ExecutionBuilderHttp} from "../../src/execution/builder/http.js"; +import {ExecutionEngineHttp} from "../../src/execution/engine/index.js"; +import {Clock} from "../../src/util/clock.js"; import {getMockedClock} from "./clock.js"; +import {getMockedLogger} from "./loggerMock.js"; export type MockedBeaconChain = Mocked & { logger: Mocked; @@ -27,6 +27,7 @@ export type MockedBeaconChain = Mocked & { eth1: Mocked; opPool: Mocked; aggregatedAttestationPool: Mocked; + syncContributionAndProofPool: Mocked; beaconProposerCache: Mocked; shufflingCache: Mocked; regen: Mocked; @@ -94,10 +95,17 @@ vi.mock("../../src/chain/opPools/index.js", async (importActual) => { }; }); + const SyncContributionAndProofPool = vi.fn().mockImplementation(() => { + return { + getAggregate: vi.fn(), + }; + }); + return { ...mod, OpPool, AggregatedAttestationPool, + SyncContributionAndProofPool, }; }); @@ -124,6 +132,7 @@ vi.mock("../../src/chain/chain.js", async (importActual) => { eth1: new Eth1ForBlockProduction(), opPool: new OpPool(), aggregatedAttestationPool: new AggregatedAttestationPool(config), + syncContributionAndProofPool: new SyncContributionAndProofPool(), // @ts-expect-error beaconProposerCache: new BeaconProposerCache(), shufflingCache: new ShufflingCache(), diff --git a/packages/beacon-node/test/mocks/mockedBeaconDb.ts b/packages/beacon-node/test/mocks/mockedBeaconDb.ts index eb209c9b44fb..87404a8965a6 100644 --- a/packages/beacon-node/test/mocks/mockedBeaconDb.ts +++ b/packages/beacon-node/test/mocks/mockedBeaconDb.ts @@ -1,20 +1,20 @@ -import {vi, Mocked} from "vitest"; import {config as minimalConfig} from "@lodestar/config/default"; +import {Mocked, vi} from "vitest"; +import {BeaconDb} from "../../src/db/index.js"; import { AttesterSlashingRepository, + BLSToExecutionChangeRepository, + BlobSidecarsArchiveRepository, + BlobSidecarsRepository, BlockArchiveRepository, BlockRepository, - DepositEventRepository, DepositDataRootRepository, + DepositEventRepository, Eth1DataRepository, ProposerSlashingRepository, StateArchiveRepository, VoluntaryExitRepository, - BLSToExecutionChangeRepository, - BlobSidecarsRepository, - BlobSidecarsArchiveRepository, } from "../../src/db/repositories/index.js"; -import {BeaconDb} from "../../src/db/index.js"; export type MockedBeaconDb = Mocked & { block: Mocked; diff --git a/packages/beacon-node/test/mocks/mockedNetwork.ts b/packages/beacon-node/test/mocks/mockedNetwork.ts index 9258acc9bc1b..27b9c3deaf79 100644 --- a/packages/beacon-node/test/mocks/mockedNetwork.ts +++ b/packages/beacon-node/test/mocks/mockedNetwork.ts @@ -1,5 +1,5 @@ -import {vi, Mocked} from "vitest"; -import {Network, INetwork} from "../../src/network/index.js"; +import {Mocked, vi} from "vitest"; +import {INetwork, Network} from "../../src/network/index.js"; vi.mock("../../src/network/index.js", async (importActual) => { const mod = await importActual(); diff --git a/packages/beacon-node/test/mocks/regenMocks.ts b/packages/beacon-node/test/mocks/regenMocks.ts index 39f7fa382760..f0be21989e83 100644 --- a/packages/beacon-node/test/mocks/regenMocks.ts +++ b/packages/beacon-node/test/mocks/regenMocks.ts @@ -1,4 +1,4 @@ -import {vi, Mocked} from "vitest"; +import {Mocked, vi} from "vitest"; import {QueuedStateRegenerator} from "../../src/chain/regen/index.js"; export type MockedQueuedStateRegenerator = Mocked; diff --git a/packages/beacon-node/test/mocks/shufflingMock.ts b/packages/beacon-node/test/mocks/shufflingMock.ts index 76482f760872..e13d8d6dce5d 100644 --- a/packages/beacon-node/test/mocks/shufflingMock.ts +++ b/packages/beacon-node/test/mocks/shufflingMock.ts @@ -1,4 +1,4 @@ -import {vi, Mocked} from "vitest"; +import {Mocked, vi} from "vitest"; import {ShufflingCache} from "../../src/chain/shufflingCache.js"; export type MockedShufflingCache = Mocked; diff --git a/packages/beacon-node/test/perf/bls/bls.test.ts b/packages/beacon-node/test/perf/bls/bls.test.ts index 9f1f90a4d879..1c6cde5e20ac 100644 --- a/packages/beacon-node/test/perf/bls/bls.test.ts +++ b/packages/beacon-node/test/perf/bls/bls.test.ts @@ -1,5 +1,4 @@ import crypto from "node:crypto"; -import {itBench} from "@dapplion/benchmark"; import { PublicKey, SecretKey, @@ -9,6 +8,7 @@ import { verify, verifyMultipleAggregateSignatures, } from "@chainsafe/blst"; +import {itBench} from "@dapplion/benchmark"; import {linspace} from "../../../src/util/numpy.js"; describe("BLS ops", () => { diff --git a/packages/beacon-node/test/perf/chain/opPools/aggregatedAttestationPool.test.ts b/packages/beacon-node/test/perf/chain/opPools/aggregatedAttestationPool.test.ts index 89bd76f34eb3..28c1f198da28 100644 --- a/packages/beacon-node/test/perf/chain/opPools/aggregatedAttestationPool.test.ts +++ b/packages/beacon-node/test/perf/chain/opPools/aggregatedAttestationPool.test.ts @@ -1,5 +1,7 @@ -import {itBench} from "@dapplion/benchmark"; import {BitArray, toHexString} from "@chainsafe/ssz"; +import {itBench} from "@dapplion/benchmark"; +import {DataAvailabilityStatus, ExecutionStatus, ForkChoice, IForkChoiceStore, ProtoArray} from "@lodestar/fork-choice"; +import {HISTORICAL_ROOTS_LIMIT, SLOTS_PER_EPOCH} from "@lodestar/params"; import { CachedBeaconStateAltair, computeAnchorCheckpoint, @@ -8,8 +10,6 @@ import { getBlockRootAtSlot, newFilledArray, } from "@lodestar/state-transition"; -import {HISTORICAL_ROOTS_LIMIT, SLOTS_PER_EPOCH} from "@lodestar/params"; -import {ExecutionStatus, ForkChoice, IForkChoiceStore, ProtoArray, DataAvailabilityStatus} from "@lodestar/fork-choice"; import {ssz} from "@lodestar/types"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; diff --git a/packages/beacon-node/test/perf/chain/opPools/opPool.test.ts b/packages/beacon-node/test/perf/chain/opPools/opPool.test.ts index 9d518c03eec9..d685ec36c6b7 100644 --- a/packages/beacon-node/test/perf/chain/opPools/opPool.test.ts +++ b/packages/beacon-node/test/perf/chain/opPools/opPool.test.ts @@ -8,6 +8,7 @@ import { import {CachedBeaconStateAltair} from "@lodestar/state-transition"; import {ssz} from "@lodestar/types"; import {generatePerfTestCachedStateAltair} from "../../../../../state-transition/test/perf/util.js"; +import {BlockType} from "../../../../src/chain/interface.js"; import {OpPool} from "../../../../src/chain/opPools/opPool.js"; import {generateBlsToExecutionChanges} from "../../../fixtures/capella.js"; import { @@ -15,7 +16,6 @@ import { generateSignedBeaconBlockHeader, generateVoluntaryExits, } from "../../../fixtures/phase0.js"; -import {BlockType} from "../../../../src/chain/interface.js"; describe("opPool", () => { let originalState: CachedBeaconStateAltair; diff --git a/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts b/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts index c08cf64fc974..6d411ca09cd5 100644 --- a/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts +++ b/packages/beacon-node/test/perf/chain/produceBlock/produceBlockBody.test.ts @@ -3,14 +3,14 @@ import {itBench} from "@dapplion/benchmark"; import {config} from "@lodestar/config/default"; import {LevelDbController} from "@lodestar/db"; import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY} from "@lodestar/params"; -import {defaultOptions as defaultValidatorOptions} from "@lodestar/validator"; import {CachedBeaconStateAltair} from "@lodestar/state-transition"; +import {defaultOptions as defaultValidatorOptions} from "@lodestar/validator"; import {generatePerfTestCachedStateAltair} from "../../../../../state-transition/test/perf/util.js"; import {BeaconChain} from "../../../../src/chain/index.js"; import {BlockType, produceBlockBody} from "../../../../src/chain/produceBlock/produceBlockBody.js"; import {Eth1ForBlockProductionDisabled} from "../../../../src/eth1/index.js"; import {ExecutionEngineDisabled} from "../../../../src/execution/engine/index.js"; -import {StateArchiveMode, BeaconDb} from "../../../../src/index.js"; +import {BeaconDb, StateArchiveMode} from "../../../../src/index.js"; import {testLogger} from "../../../utils/logger.js"; const logger = testLogger(); diff --git a/packages/beacon-node/test/perf/chain/seenCache/seenAggregateAndProof.test.ts b/packages/beacon-node/test/perf/chain/seenCache/seenAggregateAndProof.test.ts index 49c3123c14dd..b119fccdd562 100644 --- a/packages/beacon-node/test/perf/chain/seenCache/seenAggregateAndProof.test.ts +++ b/packages/beacon-node/test/perf/chain/seenCache/seenAggregateAndProof.test.ts @@ -1,5 +1,5 @@ -import {itBench} from "@dapplion/benchmark"; import {BitArray} from "@chainsafe/ssz"; +import {itBench} from "@dapplion/benchmark"; import {TARGET_AGGREGATORS_PER_COMMITTEE} from "@lodestar/params"; import {SeenAggregatedAttestations} from "../../../../src/chain/seenCache/seenAggregateAndProof.js"; diff --git a/packages/beacon-node/test/perf/chain/stateCache/inMemoryCheckpointsCache.test.ts b/packages/beacon-node/test/perf/chain/stateCache/inMemoryCheckpointsCache.test.ts index 17a46b09af8d..9f3db45cb827 100644 --- a/packages/beacon-node/test/perf/chain/stateCache/inMemoryCheckpointsCache.test.ts +++ b/packages/beacon-node/test/perf/chain/stateCache/inMemoryCheckpointsCache.test.ts @@ -1,8 +1,8 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; -import {ssz, phase0} from "@lodestar/types"; -import {generateCachedState} from "../../../utils/state.js"; +import {phase0, ssz} from "@lodestar/types"; import {InMemoryCheckpointStateCache, toCheckpointHex} from "../../../../src/chain/stateCache/index.js"; +import {generateCachedState} from "../../../utils/state.js"; describe("InMemoryCheckpointStateCache perf tests", () => { setBenchOpts({noThreshold: true}); diff --git a/packages/beacon-node/test/perf/chain/stateCache/updateUnfinalizedPubkeys.test.ts b/packages/beacon-node/test/perf/chain/stateCache/updateUnfinalizedPubkeys.test.ts deleted file mode 100644 index a4bdbe9710cb..000000000000 --- a/packages/beacon-node/test/perf/chain/stateCache/updateUnfinalizedPubkeys.test.ts +++ /dev/null @@ -1,114 +0,0 @@ -import {itBench, setBenchOpts} from "@dapplion/benchmark"; -import {Map as ImmutableMap} from "immutable"; -import {toBufferBE} from "bigint-buffer"; -import {digest} from "@chainsafe/as-sha256"; -import {SecretKey} from "@chainsafe/blst"; -import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; -import {ValidatorIndex, ssz} from "@lodestar/types"; -import {type CachedBeaconStateAllForks, toMemoryEfficientHexStr} from "@lodestar/state-transition"; -import {bytesToBigInt, intToBytes} from "@lodestar/utils"; -import {InMemoryCheckpointStateCache, BlockStateCacheImpl} from "../../../../src/chain/stateCache/index.js"; -import {BlockStateCache} from "../../../../src/chain/stateCache/types.js"; -import {generateCachedElectraState} from "../../../utils/state.js"; - -// Benchmark date from Mon Nov 21 2023 - Intel Core i7-9750H @ 2.60Ghz -// ✔ updateUnfinalizedPubkeys - updating 10 pubkeys 1444.173 ops/s 692.4380 us/op - 1057 runs 6.03 s -// ✔ updateUnfinalizedPubkeys - updating 100 pubkeys 189.5965 ops/s 5.274358 ms/op - 57 runs 1.15 s -// ✔ updateUnfinalizedPubkeys - updating 1000 pubkeys 12.90495 ops/s 77.48967 ms/op - 13 runs 1.62 s -describe("updateUnfinalizedPubkeys perf tests", () => { - setBenchOpts({noThreshold: true}); - - const numPubkeysToBeFinalizedCases = [10, 100, 1000]; - const numCheckpointStateCache = 8; - const numStateCache = 3 * 32; - - let checkpointStateCache: InMemoryCheckpointStateCache; - let stateCache: BlockStateCache; - - const unfinalizedPubkey2Index = generatePubkey2Index(0, Math.max.apply(null, numPubkeysToBeFinalizedCases)); - const baseState = generateCachedElectraState(); - - for (const numPubkeysToBeFinalized of numPubkeysToBeFinalizedCases) { - itBench({ - id: `updateUnfinalizedPubkeys - updating ${numPubkeysToBeFinalized} pubkeys`, - beforeEach: async () => { - baseState.epochCtx.unfinalizedPubkey2index = ImmutableMap(unfinalizedPubkey2Index); - baseState.epochCtx.pubkey2index = new PubkeyIndexMap(); - baseState.epochCtx.index2pubkey = []; - - checkpointStateCache = new InMemoryCheckpointStateCache({}); - stateCache = new BlockStateCacheImpl({}); - - for (let i = 0; i < numCheckpointStateCache; i++) { - const clonedState = baseState.clone(); - const checkpoint = ssz.phase0.Checkpoint.defaultValue(); - - clonedState.slot = i; - checkpoint.epoch = i; // Assigning arbitrary non-duplicate values to ensure checkpointStateCache correctly saves all the states - - checkpointStateCache.add(checkpoint, clonedState); - } - - for (let i = 0; i < numStateCache; i++) { - const clonedState = baseState.clone(); - clonedState.slot = i; - stateCache.add(clonedState); - } - }, - fn: async () => { - const newFinalizedValidators = baseState.epochCtx.unfinalizedPubkey2index.filter( - (index, _pubkey) => index < numPubkeysToBeFinalized - ); - - const states = stateCache.getStates(); - const cpStates = checkpointStateCache.getStates(); - - const firstState = states.next().value as CachedBeaconStateAllForks; - firstState.epochCtx.addFinalizedPubkeys(newFinalizedValidators); - - const pubkeysToDelete = Array.from(newFinalizedValidators.keys()); - - firstState.epochCtx.deleteUnfinalizedPubkeys(pubkeysToDelete); - - for (const s of states) { - s.epochCtx.deleteUnfinalizedPubkeys(pubkeysToDelete); - } - - for (const s of cpStates) { - s.epochCtx.deleteUnfinalizedPubkeys(pubkeysToDelete); - } - }, - }); - } - - type PubkeyHex = string; - - function generatePubkey2Index(startIndex: number, endIndex: number): Map { - const pubkey2Index = new Map(); - const pubkeys = generatePubkeys(endIndex - startIndex); - - for (let i = startIndex; i < endIndex; i++) { - pubkey2Index.set(toMemoryEfficientHexStr(pubkeys[i]), i); - } - - return pubkey2Index; - } - - function generatePubkeys(validatorCount: number): Uint8Array[] { - const keys = []; - - for (let i = 0; i < validatorCount; i++) { - const sk = generatePrivateKey(i); - const pk = sk.toPublicKey().toBytes(); - keys.push(pk); - } - - return keys; - } - - function generatePrivateKey(index: number): SecretKey { - const secretKeyBytes = toBufferBE(bytesToBigInt(digest(intToBytes(index, 32))) % BigInt("38581184513"), 32); - const secret: SecretKey = SecretKey.fromBytes(secretKeyBytes); - return secret; - } -}); diff --git a/packages/beacon-node/test/perf/chain/validation/attestation.test.ts b/packages/beacon-node/test/perf/chain/validation/attestation.test.ts index 696b6bdb1871..4814c59cce9a 100644 --- a/packages/beacon-node/test/perf/chain/validation/attestation.test.ts +++ b/packages/beacon-node/test/perf/chain/validation/attestation.test.ts @@ -1,10 +1,10 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; -import {expect} from "chai"; import {ssz} from "@lodestar/types"; +import {expect} from "chai"; import {generateTestCachedBeaconStateOnlyValidators} from "../../../../../state-transition/test/perf/util.js"; import {validateGossipAttestationsSameAttData} from "../../../../src/chain/validation/index.js"; -import {getAttestationValidData} from "../../../utils/validationData/attestation.js"; import {getAttDataFromAttestationSerialized} from "../../../../src/util/sszBytes.js"; +import {getAttestationValidData} from "../../../utils/validationData/attestation.js"; describe("validate gossip attestation", () => { setBenchOpts({ diff --git a/packages/beacon-node/test/perf/chain/verifyImportBlocks.test.ts b/packages/beacon-node/test/perf/chain/verifyImportBlocks.test.ts index 6f1cf2ef3da6..35165aa3c38f 100644 --- a/packages/beacon-node/test/perf/chain/verifyImportBlocks.test.ts +++ b/packages/beacon-node/test/perf/chain/verifyImportBlocks.test.ts @@ -1,19 +1,19 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {config} from "@lodestar/config/default"; -import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY, SLOTS_PER_EPOCH} from "@lodestar/params"; import {LevelDbController} from "@lodestar/db"; +import {SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY, SLOTS_PER_EPOCH} from "@lodestar/params"; import {sleep} from "@lodestar/utils"; import {defaultOptions as defaultValidatorOptions} from "@lodestar/validator"; import {rangeSyncTest} from "../../../../state-transition/test/perf/params.js"; -import {getNetworkCachedState, getNetworkCachedBlock} from "../../../../state-transition/test/utils/testFileCache.js"; import {beforeValue} from "../../../../state-transition/test/utils/beforeValueMocha.js"; +import {getNetworkCachedBlock, getNetworkCachedState} from "../../../../state-transition/test/utils/testFileCache.js"; +import {AttestationImportOpt, BlockSource, getBlockInput} from "../../../src/chain/blocks/types.js"; import {BeaconChain} from "../../../src/chain/index.js"; -import {ExecutionEngineDisabled} from "../../../src/execution/engine/index.js"; import {Eth1ForBlockProductionDisabled} from "../../../src/eth1/index.js"; -import {testLogger} from "../../utils/logger.js"; +import {ExecutionEngineDisabled} from "../../../src/execution/engine/index.js"; +import {BeaconDb, StateArchiveMode} from "../../../src/index.js"; import {linspace} from "../../../src/util/numpy.js"; -import {StateArchiveMode, BeaconDb} from "../../../src/index.js"; -import {getBlockInput, AttestationImportOpt, BlockSource} from "../../../src/chain/blocks/types.js"; +import {testLogger} from "../../utils/logger.js"; // Define this params in `packages/state-transition/test/perf/params.ts` // to trigger Github actions CI cache diff --git a/packages/beacon-node/test/perf/eth1/pickEth1Vote.test.ts b/packages/beacon-node/test/perf/eth1/pickEth1Vote.test.ts index 20efeefe0923..dfc5fb560b27 100644 --- a/packages/beacon-node/test/perf/eth1/pickEth1Vote.test.ts +++ b/packages/beacon-node/test/perf/eth1/pickEth1Vote.test.ts @@ -1,7 +1,7 @@ -import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {ContainerType, ListCompositeType} from "@chainsafe/ssz"; +import {itBench, setBenchOpts} from "@dapplion/benchmark"; +import {BeaconStateAllForks, newFilledArray} from "@lodestar/state-transition"; import {phase0, ssz} from "@lodestar/types"; -import {newFilledArray, BeaconStateAllForks} from "@lodestar/state-transition"; import {fastSerializeEth1Data, pickEth1Vote} from "../../../src/eth1/utils/eth1Vote.js"; describe("eth1 / pickEth1Vote", () => { diff --git a/packages/beacon-node/test/perf/misc/bytesHex.test.ts b/packages/beacon-node/test/perf/misc/bytesHex.test.ts index aa4443a65a61..bb5e2b252960 100644 --- a/packages/beacon-node/test/perf/misc/bytesHex.test.ts +++ b/packages/beacon-node/test/perf/misc/bytesHex.test.ts @@ -1,6 +1,6 @@ import crypto from "node:crypto"; -import {itBench} from "@dapplion/benchmark"; import {toHexString} from "@chainsafe/ssz"; +import {itBench} from "@dapplion/benchmark"; // Results in Linux Dec 2021 // diff --git a/packages/beacon-node/test/perf/network/gossip/fastMsgIdFn.test.ts b/packages/beacon-node/test/perf/network/gossip/fastMsgIdFn.test.ts index 4daeb64f5d79..3b31e38655db 100644 --- a/packages/beacon-node/test/perf/network/gossip/fastMsgIdFn.test.ts +++ b/packages/beacon-node/test/perf/network/gossip/fastMsgIdFn.test.ts @@ -1,7 +1,7 @@ import {randomBytes} from "node:crypto"; -import xxhashFactory from "xxhash-wasm"; -import {itBench} from "@dapplion/benchmark"; import {digest} from "@chainsafe/as-sha256"; +import {itBench} from "@dapplion/benchmark"; +import xxhashFactory from "xxhash-wasm"; const hasher = await xxhashFactory(); diff --git a/packages/beacon-node/test/perf/network/noise/sendData.test.ts b/packages/beacon-node/test/perf/network/noise/sendData.test.ts index 35538a417adf..ee4d734fd5cb 100644 --- a/packages/beacon-node/test/perf/network/noise/sendData.test.ts +++ b/packages/beacon-node/test/perf/network/noise/sendData.test.ts @@ -1,10 +1,10 @@ +import {noise} from "@chainsafe/libp2p-noise"; import {itBench} from "@dapplion/benchmark"; -import {duplexPair} from "it-pair/duplex"; +import {defaultLogger} from "@libp2p/logger"; import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; -import {pipe} from "it-pipe"; import drain from "it-drain"; -import {defaultLogger} from "@libp2p/logger"; -import {noise} from "@chainsafe/libp2p-noise"; +import {duplexPair} from "it-pair/duplex"; +import {pipe} from "it-pipe"; import {Uint8ArrayList} from "uint8arraylist"; describe("network / noise / sendData", () => { diff --git a/packages/beacon-node/test/perf/network/peers/enrSubnetsDeserialize.test.ts b/packages/beacon-node/test/perf/network/peers/enrSubnetsDeserialize.test.ts index 2507c43bcc9c..ffe22cf5bac5 100644 --- a/packages/beacon-node/test/perf/network/peers/enrSubnetsDeserialize.test.ts +++ b/packages/beacon-node/test/perf/network/peers/enrSubnetsDeserialize.test.ts @@ -1,7 +1,7 @@ import {itBench} from "@dapplion/benchmark"; -import {expect} from "chai"; -import {SYNC_COMMITTEE_SUBNET_COUNT, ATTESTATION_SUBNET_COUNT} from "@lodestar/params"; +import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {ssz} from "@lodestar/types"; +import {expect} from "chai"; import {deserializeEnrSubnets} from "../../../../src/network/peers/utils/enrSubnetsDeserialize.js"; /** diff --git a/packages/beacon-node/test/perf/network/peers/util/prioritizePeers.test.ts b/packages/beacon-node/test/perf/network/peers/util/prioritizePeers.test.ts index d5a6b4e9cb25..a8d6365be691 100644 --- a/packages/beacon-node/test/perf/network/peers/util/prioritizePeers.test.ts +++ b/packages/beacon-node/test/perf/network/peers/util/prioritizePeers.test.ts @@ -4,7 +4,7 @@ import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; import {ATTESTATION_SUBNET_COUNT, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {altair, phase0} from "@lodestar/types"; import {defaultNetworkOptions} from "../../../../../src/network/options.js"; -import {prioritizePeers, RequestedSubnet} from "../../../../../src/network/peers/utils/index.js"; +import {RequestedSubnet, prioritizePeers} from "../../../../../src/network/peers/utils/index.js"; import {getAttnets, getSyncnets} from "../../../../utils/network.js"; describe("prioritizePeers", () => { diff --git a/packages/beacon-node/test/perf/util/bitArray.test.ts b/packages/beacon-node/test/perf/util/bitArray.test.ts index fe421a8f9bd8..fae525def3c4 100644 --- a/packages/beacon-node/test/perf/util/bitArray.test.ts +++ b/packages/beacon-node/test/perf/util/bitArray.test.ts @@ -1,6 +1,6 @@ import crypto from "node:crypto"; -import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {BitArray} from "@chainsafe/ssz"; +import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {intersectUint8Arrays} from "../../../src/util/bitArray.js"; /** diff --git a/packages/beacon-node/test/setupPreset.ts b/packages/beacon-node/test/setupPreset.ts index 968c6e12c668..7d64d1336ed5 100644 --- a/packages/beacon-node/test/setupPreset.ts +++ b/packages/beacon-node/test/setupPreset.ts @@ -1,4 +1,4 @@ -import {setActivePreset, PresetName} from "@lodestar/params/setPreset"; +import {PresetName, setActivePreset} from "@lodestar/params/setPreset"; // Set minimal if (process.env.LODESTAR_PRESET === undefined) { process.env.LODESTAR_PRESET = "minimal"; diff --git a/packages/beacon-node/test/sim/electra-interop.test.ts b/packages/beacon-node/test/sim/electra-interop.test.ts index 20fedd3d4b0f..148f210f7f65 100644 --- a/packages/beacon-node/test/sim/electra-interop.test.ts +++ b/packages/beacon-node/test/sim/electra-interop.test.ts @@ -1,29 +1,29 @@ -import fs from "node:fs"; import assert from "node:assert"; -import {describe, it, vi, afterAll, afterEach} from "vitest"; +import fs from "node:fs"; +import {afterAll, afterEach, describe, it, vi} from "vitest"; -import {LogLevel, sleep} from "@lodestar/utils"; import {ForkName, SLOTS_PER_EPOCH, UNSET_DEPOSIT_REQUESTS_START_INDEX} from "@lodestar/params"; -import {electra, Epoch, Slot} from "@lodestar/types"; +import {Epoch, Slot, electra} from "@lodestar/types"; +import {LogLevel, sleep} from "@lodestar/utils"; import {ValidatorProposerConfig} from "@lodestar/validator"; import {ChainConfig} from "@lodestar/config"; import {TimestampFormatCode} from "@lodestar/logger"; import {CachedBeaconStateElectra} from "@lodestar/state-transition"; -import {initializeExecutionEngine} from "../../src/execution/index.js"; import {ExecutionPayloadStatus, PayloadAttributes} from "../../src/execution/engine/interface.js"; +import {initializeExecutionEngine} from "../../src/execution/index.js"; -import {testLogger, TestLoggerOpts} from "../utils/logger.js"; -import {runEL, ELStartMode, ELClient, sendRawTransactionBig} from "../utils/runEl.js"; +import {bytesToData} from "../../lib/eth1/provider/utils.js"; +import {BeaconRestApiServerOpts} from "../../src/api/index.js"; +import {dataToBytes} from "../../src/eth1/provider/utils.js"; import {defaultExecutionEngineHttpOpts} from "../../src/execution/engine/http.js"; +import {BeaconNode} from "../../src/index.js"; +import {ClockEvent} from "../../src/util/clock.js"; +import {TestLoggerOpts, testLogger} from "../utils/logger.js"; import {getDevBeaconNode} from "../utils/node/beacon.js"; -import {BeaconRestApiServerOpts} from "../../src/api/index.js"; import {simTestInfoTracker} from "../utils/node/simTest.js"; import {getAndInitDevValidators} from "../utils/node/validator.js"; -import {ClockEvent} from "../../src/util/clock.js"; -import {dataToBytes} from "../../src/eth1/provider/utils.js"; -import {bytesToData} from "../../lib/eth1/provider/utils.js"; -import {BeaconNode} from "../../src/index.js"; +import {ELClient, ELStartMode, runEL, sendRawTransactionBig} from "../utils/runEl.js"; import {logFilesDir} from "./params.js"; import {shell} from "./shell.js"; @@ -375,17 +375,8 @@ describe("executionEngine / ExecutionEngineHttp", () => { if (headState.validators.length !== 33 || headState.balances.length !== 33) { throw Error("New validator is not reflected in the beacon state at slot 5"); } - if (epochCtx.index2pubkey.length !== 32 || epochCtx.pubkey2index.size !== 32) { - throw Error("Finalized cache is modified."); - } - if (epochCtx.unfinalizedPubkey2index.size !== 1) { - throw Error( - `Unfinalized cache is missing the expected validator. Size: ${epochCtx.unfinalizedPubkey2index.size}` - ); - } - // validator count at epoch 1 should be empty at this point since no epoch transition has happened. - if (epochCtx.getValidatorCountAtEpoch(1) !== undefined) { - throw Error("Historical validator lengths is modified"); + if (epochCtx.index2pubkey.length !== 33 || epochCtx.pubkey2index.size !== 33) { + throw Error("Pubkey cache is not updated"); } await new Promise((resolve, _reject) => { @@ -412,23 +403,7 @@ describe("executionEngine / ExecutionEngineHttp", () => { throw Error("New validator is not reflected in the beacon state."); } if (epochCtx.index2pubkey.length !== 33 || epochCtx.pubkey2index.size !== 33) { - throw Error("New validator is not in finalized cache"); - } - if (!epochCtx.unfinalizedPubkey2index.isEmpty()) { - throw Error("Unfinalized cache still contains new validator"); - } - // After 4 epochs, headState's finalized cp epoch should be 2 - // epochCtx should only have validator count for epoch 3 and 4. - if (epochCtx.getValidatorCountAtEpoch(4) === undefined || epochCtx.getValidatorCountAtEpoch(3) === undefined) { - throw Error("Missing historical validator length for epoch 3 or 4"); - } - - if (epochCtx.getValidatorCountAtEpoch(4) !== 33 || epochCtx.getValidatorCountAtEpoch(3) !== 33) { - throw Error("Incorrect historical validator length for epoch 3 or 4"); - } - - if (epochCtx.getValidatorCountAtEpoch(2) !== undefined || epochCtx.getValidatorCountAtEpoch(1) !== undefined) { - throw Error("Historical validator length for epoch 1 or 2 is not dropped properly"); + throw Error("New validator is not in pubkey cache"); } if (headState.depositRequestsStartIndex === UNSET_DEPOSIT_REQUESTS_START_INDEX) { diff --git a/packages/beacon-node/test/sim/mergemock.test.ts b/packages/beacon-node/test/sim/mergemock.test.ts index 64020b070e11..230856291f64 100644 --- a/packages/beacon-node/test/sim/mergemock.test.ts +++ b/packages/beacon-node/test/sim/mergemock.test.ts @@ -1,23 +1,23 @@ import fs from "node:fs"; -import {describe, it, afterAll, afterEach, vi} from "vitest"; import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {LogLevel, sleep} from "@lodestar/utils"; +import {routes} from "@lodestar/api"; +import {ChainConfig} from "@lodestar/config"; import {TimestampFormatCode} from "@lodestar/logger"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {ChainConfig} from "@lodestar/config"; import {Epoch, SignedBeaconBlock, bellatrix} from "@lodestar/types"; +import {LogLevel, sleep} from "@lodestar/utils"; import {ValidatorProposerConfig} from "@lodestar/validator"; -import {routes} from "@lodestar/api"; +import {afterAll, afterEach, describe, it, vi} from "vitest"; +import {BeaconRestApiServerOpts} from "../../src/api/index.js"; +import {ZERO_HASH} from "../../src/constants/index.js"; +import {Eth1Provider} from "../../src/index.js"; import {ClockEvent} from "../../src/util/clock.js"; -import {testLogger, TestLoggerOpts} from "../utils/logger.js"; +import {TestLoggerOpts, testLogger} from "../utils/logger.js"; import {getDevBeaconNode} from "../utils/node/beacon.js"; -import {BeaconRestApiServerOpts} from "../../src/api/index.js"; import {simTestInfoTracker} from "../utils/node/simTest.js"; import {getAndInitDevValidators} from "../utils/node/validator.js"; -import {Eth1Provider} from "../../src/index.js"; -import {ZERO_HASH} from "../../src/constants/index.js"; -import {runEL, ELStartMode, ELClient} from "../utils/runEl.js"; +import {ELClient, ELStartMode, runEL} from "../utils/runEl.js"; import {logFilesDir} from "./params.js"; import {shell} from "./shell.js"; diff --git a/packages/beacon-node/test/spec/bls/bls.ts b/packages/beacon-node/test/spec/bls/bls.ts index 76c511215b61..61c86e69b47e 100644 --- a/packages/beacon-node/test/spec/bls/bls.ts +++ b/packages/beacon-node/test/spec/bls/bls.ts @@ -2,11 +2,11 @@ import { PublicKey, SecretKey, Signature, + verify as _verify, aggregateSignatures, aggregateVerify, fastAggregateVerify, verifyMultipleAggregateSignatures, - verify as _verify, } from "@chainsafe/blst"; import {fromHexString} from "@chainsafe/ssz"; diff --git a/packages/beacon-node/test/spec/bls/index.test.ts b/packages/beacon-node/test/spec/bls/index.test.ts index 32baa00d9fbc..cf1da723698f 100644 --- a/packages/beacon-node/test/spec/bls/index.test.ts +++ b/packages/beacon-node/test/spec/bls/index.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; import jsyaml from "js-yaml"; -import {expect, describe, it} from "vitest"; +import {describe, expect, it} from "vitest"; import {blsSpecTests} from "../specTestVersioning.js"; import {readdirSyncSpec} from "../utils/specTestIterator.js"; import {testFnByType} from "./bls.js"; diff --git a/packages/beacon-node/test/spec/downloadTests.ts b/packages/beacon-node/test/spec/downloadTests.ts index 57efd3ca2183..7790e52ea9e1 100644 --- a/packages/beacon-node/test/spec/downloadTests.ts +++ b/packages/beacon-node/test/spec/downloadTests.ts @@ -1,5 +1,5 @@ import {downloadTests} from "@lodestar/spec-test-util/downloadTests"; -import {ethereumConsensusSpecsTests, blsSpecTests} from "./specTestVersioning.js"; +import {blsSpecTests, ethereumConsensusSpecsTests} from "./specTestVersioning.js"; /* eslint-disable no-console */ diff --git a/packages/beacon-node/test/spec/general/bls.ts b/packages/beacon-node/test/spec/general/bls.ts index 128b5b4f5613..7d4a94481025 100644 --- a/packages/beacon-node/test/spec/general/bls.ts +++ b/packages/beacon-node/test/spec/general/bls.ts @@ -1,14 +1,14 @@ -import {fromHexString} from "@chainsafe/ssz"; import { + aggregateVerify as BLSAggregateVerify, + fastAggregateVerify as BLSFastAggregateVerify, PublicKey, SecretKey, Signature, + verify as _verify, aggregateSerializedPublicKeys, aggregateSignatures, - aggregateVerify as BLSAggregateVerify, - fastAggregateVerify as BLSFastAggregateVerify, - verify as _verify, } from "@chainsafe/blst"; +import {fromHexString} from "@chainsafe/ssz"; import {InputType} from "@lodestar/spec-test-util"; import {TestRunnerFn} from "../utils/types.js"; diff --git a/packages/beacon-node/test/spec/general/index.test.ts b/packages/beacon-node/test/spec/general/index.test.ts index 063f128c3142..c539061d217e 100644 --- a/packages/beacon-node/test/spec/general/index.test.ts +++ b/packages/beacon-node/test/spec/general/index.test.ts @@ -1,7 +1,7 @@ import path from "node:path"; -import {RunnerType} from "../utils/types.js"; -import {SkipOpts, specTestIterator} from "../utils/specTestIterator.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {SkipOpts, specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType} from "../utils/types.js"; import {blsTestRunner} from "./bls.js"; import {sszGeneric} from "./ssz_generic.js"; diff --git a/packages/beacon-node/test/spec/general/ssz_generic.ts b/packages/beacon-node/test/spec/general/ssz_generic.ts index 64e6b4455941..6cfb7686c9e7 100644 --- a/packages/beacon-node/test/spec/general/ssz_generic.ts +++ b/packages/beacon-node/test/spec/general/ssz_generic.ts @@ -1,9 +1,9 @@ import fs from "node:fs"; import path from "node:path"; import {expect, it} from "vitest"; -import {TestRunnerCustom} from "../utils/types.js"; -import {parseSszGenericInvalidTestcase, parseSszGenericValidTestcase} from "../utils/sszTestCaseParser.js"; import {runValidSszTest} from "../utils/runValidSszTest.js"; +import {parseSszGenericInvalidTestcase, parseSszGenericValidTestcase} from "../utils/sszTestCaseParser.js"; +import {TestRunnerCustom} from "../utils/types.js"; import {getTestType} from "./ssz_generic_types.js"; // Mapping of sszGeneric() fn arguments to the path in spec tests diff --git a/packages/beacon-node/test/spec/general/ssz_generic_types.ts b/packages/beacon-node/test/spec/general/ssz_generic_types.ts index fe19f08149b4..2386f770fe60 100644 --- a/packages/beacon-node/test/spec/general/ssz_generic_types.ts +++ b/packages/beacon-node/test/spec/general/ssz_generic_types.ts @@ -1,12 +1,12 @@ import { - Type, - BooleanType, - UintBigintType, - UintNumberType, - BitVectorType, BitListType, + BitVectorType, + BooleanType, ContainerType, ListBasicType, + Type, + UintBigintType, + UintNumberType, VectorBasicType, VectorCompositeType, } from "@chainsafe/ssz"; diff --git a/packages/beacon-node/test/spec/presets/epoch_processing.test.ts b/packages/beacon-node/test/spec/presets/epoch_processing.test.ts index c61aec40fee3..05ce8c4c70e3 100644 --- a/packages/beacon-node/test/spec/presets/epoch_processing.test.ts +++ b/packages/beacon-node/test/spec/presets/epoch_processing.test.ts @@ -1,22 +1,22 @@ import path from "node:path"; -import {expect} from "vitest"; +import {ACTIVE_PRESET} from "@lodestar/params"; import { + BeaconStateAllForks, CachedBeaconStateAllForks, + CachedBeaconStateAltair, EpochTransitionCache, - BeaconStateAllForks, beforeProcessEpoch, - CachedBeaconStateAltair, } from "@lodestar/state-transition"; import * as epochFns from "@lodestar/state-transition/epoch"; import {ssz} from "@lodestar/types"; -import {ACTIVE_PRESET} from "@lodestar/params"; +import {expect} from "vitest"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; export type EpochTransitionFn = (state: CachedBeaconStateAllForks, epochTransitionCache: EpochTransitionCache) => void; diff --git a/packages/beacon-node/test/spec/presets/finality.test.ts b/packages/beacon-node/test/spec/presets/finality.test.ts index 1dce91e360e5..a183d7c2197a 100644 --- a/packages/beacon-node/test/spec/presets/finality.test.ts +++ b/packages/beacon-node/test/spec/presets/finality.test.ts @@ -1,4 +1,5 @@ import path from "node:path"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import { BeaconStateAllForks, DataAvailableStatus, @@ -6,14 +7,13 @@ import { stateTransition, } from "@lodestar/state-transition"; import {altair, bellatrix, ssz} from "@lodestar/types"; -import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; -import {RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn, shouldVerify} from "../utils/types.js"; const finality: TestRunnerFn = (fork) => { return { diff --git a/packages/beacon-node/test/spec/presets/fork.test.ts b/packages/beacon-node/test/spec/presets/fork.test.ts index 626d6477bcb1..bc66bccb279e 100644 --- a/packages/beacon-node/test/spec/presets/fork.test.ts +++ b/packages/beacon-node/test/spec/presets/fork.test.ts @@ -1,21 +1,21 @@ import path from "node:path"; +import {ChainForkConfig, createChainForkConfig} from "@lodestar/config"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import { BeaconStateAllForks, - CachedBeaconStateBellatrix, CachedBeaconStateAltair, - CachedBeaconStatePhase0, + CachedBeaconStateBellatrix, CachedBeaconStateCapella, CachedBeaconStateDeneb, + CachedBeaconStatePhase0, } from "@lodestar/state-transition"; import * as slotFns from "@lodestar/state-transition/slot"; import {phase0, ssz} from "@lodestar/types"; -import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; -import {createChainForkConfig, ChainForkConfig} from "@lodestar/config"; -import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; const fork: TestRunnerFn = (forkNext) => { const config = createChainForkConfig({}); diff --git a/packages/beacon-node/test/spec/presets/fork_choice.test.ts b/packages/beacon-node/test/spec/presets/fork_choice.test.ts index 72515e703582..a12e6e0ac467 100644 --- a/packages/beacon-node/test/spec/presets/fork_choice.test.ts +++ b/packages/beacon-node/test/spec/presets/fork_choice.test.ts @@ -1,50 +1,50 @@ import path from "node:path"; -import {expect} from "vitest"; import {toHexString} from "@chainsafe/ssz"; -import {BeaconStateAllForks, isExecutionStateType, signedBlockToSignedHeader} from "@lodestar/state-transition"; -import {InputType} from "@lodestar/spec-test-util"; +import {createBeaconConfig} from "@lodestar/config"; import {CheckpointWithHex, ForkChoice} from "@lodestar/fork-choice"; +import {ACTIVE_PRESET, ForkName, ForkSeq, isForkBlobs} from "@lodestar/params"; +import {InputType} from "@lodestar/spec-test-util"; +import {BeaconStateAllForks, isExecutionStateType, signedBlockToSignedHeader} from "@lodestar/state-transition"; import { - bellatrix, - ssz, - RootHex, - deneb, + Attestation, + AttesterSlashing, BeaconBlock, + RootHex, SignedBeaconBlock, + bellatrix, + deneb, + ssz, sszTypesFor, - Attestation, - AttesterSlashing, } from "@lodestar/types"; import {bnToNum, fromHex} from "@lodestar/utils"; -import {createBeaconConfig} from "@lodestar/config"; -import {ACTIVE_PRESET, ForkSeq, isForkBlobs, ForkName} from "@lodestar/params"; -import {BeaconChain, ChainEvent} from "../../../src/chain/index.js"; -import {ClockEvent} from "../../../src/util/clock.js"; -import {computeInclusionProof} from "../../../src/util/blobs.js"; -import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {testLogger} from "../../utils/logger.js"; -import {getConfig} from "../../utils/config.js"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; -import {Eth1ForBlockProductionDisabled} from "../../../src/eth1/index.js"; -import {getExecutionEngineFromBackend} from "../../../src/execution/index.js"; -import {ExecutionPayloadStatus} from "../../../src/execution/engine/interface.js"; -import {ExecutionEngineMockBackend} from "../../../src/execution/engine/mock.js"; -import {defaultChainOptions} from "../../../src/chain/options.js"; -import {getMockedBeaconDb} from "../../mocks/mockedBeaconDb.js"; -import {ClockStopped} from "../../mocks/clock.js"; +import {expect} from "vitest"; import { - getBlockInput, AttestationImportOpt, - BlockSource, BlobSidecarValidation, BlobsSource, + BlockSource, + getBlockInput, } from "../../../src/chain/blocks/types.js"; +import {BeaconChain, ChainEvent} from "../../../src/chain/index.js"; +import {defaultChainOptions} from "../../../src/chain/options.js"; import {ZERO_HASH_HEX} from "../../../src/constants/constants.js"; +import {Eth1ForBlockProductionDisabled} from "../../../src/eth1/index.js"; import {PowMergeBlock} from "../../../src/eth1/interface.js"; -import {assertCorrectProgressiveBalances} from "../config.js"; +import {ExecutionPayloadStatus} from "../../../src/execution/engine/interface.js"; +import {ExecutionEngineMockBackend} from "../../../src/execution/engine/mock.js"; +import {getExecutionEngineFromBackend} from "../../../src/execution/index.js"; +import {computeInclusionProof} from "../../../src/util/blobs.js"; +import {ClockEvent} from "../../../src/util/clock.js"; import {initCKZG, loadEthereumTrustedSetup} from "../../../src/util/kzg.js"; +import {ClockStopped} from "../../mocks/clock.js"; +import {getMockedBeaconDb} from "../../mocks/mockedBeaconDb.js"; +import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; +import {getConfig} from "../../utils/config.js"; +import {testLogger} from "../../utils/logger.js"; +import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; const ANCHOR_STATE_FILE_NAME = "anchor_state"; const ANCHOR_BLOCK_FILE_NAME = "anchor_block"; diff --git a/packages/beacon-node/test/spec/presets/genesis.test.ts b/packages/beacon-node/test/spec/presets/genesis.test.ts index 140fa3686e67..7b19e205dc05 100644 --- a/packages/beacon-node/test/spec/presets/genesis.test.ts +++ b/packages/beacon-node/test/spec/presets/genesis.test.ts @@ -1,6 +1,5 @@ import path from "node:path"; -import {expect} from "vitest"; -import {phase0, Root, ssz, TimeSeconds, ExecutionPayloadHeader, sszTypesFor} from "@lodestar/types"; +import {ForkName} from "@lodestar/params"; import {InputType} from "@lodestar/spec-test-util"; import { BeaconStateAllForks, @@ -8,17 +7,18 @@ import { initializeBeaconStateFromEth1, isValidGenesisState, } from "@lodestar/state-transition"; +import {ExecutionPayloadHeader, Root, TimeSeconds, phase0, ssz, sszTypesFor} from "@lodestar/types"; import {bnToNum} from "@lodestar/utils"; -import {ForkName} from "@lodestar/params"; +import {expect} from "vitest"; import {ACTIVE_PRESET} from "@lodestar/params"; +import {getConfig} from "../../utils/config.js"; import {expectEqualBeaconState} from "../utils/expectEqualBeaconState.js"; import {TestRunnerFn} from "../utils/types.js"; -import {getConfig} from "../../utils/config.js"; -import {RunnerType} from "../utils/types.js"; -import {specTestIterator} from "../utils/specTestIterator.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType} from "../utils/types.js"; // The aim of the genesis tests is to provide a baseline to test genesis-state initialization and test if the // proposed genesis-validity conditions are working. diff --git a/packages/beacon-node/test/spec/presets/light_client/single_merkle_proof.ts b/packages/beacon-node/test/spec/presets/light_client/single_merkle_proof.ts index 08dcd0ab8acf..3aa73f72ee40 100644 --- a/packages/beacon-node/test/spec/presets/light_client/single_merkle_proof.ts +++ b/packages/beacon-node/test/spec/presets/light_client/single_merkle_proof.ts @@ -1,10 +1,10 @@ -import {expect} from "vitest"; import {Tree} from "@chainsafe/persistent-merkle-tree"; import {TreeViewDU, Type} from "@chainsafe/ssz"; -import {RootHex, ssz} from "@lodestar/types"; -import {InputType} from "@lodestar/spec-test-util"; import {ForkName} from "@lodestar/params"; +import {InputType} from "@lodestar/spec-test-util"; +import {RootHex, ssz} from "@lodestar/types"; import {toHex} from "@lodestar/utils"; +import {expect} from "vitest"; import {TestRunnerFn} from "../../utils/types.js"; // https://github.com/ethereum/consensus-specs/blob/da3f5af919be4abb5a6db5a80b235deb8b4b5cba/tests/formats/light_client/single_merkle_proof.md diff --git a/packages/beacon-node/test/spec/presets/light_client/sync.ts b/packages/beacon-node/test/spec/presets/light_client/sync.ts index 3e82256fab1d..5ac51b95de3b 100644 --- a/packages/beacon-node/test/spec/presets/light_client/sync.ts +++ b/packages/beacon-node/test/spec/presets/light_client/sync.ts @@ -1,13 +1,13 @@ -import {expect} from "vitest"; +import {ChainConfig, createBeaconConfig} from "@lodestar/config"; +import {LightclientSpec, toLightClientUpdateSummary} from "@lodestar/light-client/spec"; import {isForkLightClient} from "@lodestar/params"; -import {altair, phase0, RootHex, Slot, ssz, sszTypesFor} from "@lodestar/types"; import {InputType} from "@lodestar/spec-test-util"; -import {createBeaconConfig, ChainConfig} from "@lodestar/config"; -import {fromHex, toHex} from "@lodestar/utils"; -import {LightclientSpec, toLightClientUpdateSummary} from "@lodestar/light-client/spec"; import {computeSyncPeriodAtSlot} from "@lodestar/state-transition"; -import {TestRunnerFn} from "../../utils/types.js"; +import {RootHex, Slot, altair, phase0, ssz, sszTypesFor} from "@lodestar/types"; +import {fromHex, toHex} from "@lodestar/utils"; +import {expect} from "vitest"; import {testLogger} from "../../../utils/logger.js"; +import {TestRunnerFn} from "../../utils/types.js"; // https://github.com/ethereum/consensus-specs/blob/da3f5af919be4abb5a6db5a80b235deb8b4b5cba/tests/formats/light_client/single_merkle_proof.md type SyncTestCase = { diff --git a/packages/beacon-node/test/spec/presets/light_client/update_ranking.ts b/packages/beacon-node/test/spec/presets/light_client/update_ranking.ts index b51219dd4e54..97cd7639a176 100644 --- a/packages/beacon-node/test/spec/presets/light_client/update_ranking.ts +++ b/packages/beacon-node/test/spec/presets/light_client/update_ranking.ts @@ -1,8 +1,8 @@ -import {expect} from "vitest"; -import {LightClientUpdate, altair, ssz, sszTypesFor} from "@lodestar/types"; +import {LightClientUpdateSummary, isBetterUpdate, toLightClientUpdateSummary} from "@lodestar/light-client/spec"; import {isForkLightClient} from "@lodestar/params"; import {InputType} from "@lodestar/spec-test-util"; -import {isBetterUpdate, LightClientUpdateSummary, toLightClientUpdateSummary} from "@lodestar/light-client/spec"; +import {LightClientUpdate, altair, ssz, sszTypesFor} from "@lodestar/types"; +import {expect} from "vitest"; import {TestRunnerFn} from "../../utils/types.js"; // https://github.com/ethereum/consensus-specs/blob/da3f5af919be4abb5a6db5a80b235deb8b4b5cba/tests/formats/light_client/update_ranking.md diff --git a/packages/beacon-node/test/spec/presets/merkle.test.ts b/packages/beacon-node/test/spec/presets/merkle.test.ts index 71cebdbd0b5b..2bc70374bdf5 100644 --- a/packages/beacon-node/test/spec/presets/merkle.test.ts +++ b/packages/beacon-node/test/spec/presets/merkle.test.ts @@ -1,15 +1,15 @@ import path from "node:path"; -import {expect} from "vitest"; import {ProofType, SingleProof, Tree} from "@chainsafe/persistent-merkle-tree"; import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; -import {BeaconStateAllForks} from "@lodestar/state-transition"; +import {ACTIVE_PRESET} from "@lodestar/params"; import {InputType} from "@lodestar/spec-test-util"; +import {BeaconStateAllForks} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; import {verifyMerkleBranch} from "@lodestar/utils"; -import {ACTIVE_PRESET} from "@lodestar/params"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; +import {expect} from "vitest"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; const merkle: TestRunnerFn = (fork) => { return { diff --git a/packages/beacon-node/test/spec/presets/operations.test.ts b/packages/beacon-node/test/spec/presets/operations.test.ts index 4c90831ef155..0a9996c0a2b1 100644 --- a/packages/beacon-node/test/spec/presets/operations.test.ts +++ b/packages/beacon-node/test/spec/presets/operations.test.ts @@ -1,4 +1,6 @@ import path from "node:path"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; +import {InputType} from "@lodestar/spec-test-util"; import { BeaconStateAllForks, CachedBeaconStateAllForks, @@ -9,16 +11,14 @@ import { getBlockRootAtSlot, } from "@lodestar/state-transition"; import * as blockFns from "@lodestar/state-transition/block"; -import {ssz, phase0, altair, bellatrix, capella, electra, sszTypesFor} from "@lodestar/types"; -import {InputType} from "@lodestar/spec-test-util"; -import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; +import {altair, bellatrix, capella, electra, phase0, ssz, sszTypesFor} from "@lodestar/types"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; -import {BaseSpecTest, RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {BaseSpecTest, RunnerType, TestRunnerFn, shouldVerify} from "../utils/types.js"; // Define above to re-use in sync_aggregate and sync_aggregate_random const syncAggregate: BlockProcessFn = ( diff --git a/packages/beacon-node/test/spec/presets/rewards.test.ts b/packages/beacon-node/test/spec/presets/rewards.test.ts index df43c8ca612e..299bf208eb62 100644 --- a/packages/beacon-node/test/spec/presets/rewards.test.ts +++ b/packages/beacon-node/test/spec/presets/rewards.test.ts @@ -1,17 +1,17 @@ import path from "node:path"; -import {expect} from "vitest"; import {VectorCompositeType} from "@chainsafe/ssz"; +import {ACTIVE_PRESET} from "@lodestar/params"; import {BeaconStateAllForks, beforeProcessEpoch} from "@lodestar/state-transition"; import {getRewardsAndPenalties} from "@lodestar/state-transition/epoch"; import {ssz} from "@lodestar/types"; -import {ACTIVE_PRESET} from "@lodestar/params"; +import {expect} from "vitest"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {getConfig} from "../../utils/config.js"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; const deltasType = new VectorCompositeType(ssz.phase0.Balances, 2); diff --git a/packages/beacon-node/test/spec/presets/sanity.test.ts b/packages/beacon-node/test/spec/presets/sanity.test.ts index cd266483c7f8..223587d63ccc 100644 --- a/packages/beacon-node/test/spec/presets/sanity.test.ts +++ b/packages/beacon-node/test/spec/presets/sanity.test.ts @@ -1,4 +1,5 @@ import path from "node:path"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {InputType} from "@lodestar/spec-test-util"; import { BeaconStateAllForks, @@ -8,15 +9,14 @@ import { stateTransition, } from "@lodestar/state-transition"; import {SignedBeaconBlock, deneb, ssz} from "@lodestar/types"; -import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {bnToNum} from "@lodestar/utils"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; -import {RunnerType, shouldVerify, TestRunnerFn} from "../utils/types.js"; import {getConfig} from "../../utils/config.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn, shouldVerify} from "../utils/types.js"; const sanity: TestRunnerFn = (fork, testName, testSuite) => { switch (testName) { diff --git a/packages/beacon-node/test/spec/presets/shuffling.test.ts b/packages/beacon-node/test/spec/presets/shuffling.test.ts index 7b0f38ecf581..ad5fff527bac 100644 --- a/packages/beacon-node/test/spec/presets/shuffling.test.ts +++ b/packages/beacon-node/test/spec/presets/shuffling.test.ts @@ -1,11 +1,11 @@ import path from "node:path"; import {unshuffleList} from "@chainsafe/swap-or-not-shuffle"; +import {ACTIVE_PRESET, SHUFFLE_ROUND_COUNT} from "@lodestar/params"; import {InputType} from "@lodestar/spec-test-util"; import {bnToNum, fromHex} from "@lodestar/utils"; -import {ACTIVE_PRESET, SHUFFLE_ROUND_COUNT} from "@lodestar/params"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; const shuffling: TestRunnerFn = () => { return { diff --git a/packages/beacon-node/test/spec/presets/ssz_static.test.ts b/packages/beacon-node/test/spec/presets/ssz_static.test.ts index f5cdcc719b6a..34a252052f65 100644 --- a/packages/beacon-node/test/spec/presets/ssz_static.test.ts +++ b/packages/beacon-node/test/spec/presets/ssz_static.test.ts @@ -1,14 +1,14 @@ import fs from "node:fs"; import path from "node:path"; -import {expect, it, vi} from "vitest"; import {Type} from "@chainsafe/ssz"; -import {ssz, sszTypesFor} from "@lodestar/types"; import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; +import {ssz, sszTypesFor} from "@lodestar/types"; +import {expect, it, vi} from "vitest"; +import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; import {replaceUintTypeWithUintBigintType} from "../utils/replaceUintTypeWithUintBigintType.js"; -import {parseSszStaticTestcase} from "../utils/sszTestCaseParser.js"; import {runValidSszTest} from "../utils/runValidSszTest.js"; -import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {parseSszStaticTestcase} from "../utils/sszTestCaseParser.js"; import {RunnerType} from "../utils/types.js"; // ssz_static diff --git a/packages/beacon-node/test/spec/presets/transition.test.ts b/packages/beacon-node/test/spec/presets/transition.test.ts index 76ad772f8dfb..0b1aa1b522e5 100644 --- a/packages/beacon-node/test/spec/presets/transition.test.ts +++ b/packages/beacon-node/test/spec/presets/transition.test.ts @@ -1,4 +1,7 @@ import path from "node:path"; +import {ChainConfig, createChainForkConfig} from "@lodestar/config"; +import {config} from "@lodestar/config/default"; +import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import { BeaconStateAllForks, DataAvailableStatus, @@ -6,16 +9,13 @@ import { stateTransition, } from "@lodestar/state-transition"; import {SignedBeaconBlock, ssz} from "@lodestar/types"; -import {createChainForkConfig, ChainConfig} from "@lodestar/config"; -import {ACTIVE_PRESET, ForkName} from "@lodestar/params"; import {bnToNum} from "@lodestar/utils"; -import {config} from "@lodestar/config/default"; -import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {createCachedBeaconStateTest} from "../../utils/cachedBeaconState.js"; -import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {assertCorrectProgressiveBalances} from "../config.js"; import {ethereumConsensusSpecsTests} from "../specTestVersioning.js"; +import {expectEqualBeaconState, inputTypeSszTreeViewDU} from "../utils/expectEqualBeaconState.js"; import {specTestIterator} from "../utils/specTestIterator.js"; +import {RunnerType, TestRunnerFn} from "../utils/types.js"; import {getPreviousFork} from "./fork.test.js"; const transition = diff --git a/packages/beacon-node/test/spec/utils/expectEqualBeaconState.ts b/packages/beacon-node/test/spec/utils/expectEqualBeaconState.ts index 160310160054..a3f6cc149148 100644 --- a/packages/beacon-node/test/spec/utils/expectEqualBeaconState.ts +++ b/packages/beacon-node/test/spec/utils/expectEqualBeaconState.ts @@ -1,8 +1,8 @@ -import {expect} from "vitest"; -import {SSZTypesFor, ssz} from "@lodestar/types"; import {ForkAll, ForkName} from "@lodestar/params"; import {InputType} from "@lodestar/spec-test-util"; import {BeaconStateAllForks} from "@lodestar/state-transition"; +import {SSZTypesFor, ssz} from "@lodestar/types"; +import {expect} from "vitest"; /** Compare each field in BeaconState to help debug failed test easier. */ export function expectEqualBeaconState( diff --git a/packages/beacon-node/test/spec/utils/replaceUintTypeWithUintBigintType.ts b/packages/beacon-node/test/spec/utils/replaceUintTypeWithUintBigintType.ts index 8e0063291d98..356d384e5f6a 100644 --- a/packages/beacon-node/test/spec/utils/replaceUintTypeWithUintBigintType.ts +++ b/packages/beacon-node/test/spec/utils/replaceUintTypeWithUintBigintType.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment */ import { - Type, - UintNumberType, - UintBigintType, ContainerType, ListBasicType, ListCompositeType, + Type, + UintBigintType, + UintNumberType, VectorBasicType, VectorCompositeType, } from "@chainsafe/ssz"; diff --git a/packages/beacon-node/test/spec/utils/runValidSszTest.ts b/packages/beacon-node/test/spec/utils/runValidSszTest.ts index a8d3060af08d..03c4e543f276 100644 --- a/packages/beacon-node/test/spec/utils/runValidSszTest.ts +++ b/packages/beacon-node/test/spec/utils/runValidSszTest.ts @@ -1,6 +1,6 @@ -import {expect} from "vitest"; import {Node} from "@chainsafe/persistent-merkle-tree"; -import {Type, CompositeType, fromHexString, toHexString} from "@chainsafe/ssz"; +import {CompositeType, Type, fromHexString, toHexString} from "@chainsafe/ssz"; +import {expect} from "vitest"; type ValidTestCaseData = { root: string; diff --git a/packages/beacon-node/test/spec/utils/specTestIterator.ts b/packages/beacon-node/test/spec/utils/specTestIterator.ts index d8b4f9c0574c..0868183295cf 100644 --- a/packages/beacon-node/test/spec/utils/specTestIterator.ts +++ b/packages/beacon-node/test/spec/utils/specTestIterator.ts @@ -1,8 +1,8 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it} from "vitest"; import {ForkName} from "@lodestar/params"; import {describeDirectorySpecTest} from "@lodestar/spec-test-util"; +import {describe, it} from "vitest"; import {RunnerType, TestRunner} from "./types.js"; const ARTIFACT_FILENAMES = new Set([ diff --git a/packages/beacon-node/test/spec/utils/sszTestCaseParser.ts b/packages/beacon-node/test/spec/utils/sszTestCaseParser.ts index d4108a2eb011..f594a5b88193 100644 --- a/packages/beacon-node/test/spec/utils/sszTestCaseParser.ts +++ b/packages/beacon-node/test/spec/utils/sszTestCaseParser.ts @@ -1,8 +1,8 @@ -import path from "node:path"; import fs from "node:fs"; -import {uncompress} from "snappyjs"; -import jsyaml from "js-yaml"; +import path from "node:path"; import {loadYaml} from "@lodestar/utils"; +import jsyaml from "js-yaml"; +import {uncompress} from "snappyjs"; /* eslint-disable @typescript-eslint/explicit-function-return-type */ diff --git a/packages/beacon-node/test/unit-mainnet/network/gossip/scoringParameters.test.ts b/packages/beacon-node/test/unit-mainnet/network/gossip/scoringParameters.test.ts index b3137755857f..bf9e92ee2ddd 100644 --- a/packages/beacon-node/test/unit-mainnet/network/gossip/scoringParameters.test.ts +++ b/packages/beacon-node/test/unit-mainnet/network/gossip/scoringParameters.test.ts @@ -1,12 +1,12 @@ -import {describe, it, expect} from "vitest"; import {TopicScoreParams} from "@chainsafe/libp2p-gossipsub/score"; -import {ATTESTATION_SUBNET_COUNT, ForkName, SLOTS_PER_EPOCH} from "@lodestar/params"; import {createBeaconConfig} from "@lodestar/config"; import {mainnetChainConfig} from "@lodestar/config/configs"; +import {ATTESTATION_SUBNET_COUNT, ForkName, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {describe, expect, it} from "vitest"; +import {ZERO_HASH} from "../../../../src/constants/index.js"; import {computeGossipPeerScoreParams, gossipScoreThresholds} from "../../../../src/network/gossip/scoringParameters.js"; import {stringifyGossipTopic} from "../../../../src/network/gossip/topic.js"; import {GossipType} from "../../../../src/network/index.js"; -import {ZERO_HASH} from "../../../../src/constants/index.js"; /** * Refer to Teku tests at diff --git a/packages/beacon-node/test/unit-mainnet/network/subnets/util.test.ts b/packages/beacon-node/test/unit-mainnet/network/subnets/util.test.ts index af12ad3d80e8..5509b51ebd0a 100644 --- a/packages/beacon-node/test/unit-mainnet/network/subnets/util.test.ts +++ b/packages/beacon-node/test/unit-mainnet/network/subnets/util.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {bigIntToBytes} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {computeSubscribedSubnet} from "../../../../src/network/subnets/util.js"; describe("computeSubscribedSubnet", () => { diff --git a/packages/beacon-node/test/unit/api/impl/beacon/beacon.test.ts b/packages/beacon-node/test/unit/api/impl/beacon/beacon.test.ts index 99bac5de7ef4..9bfb305b7e7e 100644 --- a/packages/beacon-node/test/unit/api/impl/beacon/beacon.test.ts +++ b/packages/beacon-node/test/unit/api/impl/beacon/beacon.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect, beforeAll} from "vitest"; import {phase0} from "@lodestar/types"; -import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; +import {beforeAll, describe, expect, it} from "vitest"; import {getBeaconApi} from "../../../../../src/api/impl/beacon/index.js"; +import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; import {Mutable} from "../../../../utils/types.js"; describe("beacon api implementation", () => { diff --git a/packages/beacon-node/test/unit/api/impl/beacon/blocks/getBlockHeaders.test.ts b/packages/beacon-node/test/unit/api/impl/beacon/blocks/getBlockHeaders.test.ts index 5e4e8a31ec7f..ce8d770d86ff 100644 --- a/packages/beacon-node/test/unit/api/impl/beacon/blocks/getBlockHeaders.test.ts +++ b/packages/beacon-node/test/unit/api/impl/beacon/blocks/getBlockHeaders.test.ts @@ -1,11 +1,11 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, vi, afterEach} from "vitest"; -import {when} from "vitest-when"; import {routes} from "@lodestar/api"; import {ssz} from "@lodestar/types"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import {when} from "vitest-when"; +import {getBeaconBlockApi} from "../../../../../../src/api/impl/beacon/blocks/index.js"; import {ApiTestModules, getApiTestModules} from "../../../../../utils/api.js"; import {generateProtoBlock, generateSignedBlockAtSlot} from "../../../../../utils/typeGenerator.js"; -import {getBeaconBlockApi} from "../../../../../../src/api/impl/beacon/blocks/index.js"; describe("api - beacon - getBlockHeaders", () => { let modules: ApiTestModules; diff --git a/packages/beacon-node/test/unit/api/impl/beacon/state/utils.test.ts b/packages/beacon-node/test/unit/api/impl/beacon/state/utils.test.ts index 958093ffba6d..149e0236c448 100644 --- a/packages/beacon-node/test/unit/api/impl/beacon/state/utils.test.ts +++ b/packages/beacon-node/test/unit/api/impl/beacon/state/utils.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {toHexString} from "@chainsafe/ssz"; +import {describe, expect, it} from "vitest"; import {getStateValidatorIndex} from "../../../../../../src/api/impl/beacon/state/utils.js"; import {generateCachedAltairState} from "../../../../../utils/state.js"; diff --git a/packages/beacon-node/test/unit/api/impl/config/config.test.ts b/packages/beacon-node/test/unit/api/impl/config/config.test.ts index 7d0adebbea89..8e67d5d6b156 100644 --- a/packages/beacon-node/test/unit/api/impl/config/config.test.ts +++ b/packages/beacon-node/test/unit/api/impl/config/config.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect, beforeEach} from "vitest"; import {routes} from "@lodestar/api"; import {config} from "@lodestar/config/default"; +import {beforeEach, describe, expect, it} from "vitest"; import {getConfigApi, renderJsonSpec} from "../../../../../src/api/impl/config/index.js"; describe("config api implementation", () => { diff --git a/packages/beacon-node/test/unit/api/impl/events/events.test.ts b/packages/beacon-node/test/unit/api/impl/events/events.test.ts index 5b1686d42f57..cd42945830bc 100644 --- a/packages/beacon-node/test/unit/api/impl/events/events.test.ts +++ b/packages/beacon-node/test/unit/api/impl/events/events.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect, beforeEach, afterEach, vi, MockedObject} from "vitest"; import {routes} from "@lodestar/api"; import {config} from "@lodestar/config/default"; import {ssz} from "@lodestar/types"; -import {BeaconChain, ChainEventEmitter, HeadEventData} from "../../../../../src/chain/index.js"; +import {MockedObject, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {getEventsApi} from "../../../../../src/api/impl/events/index.js"; +import {BeaconChain, ChainEventEmitter, HeadEventData} from "../../../../../src/chain/index.js"; import {ZERO_HASH_HEX} from "../../../../../src/constants/constants.js"; vi.mock("../../../../../src/chain/index.js", async (importActual) => { diff --git a/packages/beacon-node/test/unit/api/impl/swaggerUI.test.ts b/packages/beacon-node/test/unit/api/impl/swaggerUI.test.ts index 7ae2382e6404..1b7aecb0a234 100644 --- a/packages/beacon-node/test/unit/api/impl/swaggerUI.test.ts +++ b/packages/beacon-node/test/unit/api/impl/swaggerUI.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {getFavicon, getLogo} from "../../../../src/api/rest/swaggerUI.js"; describe("swaggerUI", () => { diff --git a/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts b/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts index b954f983adcc..66cc4f79407d 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/duties/proposer.test.ts @@ -1,17 +1,17 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; import {routes} from "@lodestar/api"; import {config} from "@lodestar/config/default"; import {MAX_EFFECTIVE_BALANCE, SLOTS_PER_EPOCH} from "@lodestar/params"; import {BeaconStateAllForks} from "@lodestar/state-transition"; import {Slot} from "@lodestar/types"; -import {ApiTestModules, getApiTestModules} from "../../../../../utils/api.js"; -import {FAR_FUTURE_EPOCH} from "../../../../../../src/constants/index.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {SYNC_TOLERANCE_EPOCHS, getValidatorApi} from "../../../../../../src/api/impl/validator/index.js"; +import {defaultApiOptions} from "../../../../../../src/api/options.js"; +import {FAR_FUTURE_EPOCH} from "../../../../../../src/constants/index.js"; +import {SyncState} from "../../../../../../src/sync/interface.js"; +import {ApiTestModules, getApiTestModules} from "../../../../../utils/api.js"; +import {createCachedBeaconStateTest} from "../../../../../utils/cachedBeaconState.js"; import {generateState, zeroProtoBlock} from "../../../../../utils/state.js"; import {generateValidators} from "../../../../../utils/validator.js"; -import {createCachedBeaconStateTest} from "../../../../../utils/cachedBeaconState.js"; -import {SyncState} from "../../../../../../src/sync/interface.js"; -import {defaultApiOptions} from "../../../../../../src/api/options.js"; describe("get proposers api impl", () => { const currentEpoch = 2; diff --git a/packages/beacon-node/test/unit/api/impl/validator/produceAttestationData.test.ts b/packages/beacon-node/test/unit/api/impl/validator/produceAttestationData.test.ts index fdbfec5ac503..0486c3489800 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/produceAttestationData.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/produceAttestationData.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect, beforeEach, vi} from "vitest"; import {ProtoBlock} from "@lodestar/fork-choice"; -import {SyncState} from "../../../../../src/sync/interface.js"; -import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; +import {beforeEach, describe, expect, it, vi} from "vitest"; import {getValidatorApi} from "../../../../../src/api/impl/validator/index.js"; import {defaultApiOptions} from "../../../../../src/api/options.js"; +import {SyncState} from "../../../../../src/sync/interface.js"; +import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; describe("api - validator - produceAttestationData", () => { let modules: ApiTestModules; diff --git a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts index 306b18481c1f..418dd2e56d8d 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts @@ -1,20 +1,20 @@ import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; -import {ssz} from "@lodestar/types"; import {ProtoBlock} from "@lodestar/fork-choice"; import {ForkName} from "@lodestar/params"; -import {computeTimeAtSlot, CachedBeaconStateBellatrix} from "@lodestar/state-transition"; -import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; -import {SyncState} from "../../../../../src/sync/interface.js"; +import {CachedBeaconStateBellatrix, G2_POINT_AT_INFINITY, computeTimeAtSlot} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {getValidatorApi} from "../../../../../src/api/impl/validator/index.js"; +import {defaultApiOptions} from "../../../../../src/api/options.js"; import {BeaconChain} from "../../../../../src/chain/index.js"; -import {generateCachedBellatrixState} from "../../../../utils/state.js"; +import {BlockType, produceBlockBody} from "../../../../../src/chain/produceBlock/produceBlockBody.js"; +import {ZERO_HASH_HEX} from "../../../../../src/constants/index.js"; import {PayloadIdCache} from "../../../../../src/execution/engine/payloadIdCache.js"; +import {SyncState} from "../../../../../src/sync/interface.js"; import {toGraffitiBuffer} from "../../../../../src/util/graffiti.js"; -import {BlockType, produceBlockBody} from "../../../../../src/chain/produceBlock/produceBlockBody.js"; +import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; +import {generateCachedBellatrixState} from "../../../../utils/state.js"; import {generateProtoBlock} from "../../../../utils/typeGenerator.js"; -import {ZERO_HASH_HEX} from "../../../../../src/constants/index.js"; -import {defaultApiOptions} from "../../../../../src/api/options.js"; describe("api/validator - produceBlockV2", () => { let api: ReturnType; @@ -99,6 +99,10 @@ describe("api/validator - produceBlockV2", () => { eth1Data: ssz.phase0.Eth1Data.defaultValue(), deposits: [], }); + modules.chain["syncContributionAndProofPool"].getAggregate.mockReturnValue({ + syncCommitteeBits: ssz.altair.SyncCommitteeBits.defaultValue(), + syncCommitteeSignature: G2_POINT_AT_INFINITY, + }); modules.forkChoice.getJustifiedBlock.mockReturnValue({} as ProtoBlock); modules.forkChoice.getFinalizedBlock.mockReturnValue({} as ProtoBlock); diff --git a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV3.test.ts b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV3.test.ts index f705e4b38e14..a93529aa4858 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV3.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV3.test.ts @@ -1,16 +1,16 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; import {toHexString} from "@chainsafe/ssz"; -import {ssz} from "@lodestar/types"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {routes} from "@lodestar/api"; import {createBeaconConfig, createChainForkConfig, defaultChainConfig} from "@lodestar/config"; import {ProtoBlock} from "@lodestar/fork-choice"; -import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; -import {SyncState} from "../../../../../src/sync/interface.js"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {ssz} from "@lodestar/types"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {getValidatorApi} from "../../../../../src/api/impl/validator/index.js"; +import {defaultApiOptions} from "../../../../../src/api/options.js"; import {CommonBlockBody} from "../../../../../src/chain/interface.js"; +import {SyncState} from "../../../../../src/sync/interface.js"; +import {ApiTestModules, getApiTestModules} from "../../../../utils/api.js"; import {zeroProtoBlock} from "../../../../utils/state.js"; -import {defaultApiOptions} from "../../../../../src/api/options.js"; describe("api/validator - produceBlockV3", () => { let modules: ApiTestModules; diff --git a/packages/beacon-node/test/unit/api/impl/validator/utils.test.ts b/packages/beacon-node/test/unit/api/impl/validator/utils.test.ts index 32ef5be5d213..2579fe3224b1 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/utils.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/utils.test.ts @@ -1,7 +1,7 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeAll} from "vitest"; -import {BLSPubkey, ssz, ValidatorIndex} from "@lodestar/types"; import {BeaconStateAllForks} from "@lodestar/state-transition"; +import {BLSPubkey, ValidatorIndex, ssz} from "@lodestar/types"; +import {beforeAll, describe, expect, it} from "vitest"; import {getPubkeysForIndices} from "../../../../../src/api/impl/validator/utils.js"; describe("api / impl / validator / utils", () => { diff --git a/packages/beacon-node/test/unit/chain/archive/blockArchiver.test.ts b/packages/beacon-node/test/unit/chain/archive/blockArchiver.test.ts index dc7c9bb75291..f34e2c85f1a1 100644 --- a/packages/beacon-node/test/unit/chain/archive/blockArchiver.test.ts +++ b/packages/beacon-node/test/unit/chain/archive/blockArchiver.test.ts @@ -1,13 +1,13 @@ import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, vi, afterEach} from "vitest"; -import {ssz} from "@lodestar/types"; import {config} from "@lodestar/config/default"; -import {ZERO_HASH_HEX} from "../../../../src/constants/index.js"; -import {generateProtoBlock} from "../../../utils/typeGenerator.js"; -import {testLogger} from "../../../utils/logger.js"; +import {ssz} from "@lodestar/types"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {archiveBlocks} from "../../../../src/chain/archiver/archiveBlocks.js"; -import {MockedBeaconDb, getMockedBeaconDb} from "../../../mocks/mockedBeaconDb.js"; +import {ZERO_HASH_HEX} from "../../../../src/constants/index.js"; import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; +import {MockedBeaconDb, getMockedBeaconDb} from "../../../mocks/mockedBeaconDb.js"; +import {testLogger} from "../../../utils/logger.js"; +import {generateProtoBlock} from "../../../utils/typeGenerator.js"; describe("block archiver task", () => { const logger = testLogger(); diff --git a/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts b/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts index c58a873fe1db..c3dc5f031893 100644 --- a/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts +++ b/packages/beacon-node/test/unit/chain/archive/nonCheckpoint.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect, beforeAll} from "vitest"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {Slot} from "@lodestar/types"; +import {beforeAll, describe, expect, it} from "vitest"; import {getNonCheckpointBlocks} from "../../../../src/chain/archiver/archiveBlocks.js"; describe("chain / archive / getNonCheckpointBlocks", () => { diff --git a/packages/beacon-node/test/unit/chain/archive/stateArchiver.test.ts b/packages/beacon-node/test/unit/chain/archive/stateArchiver.test.ts index cbfba0a362df..80ef6b885ae4 100644 --- a/packages/beacon-node/test/unit/chain/archive/stateArchiver.test.ts +++ b/packages/beacon-node/test/unit/chain/archive/stateArchiver.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; +import {describe, expect, it} from "vitest"; import {computeStateSlotsToDelete} from "../../../../src/chain/archiver/strategies/frequencyStateArchiveStrategy.js"; describe("state archiver task", () => { diff --git a/packages/beacon-node/test/unit/chain/beaconProposerCache.ts b/packages/beacon-node/test/unit/chain/beaconProposerCache.ts index b75bbf546a98..96178d508732 100644 --- a/packages/beacon-node/test/unit/chain/beaconProposerCache.ts +++ b/packages/beacon-node/test/unit/chain/beaconProposerCache.ts @@ -1,4 +1,4 @@ -import {expect, describe, it, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {BeaconProposerCache} from "../../../src/chain/beaconProposerCache.js"; const suggestedFeeRecipient = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; diff --git a/packages/beacon-node/test/unit/chain/blocks/rejectFirstInvalidResolveAllValid.test.ts b/packages/beacon-node/test/unit/chain/blocks/rejectFirstInvalidResolveAllValid.test.ts index 2e032f558fe2..5de44a532631 100644 --- a/packages/beacon-node/test/unit/chain/blocks/rejectFirstInvalidResolveAllValid.test.ts +++ b/packages/beacon-node/test/unit/chain/blocks/rejectFirstInvalidResolveAllValid.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {rejectFirstInvalidResolveAllValid} from "../../../../src/chain/blocks/verifyBlocksSignatures.js"; /* eslint-disable @typescript-eslint/explicit-function-return-type */ diff --git a/packages/beacon-node/test/unit/chain/blocks/verifyBlocksSanityChecks.test.ts b/packages/beacon-node/test/unit/chain/blocks/verifyBlocksSanityChecks.test.ts index 1296a79d5eab..48ffe51e4636 100644 --- a/packages/beacon-node/test/unit/chain/blocks/verifyBlocksSanityChecks.test.ts +++ b/packages/beacon-node/test/unit/chain/blocks/verifyBlocksSanityChecks.test.ts @@ -1,17 +1,17 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {ChainForkConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {toHex} from "@lodestar/utils"; -import {ChainForkConfig} from "@lodestar/config"; import {SignedBeaconBlock, Slot, ssz} from "@lodestar/types"; +import {toHex} from "@lodestar/utils"; +import {beforeEach, describe, expect, it} from "vitest"; +import {BlockSource, getBlockInput} from "../../../../src/chain/blocks/types.js"; import {verifyBlocksSanityChecks as verifyBlocksImportSanityChecks} from "../../../../src/chain/blocks/verifyBlocksSanityChecks.js"; import {BlockErrorCode} from "../../../../src/chain/errors/index.js"; -import {expectThrowsLodestarError} from "../../../utils/errors.js"; import {IClock} from "../../../../src/util/clock.js"; import {ClockStopped} from "../../../mocks/clock.js"; -import {BlockSource, getBlockInput} from "../../../../src/chain/blocks/types.js"; import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; +import {expectThrowsLodestarError} from "../../../utils/errors.js"; describe("chain / blocks / verifyBlocksSanityChecks", () => { let forkChoice: MockedBeaconChain["forkChoice"]; diff --git a/packages/beacon-node/test/unit/chain/bls/bls.test.ts b/packages/beacon-node/test/unit/chain/bls/bls.test.ts index 137f2c4dd9df..fbc602785a68 100644 --- a/packages/beacon-node/test/unit/chain/bls/bls.test.ts +++ b/packages/beacon-node/test/unit/chain/bls/bls.test.ts @@ -1,8 +1,8 @@ -import {describe, it, expect, beforeEach} from "vitest"; import {PublicKey, SecretKey, Signature} from "@chainsafe/blst"; import {ISignatureSet, SignatureSetType} from "@lodestar/state-transition"; -import {BlsSingleThreadVerifier} from "../../../../src/chain/bls/singleThread.js"; +import {beforeEach, describe, expect, it} from "vitest"; import {BlsMultiThreadWorkerPool} from "../../../../src/chain/bls/multithread/index.js"; +import {BlsSingleThreadVerifier} from "../../../../src/chain/bls/singleThread.js"; import {testLogger} from "../../../utils/logger.js"; describe("BlsVerifier ", () => { diff --git a/packages/beacon-node/test/unit/chain/bls/utils.test.ts b/packages/beacon-node/test/unit/chain/bls/utils.test.ts index d492a36b4d56..5e5259b8649f 100644 --- a/packages/beacon-node/test/unit/chain/bls/utils.test.ts +++ b/packages/beacon-node/test/unit/chain/bls/utils.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {chunkifyMaximizeChunkSize} from "../../../../src/chain/bls/multithread/utils.js"; import {linspace} from "../../../../src/util/numpy.js"; diff --git a/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts b/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts index 7cb5d23ba296..017e46f6294b 100644 --- a/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts +++ b/packages/beacon-node/test/unit/chain/forkChoice/forkChoice.test.ts @@ -1,7 +1,6 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, beforeAll, vi} from "vitest"; import {config} from "@lodestar/config/default"; -import {CheckpointWithHex, ExecutionStatus, ForkChoice, DataAvailabilityStatus} from "@lodestar/fork-choice"; +import {CheckpointWithHex, DataAvailabilityStatus, ExecutionStatus, ForkChoice} from "@lodestar/fork-choice"; import {FAR_FUTURE_EPOCH, MAX_EFFECTIVE_BALANCE} from "@lodestar/params"; import { CachedBeaconStateAllForks, @@ -9,12 +8,13 @@ import { computeEpochAtSlot, getEffectiveBalanceIncrementsZeroed, } from "@lodestar/state-transition"; -import {phase0, Slot, ssz, ValidatorIndex} from "@lodestar/types"; import {getTemporaryBlockHeader, processSlots} from "@lodestar/state-transition"; +import {Slot, ValidatorIndex, phase0, ssz} from "@lodestar/types"; +import {beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import {ChainEventEmitter, initializeForkChoice} from "../../../../src/chain/index.js"; -import {generateSignedBlockAtSlot} from "../../../utils/typeGenerator.js"; import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; import {generateState} from "../../../utils/state.js"; +import {generateSignedBlockAtSlot} from "../../../utils/typeGenerator.js"; import {generateValidators} from "../../../utils/validator.js"; // We mock this package globally diff --git a/packages/beacon-node/test/unit/chain/genesis/genesis.test.ts b/packages/beacon-node/test/unit/chain/genesis/genesis.test.ts index 40570fcd26e1..40c76bb48045 100644 --- a/packages/beacon-node/test/unit/chain/genesis/genesis.test.ts +++ b/packages/beacon-node/test/unit/chain/genesis/genesis.test.ts @@ -1,15 +1,15 @@ -import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect} from "vitest"; import {PublicKey, SecretKey} from "@chainsafe/blst"; -import {DOMAIN_DEPOSIT, MAX_EFFECTIVE_BALANCE} from "@lodestar/params"; +import {toHexString} from "@chainsafe/ssz"; import {config} from "@lodestar/config/default"; -import {computeDomain, computeSigningRoot, interopSecretKey, ZERO_HASH} from "@lodestar/state-transition"; +import {DOMAIN_DEPOSIT, MAX_EFFECTIVE_BALANCE} from "@lodestar/params"; +import {ZERO_HASH, computeDomain, computeSigningRoot, interopSecretKey} from "@lodestar/state-transition"; import {ValidatorIndex, phase0, ssz} from "@lodestar/types"; import {ErrorAborted} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {GenesisBuilder} from "../../../../src/chain/genesis/genesis.js"; -import {testLogger} from "../../../utils/logger.js"; import {ZERO_HASH_HEX} from "../../../../src/constants/index.js"; import {Eth1ProviderState, EthJsonRpcBlockRaw, IEth1Provider} from "../../../../src/eth1/interface.js"; +import {testLogger} from "../../../utils/logger.js"; describe("genesis builder", () => { const logger = testLogger(); diff --git a/packages/beacon-node/test/unit/chain/lightclient/upgradeLightClientHeader.test.ts b/packages/beacon-node/test/unit/chain/lightclient/upgradeLightClientHeader.test.ts index 3c2f5a664c77..9e602040b315 100644 --- a/packages/beacon-node/test/unit/chain/lightclient/upgradeLightClientHeader.test.ts +++ b/packages/beacon-node/test/unit/chain/lightclient/upgradeLightClientHeader.test.ts @@ -1,8 +1,8 @@ -import {describe, it, expect, beforeEach} from "vitest"; -import {LightClientHeader, ssz} from "@lodestar/types"; -import {ForkName, ForkSeq} from "@lodestar/params"; import {createBeaconConfig, createChainForkConfig, defaultChainConfig} from "@lodestar/config"; import {upgradeLightClientHeader} from "@lodestar/light-client/spec"; +import {ForkName, ForkSeq} from "@lodestar/params"; +import {LightClientHeader, ssz} from "@lodestar/types"; +import {beforeEach, describe, expect, it} from "vitest"; describe("UpgradeLightClientHeader", () => { let lcHeaderByFork: Record; diff --git a/packages/beacon-node/test/unit/chain/opPools/aggregatedAttestationPool.test.ts b/packages/beacon-node/test/unit/chain/opPools/aggregatedAttestationPool.test.ts index 8742d7da9147..b5bfe191a9f3 100644 --- a/packages/beacon-node/test/unit/chain/opPools/aggregatedAttestationPool.test.ts +++ b/packages/beacon-node/test/unit/chain/opPools/aggregatedAttestationPool.test.ts @@ -1,7 +1,6 @@ +import {SecretKey, Signature, aggregateSignatures, fastAggregateVerify} from "@chainsafe/blst"; import {BitArray, fromHexString, toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, beforeAll, afterEach, vi} from "vitest"; -import {SecretKey, Signature, fastAggregateVerify, aggregateSignatures} from "@chainsafe/blst"; -import {CachedBeaconStateAllForks, newFilledArray} from "@lodestar/state-transition"; +import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; import { FAR_FUTURE_EPOCH, ForkName, @@ -9,23 +8,24 @@ import { MAX_EFFECTIVE_BALANCE, SLOTS_PER_EPOCH, } from "@lodestar/params"; -import {ssz, phase0} from "@lodestar/types"; +import {CachedBeaconStateAllForks, newFilledArray} from "@lodestar/state-transition"; import {CachedBeaconStateAltair} from "@lodestar/state-transition/src/types.js"; -import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {MockedForkChoice, getMockedForkChoice} from "../../../mocks/mockedBeaconChain.js"; +import {phase0, ssz} from "@lodestar/types"; +import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import { - aggregateConsolidation, AggregatedAttestationPool, - aggregateInto, AttestationsConsolidation, - getNotSeenValidatorsFn, MatchingDataAttestationGroup, + aggregateConsolidation, + aggregateInto, + getNotSeenValidatorsFn, } from "../../../../src/chain/opPools/aggregatedAttestationPool.js"; import {InsertOutcome} from "../../../../src/chain/opPools/types.js"; +import {ZERO_HASH_HEX} from "../../../../src/constants/constants.js"; import {linspace} from "../../../../src/util/numpy.js"; -import {generateCachedAltairState} from "../../../utils/state.js"; +import {MockedForkChoice, getMockedForkChoice} from "../../../mocks/mockedBeaconChain.js"; import {renderBitArray} from "../../../utils/render.js"; -import {ZERO_HASH_HEX} from "../../../../src/constants/constants.js"; +import {generateCachedAltairState} from "../../../utils/state.js"; import {generateProtoBlock} from "../../../utils/typeGenerator.js"; import {generateValidators} from "../../../utils/validator.js"; diff --git a/packages/beacon-node/test/unit/chain/opPools/attestationPool.test.ts b/packages/beacon-node/test/unit/chain/opPools/attestationPool.test.ts index 98453efaa3b6..fd22f9a7c6a5 100644 --- a/packages/beacon-node/test/unit/chain/opPools/attestationPool.test.ts +++ b/packages/beacon-node/test/unit/chain/opPools/attestationPool.test.ts @@ -1,10 +1,10 @@ import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, vi} from "vitest"; +import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; import {GENESIS_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params"; import {ssz} from "@lodestar/types"; -import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {InsertOutcome} from "../../../../src/chain/opPools/types.js"; +import {beforeEach, describe, expect, it, vi} from "vitest"; import {AttestationPool} from "../../../../src/chain/opPools/attestationPool.js"; +import {InsertOutcome} from "../../../../src/chain/opPools/types.js"; import {getMockedClock} from "../../../mocks/clock.js"; /** Valid signature of random data to prevent BLS errors */ diff --git a/packages/beacon-node/test/unit/chain/opPools/syncCommittee.test.ts b/packages/beacon-node/test/unit/chain/opPools/syncCommittee.test.ts index e91eaa58aa73..9af19cc84c71 100644 --- a/packages/beacon-node/test/unit/chain/opPools/syncCommittee.test.ts +++ b/packages/beacon-node/test/unit/chain/opPools/syncCommittee.test.ts @@ -1,7 +1,7 @@ -import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, beforeAll, afterEach, vi, MockedObject} from "vitest"; import {SecretKey} from "@chainsafe/blst"; +import {toHexString} from "@chainsafe/ssz"; import {altair} from "@lodestar/types"; +import {MockedObject, afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import {SyncCommitteeMessagePool} from "../../../../src/chain/opPools/index.js"; import {Clock} from "../../../../src/util/clock.js"; diff --git a/packages/beacon-node/test/unit/chain/opPools/syncCommitteeContribution.test.ts b/packages/beacon-node/test/unit/chain/opPools/syncCommitteeContribution.test.ts index e1bd60a2305e..c0a639633f37 100644 --- a/packages/beacon-node/test/unit/chain/opPools/syncCommitteeContribution.test.ts +++ b/packages/beacon-node/test/unit/chain/opPools/syncCommitteeContribution.test.ts @@ -1,14 +1,14 @@ -import {BitArray} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, beforeAll} from "vitest"; import {SecretKey, Signature, fastAggregateVerify} from "@chainsafe/blst"; +import {BitArray} from "@chainsafe/ssz"; +import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {newFilledArray} from "@lodestar/state-transition"; import {ssz} from "@lodestar/types"; -import {SYNC_COMMITTEE_SIZE, SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; +import {beforeAll, beforeEach, describe, expect, it} from "vitest"; import { - aggregate, - replaceIfBetter, SyncContributionAndProofPool, SyncContributionFast, + aggregate, + replaceIfBetter, } from "../../../../src/chain/opPools/syncContributionAndProofPool.js"; import {InsertOutcome} from "../../../../src/chain/opPools/types.js"; import {EMPTY_SIGNATURE} from "../../../../src/constants/index.js"; diff --git a/packages/beacon-node/test/unit/chain/prepareNextSlot.test.ts b/packages/beacon-node/test/unit/chain/prepareNextSlot.test.ts index c7d0a7801fec..fa95a00eebfd 100644 --- a/packages/beacon-node/test/unit/chain/prepareNextSlot.test.ts +++ b/packages/beacon-node/test/unit/chain/prepareNextSlot.test.ts @@ -1,14 +1,14 @@ -import {describe, it, expect, beforeEach, afterEach, vi, Mock, MockInstance} from "vitest"; -import {config} from "@lodestar/config/default"; -import {ForkName, SLOTS_PER_EPOCH} from "@lodestar/params"; import {routes} from "@lodestar/api"; +import {config} from "@lodestar/config/default"; import {ProtoBlock} from "@lodestar/fork-choice"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; -import {MockedLogger, getMockedLogger} from "../../mocks/loggerMock.js"; +import {ForkName, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {Mock, MockInstance, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {IChainOptions} from "../../../src/chain/options.js"; import {PrepareNextSlotScheduler} from "../../../src/chain/prepareNextSlot.js"; -import {generateCachedBellatrixState, zeroProtoBlock} from "../../utils/state.js"; import {PayloadIdCache} from "../../../src/execution/engine/payloadIdCache.js"; +import {MockedLogger, getMockedLogger} from "../../mocks/loggerMock.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; +import {generateCachedBellatrixState, zeroProtoBlock} from "../../utils/state.js"; describe("PrepareNextSlot scheduler", () => { const abortController = new AbortController(); diff --git a/packages/beacon-node/test/unit/chain/reprocess.test.ts b/packages/beacon-node/test/unit/chain/reprocess.test.ts index 927e4cf8d05f..339dc20de27f 100644 --- a/packages/beacon-node/test/unit/chain/reprocess.test.ts +++ b/packages/beacon-node/test/unit/chain/reprocess.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {ReprocessController} from "../../../src/chain/reprocess.js"; describe("ReprocessController", () => { diff --git a/packages/beacon-node/test/unit/chain/rewards/blockRewards.test.ts b/packages/beacon-node/test/unit/chain/rewards/blockRewards.test.ts index d417d83e2da9..ec42395641f4 100644 --- a/packages/beacon-node/test/unit/chain/rewards/blockRewards.test.ts +++ b/packages/beacon-node/test/unit/chain/rewards/blockRewards.test.ts @@ -1,17 +1,17 @@ -import {describe, it, expect} from "vitest"; import {SYNC_COMMITTEE_SIZE} from "@lodestar/params"; -import {ssz} from "@lodestar/types"; import { CachedBeaconStateAllForks, DataAvailableStatus, ExecutionPayloadStatus, stateTransition, } from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; +import {BlockAltairOpts, getBlockAltair} from "../../../../../state-transition/test/perf/block/util.js"; import { - generatePerfTestCachedStateAltair, cachedStateAltairPopulateCaches, + generatePerfTestCachedStateAltair, } from "../../../../../state-transition/test/perf/util.js"; -import {BlockAltairOpts, getBlockAltair} from "../../../../../state-transition/test/perf/block/util.js"; import {computeBlockRewards} from "../../../../src/chain/rewards/blockRewards.js"; describe("chain / rewards / blockRewards", () => { diff --git a/packages/beacon-node/test/unit/chain/seenCache/aggregateAndProof.test.ts b/packages/beacon-node/test/unit/chain/seenCache/aggregateAndProof.test.ts index d83433a649ca..c69004ac98b9 100644 --- a/packages/beacon-node/test/unit/chain/seenCache/aggregateAndProof.test.ts +++ b/packages/beacon-node/test/unit/chain/seenCache/aggregateAndProof.test.ts @@ -1,9 +1,9 @@ import {BitArray} from "@chainsafe/ssz"; -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import { AggregationInfo, - insertDesc, SeenAggregatedAttestations, + insertDesc, } from "../../../../src/chain/seenCache/seenAggregateAndProof.js"; describe("SeenAggregatedAttestations.isKnown", () => { diff --git a/packages/beacon-node/test/unit/chain/seenCache/seenAttestationData.test.ts b/packages/beacon-node/test/unit/chain/seenCache/seenAttestationData.test.ts index b4857226267e..ee5cb94ae959 100644 --- a/packages/beacon-node/test/unit/chain/seenCache/seenAttestationData.test.ts +++ b/packages/beacon-node/test/unit/chain/seenCache/seenAttestationData.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {InsertOutcome} from "../../../../src/chain/opPools/types.js"; import {AttestationDataCacheEntry, SeenAttestationDatas} from "../../../../src/chain/seenCache/seenAttestationData.js"; diff --git a/packages/beacon-node/test/unit/chain/seenCache/seenGossipBlockInput.test.ts b/packages/beacon-node/test/unit/chain/seenCache/seenGossipBlockInput.test.ts index 27b5eadecf11..2af9f40d2de3 100644 --- a/packages/beacon-node/test/unit/chain/seenCache/seenGossipBlockInput.test.ts +++ b/packages/beacon-node/test/unit/chain/seenCache/seenGossipBlockInput.test.ts @@ -1,9 +1,9 @@ -import {describe, it, expect} from "vitest"; import {createBeaconConfig, createChainForkConfig, defaultChainConfig} from "@lodestar/config"; import {ssz} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; +import {BlockInput, BlockInputType, GossipedInputType} from "../../../../src/chain/blocks/types.js"; import {SeenGossipBlockInput} from "../../../../src/chain/seenCache/seenGossipBlockInput.js"; -import {BlockInputType, GossipedInputType, BlockInput} from "../../../../src/chain/blocks/types.js"; describe("SeenGossipBlockInput", () => { const chainConfig = createChainForkConfig({ diff --git a/packages/beacon-node/test/unit/chain/seenCache/syncCommittee.test.ts b/packages/beacon-node/test/unit/chain/seenCache/syncCommittee.test.ts index 59c67f9cedc2..a24fcc41443d 100644 --- a/packages/beacon-node/test/unit/chain/seenCache/syncCommittee.test.ts +++ b/packages/beacon-node/test/unit/chain/seenCache/syncCommittee.test.ts @@ -1,7 +1,7 @@ import {BitArray} from "@chainsafe/ssz"; -import {describe, it, expect} from "vitest"; import {ssz} from "@lodestar/types"; -import {SeenSyncCommitteeMessages, SeenContributionAndProof} from "../../../../src/chain/seenCache/index.js"; +import {describe, expect, it} from "vitest"; +import {SeenContributionAndProof, SeenSyncCommitteeMessages} from "../../../../src/chain/seenCache/index.js"; const NUM_SLOTS_IN_CACHE = 3; diff --git a/packages/beacon-node/test/unit/chain/shufflingCache.test.ts b/packages/beacon-node/test/unit/chain/shufflingCache.test.ts index d417e555872c..b8a9602ea6ce 100644 --- a/packages/beacon-node/test/unit/chain/shufflingCache.test.ts +++ b/packages/beacon-node/test/unit/chain/shufflingCache.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {generateTestCachedBeaconStateOnlyValidators} from "../../../../state-transition/test/perf/util.js"; import {ShufflingCache} from "../../../src/chain/shufflingCache.js"; diff --git a/packages/beacon-node/test/unit/chain/stateCache/blockStateCacheImpl.test.ts b/packages/beacon-node/test/unit/chain/stateCache/blockStateCacheImpl.test.ts index 19dc0f3a2c60..50ec0b6fc63d 100644 --- a/packages/beacon-node/test/unit/chain/stateCache/blockStateCacheImpl.test.ts +++ b/packages/beacon-node/test/unit/chain/stateCache/blockStateCacheImpl.test.ts @@ -1,11 +1,11 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach} from "vitest"; -import {EpochShuffling} from "@lodestar/state-transition"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {EpochShuffling} from "@lodestar/state-transition"; import {Root} from "@lodestar/types"; +import {beforeEach, describe, expect, it} from "vitest"; import {BlockStateCacheImpl} from "../../../../src/chain/stateCache/index.js"; -import {generateCachedState} from "../../../utils/state.js"; import {ZERO_HASH} from "../../../../src/constants/index.js"; +import {generateCachedState} from "../../../utils/state.js"; describe("BlockStateCacheImpl", () => { let cache: BlockStateCacheImpl; diff --git a/packages/beacon-node/test/unit/chain/stateCache/fifoBlockStateCache.test.ts b/packages/beacon-node/test/unit/chain/stateCache/fifoBlockStateCache.test.ts index 07a8ec12093d..9a341438479d 100644 --- a/packages/beacon-node/test/unit/chain/stateCache/fifoBlockStateCache.test.ts +++ b/packages/beacon-node/test/unit/chain/stateCache/fifoBlockStateCache.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect, beforeEach} from "vitest"; import {toHexString} from "@chainsafe/ssz"; -import {EpochShuffling, CachedBeaconStateAllForks} from "@lodestar/state-transition"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {CachedBeaconStateAllForks, EpochShuffling} from "@lodestar/state-transition"; +import {beforeEach, describe, expect, it} from "vitest"; import {FIFOBlockStateCache} from "../../../../src/chain/stateCache/index.js"; import {generateCachedState} from "../../../utils/state.js"; diff --git a/packages/beacon-node/test/unit/chain/stateCache/inMemoryCheckpointsCache.test.ts b/packages/beacon-node/test/unit/chain/stateCache/inMemoryCheckpointsCache.test.ts index 23a792bef0a8..edfec599b6eb 100644 --- a/packages/beacon-node/test/unit/chain/stateCache/inMemoryCheckpointsCache.test.ts +++ b/packages/beacon-node/test/unit/chain/stateCache/inMemoryCheckpointsCache.test.ts @@ -1,7 +1,7 @@ -import {describe, beforeAll, it, expect, beforeEach} from "vitest"; +import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; import {CachedBeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {phase0} from "@lodestar/types"; -import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; +import {beforeAll, beforeEach, describe, expect, it} from "vitest"; import { CheckpointHex, InMemoryCheckpointStateCache, diff --git a/packages/beacon-node/test/unit/chain/stateCache/persistentCheckpointsCache.test.ts b/packages/beacon-node/test/unit/chain/stateCache/persistentCheckpointsCache.test.ts index aecec564bd92..4e8b62013331 100644 --- a/packages/beacon-node/test/unit/chain/stateCache/persistentCheckpointsCache.test.ts +++ b/packages/beacon-node/test/unit/chain/stateCache/persistentCheckpointsCache.test.ts @@ -1,16 +1,16 @@ -import {describe, it, expect, beforeAll, beforeEach} from "vitest"; import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; import {CachedBeaconStateAllForks, computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {RootHex, phase0} from "@lodestar/types"; import {mapValues, toHexString} from "@lodestar/utils"; -import {PersistentCheckpointStateCache} from "../../../../src/chain/stateCache/persistentCheckpointsCache.js"; -import {checkpointToDatastoreKey} from "../../../../src/chain/stateCache/datastore/index.js"; -import {generateCachedState} from "../../../utils/state.js"; +import {beforeAll, beforeEach, describe, expect, it} from "vitest"; +import {FIFOBlockStateCache, toCheckpointHex} from "../../../../src/chain/index.js"; import {ShufflingCache} from "../../../../src/chain/shufflingCache.js"; -import {testLogger} from "../../../utils/logger.js"; -import {getTestDatastore} from "../../../utils/chain/stateCache/datastore.js"; +import {checkpointToDatastoreKey} from "../../../../src/chain/stateCache/datastore/index.js"; +import {PersistentCheckpointStateCache} from "../../../../src/chain/stateCache/persistentCheckpointsCache.js"; import {CheckpointHex} from "../../../../src/chain/stateCache/types.js"; -import {FIFOBlockStateCache, toCheckpointHex} from "../../../../src/chain/index.js"; +import {getTestDatastore} from "../../../utils/chain/stateCache/datastore.js"; +import {testLogger} from "../../../utils/logger.js"; +import {generateCachedState} from "../../../utils/state.js"; describe("PersistentCheckpointStateCache", () => { let root0a: Buffer, root0b: Buffer, root1: Buffer, root2: Buffer; diff --git a/packages/beacon-node/test/unit/chain/validation/aggregateAndProof.test.ts b/packages/beacon-node/test/unit/chain/validation/aggregateAndProof.test.ts index e2bc392b4ea2..d9833740a9a5 100644 --- a/packages/beacon-node/test/unit/chain/validation/aggregateAndProof.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/aggregateAndProof.test.ts @@ -1,16 +1,16 @@ import {BitArray, toHexString} from "@chainsafe/ssz"; -import {describe, it} from "vitest"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {phase0, ssz} from "@lodestar/types"; +import {describe, it} from "vitest"; import {generateTestCachedBeaconStateOnlyValidators} from "../../../../../state-transition/test/perf/util.js"; -import {IBeaconChain} from "../../../../src/chain/index.js"; import {AttestationErrorCode} from "../../../../src/chain/errors/index.js"; +import {IBeaconChain} from "../../../../src/chain/index.js"; import {validateApiAggregateAndProof, validateGossipAggregateAndProof} from "../../../../src/chain/validation/index.js"; -import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; import {memoOnce} from "../../../utils/cache.js"; +import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; import { - getAggregateAndProofValidData, AggregateAndProofValidDataOpts, + getAggregateAndProofValidData, } from "../../../utils/validationData/aggregateAndProof.js"; describe("chain / validation / aggregateAndProof", () => { diff --git a/packages/beacon-node/test/unit/chain/validation/attestation/getShufflingForAttestationVerification.test.ts b/packages/beacon-node/test/unit/chain/validation/attestation/getShufflingForAttestationVerification.test.ts index 4ba65270e17a..729c03d9d6e5 100644 --- a/packages/beacon-node/test/unit/chain/validation/attestation/getShufflingForAttestationVerification.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/attestation/getShufflingForAttestationVerification.test.ts @@ -1,11 +1,11 @@ -import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; -// We need to import the mock before the packages -import {MockedBeaconChain, getMockedBeaconChain} from "../../../../mocks/mockedBeaconChain.js"; -import {EpochShuffling, computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {EpochDifference, ProtoBlock} from "@lodestar/fork-choice"; +import {EpochShuffling, computeStartSlotAtEpoch} from "@lodestar/state-transition"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {RegenCaller} from "../../../../../src/chain/regen/interface.js"; import {getShufflingForAttestationVerification} from "../../../../../src/chain/validation/index.js"; import {ZERO_HASH_HEX} from "../../../../../src/constants/constants.js"; +// We need to import the mock before the packages +import {MockedBeaconChain, getMockedBeaconChain} from "../../../../mocks/mockedBeaconChain.js"; describe("getShufflingForAttestationVerification", () => { let chain: MockedBeaconChain; diff --git a/packages/beacon-node/test/unit/chain/validation/attestation/validateAttestation.test.ts b/packages/beacon-node/test/unit/chain/validation/attestation/validateAttestation.test.ts index be9fd3587b7c..1ffbf7696111 100644 --- a/packages/beacon-node/test/unit/chain/validation/attestation/validateAttestation.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/attestation/validateAttestation.test.ts @@ -1,8 +1,8 @@ import {BitArray} from "@chainsafe/ssz"; -import {describe, expect, it} from "vitest"; import {ForkName, SLOTS_PER_EPOCH} from "@lodestar/params"; import {ssz} from "@lodestar/types"; import {LodestarError} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {generateTestCachedBeaconStateOnlyValidators} from "../../../../../../state-transition/test/perf/util.js"; import {AttestationErrorCode, GossipErrorCode} from "../../../../../src/chain/errors/index.js"; import {IBeaconChain} from "../../../../../src/chain/index.js"; diff --git a/packages/beacon-node/test/unit/chain/validation/attestation/validateGossipAttestationsSameAttData.test.ts b/packages/beacon-node/test/unit/chain/validation/attestation/validateGossipAttestationsSameAttData.test.ts index 24fae8a03f0b..1b3688fc2e33 100644 --- a/packages/beacon-node/test/unit/chain/validation/attestation/validateGossipAttestationsSameAttData.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/attestation/validateGossipAttestationsSameAttData.test.ts @@ -1,8 +1,8 @@ -import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {PublicKey, SecretKey} from "@chainsafe/blst"; import {ForkName} from "@lodestar/params"; import {SignatureSetType} from "@lodestar/state-transition"; import {ssz} from "@lodestar/types"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {BlsSingleThreadVerifier} from "../../../../../src/chain/bls/singleThread.js"; import {AttestationError, AttestationErrorCode, GossipAction} from "../../../../../src/chain/errors/index.js"; import {IBeaconChain} from "../../../../../src/chain/index.js"; diff --git a/packages/beacon-node/test/unit/chain/validation/attesterSlashing.test.ts b/packages/beacon-node/test/unit/chain/validation/attesterSlashing.test.ts index 629753824669..c9577767f78f 100644 --- a/packages/beacon-node/test/unit/chain/validation/attesterSlashing.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/attesterSlashing.test.ts @@ -1,10 +1,10 @@ -import {describe, it, beforeEach, afterEach, vi} from "vitest"; import {phase0, ssz} from "@lodestar/types"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; -import {generateCachedState} from "../../../utils/state.js"; -import {validateGossipAttesterSlashing} from "../../../../src/chain/validation/attesterSlashing.js"; +import {afterEach, beforeEach, describe, it, vi} from "vitest"; import {AttesterSlashingErrorCode} from "../../../../src/chain/errors/attesterSlashingError.js"; +import {validateGossipAttesterSlashing} from "../../../../src/chain/validation/attesterSlashing.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {generateCachedState} from "../../../utils/state.js"; describe("GossipMessageValidator", () => { let chainStub: MockedBeaconChain; diff --git a/packages/beacon-node/test/unit/chain/validation/block.test.ts b/packages/beacon-node/test/unit/chain/validation/block.test.ts index f8a2b7245ef7..5e3faf794453 100644 --- a/packages/beacon-node/test/unit/chain/validation/block.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/block.test.ts @@ -1,14 +1,14 @@ -import {Mock, Mocked, beforeEach, describe, it, vi} from "vitest"; import {config} from "@lodestar/config/default"; import {ProtoBlock} from "@lodestar/fork-choice"; -import {ForkName} from "@lodestar/params"; +import {ForkBlobs, ForkName} from "@lodestar/params"; import {SignedBeaconBlock, ssz} from "@lodestar/types"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; +import {Mock, Mocked, beforeEach, describe, it, vi} from "vitest"; import {BlockErrorCode} from "../../../../src/chain/errors/index.js"; import {QueuedStateRegenerator} from "../../../../src/chain/regen/index.js"; import {SeenBlockProposers} from "../../../../src/chain/seenCache/index.js"; import {validateGossipBlock} from "../../../../src/chain/validation/index.js"; import {EMPTY_SIGNATURE, ZERO_HASH} from "../../../../src/constants/index.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; import {generateCachedState} from "../../../utils/state.js"; @@ -20,12 +20,15 @@ describe("gossip block validation", () => { let job: SignedBeaconBlock; const proposerIndex = 0; const clockSlot = 32; - const block = ssz.phase0.BeaconBlock.defaultValue(); + const block = ssz.deneb.BeaconBlock.defaultValue(); block.slot = clockSlot; const signature = EMPTY_SIGNATURE; const maxSkipSlots = 10; beforeEach(() => { + // Fill up with kzg commitments + block.body.blobKzgCommitments = Array.from({length: config.MAX_BLOBS_PER_BLOCK}, () => new Uint8Array([0])); + chain = getMockedBeaconChain(); vi.spyOn(chain.clock, "currentSlotWithGossipDisparity", "get").mockReturnValue(clockSlot); forkChoice = chain.forkChoice; @@ -184,9 +187,47 @@ describe("gossip block validation", () => { regen.getPreState.mockResolvedValue(state); // BLS signature verifier returns valid verifySignature.mockResolvedValue(true); - // Force proposer shuffling cache to return wrong value + // Force proposer shuffling cache to return correct value vi.spyOn(state.epochCtx, "getBeaconProposer").mockReturnValue(proposerIndex); await validateGossipBlock(config, chain, job, ForkName.phase0); }); + + it("deneb - TOO_MANY_KZG_COMMITMENTS", async () => { + // Return not known for proposed block + forkChoice.getBlockHex.mockReturnValueOnce(null); + // Returned parent block is latter than proposed block + forkChoice.getBlockHex.mockReturnValueOnce({slot: clockSlot - 1} as ProtoBlock); + // Regen returns some state + const state = generateCachedState(); + regen.getPreState.mockResolvedValue(state); + // BLS signature verifier returns valid + verifySignature.mockResolvedValue(true); + // Force proposer shuffling cache to return correct value + vi.spyOn(state.epochCtx, "getBeaconProposer").mockReturnValue(proposerIndex + 1); + // Add one extra kzg commitment in the block so it goes over the limit + (job as SignedBeaconBlock).message.body.blobKzgCommitments.push(new Uint8Array([0])); + + await expectRejectedWithLodestarError( + validateGossipBlock(config, chain, job, ForkName.deneb), + BlockErrorCode.TOO_MANY_KZG_COMMITMENTS + ); + }); + + it("deneb - valid", async () => { + // Return not known for proposed block + forkChoice.getBlockHex.mockReturnValueOnce(null); + // Returned parent block is latter than proposed block + forkChoice.getBlockHex.mockReturnValueOnce({slot: clockSlot - 1} as ProtoBlock); + // Regen returns some state + const state = generateCachedState(); + regen.getPreState.mockResolvedValue(state); + // BLS signature verifier returns valid + verifySignature.mockResolvedValue(true); + // Force proposer shuffling cache to return correct value + vi.spyOn(state.epochCtx, "getBeaconProposer").mockReturnValue(proposerIndex); + // Keep number of kzg commitments as is so it stays within the limit + + await validateGossipBlock(config, chain, job, ForkName.deneb); + }); }); diff --git a/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts b/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts index 8d5032ed3ec7..6c1d1def3d9d 100644 --- a/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/blsToExecutionChange.test.ts @@ -1,24 +1,24 @@ import {digest} from "@chainsafe/as-sha256"; -import {describe, it, beforeEach, afterEach, vi} from "vitest"; import {SecretKey} from "@chainsafe/blst"; +import {createBeaconConfig} from "@lodestar/config"; import {config as defaultConfig} from "@lodestar/config/default"; -import {computeSigningRoot} from "@lodestar/state-transition"; -import {capella, ssz} from "@lodestar/types"; import { BLS_WITHDRAWAL_PREFIX, - ETH1_ADDRESS_WITHDRAWAL_PREFIX, DOMAIN_BLS_TO_EXECUTION_CHANGE, + ETH1_ADDRESS_WITHDRAWAL_PREFIX, FAR_FUTURE_EPOCH, - SLOTS_PER_EPOCH, ForkName, + SLOTS_PER_EPOCH, } from "@lodestar/params"; -import {createBeaconConfig} from "@lodestar/config"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; -import {generateState} from "../../../utils/state.js"; -import {validateGossipBlsToExecutionChange} from "../../../../src/chain/validation/blsToExecutionChange.js"; +import {computeSigningRoot} from "@lodestar/state-transition"; +import {capella, ssz} from "@lodestar/types"; +import {afterEach, beforeEach, describe, it, vi} from "vitest"; import {BlsToExecutionChangeErrorCode} from "../../../../src/chain/errors/blsToExecutionChangeError.js"; -import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {validateGossipBlsToExecutionChange} from "../../../../src/chain/validation/blsToExecutionChange.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {generateState} from "../../../utils/state.js"; describe("validate bls to execution change", () => { let chainStub: MockedBeaconChain; diff --git a/packages/beacon-node/test/unit/chain/validation/lightClientFinalityUpdate.test.ts b/packages/beacon-node/test/unit/chain/validation/lightClientFinalityUpdate.test.ts index cbd231c926ce..4288b7f440c9 100644 --- a/packages/beacon-node/test/unit/chain/validation/lightClientFinalityUpdate.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/lightClientFinalityUpdate.test.ts @@ -1,11 +1,11 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {altair, ssz} from "@lodestar/types"; import {computeTimeAtSlot} from "@lodestar/state-transition"; +import {altair, ssz} from "@lodestar/types"; import {RequiredSelective} from "@lodestar/utils"; -import {validateLightClientFinalityUpdate} from "../../../../src/chain/validation/lightClientFinalityUpdate.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {LightClientErrorCode} from "../../../../src/chain/errors/lightClientError.js"; import {IBeaconChain} from "../../../../src/chain/index.js"; +import {validateLightClientFinalityUpdate} from "../../../../src/chain/validation/lightClientFinalityUpdate.js"; import {getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; describe("Light Client Finality Update validation", () => { diff --git a/packages/beacon-node/test/unit/chain/validation/lightClientOptimisticUpdate.test.ts b/packages/beacon-node/test/unit/chain/validation/lightClientOptimisticUpdate.test.ts index 7665b4f89179..85a1ebb16330 100644 --- a/packages/beacon-node/test/unit/chain/validation/lightClientOptimisticUpdate.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/lightClientOptimisticUpdate.test.ts @@ -1,11 +1,11 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {altair, ssz} from "@lodestar/types"; import {computeTimeAtSlot} from "@lodestar/state-transition"; +import {altair, ssz} from "@lodestar/types"; import {RequiredSelective} from "@lodestar/utils"; -import {validateLightClientOptimisticUpdate} from "../../../../src/chain/validation/lightClientOptimisticUpdate.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {LightClientErrorCode} from "../../../../src/chain/errors/lightClientError.js"; import {IBeaconChain} from "../../../../src/chain/index.js"; +import {validateLightClientOptimisticUpdate} from "../../../../src/chain/validation/lightClientOptimisticUpdate.js"; import {getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; describe("Light Client Optimistic Update validation", () => { diff --git a/packages/beacon-node/test/unit/chain/validation/proposerSlashing.test.ts b/packages/beacon-node/test/unit/chain/validation/proposerSlashing.test.ts index f5eb7310a39c..4d1fcb3f2490 100644 --- a/packages/beacon-node/test/unit/chain/validation/proposerSlashing.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/proposerSlashing.test.ts @@ -1,10 +1,10 @@ -import {describe, it, beforeEach, afterEach, vi} from "vitest"; import {phase0, ssz} from "@lodestar/types"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; -import {generateCachedState} from "../../../utils/state.js"; +import {afterEach, beforeEach, describe, it, vi} from "vitest"; import {ProposerSlashingErrorCode} from "../../../../src/chain/errors/proposerSlashingError.js"; import {validateGossipProposerSlashing} from "../../../../src/chain/validation/proposerSlashing.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {generateCachedState} from "../../../utils/state.js"; describe("validate proposer slashing", () => { let chainStub: MockedBeaconChain; diff --git a/packages/beacon-node/test/unit/chain/validation/syncCommittee.test.ts b/packages/beacon-node/test/unit/chain/validation/syncCommittee.test.ts index cbffc2a4ffd9..6ed254254154 100644 --- a/packages/beacon-node/test/unit/chain/validation/syncCommittee.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/syncCommittee.test.ts @@ -1,15 +1,15 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, afterEach, beforeEach, beforeAll, afterAll, vi, Mock} from "vitest"; -import {altair, Epoch, Slot} from "@lodestar/types"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {Epoch, Slot, altair} from "@lodestar/types"; +import {Mock, afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import {SyncCommitteeErrorCode} from "../../../../src/chain/errors/syncCommitteeError.js"; +import {SeenSyncCommitteeMessages} from "../../../../src/chain/seenCache/index.js"; import {validateGossipSyncCommittee} from "../../../../src/chain/validation/syncCommittee.js"; +import {ZERO_HASH} from "../../../../src/constants/constants.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; import {generateCachedAltairState} from "../../../utils/state.js"; -import {SeenSyncCommitteeMessages} from "../../../../src/chain/seenCache/index.js"; -import {ZERO_HASH} from "../../../../src/constants/constants.js"; // https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/altair/p2p-interface.md describe("Sync Committee Signature validation", () => { diff --git a/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts b/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts index d556ff610961..697489b8523d 100644 --- a/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts +++ b/packages/beacon-node/test/unit/chain/validation/voluntaryExit.test.ts @@ -1,21 +1,21 @@ -import {describe, it, beforeEach, beforeAll, vi, afterEach} from "vitest"; import {SecretKey} from "@chainsafe/blst"; +import {createBeaconConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; +import {DOMAIN_VOLUNTARY_EXIT, FAR_FUTURE_EPOCH, SLOTS_PER_EPOCH} from "@lodestar/params"; import { CachedBeaconStateAllForks, - computeEpochAtSlot, computeDomain, + computeEpochAtSlot, computeSigningRoot, } from "@lodestar/state-transition"; import {phase0, ssz} from "@lodestar/types"; -import {DOMAIN_VOLUNTARY_EXIT, FAR_FUTURE_EPOCH, SLOTS_PER_EPOCH} from "@lodestar/params"; -import {createBeaconConfig} from "@lodestar/config"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; -import {generateState} from "../../../utils/state.js"; -import {validateGossipVoluntaryExit} from "../../../../src/chain/validation/voluntaryExit.js"; +import {afterEach, beforeAll, beforeEach, describe, it, vi} from "vitest"; import {VoluntaryExitErrorCode} from "../../../../src/chain/errors/voluntaryExitError.js"; -import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {validateGossipVoluntaryExit} from "../../../../src/chain/validation/voluntaryExit.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../../mocks/mockedBeaconChain.js"; import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {generateState} from "../../../utils/state.js"; describe("validate voluntary exit", () => { let chainStub: MockedBeaconChain; diff --git a/packages/beacon-node/test/unit/db/api/repositories/blockArchive.test.ts b/packages/beacon-node/test/unit/db/api/repositories/blockArchive.test.ts index b87e9b926fdd..923a143b6766 100644 --- a/packages/beacon-node/test/unit/db/api/repositories/blockArchive.test.ts +++ b/packages/beacon-node/test/unit/db/api/repositories/blockArchive.test.ts @@ -1,13 +1,13 @@ -import {rimraf} from "rimraf"; -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; -import {ssz} from "@lodestar/types"; import {config} from "@lodestar/config/default"; -import {intToBytes} from "@lodestar/utils"; import {LevelDbController, encodeKey} from "@lodestar/db"; +import {ssz} from "@lodestar/types"; +import {intToBytes} from "@lodestar/utils"; +import {rimraf} from "rimraf"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import {Bucket} from "../../../../../src/db/buckets.js"; import {BlockArchiveRepository} from "../../../../../src/db/repositories/index.js"; import {testLogger} from "../../../../utils/logger.js"; -import {Bucket} from "../../../../../src/db/buckets.js"; describe("block archive repository", () => { const testDir = "./.tmp"; diff --git a/packages/beacon-node/test/unit/db/api/repository.test.ts b/packages/beacon-node/test/unit/db/api/repository.test.ts index 3b2840b3f0be..e2b908bac777 100644 --- a/packages/beacon-node/test/unit/db/api/repository.test.ts +++ b/packages/beacon-node/test/unit/db/api/repository.test.ts @@ -1,9 +1,9 @@ -import all from "it-all"; import {ContainerType} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, vi, afterEach, MockedObject} from "vitest"; -import {Bytes32, ssz} from "@lodestar/types"; import {config} from "@lodestar/config/default"; import {Db, LevelDbController, Repository} from "@lodestar/db"; +import {Bytes32, ssz} from "@lodestar/types"; +import all from "it-all"; +import {MockedObject, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {Bucket} from "../../../../src/db/buckets.js"; vi.mock("@lodestar/db", async (importOriginal) => { diff --git a/packages/beacon-node/test/unit/eth1/eth1DepositDataTracker.test.ts b/packages/beacon-node/test/unit/eth1/eth1DepositDataTracker.test.ts index 40988ed21728..d46e2870fd41 100644 --- a/packages/beacon-node/test/unit/eth1/eth1DepositDataTracker.test.ts +++ b/packages/beacon-node/test/unit/eth1/eth1DepositDataTracker.test.ts @@ -1,12 +1,12 @@ -import {describe, it, expect, beforeEach, afterEach, vi, MockInstance} from "vitest"; import {config} from "@lodestar/config/default"; import {TimeoutError} from "@lodestar/utils"; +import {MockInstance, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import {BeaconDb} from "../../../src/db/beacon.js"; import {Eth1DepositDataTracker} from "../../../src/eth1/eth1DepositDataTracker.js"; -import {Eth1Provider} from "../../../src/eth1/provider/eth1Provider.js"; -import {testLogger} from "../../utils/logger.js"; import {defaultEth1Options} from "../../../src/eth1/options.js"; -import {BeaconDb} from "../../../src/db/beacon.js"; +import {Eth1Provider} from "../../../src/eth1/provider/eth1Provider.js"; import {getMockedBeaconDb} from "../../mocks/mockedBeaconDb.js"; +import {testLogger} from "../../utils/logger.js"; describe("Eth1DepositDataTracker", () => { const controller = new AbortController(); diff --git a/packages/beacon-node/test/unit/eth1/eth1MergeBlockTracker.test.ts b/packages/beacon-node/test/unit/eth1/eth1MergeBlockTracker.test.ts index c7f4c8fb7aa4..38ac5dd87fb7 100644 --- a/packages/beacon-node/test/unit/eth1/eth1MergeBlockTracker.test.ts +++ b/packages/beacon-node/test/unit/eth1/eth1MergeBlockTracker.test.ts @@ -1,11 +1,11 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, afterEach} from "vitest"; import {ChainConfig} from "@lodestar/config"; import {sleep} from "@lodestar/utils"; -import {IEth1Provider} from "../../../src/index.js"; +import {afterEach, beforeEach, describe, expect, it} from "vitest"; import {ZERO_HASH} from "../../../src/constants/index.js"; import {Eth1MergeBlockTracker, StatusCode, toPowBlock} from "../../../src/eth1/eth1MergeBlockTracker.js"; import {Eth1ProviderState, EthJsonRpcBlockRaw} from "../../../src/eth1/interface.js"; +import {IEth1Provider} from "../../../src/index.js"; import {testLogger} from "../../utils/logger.js"; describe("eth1 / Eth1MergeBlockTracker", () => { diff --git a/packages/beacon-node/test/unit/eth1/hexEncoding.test.ts b/packages/beacon-node/test/unit/eth1/hexEncoding.test.ts index 5e5dd953cd61..bb2782f2f735 100644 --- a/packages/beacon-node/test/unit/eth1/hexEncoding.test.ts +++ b/packages/beacon-node/test/unit/eth1/hexEncoding.test.ts @@ -1,11 +1,11 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import { QUANTITY, + bytesToQuantity, + numToQuantity, + quantityToBigint, quantityToBytes, quantityToNum, - quantityToBigint, - numToQuantity, - bytesToQuantity, } from "../../../src/eth1/provider/utils.js"; describe("eth1 / hex encoding", () => { diff --git a/packages/beacon-node/test/unit/eth1/jwt.test.ts b/packages/beacon-node/test/unit/eth1/jwt.test.ts index 5ebcdc17e355..c96344b37c6a 100644 --- a/packages/beacon-node/test/unit/eth1/jwt.test.ts +++ b/packages/beacon-node/test/unit/eth1/jwt.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; -import {encodeJwtToken, decodeJwtToken} from "../../../src/eth1/provider/jwt.js"; +import {describe, expect, it} from "vitest"; +import {decodeJwtToken, encodeJwtToken} from "../../../src/eth1/provider/jwt.js"; describe("ExecutionEngine / jwt", () => { it("encode/decode correctly", () => { diff --git a/packages/beacon-node/test/unit/eth1/utils/depositContract.test.ts b/packages/beacon-node/test/unit/eth1/utils/depositContract.test.ts index 22ca95765a9a..260cb4fef4bd 100644 --- a/packages/beacon-node/test/unit/eth1/utils/depositContract.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/depositContract.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {goerliTestnetLogs, goerliTestnetDepositEvents} from "../../../utils/testnet.js"; +import {describe, expect, it} from "vitest"; import {parseDepositLog} from "../../../../src/eth1/utils/depositContract.js"; +import {goerliTestnetDepositEvents, goerliTestnetLogs} from "../../../utils/testnet.js"; describe("eth1 / util / depositContract", () => { it("Should parse a raw deposit log", () => { diff --git a/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts b/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts index 34334d1b3f8b..2853bff0f8dd 100644 --- a/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/deposits.test.ts @@ -1,15 +1,15 @@ -import {describe, it, expect} from "vitest"; -import {phase0, ssz} from "@lodestar/types"; +import {createChainForkConfig} from "@lodestar/config"; import {MAX_DEPOSITS, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {phase0, ssz} from "@lodestar/types"; import {verifyMerkleBranch} from "@lodestar/utils"; -import {createChainForkConfig} from "@lodestar/config"; -import {filterBy} from "../../../utils/db.js"; -import {Eth1ErrorCode} from "../../../../src/eth1/errors.js"; -import {generateState} from "../../../utils/state.js"; -import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; -import {getDeposits, getDepositsWithProofs, DepositGetter} from "../../../../src/eth1/utils/deposits.js"; +import {describe, expect, it} from "vitest"; import {DepositTree} from "../../../../src/db/repositories/depositDataRoot.js"; +import {Eth1ErrorCode} from "../../../../src/eth1/errors.js"; +import {DepositGetter, getDeposits, getDepositsWithProofs} from "../../../../src/eth1/utils/deposits.js"; import {createCachedBeaconStateTest} from "../../../utils/cachedBeaconState.js"; +import {filterBy} from "../../../utils/db.js"; +import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; +import {generateState} from "../../../utils/state.js"; describe("eth1 / util / deposits", () => { describe("getDeposits", () => { diff --git a/packages/beacon-node/test/unit/eth1/utils/eth1Data.test.ts b/packages/beacon-node/test/unit/eth1/utils/eth1Data.test.ts index dff98500b293..c4107d06e43e 100644 --- a/packages/beacon-node/test/unit/eth1/utils/eth1Data.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/eth1Data.test.ts @@ -1,16 +1,16 @@ -import {describe, it, expect} from "vitest"; import {Root, phase0, ssz} from "@lodestar/types"; import {toHex} from "@lodestar/utils"; -import {iteratorFromArray} from "../../../utils/interator.js"; +import {describe, expect, it} from "vitest"; +import {DepositTree} from "../../../../src/db/repositories/depositDataRoot.js"; +import {Eth1ErrorCode} from "../../../../src/eth1/errors.js"; +import {Eth1Block} from "../../../../src/eth1/interface.js"; import { - getEth1DataForBlocks, - getDepositsByBlockNumber, getDepositRootByDepositCount, + getDepositsByBlockNumber, + getEth1DataForBlocks, } from "../../../../src/eth1/utils/eth1Data.js"; -import {Eth1Block} from "../../../../src/eth1/interface.js"; import {expectRejectedWithLodestarError} from "../../../utils/errors.js"; -import {Eth1ErrorCode} from "../../../../src/eth1/errors.js"; -import {DepositTree} from "../../../../src/db/repositories/depositDataRoot.js"; +import {iteratorFromArray} from "../../../utils/interator.js"; describe("eth1 / util / getEth1DataForBlocks", () => { type TestCase = { diff --git a/packages/beacon-node/test/unit/eth1/utils/eth1DepositEvent.test.ts b/packages/beacon-node/test/unit/eth1/utils/eth1DepositEvent.test.ts index ea504464778c..a1de0fa748e3 100644 --- a/packages/beacon-node/test/unit/eth1/utils/eth1DepositEvent.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/eth1DepositEvent.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {assertConsecutiveDeposits} from "../../../../src/eth1/utils/eth1DepositEvent.js"; describe("eth1 / util / assertConsecutiveDeposits", () => { diff --git a/packages/beacon-node/test/unit/eth1/utils/eth1Vote.test.ts b/packages/beacon-node/test/unit/eth1/utils/eth1Vote.test.ts index e9a9ab5aad24..f8221f76a0f5 100644 --- a/packages/beacon-node/test/unit/eth1/utils/eth1Vote.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/eth1Vote.test.ts @@ -1,16 +1,16 @@ -import {describe, it, expect} from "vitest"; -import {config} from "@lodestar/config/default"; -import {phase0, ssz} from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; +import {config} from "@lodestar/config/default"; import {BeaconStateAllForks} from "@lodestar/state-transition"; -import {generateState} from "../../../utils/state.js"; -import {filterBy} from "../../../utils/db.js"; +import {phase0, ssz} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import { + Eth1DataGetter, getEth1VotesToConsider, pickEth1Vote, votingPeriodStartTime, - Eth1DataGetter, } from "../../../../src/eth1/utils/eth1Vote.js"; +import {filterBy} from "../../../utils/db.js"; +import {generateState} from "../../../utils/state.js"; describe("eth1 / util / eth1Vote", () => { function generateEth1Vote(i: number): phase0.Eth1Data { diff --git a/packages/beacon-node/test/unit/eth1/utils/groupDepositEventsByBlock.test.ts b/packages/beacon-node/test/unit/eth1/utils/groupDepositEventsByBlock.test.ts index a4e786b3aa68..6c9e9b47c1ae 100644 --- a/packages/beacon-node/test/unit/eth1/utils/groupDepositEventsByBlock.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/groupDepositEventsByBlock.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {phase0} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import {groupDepositEventsByBlock} from "../../../../src/eth1/utils/groupDepositEventsByBlock.js"; describe("eth1 / util / groupDepositEventsByBlock", () => { diff --git a/packages/beacon-node/test/unit/eth1/utils/optimizeNextBlockDiffForGenesis.test.ts b/packages/beacon-node/test/unit/eth1/utils/optimizeNextBlockDiffForGenesis.test.ts index 39c4a4d6e773..38a4e6fa83e2 100644 --- a/packages/beacon-node/test/unit/eth1/utils/optimizeNextBlockDiffForGenesis.test.ts +++ b/packages/beacon-node/test/unit/eth1/utils/optimizeNextBlockDiffForGenesis.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {optimizeNextBlockDiffForGenesis} from "../../../../src/eth1/utils/optimizeNextBlockDiffForGenesis.js"; +import {describe, expect, it} from "vitest"; import {Eth1Block} from "../../../../src/eth1/interface.js"; +import {optimizeNextBlockDiffForGenesis} from "../../../../src/eth1/utils/optimizeNextBlockDiffForGenesis.js"; describe("eth1 / utils / optimizeNextBlockDiffForGenesis", () => { it("should return optimized block diff to find genesis time", () => { diff --git a/packages/beacon-node/test/unit/execution/engine/utils.test.ts b/packages/beacon-node/test/unit/execution/engine/utils.test.ts index b81c3e965390..c181166c2aea 100644 --- a/packages/beacon-node/test/unit/execution/engine/utils.test.ts +++ b/packages/beacon-node/test/unit/execution/engine/utils.test.ts @@ -1,14 +1,14 @@ -import {describe, it, expect} from "vitest"; -import {ErrorAborted} from "@lodestar/utils"; import {FetchError} from "@lodestar/api"; -import {ExecutionPayloadStatus, ExecutionEngineState} from "../../../../src/execution/index.js"; +import {ErrorAborted} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; +import {ErrorJsonRpcResponse, HttpRpcError} from "../../../../src/eth1/provider/jsonRpcHttpClient.js"; import { HTTP_CONNECTION_ERROR_CODES, HTTP_FATAL_ERROR_CODES, getExecutionEngineState, } from "../../../../src/execution/engine/utils.js"; +import {ExecutionEngineState, ExecutionPayloadStatus} from "../../../../src/execution/index.js"; import {QueueError, QueueErrorCode} from "../../../../src/util/queue/errors.js"; -import {ErrorJsonRpcResponse, HttpRpcError} from "../../../../src/eth1/provider/jsonRpcHttpClient.js"; describe("execution / engine / utils", () => { describe("getExecutionEngineState", () => { diff --git a/packages/beacon-node/test/unit/executionEngine/http.test.ts b/packages/beacon-node/test/unit/executionEngine/http.test.ts index c9f4ae671e53..5c7078500640 100644 --- a/packages/beacon-node/test/unit/executionEngine/http.test.ts +++ b/packages/beacon-node/test/unit/executionEngine/http.test.ts @@ -1,16 +1,16 @@ -import {fastify} from "fastify"; -import {describe, it, expect, beforeAll, afterAll} from "vitest"; -import {ForkName} from "@lodestar/params"; import {Logger} from "@lodestar/logger"; +import {ForkName} from "@lodestar/params"; +import {fastify} from "fastify"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; +import {RpcPayload} from "../../../src/eth1/interface.js"; +import {numToQuantity} from "../../../src/eth1/provider/utils.js"; import {defaultExecutionEngineHttpOpts} from "../../../src/execution/engine/http.js"; -import {IExecutionEngine, initializeExecutionEngine} from "../../../src/execution/index.js"; import { parseExecutionPayload, serializeExecutionPayload, serializeExecutionPayloadBody, } from "../../../src/execution/engine/types.js"; -import {RpcPayload} from "../../../src/eth1/interface.js"; -import {numToQuantity} from "../../../src/eth1/provider/utils.js"; +import {IExecutionEngine, initializeExecutionEngine} from "../../../src/execution/index.js"; describe("ExecutionEngine / http", () => { const afterCallbacks: (() => Promise | void)[] = []; diff --git a/packages/beacon-node/test/unit/executionEngine/httpRetry.test.ts b/packages/beacon-node/test/unit/executionEngine/httpRetry.test.ts index b254fc9d8b45..e84a1edd1e4f 100644 --- a/packages/beacon-node/test/unit/executionEngine/httpRetry.test.ts +++ b/packages/beacon-node/test/unit/executionEngine/httpRetry.test.ts @@ -1,11 +1,11 @@ -import {fastify} from "fastify"; import {fromHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeAll, afterAll} from "vitest"; -import {ForkName} from "@lodestar/params"; import {Logger} from "@lodestar/logger"; -import {defaultExecutionEngineHttpOpts} from "../../../src/execution/engine/http.js"; +import {ForkName} from "@lodestar/params"; +import {fastify} from "fastify"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; import {bytesToData, numToQuantity} from "../../../src/eth1/provider/utils.js"; -import {IExecutionEngine, initializeExecutionEngine, PayloadAttributes} from "../../../src/execution/index.js"; +import {defaultExecutionEngineHttpOpts} from "../../../src/execution/engine/http.js"; +import {IExecutionEngine, PayloadAttributes, initializeExecutionEngine} from "../../../src/execution/index.js"; describe("ExecutionEngine / http ", () => { const afterCallbacks: (() => Promise | void)[] = []; diff --git a/packages/beacon-node/test/unit/metrics/beacon.test.ts b/packages/beacon-node/test/unit/metrics/beacon.test.ts index 070ea9064be5..b1d32166fe33 100644 --- a/packages/beacon-node/test/unit/metrics/beacon.test.ts +++ b/packages/beacon-node/test/unit/metrics/beacon.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {createMetricsTest} from "./utils.js"; describe("BeaconMetrics", () => { diff --git a/packages/beacon-node/test/unit/metrics/metrics.test.ts b/packages/beacon-node/test/unit/metrics/metrics.test.ts index 327142a81b5f..f654f97180af 100644 --- a/packages/beacon-node/test/unit/metrics/metrics.test.ts +++ b/packages/beacon-node/test/unit/metrics/metrics.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {createMetricsTest} from "./utils.js"; describe("Metrics", () => { diff --git a/packages/beacon-node/test/unit/metrics/server/http.test.ts b/packages/beacon-node/test/unit/metrics/server/http.test.ts index 623410ccd7ae..4356a2e579e8 100644 --- a/packages/beacon-node/test/unit/metrics/server/http.test.ts +++ b/packages/beacon-node/test/unit/metrics/server/http.test.ts @@ -1,6 +1,6 @@ -import {describe, it, afterAll} from "vitest"; import {fetch} from "@lodestar/api"; -import {getHttpMetricsServer, HttpMetricsServer} from "../../../../src/metrics/index.js"; +import {afterAll, describe, it} from "vitest"; +import {HttpMetricsServer, getHttpMetricsServer} from "../../../../src/metrics/index.js"; import {testLogger} from "../../../utils/logger.js"; import {createMetricsTest} from "../utils.js"; diff --git a/packages/beacon-node/test/unit/metrics/utils.test.ts b/packages/beacon-node/test/unit/metrics/utils.test.ts index 921a549eaf5c..8932d601c273 100644 --- a/packages/beacon-node/test/unit/metrics/utils.test.ts +++ b/packages/beacon-node/test/unit/metrics/utils.test.ts @@ -1,5 +1,5 @@ import {Gauge, Registry} from "prom-client"; -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {GaugeExtra} from "../../../src/metrics/utils/gauge.js"; type MetricValue = { diff --git a/packages/beacon-node/test/unit/metrics/utils.ts b/packages/beacon-node/test/unit/metrics/utils.ts index 53e61826250c..93c635d15b85 100644 --- a/packages/beacon-node/test/unit/metrics/utils.ts +++ b/packages/beacon-node/test/unit/metrics/utils.ts @@ -1,6 +1,6 @@ import {config} from "@lodestar/config/default"; import {ssz} from "@lodestar/types"; -import {createMetrics, Metrics} from "../../../src/metrics/index.js"; +import {Metrics, createMetrics} from "../../../src/metrics/index.js"; import {testLogger} from "../../utils/logger.js"; export function createMetricsTest(): Metrics { diff --git a/packages/beacon-node/test/unit/monitoring/clientStats.test.ts b/packages/beacon-node/test/unit/monitoring/clientStats.test.ts index d14fd88796f2..e4e1e3714a6e 100644 --- a/packages/beacon-node/test/unit/monitoring/clientStats.test.ts +++ b/packages/beacon-node/test/unit/monitoring/clientStats.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {ClientStats} from "../../../src/monitoring/types.js"; +import {describe, expect, it} from "vitest"; import {createClientStats} from "../../../src/monitoring/clientStats.js"; +import {ClientStats} from "../../../src/monitoring/types.js"; import {BEACON_NODE_STATS_SCHEMA, ClientStatsSchema, SYSTEM_STATS_SCHEMA, VALIDATOR_STATS_SCHEMA} from "./schemas.js"; describe("monitoring / clientStats", () => { diff --git a/packages/beacon-node/test/unit/monitoring/properties.test.ts b/packages/beacon-node/test/unit/monitoring/properties.test.ts index 1a2e2c58377a..184617389443 100644 --- a/packages/beacon-node/test/unit/monitoring/properties.test.ts +++ b/packages/beacon-node/test/unit/monitoring/properties.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeAll} from "vitest"; +import {beforeAll, describe, expect, it} from "vitest"; import {Metrics} from "../../../src/metrics/index.js"; import {DynamicProperty, MetricProperty, StaticProperty} from "../../../src/monitoring/properties.js"; import {JsonType} from "../../../src/monitoring/types.js"; diff --git a/packages/beacon-node/test/unit/monitoring/service.test.ts b/packages/beacon-node/test/unit/monitoring/service.test.ts index fed64b9bc553..06fd0d1f511a 100644 --- a/packages/beacon-node/test/unit/monitoring/service.test.ts +++ b/packages/beacon-node/test/unit/monitoring/service.test.ts @@ -1,12 +1,12 @@ -import {describe, it, expect, beforeEach, beforeAll, afterAll, vi, afterEach, MockInstance} from "vitest"; -import {Histogram} from "prom-client"; import {ErrorAborted, TimeoutError} from "@lodestar/utils"; +import {Histogram} from "prom-client"; +import {MockInstance, afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import {RegistryMetricCreator} from "../../../src/index.js"; -import {MonitoringService} from "../../../src/monitoring/service.js"; import {MonitoringOptions} from "../../../src/monitoring/options.js"; -import {sleep} from "../../utils/sleep.js"; +import {MonitoringService} from "../../../src/monitoring/service.js"; import {MockedLogger, getMockedLogger} from "../../mocks/loggerMock.js"; -import {startRemoteService, remoteServiceRoutes, remoteServiceError} from "./remoteService.js"; +import {sleep} from "../../utils/sleep.js"; +import {remoteServiceError, remoteServiceRoutes, startRemoteService} from "./remoteService.js"; describe("monitoring / service", () => { const endpoint = "https://test.example.com/api/v1/client/metrics"; diff --git a/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts b/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts index 2104235e7215..2d9c0967a409 100644 --- a/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts +++ b/packages/beacon-node/test/unit/network/beaconBlocksMaybeBlobsByRange.test.ts @@ -1,13 +1,13 @@ -import {describe, it, expect, beforeAll} from "vitest"; -import {ssz, deneb} from "@lodestar/types"; -import {ForkName} from "@lodestar/params"; import {createBeaconConfig, createChainForkConfig, defaultChainConfig} from "@lodestar/config"; +import {ForkName} from "@lodestar/params"; +import {deneb, ssz} from "@lodestar/types"; +import {beforeAll, describe, expect, it} from "vitest"; +import {BlobsSource, BlockSource, getBlockInput} from "../../../src/chain/blocks/types.js"; +import {ZERO_HASH} from "../../../src/constants/constants.js"; +import {INetwork} from "../../../src/network/interface.js"; import {beaconBlocksMaybeBlobsByRange} from "../../../src/network/reqresp/index.js"; -import {BlockSource, BlobsSource, getBlockInput} from "../../../src/chain/blocks/types.js"; import {initCKZG, loadEthereumTrustedSetup} from "../../../src/util/kzg.js"; -import {INetwork} from "../../../src/network/interface.js"; -import {ZERO_HASH} from "../../../src/constants/constants.js"; describe("beaconBlocksMaybeBlobsByRange", () => { beforeAll(async () => { diff --git a/packages/beacon-node/test/unit/network/fork.test.ts b/packages/beacon-node/test/unit/network/fork.test.ts index bbe1c0870d30..ed11ce979ef0 100644 --- a/packages/beacon-node/test/unit/network/fork.test.ts +++ b/packages/beacon-node/test/unit/network/fork.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; -import {ForkName, ForkSeq} from "@lodestar/params"; import {BeaconConfig, ForkInfo} from "@lodestar/config"; -import {getCurrentAndNextFork, getActiveForks} from "../../../src/network/forks.js"; +import {ForkName, ForkSeq} from "@lodestar/params"; +import {describe, expect, it} from "vitest"; +import {getActiveForks, getCurrentAndNextFork} from "../../../src/network/forks.js"; function getForkConfig({ phase0, diff --git a/packages/beacon-node/test/unit/network/gossip/topic.test.ts b/packages/beacon-node/test/unit/network/gossip/topic.test.ts index 2a61d8604439..4b323865061e 100644 --- a/packages/beacon-node/test/unit/network/gossip/topic.test.ts +++ b/packages/beacon-node/test/unit/network/gossip/topic.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; import {ForkName} from "@lodestar/params"; -import {GossipType, GossipEncoding, GossipTopicMap} from "../../../../src/network/gossip/index.js"; +import {describe, expect, it} from "vitest"; +import {GossipEncoding, GossipTopicMap, GossipType} from "../../../../src/network/gossip/index.js"; import {parseGossipTopic, stringifyGossipTopic} from "../../../../src/network/gossip/topic.js"; import {config} from "../../../utils/config.js"; @@ -17,7 +17,7 @@ describe("network / gossip / topic", () => { ], [GossipType.blob_sidecar]: [ { - topic: {type: GossipType.blob_sidecar, index: 1, fork: ForkName.deneb, encoding}, + topic: {type: GossipType.blob_sidecar, subnet: 1, fork: ForkName.deneb, encoding}, topicStr: "/eth2/46acb19a/blob_sidecar_1/ssz_snappy", }, ], diff --git a/packages/beacon-node/test/unit/network/metadata.test.ts b/packages/beacon-node/test/unit/network/metadata.test.ts index 50e4157a29cd..90b75a16df66 100644 --- a/packages/beacon-node/test/unit/network/metadata.test.ts +++ b/packages/beacon-node/test/unit/network/metadata.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {toHex} from "@lodestar/utils"; import {ssz} from "@lodestar/types"; +import {toHex} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {getENRForkID} from "../../../src/network/metadata.js"; import {config} from "../../utils/config.js"; diff --git a/packages/beacon-node/test/unit/network/peers/client.test.ts b/packages/beacon-node/test/unit/network/peers/client.test.ts index 44d16ad4bb8f..6d280d82ddcf 100644 --- a/packages/beacon-node/test/unit/network/peers/client.test.ts +++ b/packages/beacon-node/test/unit/network/peers/client.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; -import {getKnownClientFromAgentVersion, ClientKind} from "../../../../src/network/peers/client.js"; +import {describe, expect, it} from "vitest"; +import {ClientKind, getKnownClientFromAgentVersion} from "../../../../src/network/peers/client.js"; describe("clientFromAgentVersion", () => { const testCases: {name: string; agentVersion: string; client: ClientKind | null}[] = [ diff --git a/packages/beacon-node/test/unit/network/peers/datastore.test.ts b/packages/beacon-node/test/unit/network/peers/datastore.test.ts index 6ef60b0962e5..01bdc5b058e5 100644 --- a/packages/beacon-node/test/unit/network/peers/datastore.test.ts +++ b/packages/beacon-node/test/unit/network/peers/datastore.test.ts @@ -1,6 +1,6 @@ import {LevelDatastore} from "datastore-level"; import {Key} from "interface-datastore"; -import {describe, it, expect, beforeEach, afterEach, vi, MockedObject} from "vitest"; +import {MockedObject, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {Eth2PeerDataStore} from "../../../../src/network/peers/datastore.js"; vi.mock("datastore-level"); diff --git a/packages/beacon-node/test/unit/network/peers/discover.test.ts b/packages/beacon-node/test/unit/network/peers/discover.test.ts index 52e254ec70aa..40614a3c55d1 100644 --- a/packages/beacon-node/test/unit/network/peers/discover.test.ts +++ b/packages/beacon-node/test/unit/network/peers/discover.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {getValidPeerId} from "../../../utils/peer.js"; +import {describe, expect, it} from "vitest"; import {peerIdFromString} from "../../../../src/util/peerId.js"; +import {getValidPeerId} from "../../../utils/peer.js"; describe("network / peers / discover", () => { it("PeerId API", () => { diff --git a/packages/beacon-node/test/unit/network/peers/priorization.test.ts b/packages/beacon-node/test/unit/network/peers/priorization.test.ts index 26f8d8c9e535..168335a4bd31 100644 --- a/packages/beacon-node/test/unit/network/peers/priorization.test.ts +++ b/packages/beacon-node/test/unit/network/peers/priorization.test.ts @@ -1,16 +1,16 @@ +import {BitArray} from "@chainsafe/ssz"; import {PeerId} from "@libp2p/interface"; import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; -import {BitArray} from "@chainsafe/ssz"; -import {describe, it, expect} from "vitest"; import {ATTESTATION_SUBNET_COUNT} from "@lodestar/params"; +import {describe, expect, it} from "vitest"; +import {RequestedSubnet} from "../../../../src/network/peers/utils/index.js"; import { ExcessPeerDisconnectReason, - prioritizePeers, PrioritizePeersOpts, + prioritizePeers, sortPeersToPrune, } from "../../../../src/network/peers/utils/prioritizePeers.js"; import {getAttnets, getSyncnets} from "../../../utils/network.js"; -import {RequestedSubnet} from "../../../../src/network/peers/utils/index.js"; type Result = ReturnType; diff --git a/packages/beacon-node/test/unit/network/peers/score.test.ts b/packages/beacon-node/test/unit/network/peers/score.test.ts index 8962b282e0ad..2a5c7d51be59 100644 --- a/packages/beacon-node/test/unit/network/peers/score.test.ts +++ b/packages/beacon-node/test/unit/network/peers/score.test.ts @@ -1,13 +1,13 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; import {MapDef} from "@lodestar/utils"; -import {peerIdFromString} from "../../../../src/util/peerId.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import { PeerAction, - ScoreState, PeerRpcScoreStore, - updateGossipsubScores, RealScore, + ScoreState, + updateGossipsubScores, } from "../../../../src/network/peers/score/index.js"; +import {peerIdFromString} from "../../../../src/util/peerId.js"; vi.mock("../../../../src/network/peers/score/index.js", async (importActual) => { const mod = await importActual(); diff --git a/packages/beacon-node/test/unit/network/peers/utils/assertPeerRelevance.test.ts b/packages/beacon-node/test/unit/network/peers/utils/assertPeerRelevance.test.ts index 19cf4a9e9c5e..b3ee9e49b3ed 100644 --- a/packages/beacon-node/test/unit/network/peers/utils/assertPeerRelevance.test.ts +++ b/packages/beacon-node/test/unit/network/peers/utils/assertPeerRelevance.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; import {phase0} from "@lodestar/types"; -import {assertPeerRelevance, IrrelevantPeerCode} from "../../../../../src/network/peers/utils/assertPeerRelevance.js"; +import {describe, expect, it} from "vitest"; +import {IrrelevantPeerCode, assertPeerRelevance} from "../../../../../src/network/peers/utils/assertPeerRelevance.js"; describe("network / peers / utils / assertPeerRelevance", () => { const correctForkDigest = Buffer.alloc(4, 0); diff --git a/packages/beacon-node/test/unit/network/peers/utils/enrSubnets.test.ts b/packages/beacon-node/test/unit/network/peers/utils/enrSubnets.test.ts index 1c738c764404..c13cc6152f36 100644 --- a/packages/beacon-node/test/unit/network/peers/utils/enrSubnets.test.ts +++ b/packages/beacon-node/test/unit/network/peers/utils/enrSubnets.test.ts @@ -1,8 +1,8 @@ import {BitArray} from "@chainsafe/ssz"; -import {describe, it, expect} from "vitest"; import {SYNC_COMMITTEE_SUBNET_COUNT} from "@lodestar/params"; import {ssz} from "@lodestar/types"; import {toHex} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {deserializeEnrSubnets} from "../../../../../src/network/peers/utils/enrSubnetsDeserialize.js"; describe("ENR syncnets", () => { diff --git a/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts b/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts index da907fd737e9..f211ebbeffae 100644 --- a/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts +++ b/packages/beacon-node/test/unit/network/processor/aggregatorTracker.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {AggregatorTracker} from "../../../../src/network/processor/aggregatorTracker.js"; describe("AggregatorTracker", () => { diff --git a/packages/beacon-node/test/unit/network/processor/gossipQueues/indexed.test.ts b/packages/beacon-node/test/unit/network/processor/gossipQueues/indexed.test.ts index 97f6bb804c99..3776f3e6cfd1 100644 --- a/packages/beacon-node/test/unit/network/processor/gossipQueues/indexed.test.ts +++ b/packages/beacon-node/test/unit/network/processor/gossipQueues/indexed.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {IndexedGossipQueueMinSize} from "../../../../../src/network/processor/gossipQueues/indexed.js"; type Item = { diff --git a/packages/beacon-node/test/unit/network/processor/gossipQueues/linear.test.ts b/packages/beacon-node/test/unit/network/processor/gossipQueues/linear.test.ts index 5848e1885622..9ad7c8e8b4ad 100644 --- a/packages/beacon-node/test/unit/network/processor/gossipQueues/linear.test.ts +++ b/packages/beacon-node/test/unit/network/processor/gossipQueues/linear.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {LinearGossipQueue} from "../../../../../src/network/processor/gossipQueues/linear.js"; import {DropType} from "../../../../../src/network/processor/gossipQueues/types.js"; import {QueueType} from "../../../../../src/util/queue/index.js"; diff --git a/packages/beacon-node/test/unit/network/processorQueues.test.ts b/packages/beacon-node/test/unit/network/processorQueues.test.ts index 07a10591c0ad..23caae9dd774 100644 --- a/packages/beacon-node/test/unit/network/processorQueues.test.ts +++ b/packages/beacon-node/test/unit/network/processorQueues.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {sleep} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; type ValidateOpts = { skipAsync1: boolean; diff --git a/packages/beacon-node/test/unit/network/reqresp/collectSequentialBlocksInRange.test.ts b/packages/beacon-node/test/unit/network/reqresp/collectSequentialBlocksInRange.test.ts index fa9b47ebf026..79f076c828a7 100644 --- a/packages/beacon-node/test/unit/network/reqresp/collectSequentialBlocksInRange.test.ts +++ b/packages/beacon-node/test/unit/network/reqresp/collectSequentialBlocksInRange.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; -import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types"; -import {ResponseIncoming} from "@lodestar/reqresp"; import {ForkName} from "@lodestar/params"; +import {ResponseIncoming} from "@lodestar/reqresp"; +import {SignedBeaconBlock, phase0, ssz} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import { BlocksByRangeError, BlocksByRangeErrorCode, diff --git a/packages/beacon-node/test/unit/network/reqresp/utils.ts b/packages/beacon-node/test/unit/network/reqresp/utils.ts index 231bd0cc42fb..01ec743b5258 100644 --- a/packages/beacon-node/test/unit/network/reqresp/utils.ts +++ b/packages/beacon-node/test/unit/network/reqresp/utils.ts @@ -1,9 +1,9 @@ -import {expect} from "vitest"; +import {toHexString} from "@chainsafe/ssz"; import {Direction, ReadStatus, Stream, StreamStatus, WriteStatus} from "@libp2p/interface"; import {logger} from "@libp2p/logger"; -import {Uint8ArrayList} from "uint8arraylist"; -import {toHexString} from "@chainsafe/ssz"; import {Root} from "@lodestar/types"; +import {Uint8ArrayList} from "uint8arraylist"; +import {expect} from "vitest"; export function generateRoots(count: number, offset = 0): Root[] { const roots: Root[] = []; diff --git a/packages/beacon-node/test/unit/network/subnets/attnetsService.test.ts b/packages/beacon-node/test/unit/network/subnets/attnetsService.test.ts index d279a5d759d7..5e7149f4d7f8 100644 --- a/packages/beacon-node/test/unit/network/subnets/attnetsService.test.ts +++ b/packages/beacon-node/test/unit/network/subnets/attnetsService.test.ts @@ -1,6 +1,4 @@ -import {describe, it, expect, beforeEach, vi, MockedObject, afterEach} from "vitest"; import {createBeaconConfig} from "@lodestar/config"; -import {ZERO_HASH} from "@lodestar/state-transition"; import { ATTESTATION_SUBNET_COUNT, EPOCHS_PER_SUBNET_SUBSCRIPTION, @@ -8,14 +6,16 @@ import { SLOTS_PER_EPOCH, SUBNETS_PER_NODE, } from "@lodestar/params"; +import {ZERO_HASH} from "@lodestar/state-transition"; import {getCurrentSlot} from "@lodestar/state-transition"; import {bigIntToBytes} from "@lodestar/utils"; -import {Clock, IClock} from "../../../../src/util/clock.js"; +import {MockedObject, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {Eth2Gossipsub} from "../../../../src/network/gossip/gossipsub.js"; import {MetadataController} from "../../../../src/network/metadata.js"; -import {testLogger} from "../../../utils/logger.js"; import {AttnetsService} from "../../../../src/network/subnets/attnetsService.js"; import {CommitteeSubscription} from "../../../../src/network/subnets/interface.js"; +import {Clock, IClock} from "../../../../src/util/clock.js"; +import {testLogger} from "../../../utils/logger.js"; vi.mock("../../../../src/network/gossip/gossipsub.js"); diff --git a/packages/beacon-node/test/unit/network/subnets/util.test.ts b/packages/beacon-node/test/unit/network/subnets/util.test.ts index dc2f261d021e..edcc96a772da 100644 --- a/packages/beacon-node/test/unit/network/subnets/util.test.ts +++ b/packages/beacon-node/test/unit/network/subnets/util.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {bigIntToBytes} from "@lodestar/utils"; import {ATTESTATION_SUBNET_PREFIX_BITS, NODE_ID_BITS} from "@lodestar/params"; +import {bigIntToBytes} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {getNodeIdPrefix, getNodeOffset} from "../../../../src/network/subnets/util.js"; const nodeIds: string[] = [ diff --git a/packages/beacon-node/test/unit/network/unavailableBeaconBlobsByRoot.test.ts b/packages/beacon-node/test/unit/network/unavailableBeaconBlobsByRoot.test.ts new file mode 100644 index 000000000000..b222b2ac38d8 --- /dev/null +++ b/packages/beacon-node/test/unit/network/unavailableBeaconBlobsByRoot.test.ts @@ -0,0 +1,257 @@ +import {toHexString} from "@chainsafe/ssz"; +import {createBeaconConfig, createChainForkConfig, defaultChainConfig} from "@lodestar/config"; +import {BYTES_PER_FIELD_ELEMENT, FIELD_ELEMENTS_PER_BLOB, ForkBlobs, ForkName, isForkBlobs} from "@lodestar/params"; +import {signedBlockToSignedHeader} from "@lodestar/state-transition"; +import {SignedBeaconBlock, deneb, ssz} from "@lodestar/types"; +import {beforeAll, describe, expect, it, vi} from "vitest"; +import { + BlobsSource, + BlockInput, + BlockInputDataBlobs, + BlockInputType, + BlockSource, + CachedData, + getBlockInput, +} from "../../../src/chain/blocks/types.js"; +import {IExecutionEngine} from "../../../src/execution/index.js"; +import {INetwork} from "../../../src/network/interface.js"; +import {unavailableBeaconBlobsByRoot} from "../../../src/network/reqresp/index.js"; +import {computeInclusionProof, kzgCommitmentToVersionedHash} from "../../../src/util/blobs.js"; +import {ckzg} from "../../../src/util/kzg.js"; +import {initCKZG, loadEthereumTrustedSetup} from "../../../src/util/kzg.js"; + +describe("unavailableBeaconBlobsByRoot", () => { + beforeAll(async () => { + await initCKZG(); + loadEthereumTrustedSetup(); + }); + + /* eslint-disable @typescript-eslint/naming-convention */ + const chainConfig = createChainForkConfig({ + ...defaultChainConfig, + ALTAIR_FORK_EPOCH: 0, + BELLATRIX_FORK_EPOCH: 0, + CAPELLA_FORK_EPOCH: 0, + DENEB_FORK_EPOCH: 0, + }); + const genesisValidatorsRoot = Buffer.alloc(32, 0xaa); + const config = createBeaconConfig(chainConfig, genesisValidatorsRoot); + + const executionEngine = { + getBlobs: vi.fn(), + }; + + const network = { + sendBeaconBlocksByRoot: vi.fn(), + sendBlobSidecarsByRoot: vi.fn(), + }; + + const peerId = "mockPeerId"; + const engineGetBlobsCache = new Map(); + + it("should successfully resolve all blobs from engine and network", async () => { + // Simulate a block 1 with 5 blobs + const signedBlock = ssz.deneb.SignedBeaconBlock.defaultValue(); + signedBlock.message.slot = 1; + const blobscommitmentsandproofs = generateBlobs(5); + signedBlock.message.body.blobKzgCommitments.push(...blobscommitmentsandproofs.kzgCommitments); + const blockheader = signedBlockToSignedHeader(config, signedBlock); + + const unavailableBlockInput = { + block: signedBlock, + source: BlockSource.gossip, + blockBytes: null, + type: BlockInputType.dataPromise, + cachedData: getEmptyBlockInputCacheEntry(ForkName.deneb).cachedData, + } as BlockInput; + + // total of 5 blobs + // blob 0. not in cache & to resolved by getBlobs + // blob 1. not in cache & to resolved by getBlobs + // blob 2. to be found in engineGetBlobsCache + // blob 3. null cached earlier so should directly go to network query and skip engine query + // blob 4. to hit getBlobs first with null response and then go to the network query + // + // engineGetBlobsCache caches 2 fully, and null for 3 + // getBlobs should see 0,1,4 and return first two non null and last null + // network should see 3,4 + + engineGetBlobsCache.set(toHexString(blobscommitmentsandproofs.blobVersionedHashes[2]), { + blob: blobscommitmentsandproofs.blobs[2], + proof: blobscommitmentsandproofs.kzgProofs[2], + }); + engineGetBlobsCache.set(toHexString(blobscommitmentsandproofs.blobVersionedHashes[3]), null); + + // Mock execution engine to return 2 blobs + executionEngine.getBlobs.mockResolvedValueOnce([ + { + blob: blobscommitmentsandproofs.blobs[0], + proof: blobscommitmentsandproofs.kzgProofs[0], + }, + { + blob: blobscommitmentsandproofs.blobs[1], + proof: blobscommitmentsandproofs.kzgProofs[1], + }, + null, + ]); + + // Mock network to return 2 blobs + network.sendBlobSidecarsByRoot.mockResolvedValueOnce([ + { + index: 3, + blob: blobscommitmentsandproofs.blobs[3], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[3], + kzgProof: blobscommitmentsandproofs.kzgProofs[3], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 3), + }, + { + index: 4, + blob: blobscommitmentsandproofs.blobs[4], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[4], + kzgProof: blobscommitmentsandproofs.kzgProofs[4], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 4), + }, + ]); + + const result = await unavailableBeaconBlobsByRoot( + config, + network as unknown as INetwork, + peerId, + unavailableBlockInput, + { + executionEngine: executionEngine as unknown as IExecutionEngine, + metrics: null, + engineGetBlobsCache, + } + ); + + // Check if all blobs are aggregated + const allBlobs = [ + { + index: 0, + blob: blobscommitmentsandproofs.blobs[0], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[0], + kzgProof: blobscommitmentsandproofs.kzgProofs[0], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 0), + }, + { + index: 1, + blob: blobscommitmentsandproofs.blobs[1], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[1], + kzgProof: blobscommitmentsandproofs.kzgProofs[1], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 1), + }, + { + index: 2, + blob: blobscommitmentsandproofs.blobs[2], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[2], + kzgProof: blobscommitmentsandproofs.kzgProofs[2], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 2), + }, + { + index: 3, + blob: blobscommitmentsandproofs.blobs[3], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[3], + kzgProof: blobscommitmentsandproofs.kzgProofs[3], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 3), + }, + { + index: 4, + blob: blobscommitmentsandproofs.blobs[4], + kzgCommitment: blobscommitmentsandproofs.kzgCommitments[4], + kzgProof: blobscommitmentsandproofs.kzgProofs[4], + signedBlockHeader: blockheader, + kzgCommitmentInclusionProof: computeInclusionProof(ForkName.deneb, signedBlock.message.body, 4), + }, + ]; + + const blockData = { + fork: ForkName.deneb as ForkBlobs, + blobs: allBlobs, + blobsBytes: [null, null, null, null, null], + blobsSource: BlobsSource.byRoot, + }; + const resolvedBlobs = getBlockInput.availableData(config, signedBlock, BlockSource.byRoot, null, blockData); + + const engineReqIdentifiers = [...blobscommitmentsandproofs.blobVersionedHashes]; + // versionedHashes: 1,2,4 + engineReqIdentifiers.splice(2, 2); + expect(result).toBeDefined(); + expect(executionEngine.getBlobs).toHaveBeenCalledWith("deneb", engineReqIdentifiers); + expect(result).toEqual(resolvedBlobs); + }); +}); + +type BlockInputCacheType = { + fork: ForkName; + block?: SignedBeaconBlock; + blockBytes?: Uint8Array | null; + cachedData?: CachedData; + // block promise and its callback cached for delayed resolution + blockInputPromise: Promise; + resolveBlockInput: (blockInput: BlockInput) => void; +}; + +function getEmptyBlockInputCacheEntry(fork: ForkName): BlockInputCacheType { + // Capture both the promise and its callbacks for blockInput and final availability + // It is not spec'ed but in tests in Firefox and NodeJS the promise constructor is run immediately + let resolveBlockInput: ((block: BlockInput) => void) | null = null; + const blockInputPromise = new Promise((resolveCB) => { + resolveBlockInput = resolveCB; + }); + if (resolveBlockInput === null) { + throw Error("Promise Constructor was not executed immediately"); + } + if (!isForkBlobs(fork)) { + return {fork, blockInputPromise, resolveBlockInput}; + } + + let resolveAvailability: ((blobs: BlockInputDataBlobs) => void) | null = null; + const availabilityPromise = new Promise((resolveCB) => { + resolveAvailability = resolveCB; + }); + + if (resolveAvailability === null) { + throw Error("Promise Constructor was not executed immediately"); + } + + const blobsCache = new Map(); + const cachedData: CachedData = {fork, blobsCache, availabilityPromise, resolveAvailability}; + return {fork, blockInputPromise, resolveBlockInput, cachedData}; +} + +function generateBlobs(count: number): { + blobs: Uint8Array[]; + kzgCommitments: Uint8Array[]; + blobVersionedHashes: Uint8Array[]; + kzgProofs: Uint8Array[]; +} { + const blobs = Array.from({length: count}, (_, index) => generateRandomBlob(index)); + const kzgCommitments = blobs.map((blob) => ckzg.blobToKzgCommitment(blob)); + const versionedHash = kzgCommitments.map((kzgCommitment) => kzgCommitmentToVersionedHash(kzgCommitment)); + const kzgProofs = blobs.map((blob, index) => ckzg.computeBlobKzgProof(blob, kzgCommitments[index])); + + return { + blobs, + kzgCommitments, + blobVersionedHashes: versionedHash.map((hash) => hash), + kzgProofs, + }; +} + +function generateRandomBlob(index: number): deneb.Blob { + const blob = new Uint8Array(FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT); + const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength); + + for (let i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) { + // Generate a unique value based on the index + dv.setUint32(i * BYTES_PER_FIELD_ELEMENT, index + i); + } + return blob; +} diff --git a/packages/beacon-node/test/unit/network/util.test.ts b/packages/beacon-node/test/unit/network/util.test.ts index 70da41bd2c2a..57e18a34a77b 100644 --- a/packages/beacon-node/test/unit/network/util.test.ts +++ b/packages/beacon-node/test/unit/network/util.test.ts @@ -1,8 +1,8 @@ -import {describe, it, expect, afterEach} from "vitest"; import {config} from "@lodestar/config/default"; import {ForkName} from "@lodestar/params"; -import {getDiscv5Multiaddrs} from "../../../src/network/libp2p/index.js"; +import {afterEach, describe, expect, it} from "vitest"; import {getCurrentAndNextFork} from "../../../src/network/forks.js"; +import {getDiscv5Multiaddrs} from "../../../src/network/libp2p/index.js"; describe("getCurrentAndNextFork", () => { const altairEpoch = config.forks.altair.epoch; diff --git a/packages/beacon-node/test/unit/sync/backfill/verify.test.ts b/packages/beacon-node/test/unit/sync/backfill/verify.test.ts index 3197013455e3..fb00e5840317 100644 --- a/packages/beacon-node/test/unit/sync/backfill/verify.test.ts +++ b/packages/beacon-node/test/unit/sync/backfill/verify.test.ts @@ -1,13 +1,13 @@ import fs from "node:fs"; import path from "node:path"; import {fileURLToPath} from "node:url"; -import {describe, it, expect} from "vitest"; import {createBeaconConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; -import {phase0, ssz, WithBytes} from "@lodestar/types"; -import {verifyBlockSequence} from "../../../../src/sync/backfill/verify.js"; +import {WithBytes, phase0, ssz} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import {ZERO_HASH} from "../../../../src/constants/constants.js"; -import {BackfillSyncErrorCode, BackfillSyncError} from "./../../../../src/sync/backfill/errors.js"; +import {verifyBlockSequence} from "../../../../src/sync/backfill/verify.js"; +import {BackfillSyncError, BackfillSyncErrorCode} from "./../../../../src/sync/backfill/errors.js"; // Global variable __dirname no longer available in ES6 modules. // Solutions: https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules diff --git a/packages/beacon-node/test/unit/sync/range/batch.test.ts b/packages/beacon-node/test/unit/sync/range/batch.test.ts index 02f49226c11f..2a140760e827 100644 --- a/packages/beacon-node/test/unit/sync/range/batch.test.ts +++ b/packages/beacon-node/test/unit/sync/range/batch.test.ts @@ -1,11 +1,11 @@ -import {describe, it, expect} from "vitest"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {config} from "@lodestar/config/default"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {ssz} from "@lodestar/types"; -import {expectThrowsLodestarError} from "../../../utils/errors.js"; -import {Batch, BatchStatus, BatchErrorCode, BatchError} from "../../../../src/sync/range/batch.js"; -import {EPOCHS_PER_BATCH} from "../../../../src/sync/constants.js"; +import {describe, expect, it} from "vitest"; import {BlockSource, getBlockInput} from "../../../../src/chain/blocks/types.js"; +import {EPOCHS_PER_BATCH} from "../../../../src/sync/constants.js"; +import {Batch, BatchError, BatchErrorCode, BatchStatus} from "../../../../src/sync/range/batch.js"; +import {expectThrowsLodestarError} from "../../../utils/errors.js"; import {validPeerIdStr} from "../../../utils/peer.js"; describe("sync / range / batch", () => { // Common mock data diff --git a/packages/beacon-node/test/unit/sync/range/chain.test.ts b/packages/beacon-node/test/unit/sync/range/chain.test.ts index 658f950b2c18..a761cd3a739a 100644 --- a/packages/beacon-node/test/unit/sync/range/chain.test.ts +++ b/packages/beacon-node/test/unit/sync/range/chain.test.ts @@ -1,16 +1,16 @@ -import {describe, it, afterEach} from "vitest"; import {config} from "@lodestar/config/default"; -import {Logger} from "@lodestar/utils"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {Epoch, phase0, Slot, ssz} from "@lodestar/types"; import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {linspace} from "../../../../src/util/numpy.js"; -import {SyncChain, SyncChainFns, ChainTarget} from "../../../../src/sync/range/chain.js"; -import {RangeSyncType} from "../../../../src/sync/utils/remoteSyncType.js"; +import {Epoch, Slot, phase0, ssz} from "@lodestar/types"; +import {Logger} from "@lodestar/utils"; +import {afterEach, describe, it} from "vitest"; +import {BlockInput, BlockSource, getBlockInput} from "../../../../src/chain/blocks/types.js"; import {ZERO_HASH} from "../../../../src/constants/index.js"; +import {ChainTarget, SyncChain, SyncChainFns} from "../../../../src/sync/range/chain.js"; +import {RangeSyncType} from "../../../../src/sync/utils/remoteSyncType.js"; +import {linspace} from "../../../../src/util/numpy.js"; import {testLogger} from "../../../utils/logger.js"; import {validPeerIdStr} from "../../../utils/peer.js"; -import {BlockInput, BlockSource, getBlockInput} from "../../../../src/chain/blocks/types.js"; describe("sync / range / chain", () => { const testCases: { diff --git a/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts b/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts index c3c6a273dd8d..fcc5f9a1561a 100644 --- a/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts +++ b/packages/beacon-node/test/unit/sync/range/utils/batches.test.ts @@ -1,15 +1,15 @@ -import {describe, it, expect} from "vitest"; import {config} from "@lodestar/config/default"; -import {Epoch, Slot} from "@lodestar/types"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {validPeerIdStr} from "../../../../utils/peer.js"; +import {Epoch, Slot} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import {Batch, BatchStatus} from "../../../../../src/sync/range/batch.js"; import { - validateBatchesStatus, getNextBatchToProcess, isSyncChainDone, toBeDownloadedStartEpoch, + validateBatchesStatus, } from "../../../../../src/sync/range/utils/batches.js"; +import {validPeerIdStr} from "../../../../utils/peer.js"; describe("sync / range / batches", () => { const peer = validPeerIdStr; diff --git a/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts b/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts index a495c41683d6..0eac008d2ecf 100644 --- a/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts +++ b/packages/beacon-node/test/unit/sync/range/utils/peerBalancer.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {config} from "@lodestar/config/default"; +import {describe, expect, it} from "vitest"; import {Batch} from "../../../../../src/sync/range/batch.js"; import {ChainPeersBalancer} from "../../../../../src/sync/range/utils/peerBalancer.js"; import {getRandPeerIdStr} from "../../../../utils/peer.js"; diff --git a/packages/beacon-node/test/unit/sync/range/utils/updateChains.test.ts b/packages/beacon-node/test/unit/sync/range/utils/updateChains.test.ts index 4ff2da3d4441..cfdad515fb3c 100644 --- a/packages/beacon-node/test/unit/sync/range/utils/updateChains.test.ts +++ b/packages/beacon-node/test/unit/sync/range/utils/updateChains.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {updateChains} from "../../../../../src/sync/range/utils/updateChains.js"; +import {describe, expect, it} from "vitest"; import {SyncChain} from "../../../../../src/sync/range/chain.js"; +import {updateChains} from "../../../../../src/sync/range/utils/updateChains.js"; import {RangeSyncType} from "../../../../../src/sync/utils/remoteSyncType.js"; describe("sync / range / utils / updateChains", () => { diff --git a/packages/beacon-node/test/unit/sync/unknownBlock.test.ts b/packages/beacon-node/test/unit/sync/unknownBlock.test.ts index 0694cb97f4ab..8476d025d4f9 100644 --- a/packages/beacon-node/test/unit/sync/unknownBlock.test.ts +++ b/packages/beacon-node/test/unit/sync/unknownBlock.test.ts @@ -1,23 +1,23 @@ import EventEmitter from "node:events"; import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; -import {config as minimalConfig} from "@lodestar/config/default"; import {createChainForkConfig} from "@lodestar/config"; +import {config as minimalConfig} from "@lodestar/config/default"; import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {ssz} from "@lodestar/types"; import {notNullish, sleep} from "@lodestar/utils"; -import {MockedBeaconChain, getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; +import {BlockSource, getBlockInput} from "../../../src/chain/blocks/types.js"; +import {BlockError, BlockErrorCode} from "../../../src/chain/errors/blockError.js"; import {IBeaconChain} from "../../../src/chain/index.js"; +import {SeenBlockProposers} from "../../../src/chain/seenCache/seenBlockProposers.js"; +import {ZERO_HASH} from "../../../src/constants/constants.js"; import {INetwork, NetworkEvent, NetworkEventBus, PeerAction} from "../../../src/network/index.js"; +import {defaultSyncOptions} from "../../../src/sync/options.js"; import {UnknownBlockSync} from "../../../src/sync/unknownBlock.js"; +import {ClockStopped} from "../../mocks/clock.js"; +import {MockedBeaconChain, getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; import {testLogger} from "../../utils/logger.js"; import {getRandPeerIdStr} from "../../utils/peer.js"; -import {BlockSource, getBlockInput} from "../../../src/chain/blocks/types.js"; -import {ClockStopped} from "../../mocks/clock.js"; -import {SeenBlockProposers} from "../../../src/chain/seenCache/seenBlockProposers.js"; -import {BlockError, BlockErrorCode} from "../../../src/chain/errors/blockError.js"; -import {defaultSyncOptions} from "../../../src/sync/options.js"; -import {ZERO_HASH} from "../../../src/constants/constants.js"; describe("sync by UnknownBlockSync", () => { const logger = testLogger(); diff --git a/packages/beacon-node/test/unit/sync/utils/pendingBlocksTree.test.ts b/packages/beacon-node/test/unit/sync/utils/pendingBlocksTree.test.ts index 8e343acc80df..9251c1159c64 100644 --- a/packages/beacon-node/test/unit/sync/utils/pendingBlocksTree.test.ts +++ b/packages/beacon-node/test/unit/sync/utils/pendingBlocksTree.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {RootHex} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import {PendingBlock, PendingBlockStatus, UnknownAndAncestorBlocks} from "../../../../src/sync/index.js"; import { getAllDescendantBlocks, diff --git a/packages/beacon-node/test/unit/sync/utils/remoteSyncType.test.ts b/packages/beacon-node/test/unit/sync/utils/remoteSyncType.test.ts index 0c74170e8029..7404362d8805 100644 --- a/packages/beacon-node/test/unit/sync/utils/remoteSyncType.test.ts +++ b/packages/beacon-node/test/unit/sync/utils/remoteSyncType.test.ts @@ -1,13 +1,13 @@ import {toHexString} from "@chainsafe/ssz"; -import {describe, it, expect} from "vitest"; import {IForkChoice} from "@lodestar/fork-choice"; import {Root, phase0} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; import {ZERO_HASH} from "../../../../src/constants/index.js"; import { - getPeerSyncType, - getRangeSyncType, PeerSyncType, RangeSyncType, + getPeerSyncType, + getRangeSyncType, } from "../../../../src/sync/utils/remoteSyncType.js"; describe("network / peers / remoteSyncType", () => { diff --git a/packages/beacon-node/test/unit/util/address.test.ts b/packages/beacon-node/test/unit/util/address.test.ts index 27f7eba48e0c..cdc01f52797b 100644 --- a/packages/beacon-node/test/unit/util/address.test.ts +++ b/packages/beacon-node/test/unit/util/address.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {isValidAddress} from "../../../src/util/address.js"; describe("Eth address helper", () => { diff --git a/packages/beacon-node/test/unit/util/array.test.ts b/packages/beacon-node/test/unit/util/array.test.ts index 75d3a1b0856d..343a152bb857 100644 --- a/packages/beacon-node/test/unit/util/array.test.ts +++ b/packages/beacon-node/test/unit/util/array.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect, beforeEach} from "vitest"; -import {findLastIndex, LinkedList} from "../../../src/util/array.js"; +import {beforeEach, describe, expect, it} from "vitest"; +import {LinkedList, findLastIndex} from "../../../src/util/array.js"; describe("findLastIndex", () => { it("should return the last index that matches a predicate", () => { diff --git a/packages/beacon-node/test/unit/util/binarySearch.test.ts b/packages/beacon-node/test/unit/util/binarySearch.test.ts index a64420400c24..cccddbd9ffd8 100644 --- a/packages/beacon-node/test/unit/util/binarySearch.test.ts +++ b/packages/beacon-node/test/unit/util/binarySearch.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; -import {binarySearchLte, ErrorNoValues, ErrorNoValueMinValue} from "../../../src/util/binarySearch.js"; +import {describe, expect, it} from "vitest"; +import {ErrorNoValueMinValue, ErrorNoValues, binarySearchLte} from "../../../src/util/binarySearch.js"; describe("util / binarySearch", () => { describe("binarySearchLte", () => { diff --git a/packages/beacon-node/test/unit/util/bitArray.test.ts b/packages/beacon-node/test/unit/util/bitArray.test.ts index 516b4ae79155..7e569b71a8e2 100644 --- a/packages/beacon-node/test/unit/util/bitArray.test.ts +++ b/packages/beacon-node/test/unit/util/bitArray.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {IntersectResult, intersectUint8Arrays} from "../../../src/util/bitArray.js"; describe("util / bitArray / intersectUint8Arrays", () => { diff --git a/packages/beacon-node/test/unit/util/bufferPool.test.ts b/packages/beacon-node/test/unit/util/bufferPool.test.ts index ff66504ae65f..5c97a05a58e4 100644 --- a/packages/beacon-node/test/unit/util/bufferPool.test.ts +++ b/packages/beacon-node/test/unit/util/bufferPool.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {AllocSource, BufferPool} from "../../../src/util/bufferPool.js"; describe("BufferPool", () => { diff --git a/packages/beacon-node/test/unit/util/bytes.test.ts b/packages/beacon-node/test/unit/util/bytes.test.ts index 1942307cde75..38823939d48b 100644 --- a/packages/beacon-node/test/unit/util/bytes.test.ts +++ b/packages/beacon-node/test/unit/util/bytes.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {fromHexString, toHexString} from "@chainsafe/ssz"; +import {describe, expect, it} from "vitest"; import {byteArrayEquals} from "../../../src/util/bytes.js"; diff --git a/packages/beacon-node/test/unit/util/chunkify.test.ts b/packages/beacon-node/test/unit/util/chunkify.test.ts index 595c5807e1b3..c8af022ccf8e 100644 --- a/packages/beacon-node/test/unit/util/chunkify.test.ts +++ b/packages/beacon-node/test/unit/util/chunkify.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {chunkifyInclusiveRange} from "../../../src/util/chunkify.js"; describe("chunkifyInclusiveRange", () => { diff --git a/packages/beacon-node/test/unit/util/clock.test.ts b/packages/beacon-node/test/unit/util/clock.test.ts index 87955b98182c..cdb4aa39e1aa 100644 --- a/packages/beacon-node/test/unit/util/clock.test.ts +++ b/packages/beacon-node/test/unit/util/clock.test.ts @@ -1,8 +1,8 @@ -import {describe, it, expect, beforeEach, afterEach, vi} from "vitest"; import {config} from "@lodestar/config/default"; import {SLOTS_PER_EPOCH} from "@lodestar/params"; -import {Clock, ClockEvent} from "../../../src/util/clock.js"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {MAXIMUM_GOSSIP_CLOCK_DISPARITY} from "../../../src/constants/index.js"; +import {Clock, ClockEvent} from "../../../src/util/clock.js"; describe("Clock", () => { let abortController: AbortController; diff --git a/packages/beacon-node/test/unit/util/dependentRoot.test.ts b/packages/beacon-node/test/unit/util/dependentRoot.test.ts index c8044f332e34..3961c3e1730b 100644 --- a/packages/beacon-node/test/unit/util/dependentRoot.test.ts +++ b/packages/beacon-node/test/unit/util/dependentRoot.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect, beforeEach, afterEach, vi, Mocked} from "vitest"; -import {EpochDifference, ProtoBlock, ForkChoice} from "@lodestar/fork-choice"; +import {EpochDifference, ForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {computeEpochAtSlot} from "@lodestar/state-transition"; +import {Mocked, afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {getShufflingDependentRoot} from "../../../src/util/dependentRoot.js"; vi.mock("@lodestar/fork-choice"); diff --git a/packages/beacon-node/test/unit/util/error.test.ts b/packages/beacon-node/test/unit/util/error.test.ts index 61aa4e42d35e..0293acf3f2ba 100644 --- a/packages/beacon-node/test/unit/util/error.test.ts +++ b/packages/beacon-node/test/unit/util/error.test.ts @@ -1,6 +1,6 @@ import v8 from "node:v8"; -import {describe, it, expect} from "vitest"; import {RequestError, RequestErrorCode, RespStatus, ResponseError} from "@lodestar/reqresp"; +import {describe, expect, it} from "vitest"; import {fromThreadBoundaryError, toThreadBoundaryError} from "../../../src/util/error.js"; function structuredClone(value: T): T { diff --git a/packages/beacon-node/test/unit/util/file.test.ts b/packages/beacon-node/test/unit/util/file.test.ts index 6040e14b4263..ad8a1a324fff 100644 --- a/packages/beacon-node/test/unit/util/file.test.ts +++ b/packages/beacon-node/test/unit/util/file.test.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it, expect, beforeAll, afterAll} from "vitest"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; import {ensureDir, writeIfNotExist} from "../../../src/util/file.js"; describe("file util", () => { diff --git a/packages/beacon-node/test/unit/util/graffiti.test.ts b/packages/beacon-node/test/unit/util/graffiti.test.ts index 0197e39c5e52..89750d423790 100644 --- a/packages/beacon-node/test/unit/util/graffiti.test.ts +++ b/packages/beacon-node/test/unit/util/graffiti.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {getDefaultGraffiti, toGraffitiBuffer} from "../../../src/util/graffiti.js"; +import {describe, expect, it} from "vitest"; import {ClientCode} from "../../../src/execution/index.js"; +import {getDefaultGraffiti, toGraffitiBuffer} from "../../../src/util/graffiti.js"; describe("Graffiti helper", () => { describe("toGraffitiBuffer", () => { diff --git a/packages/beacon-node/test/unit/util/itTrigger.test.ts b/packages/beacon-node/test/unit/util/itTrigger.test.ts index 942791c118bd..ff76cf13eafa 100644 --- a/packages/beacon-node/test/unit/util/itTrigger.test.ts +++ b/packages/beacon-node/test/unit/util/itTrigger.test.ts @@ -1,5 +1,5 @@ import all from "it-all"; -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {ItTrigger} from "../../../src/util/itTrigger.js"; describe("util / itTrigger", () => { diff --git a/packages/beacon-node/test/unit/util/kzg.test.ts b/packages/beacon-node/test/unit/util/kzg.test.ts index 3b1de419ae93..616505268ae1 100644 --- a/packages/beacon-node/test/unit/util/kzg.test.ts +++ b/packages/beacon-node/test/unit/util/kzg.test.ts @@ -1,11 +1,11 @@ -import {describe, it, expect, afterEach, beforeAll} from "vitest"; -import {bellatrix, deneb, ssz} from "@lodestar/types"; -import {BYTES_PER_FIELD_ELEMENT, BLOB_TX_TYPE} from "@lodestar/params"; import {createBeaconConfig, createChainForkConfig, defaultChainConfig} from "@lodestar/config"; -import {getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; -import {computeBlobSidecars, kzgCommitmentToVersionedHash} from "../../../src/util/blobs.js"; -import {loadEthereumTrustedSetup, initCKZG, ckzg, FIELD_ELEMENTS_PER_BLOB_MAINNET} from "../../../src/util/kzg.js"; +import {BLOB_TX_TYPE, BYTES_PER_FIELD_ELEMENT} from "@lodestar/params"; +import {bellatrix, deneb, ssz} from "@lodestar/types"; +import {afterEach, beforeAll, describe, expect, it} from "vitest"; import {validateBlobSidecars, validateGossipBlobSidecar} from "../../../src/chain/validation/blobSidecar.js"; +import {computeBlobSidecars, kzgCommitmentToVersionedHash} from "../../../src/util/blobs.js"; +import {FIELD_ELEMENTS_PER_BLOB_MAINNET, ckzg, initCKZG, loadEthereumTrustedSetup} from "../../../src/util/kzg.js"; +import {getMockedBeaconChain} from "../../mocks/mockedBeaconChain.js"; describe("C-KZG", () => { const afterEachCallbacks: (() => Promise | void)[] = []; diff --git a/packages/beacon-node/test/unit/util/map.test.ts b/packages/beacon-node/test/unit/util/map.test.ts index 2d568b89ae3f..f336ac1d3d8e 100644 --- a/packages/beacon-node/test/unit/util/map.test.ts +++ b/packages/beacon-node/test/unit/util/map.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {OrderedMap} from "../../../src/util/map.js"; describe("OrderedMap", () => { diff --git a/packages/beacon-node/test/unit/util/metadata.test.ts b/packages/beacon-node/test/unit/util/metadata.test.ts index 4e732d93e5d0..17e2ba04ce37 100644 --- a/packages/beacon-node/test/unit/util/metadata.test.ts +++ b/packages/beacon-node/test/unit/util/metadata.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {getLodestarClientVersion} from "../../../src/util/metadata.js"; +import {describe, expect, it} from "vitest"; import {ClientCode} from "../../../src/execution/index.js"; +import {getLodestarClientVersion} from "../../../src/util/metadata.js"; describe("util / metadata", () => { describe("getLodestarClientVersion", () => { diff --git a/packages/beacon-node/test/unit/util/peerId.test.ts b/packages/beacon-node/test/unit/util/peerId.test.ts index 92205c5d0334..5014741aa4b9 100644 --- a/packages/beacon-node/test/unit/util/peerId.test.ts +++ b/packages/beacon-node/test/unit/util/peerId.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {peerIdFromString, peerIdToString} from "../../../src/util/peerId.js"; describe("network peerid", () => { diff --git a/packages/beacon-node/test/unit/util/queue.test.ts b/packages/beacon-node/test/unit/util/queue.test.ts index 10c411547c89..3263ec12a0b7 100644 --- a/packages/beacon-node/test/unit/util/queue.test.ts +++ b/packages/beacon-node/test/unit/util/queue.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {sleep} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {JobFnQueue, QueueError, QueueErrorCode, QueueType} from "../../../src/util/queue/index.js"; import {expectLodestarError, expectRejectedWithLodestarError} from "../../utils/errors.js"; diff --git a/packages/beacon-node/test/unit/util/set.test.ts b/packages/beacon-node/test/unit/util/set.test.ts index 482819b3b77d..361680d2930c 100644 --- a/packages/beacon-node/test/unit/util/set.test.ts +++ b/packages/beacon-node/test/unit/util/set.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, beforeEach} from "vitest"; +import {beforeEach, describe, expect, it} from "vitest"; import {OrderedSet} from "../../../src/util/set.js"; describe("OrderedSet", () => { diff --git a/packages/beacon-node/test/unit/util/shuffle.test.ts b/packages/beacon-node/test/unit/util/shuffle.test.ts index 2ba879514020..faa99ef67737 100644 --- a/packages/beacon-node/test/unit/util/shuffle.test.ts +++ b/packages/beacon-node/test/unit/util/shuffle.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {shuffle} from "../../../src/util/shuffle.js"; describe("util / shuffle", () => { diff --git a/packages/beacon-node/test/unit/util/sortBy.test.ts b/packages/beacon-node/test/unit/util/sortBy.test.ts index 747327cc2bbd..1c648640ffff 100644 --- a/packages/beacon-node/test/unit/util/sortBy.test.ts +++ b/packages/beacon-node/test/unit/util/sortBy.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {sortBy} from "../../../src/util/sortBy.js"; describe("util / sortBy", () => { diff --git a/packages/beacon-node/test/unit/util/sszBytes.test.ts b/packages/beacon-node/test/unit/util/sszBytes.test.ts index 8b72c31df6c8..8fd6011e6255 100644 --- a/packages/beacon-node/test/unit/util/sszBytes.test.ts +++ b/packages/beacon-node/test/unit/util/sszBytes.test.ts @@ -1,22 +1,22 @@ -import {describe, it, expect} from "vitest"; import {BitArray} from "@chainsafe/ssz"; -import {deneb, electra, Epoch, isElectraAttestation, phase0, RootHex, Slot, ssz} from "@lodestar/types"; -import {fromHex, toHex} from "@lodestar/utils"; import {ForkName, MAX_COMMITTEES_PER_SLOT} from "@lodestar/params"; +import {Epoch, RootHex, Slot, deneb, electra, isElectraAttestation, phase0, ssz} from "@lodestar/types"; +import {fromHex, toHex} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import { + getAggregationBitsFromAttestationSerialized, getAttDataFromAttestationSerialized, + getAttDataFromSignedAggregateAndProofElectra, getAttDataFromSignedAggregateAndProofPhase0, - getAggregationBitsFromAttestationSerialized, getBlockRootFromAttestationSerialized, getBlockRootFromSignedAggregateAndProofSerialized, + getCommitteeBitsFromAttestationSerialized, + getCommitteeBitsFromSignedAggregateAndProofElectra, + getSignatureFromAttestationSerialized, getSlotFromAttestationSerialized, + getSlotFromBlobSidecarSerialized, getSlotFromSignedAggregateAndProofSerialized, - getSignatureFromAttestationSerialized, getSlotFromSignedBeaconBlockSerialized, - getSlotFromBlobSidecarSerialized, - getCommitteeBitsFromAttestationSerialized, - getCommitteeBitsFromSignedAggregateAndProofElectra, - getAttDataFromSignedAggregateAndProofElectra, } from "../../../src/util/sszBytes.js"; describe("attestation SSZ serialized picking", () => { diff --git a/packages/beacon-node/test/unit/util/time.test.ts b/packages/beacon-node/test/unit/util/time.test.ts index ccf1b9e308c8..2f32729a5225 100644 --- a/packages/beacon-node/test/unit/util/time.test.ts +++ b/packages/beacon-node/test/unit/util/time.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {prettyTimeDiffSec} from "../../../src/util/time.js"; describe("util / time / prettyTimeDiffSec", () => { diff --git a/packages/beacon-node/test/unit/util/timeSeries.test.ts b/packages/beacon-node/test/unit/util/timeSeries.test.ts index b338310c83b1..f273508e885f 100644 --- a/packages/beacon-node/test/unit/util/timeSeries.test.ts +++ b/packages/beacon-node/test/unit/util/timeSeries.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {TimeSeries} from "../../../src/util/timeSeries.js"; // Even with rounding to 3 decimals, the test still breaks sometimes... diff --git a/packages/beacon-node/test/unit/util/wrapError.test.ts b/packages/beacon-node/test/unit/util/wrapError.test.ts index 2a8e5ca15ceb..f972a1bff148 100644 --- a/packages/beacon-node/test/unit/util/wrapError.test.ts +++ b/packages/beacon-node/test/unit/util/wrapError.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {wrapError} from "../../../src/util/wrapError.js"; describe("util / wrapError", () => { diff --git a/packages/beacon-node/test/utils/api.ts b/packages/beacon-node/test/utils/api.ts index 593bae0c2643..17126defc2c2 100644 --- a/packages/beacon-node/test/utils/api.ts +++ b/packages/beacon-node/test/utils/api.ts @@ -1,11 +1,11 @@ -import {Mocked} from "vitest"; import {config} from "@lodestar/config/default"; import {ForkChoice} from "@lodestar/fork-choice"; -import {MockedBeaconChain, MockedBeaconChainOptions, getMockedBeaconChain} from "../mocks/mockedBeaconChain.js"; +import {Mocked} from "vitest"; +import {ApiModules} from "../../src/api/index.js"; import {getMockedBeaconSync} from "../mocks/beaconSyncMock.js"; +import {MockedBeaconChain, MockedBeaconChainOptions, getMockedBeaconChain} from "../mocks/mockedBeaconChain.js"; import {MockedBeaconDb, getMockedBeaconDb} from "../mocks/mockedBeaconDb.js"; import {getMockedNetwork} from "../mocks/mockedNetwork.js"; -import {ApiModules} from "../../src/api/index.js"; type ApiModulesWithoutConfig = Omit; diff --git a/packages/beacon-node/test/utils/cachedBeaconState.ts b/packages/beacon-node/test/utils/cachedBeaconState.ts index 3efb16b6250f..1c092f2ba4a2 100644 --- a/packages/beacon-node/test/utils/cachedBeaconState.ts +++ b/packages/beacon-node/test/utils/cachedBeaconState.ts @@ -1,10 +1,10 @@ +import {ChainForkConfig} from "@lodestar/config"; import { BeaconStateAllForks, BeaconStateCache, createCachedBeaconState, createEmptyEpochCacheImmutableData, } from "@lodestar/state-transition"; -import {ChainForkConfig} from "@lodestar/config"; export function createCachedBeaconStateTest( state: T, diff --git a/packages/beacon-node/test/utils/cliTools/kzgTrustedSetupFromJson.ts b/packages/beacon-node/test/utils/cliTools/kzgTrustedSetupFromJson.ts index 731f44df59c8..d3cb51458c56 100644 --- a/packages/beacon-node/test/utils/cliTools/kzgTrustedSetupFromJson.ts +++ b/packages/beacon-node/test/utils/cliTools/kzgTrustedSetupFromJson.ts @@ -1,5 +1,5 @@ import fs from "node:fs"; -import {TrustedSetupJSON, trustedSetupJsonToBin, TRUSTED_SETUP_BIN_FILEPATH} from "../../../src/util/kzg.js"; +import {TRUSTED_SETUP_BIN_FILEPATH, TrustedSetupJSON, trustedSetupJsonToBin} from "../../../src/util/kzg.js"; // CLI TOOL: Use to transform a JSON trusted setup into .ssz // diff --git a/packages/beacon-node/test/utils/clock.ts b/packages/beacon-node/test/utils/clock.ts index 390d7dd095dd..1e44b1c42551 100644 --- a/packages/beacon-node/test/utils/clock.ts +++ b/packages/beacon-node/test/utils/clock.ts @@ -1,6 +1,6 @@ import EventEmitter from "node:events"; import {computeEpochAtSlot} from "@lodestar/state-transition"; -import {Slot, Epoch} from "@lodestar/types"; +import {Epoch, Slot} from "@lodestar/types"; import {IClock} from "../../src/util/clock.js"; export class ClockStatic extends EventEmitter implements IClock { diff --git a/packages/beacon-node/test/utils/config.ts b/packages/beacon-node/test/utils/config.ts index f5d566560b65..6822b546de1e 100644 --- a/packages/beacon-node/test/utils/config.ts +++ b/packages/beacon-node/test/utils/config.ts @@ -1,5 +1,5 @@ +import {ChainForkConfig, createBeaconConfig, createChainForkConfig} from "@lodestar/config"; import {config as chainConfig} from "@lodestar/config/default"; -import {createBeaconConfig, ChainForkConfig, createChainForkConfig} from "@lodestar/config"; import {ForkName} from "@lodestar/params"; import {ZERO_HASH} from "../../src/constants/index.js"; diff --git a/packages/beacon-node/test/utils/db.ts b/packages/beacon-node/test/utils/db.ts index c44aa7f878dc..88f8de8c0b30 100644 --- a/packages/beacon-node/test/utils/db.ts +++ b/packages/beacon-node/test/utils/db.ts @@ -1,6 +1,6 @@ import childProcess from "node:child_process"; -import {FilterOptions, LevelDbController} from "@lodestar/db"; import {ChainForkConfig} from "@lodestar/config"; +import {FilterOptions, LevelDbController} from "@lodestar/db"; import {BeaconDb} from "../../src/index.js"; import {testLogger} from "./logger.js"; diff --git a/packages/beacon-node/test/utils/errors.ts b/packages/beacon-node/test/utils/errors.ts index 1bf31a2ce9af..7380433292f2 100644 --- a/packages/beacon-node/test/utils/errors.ts +++ b/packages/beacon-node/test/utils/errors.ts @@ -1,5 +1,5 @@ -import {expect} from "vitest"; import {LodestarError, mapValues} from "@lodestar/utils"; +import {expect} from "vitest"; export function expectThrowsLodestarError(fn: () => void, expectedErr: LodestarError | string): void { try { diff --git a/packages/beacon-node/test/utils/logger.ts b/packages/beacon-node/test/utils/logger.ts index 10f27565216f..7d67dd6fbd16 100644 --- a/packages/beacon-node/test/utils/logger.ts +++ b/packages/beacon-node/test/utils/logger.ts @@ -1,6 +1,6 @@ -import {LogLevel} from "@lodestar/utils"; -import {getNodeLogger, LoggerNode, LoggerNodeOpts} from "@lodestar/logger/node"; import {getEnvLogLevel} from "@lodestar/logger/env"; +import {LoggerNode, LoggerNodeOpts, getNodeLogger} from "@lodestar/logger/node"; +import {LogLevel} from "@lodestar/utils"; export {LogLevel}; export type TestLoggerOpts = LoggerNodeOpts; diff --git a/packages/beacon-node/test/utils/networkWithMockDb.ts b/packages/beacon-node/test/utils/networkWithMockDb.ts index 689d332ebbce..d3b7e70e8168 100644 --- a/packages/beacon-node/test/utils/networkWithMockDb.ts +++ b/packages/beacon-node/test/utils/networkWithMockDb.ts @@ -4,6 +4,7 @@ import {ssz} from "@lodestar/types"; import {BeaconChain} from "../../src/chain/chain.js"; import {Eth1ForBlockProductionDisabled} from "../../src/eth1/index.js"; import {ExecutionEngineDisabled} from "../../src/execution/index.js"; +import {StateArchiveMode} from "../../src/index.js"; import {GossipHandlers, Network, NetworkInitModules, getReqRespHandlers} from "../../src/network/index.js"; import {NetworkOptions, defaultNetworkOptions} from "../../src/network/options.js"; import {GetReqRespHandlerFn} from "../../src/network/reqresp/types.js"; @@ -12,7 +13,6 @@ import {createCachedBeaconStateTest} from "./cachedBeaconState.js"; import {ClockStatic} from "./clock.js"; import {testLogger} from "./logger.js"; import {generateState} from "./state.js"; -import {StateArchiveMode} from "../../src/index.js"; export type NetworkForTestOpts = { startSlot?: number; diff --git a/packages/beacon-node/test/utils/node/beacon.ts b/packages/beacon-node/test/utils/node/beacon.ts index 0163fa148102..ea1d7aa3300d 100644 --- a/packages/beacon-node/test/utils/node/beacon.ts +++ b/packages/beacon-node/test/utils/node/beacon.ts @@ -1,24 +1,24 @@ -import deepmerge from "deepmerge"; -import tmp from "tmp"; import {PeerId} from "@libp2p/interface"; import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; +import {ChainConfig, createBeaconConfig, createChainForkConfig} from "@lodestar/config"; import {config as minimalConfig} from "@lodestar/config/default"; -import {createBeaconConfig, createChainForkConfig, ChainConfig} from "@lodestar/config"; -import {RecursivePartial} from "@lodestar/utils"; import {LevelDbController} from "@lodestar/db"; -import {phase0, ssz} from "@lodestar/types"; +import {LoggerNode} from "@lodestar/logger/node"; import {ForkSeq, GENESIS_SLOT} from "@lodestar/params"; import {BeaconStateAllForks} from "@lodestar/state-transition"; +import {phase0, ssz} from "@lodestar/types"; +import {RecursivePartial} from "@lodestar/utils"; import {isPlainObject} from "@lodestar/utils"; -import {LoggerNode} from "@lodestar/logger/node"; +import deepmerge from "deepmerge"; +import tmp from "tmp"; +import {BeaconDb} from "../../../src/db/index.js"; import {BeaconNode} from "../../../src/index.js"; import {defaultNetworkOptions} from "../../../src/network/options.js"; -import {initDevState, writeDeposits} from "../../../src/node/utils/state.js"; import {IBeaconNodeOptions} from "../../../src/node/options.js"; import {defaultOptions} from "../../../src/node/options.js"; -import {BeaconDb} from "../../../src/db/index.js"; -import {testLogger} from "../logger.js"; import {InteropStateOpts} from "../../../src/node/utils/interop/state.js"; +import {initDevState, writeDeposits} from "../../../src/node/utils/state.js"; +import {testLogger} from "../logger.js"; export async function getDevBeaconNode( opts: { diff --git a/packages/beacon-node/test/utils/node/simTest.ts b/packages/beacon-node/test/utils/node/simTest.ts index 7b771b8534ed..391fc6345b22 100644 --- a/packages/beacon-node/test/utils/node/simTest.ts +++ b/packages/beacon-node/test/utils/node/simTest.ts @@ -1,20 +1,20 @@ import {toHexString} from "@chainsafe/ssz"; +import {routes} from "@lodestar/api"; +import {BeaconConfig} from "@lodestar/config"; +import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; import { - computeEpochAtSlot, - computeStartSlotAtEpoch, CachedBeaconStateAllForks, beforeProcessEpoch, + computeEpochAtSlot, + computeStartSlotAtEpoch, } from "@lodestar/state-transition"; -import {BeaconConfig} from "@lodestar/config"; -import {SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; import {BeaconBlock, Epoch, Slot} from "@lodestar/types"; import {Checkpoint} from "@lodestar/types/phase0"; import {Logger, mapValues} from "@lodestar/utils"; -import {routes} from "@lodestar/api"; -import {BeaconNode} from "../../../src/index.js"; import {ChainEvent, HeadEventData} from "../../../src/chain/index.js"; -import {linspace} from "../../../src/util/numpy.js"; import {RegenCaller} from "../../../src/chain/regen/index.js"; +import {BeaconNode} from "../../../src/index.js"; +import {linspace} from "../../../src/util/numpy.js"; /* eslint-disable no-console */ diff --git a/packages/beacon-node/test/utils/node/validator.ts b/packages/beacon-node/test/utils/node/validator.ts index 285fa13fd01f..f841d0681992 100644 --- a/packages/beacon-node/test/utils/node/validator.ts +++ b/packages/beacon-node/test/utils/node/validator.ts @@ -1,14 +1,14 @@ -import tmp from "tmp"; -import {vi} from "vitest"; import {SecretKey} from "@chainsafe/blst"; +import {ApiClient, ApiError, ApiResponse, HttpStatusCode} from "@lodestar/api"; +import {BeaconApiMethods} from "@lodestar/api/beacon/server"; import {LevelDbController} from "@lodestar/db"; import {interopSecretKey} from "@lodestar/state-transition"; -import {SlashingProtection, Validator, Signer, SignerType, ValidatorProposerConfig} from "@lodestar/validator"; -import {ApiClient, ApiError, HttpStatusCode, ApiResponse} from "@lodestar/api"; -import {BeaconApiMethods} from "@lodestar/api/beacon/server"; import {mapValues} from "@lodestar/utils"; +import {Signer, SignerType, SlashingProtection, Validator, ValidatorProposerConfig} from "@lodestar/validator"; +import tmp from "tmp"; +import {vi} from "vitest"; import {BeaconNode} from "../../../src/index.js"; -import {testLogger, TestLoggerOpts} from "../logger.js"; +import {TestLoggerOpts, testLogger} from "../logger.js"; export async function getAndInitDevValidators({ node, diff --git a/packages/beacon-node/test/utils/peer.ts b/packages/beacon-node/test/utils/peer.ts index 8bd5c6c67be8..81cb83665007 100644 --- a/packages/beacon-node/test/utils/peer.ts +++ b/packages/beacon-node/test/utils/peer.ts @@ -1,6 +1,6 @@ import {PeerId} from "@libp2p/interface"; -import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; import {peerIdFromBytes} from "@libp2p/peer-id"; +import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; import {peerIdToString} from "../../src/util/peerId.js"; /** diff --git a/packages/beacon-node/test/utils/runEl.ts b/packages/beacon-node/test/utils/runEl.ts index 9a407f91d414..0cd3189329f8 100644 --- a/packages/beacon-node/test/utils/runEl.ts +++ b/packages/beacon-node/test/utils/runEl.ts @@ -1,10 +1,10 @@ +import {spawn} from "node:child_process"; import fs from "node:fs"; import net from "node:net"; -import {spawn} from "node:child_process"; -import {sleep} from "@lodestar/utils"; import {ChainConfig} from "@lodestar/config"; -import {Eth1Provider} from "../../src/index.js"; +import {sleep} from "@lodestar/utils"; import {ZERO_HASH} from "../../src/constants/index.js"; +import {Eth1Provider} from "../../src/index.js"; import {shell} from "../sim/shell.js"; /* eslint-disable no-console */ diff --git a/packages/beacon-node/test/utils/state.ts b/packages/beacon-node/test/utils/state.ts index 6ad85f3422f7..3e14ccf7630b 100644 --- a/packages/beacon-node/test/utils/state.ts +++ b/packages/beacon-node/test/utils/state.ts @@ -1,23 +1,23 @@ import {SecretKey} from "@chainsafe/blst"; import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map"; +import {ChainForkConfig, createBeaconConfig} from "@lodestar/config"; import {config as minimalConfig} from "@lodestar/config/default"; +import {FAR_FUTURE_EPOCH, ForkName, ForkSeq, MAX_EFFECTIVE_BALANCE, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; import { BeaconStateAllForks, + BeaconStateBellatrix, + BeaconStateElectra, CachedBeaconStateAllForks, - createCachedBeaconState, CachedBeaconStateBellatrix, - BeaconStateBellatrix, CachedBeaconStateElectra, - BeaconStateElectra, + createCachedBeaconState, } from "@lodestar/state-transition"; import {BeaconState, altair, bellatrix, electra, ssz} from "@lodestar/types"; -import {createBeaconConfig, ChainForkConfig} from "@lodestar/config"; -import {FAR_FUTURE_EPOCH, ForkName, ForkSeq, MAX_EFFECTIVE_BALANCE, SYNC_COMMITTEE_SIZE} from "@lodestar/params"; -import {ExecutionStatus, ProtoBlock, DataAvailabilityStatus} from "@lodestar/fork-choice"; +import {DataAvailabilityStatus, ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice"; import {ZERO_HASH_HEX} from "../../src/constants/constants.js"; -import {generateValidator, generateValidators} from "./validator.js"; import {getConfig} from "./config.js"; +import {generateValidator, generateValidators} from "./validator.js"; /** * Copy of BeaconState, but all fields are marked optional to allow for swapping out variables as needed. diff --git a/packages/beacon-node/test/utils/testnet.ts b/packages/beacon-node/test/utils/testnet.ts index 0c0c7a8369c8..95abc185b62d 100644 --- a/packages/beacon-node/test/utils/testnet.ts +++ b/packages/beacon-node/test/utils/testnet.ts @@ -1,7 +1,7 @@ import {fromHexString} from "@chainsafe/ssz"; -import {phase0} from "@lodestar/types"; -import {createChainForkConfig, ChainForkConfig} from "@lodestar/config"; +import {ChainForkConfig, createChainForkConfig} from "@lodestar/config"; import {chainConfig} from "@lodestar/config/default"; +import {phase0} from "@lodestar/types"; /** Generic testnet data taken from the Medalla testnet */ export const medallaTestnetConfig = { diff --git a/packages/beacon-node/test/utils/typeGenerator.ts b/packages/beacon-node/test/utils/typeGenerator.ts index dde169ebce26..329060e6eb31 100644 --- a/packages/beacon-node/test/utils/typeGenerator.ts +++ b/packages/beacon-node/test/utils/typeGenerator.ts @@ -1,6 +1,6 @@ +import {DataAvailabilityStatus, ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice"; import {Slot} from "@lodestar/types"; import {phase0} from "@lodestar/types"; -import {ProtoBlock, ExecutionStatus, DataAvailabilityStatus} from "@lodestar/fork-choice"; import {ssz} from "@lodestar/types"; import {fromHex} from "@lodestar/utils"; import {ZERO_HASH_HEX} from "../../src/constants/index.js"; diff --git a/packages/beacon-node/test/utils/validationData/aggregateAndProof.ts b/packages/beacon-node/test/utils/validationData/aggregateAndProof.ts index 462502719134..a8ac5833fbd5 100644 --- a/packages/beacon-node/test/utils/validationData/aggregateAndProof.ts +++ b/packages/beacon-node/test/utils/validationData/aggregateAndProof.ts @@ -1,11 +1,11 @@ -import {computeSigningRoot} from "@lodestar/state-transition"; import {DOMAIN_AGGREGATE_AND_PROOF, DOMAIN_SELECTION_PROOF} from "@lodestar/params"; +import {computeSigningRoot} from "@lodestar/state-transition"; import {phase0, ssz} from "@lodestar/types"; import {getSecretKeyFromIndexCached} from "../../../../state-transition/test/perf/util.js"; import {IBeaconChain} from "../../../src/chain/index.js"; import {SeenAggregators} from "../../../src/chain/seenCache/index.js"; import {signCached} from "../cache.js"; -import {getAttestationValidData, AttestationValidDataOpts} from "./attestation.js"; +import {AttestationValidDataOpts, getAttestationValidData} from "./attestation.js"; export type AggregateAndProofValidDataOpts = AttestationValidDataOpts; diff --git a/packages/beacon-node/test/utils/validationData/attestation.ts b/packages/beacon-node/test/utils/validationData/attestation.ts index 6715512ac667..40dccbd77f18 100644 --- a/packages/beacon-node/test/utils/validationData/attestation.ts +++ b/packages/beacon-node/test/utils/validationData/attestation.ts @@ -1,24 +1,24 @@ import {BitArray, toHexString} from "@chainsafe/ssz"; -import {computeEpochAtSlot, computeSigningRoot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; -import {ProtoBlock, IForkChoice, ExecutionStatus, DataAvailabilityStatus} from "@lodestar/fork-choice"; +import {DataAvailabilityStatus, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {DOMAIN_BEACON_ATTESTER} from "@lodestar/params"; -import {phase0, Slot, ssz} from "@lodestar/types"; +import {computeEpochAtSlot, computeSigningRoot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; +import {Slot, phase0, ssz} from "@lodestar/types"; import { generateTestCachedBeaconStateOnlyValidators, getSecretKeyFromIndexCached, } from "../../../../state-transition/test/perf/util.js"; +import {BlsMultiThreadWorkerPool, BlsSingleThreadVerifier} from "../../../src/chain/bls/index.js"; import {IBeaconChain} from "../../../src/chain/index.js"; +import {defaultChainOptions} from "../../../src/chain/options.js"; import {IStateRegenerator} from "../../../src/chain/regen/index.js"; -import {ZERO_HASH, ZERO_HASH_HEX} from "../../../src/constants/index.js"; import {SeenAttesters} from "../../../src/chain/seenCache/index.js"; -import {BlsMultiThreadWorkerPool, BlsSingleThreadVerifier} from "../../../src/chain/bls/index.js"; -import {signCached} from "../cache.js"; -import {ClockStatic} from "../clock.js"; import {SeenAggregatedAttestations} from "../../../src/chain/seenCache/seenAggregateAndProof.js"; import {SeenAttestationDatas} from "../../../src/chain/seenCache/seenAttestationData.js"; -import {defaultChainOptions} from "../../../src/chain/options.js"; -import {testLogger} from "../logger.js"; import {ShufflingCache} from "../../../src/chain/shufflingCache.js"; +import {ZERO_HASH, ZERO_HASH_HEX} from "../../../src/constants/index.js"; +import {signCached} from "../cache.js"; +import {ClockStatic} from "../clock.js"; +import {testLogger} from "../logger.js"; export type AttestationValidDataOpts = { currentSlot?: Slot; diff --git a/packages/cli/package.json b/packages/cli/package.json index e1b2134f5f82..8f3cc163cc57 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@chainsafe/lodestar", - "version": "1.23.1", + "version": "1.24.0", "description": "Command line interface for lodestar", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -62,17 +62,17 @@ "@libp2p/crypto": "^4.1.0", "@libp2p/peer-id": "^4.1.0", "@libp2p/peer-id-factory": "^4.1.0", - "@lodestar/api": "^1.23.1", - "@lodestar/beacon-node": "^1.23.1", - "@lodestar/config": "^1.23.1", - "@lodestar/db": "^1.23.1", - "@lodestar/light-client": "^1.23.1", - "@lodestar/logger": "^1.23.1", - "@lodestar/params": "^1.23.1", - "@lodestar/state-transition": "^1.23.1", - "@lodestar/types": "^1.23.1", - "@lodestar/utils": "^1.23.1", - "@lodestar/validator": "^1.23.1", + "@lodestar/api": "^1.24.0", + "@lodestar/beacon-node": "^1.24.0", + "@lodestar/config": "^1.24.0", + "@lodestar/db": "^1.24.0", + "@lodestar/light-client": "^1.24.0", + "@lodestar/logger": "^1.24.0", + "@lodestar/params": "^1.24.0", + "@lodestar/state-transition": "^1.24.0", + "@lodestar/types": "^1.24.0", + "@lodestar/utils": "^1.24.0", + "@lodestar/validator": "^1.24.0", "@multiformats/multiaddr": "^12.1.3", "deepmerge": "^4.3.1", "ethers": "^6.7.0", @@ -88,7 +88,7 @@ "yargs": "^17.7.1" }, "devDependencies": { - "@lodestar/test-utils": "^1.23.1", + "@lodestar/test-utils": "^1.24.0", "@types/debug": "^4.1.7", "@types/got": "^9.6.12", "@types/inquirer": "^9.0.3", diff --git a/packages/cli/src/applyPreset.ts b/packages/cli/src/applyPreset.ts index 612c5d648c63..06d29d353af8 100644 --- a/packages/cli/src/applyPreset.ts +++ b/packages/cli/src/applyPreset.ts @@ -21,7 +21,7 @@ setHasher(hasher); // set LODESTAR_PRESET manually every time. // IMPORTANT: only import Lodestar code here which does not import any other Lodestar libraries -import {setActivePreset, presetFromJson, PresetName} from "@lodestar/params/setPreset"; +import {PresetName, presetFromJson, setActivePreset} from "@lodestar/params/setPreset"; import {readFile} from "./util/file.js"; const network = valueOfArg("network"); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index e8f4aeba8ebc..d64661f6ec66 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -1,7 +1,7 @@ +import {registerCommandToYargs} from "@lodestar/utils"; // Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131 import yargs from "yargs"; import {hideBin} from "yargs/helpers"; -import {registerCommandToYargs} from "@lodestar/utils"; import {cmds} from "./cmds/index.js"; import {globalOptions, rcConfigOption} from "./options/index.js"; import {getVersionData} from "./util/version.js"; diff --git a/packages/cli/src/cmds/beacon/handler.ts b/packages/cli/src/cmds/beacon/handler.ts index ea424e04824a..389bcea25223 100644 --- a/packages/cli/src/cmds/beacon/handler.ts +++ b/packages/cli/src/cmds/beacon/handler.ts @@ -1,30 +1,30 @@ import path from "node:path"; import {getHeapStatistics} from "node:v8"; -import {ErrorAborted} from "@lodestar/utils"; -import {LevelDbController} from "@lodestar/db"; -import {BeaconNode, BeaconDb} from "@lodestar/beacon-node"; +import {BeaconDb, BeaconNode} from "@lodestar/beacon-node"; import {ChainForkConfig, createBeaconConfig} from "@lodestar/config"; +import {LevelDbController} from "@lodestar/db"; +import {LoggerNode, getNodeLogger} from "@lodestar/logger/node"; import {ACTIVE_PRESET, PresetName} from "@lodestar/params"; +import {ErrorAborted} from "@lodestar/utils"; import {ProcessShutdownCallback} from "@lodestar/validator"; -import {LoggerNode, getNodeLogger} from "@lodestar/logger/node"; -import {GlobalArgs, parseBeaconNodeArgs} from "../../options/index.js"; import {BeaconNodeOptions, getBeaconConfigFromArgs} from "../../config/index.js"; import {getNetworkBootnodes, getNetworkData, isKnownNetworkName, readBootnodes} from "../../networks/index.js"; +import {GlobalArgs, parseBeaconNodeArgs} from "../../options/index.js"; +import {LogArgs} from "../../options/logOptions.js"; import { - onGracefulShutdown, - mkdir, - writeFile600Perm, cleanOldLogFiles, + mkdir, + onGracefulShutdown, parseLoggerArgs, pruneOldFilesInDir, + writeFile600Perm, } from "../../util/index.js"; import {getVersionData} from "../../util/version.js"; -import {LogArgs} from "../../options/logOptions.js"; -import {BeaconArgs} from "./options.js"; -import {getBeaconPaths} from "./paths.js"; import {initBeaconState} from "./initBeaconState.js"; import {initPeerIdAndEnr} from "./initPeerIdAndEnr.js"; +import {BeaconArgs} from "./options.js"; +import {getBeaconPaths} from "./paths.js"; const DEFAULT_RETENTION_SSZ_OBJECTS_HOURS = 15 * 24; const HOURS_TO_MS = 3600 * 1000; diff --git a/packages/cli/src/cmds/beacon/index.ts b/packages/cli/src/cmds/beacon/index.ts index d1d91b9fe424..9746a43d40fb 100644 --- a/packages/cli/src/cmds/beacon/index.ts +++ b/packages/cli/src/cmds/beacon/index.ts @@ -1,7 +1,7 @@ import {CliCommand, CliCommandOptions} from "@lodestar/utils"; import {GlobalArgs} from "../../options/index.js"; -import {beaconOptions, BeaconArgs} from "./options.js"; import {beaconHandler} from "./handler.js"; +import {BeaconArgs, beaconOptions} from "./options.js"; export const beacon: CliCommand = { command: "beacon", diff --git a/packages/cli/src/cmds/beacon/initBeaconState.ts b/packages/cli/src/cmds/beacon/initBeaconState.ts index 8dc9e9317c65..5fc32d63de6b 100644 --- a/packages/cli/src/cmds/beacon/initBeaconState.ts +++ b/packages/cli/src/cmds/beacon/initBeaconState.ts @@ -1,30 +1,30 @@ -import {ssz} from "@lodestar/types"; -import {createBeaconConfig, BeaconConfig, ChainForkConfig} from "@lodestar/config"; -import {Logger, formatBytes} from "@lodestar/utils"; -import { - isWithinWeakSubjectivityPeriod, - ensureWithinWeakSubjectivityPeriod, - BeaconStateAllForks, - loadState, - loadStateAndValidators, -} from "@lodestar/state-transition"; import { IBeaconDb, IBeaconNodeOptions, checkAndPersistAnchorState, - initStateFromEth1, getStateTypeFromBytes, + initStateFromEth1, } from "@lodestar/beacon-node"; +import {BeaconConfig, ChainForkConfig, createBeaconConfig} from "@lodestar/config"; +import { + BeaconStateAllForks, + ensureWithinWeakSubjectivityPeriod, + isWithinWeakSubjectivityPeriod, + loadState, + loadStateAndValidators, +} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; import {Checkpoint} from "@lodestar/types/phase0"; +import {Logger, formatBytes} from "@lodestar/utils"; -import {downloadOrLoadFile, wrapFnError} from "../../util/index.js"; -import {defaultNetwork, GlobalArgs} from "../../options/globalOptions.js"; import { fetchWeakSubjectivityState, getCheckpointFromArg, - getGenesisFileUrl, getCheckpointFromState, + getGenesisFileUrl, } from "../../networks/index.js"; +import {GlobalArgs, defaultNetwork} from "../../options/globalOptions.js"; +import {downloadOrLoadFile, wrapFnError} from "../../util/index.js"; import {BeaconArgs} from "./options.js"; type StateWithBytes = {state: BeaconStateAllForks; stateBytes: Uint8Array}; diff --git a/packages/cli/src/cmds/beacon/initPeerIdAndEnr.ts b/packages/cli/src/cmds/beacon/initPeerIdAndEnr.ts index 3e5963797c3d..cac34d65b194 100644 --- a/packages/cli/src/cmds/beacon/initPeerIdAndEnr.ts +++ b/packages/cli/src/cmds/beacon/initPeerIdAndEnr.ts @@ -1,14 +1,14 @@ import fs from "node:fs"; -import path from "node:path"; import os from "node:os"; +import path from "node:path"; +import {SignableENR, createPrivateKeyFromPeerId} from "@chainsafe/enr"; import type {PeerId} from "@libp2p/interface"; import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; -import {Multiaddr} from "@multiformats/multiaddr"; -import {createPrivateKeyFromPeerId, SignableENR} from "@chainsafe/enr"; import {Logger} from "@lodestar/utils"; +import {Multiaddr} from "@multiformats/multiaddr"; import {exportToJSON, readPeerId} from "../../config/index.js"; -import {writeFile600Perm} from "../../util/file.js"; import {parseListenArgs} from "../../options/beaconNodeOptions/network.js"; +import {writeFile600Perm} from "../../util/file.js"; import {BeaconArgs} from "./options.js"; /** diff --git a/packages/cli/src/cmds/beacon/options.ts b/packages/cli/src/cmds/beacon/options.ts index 5b57b58e82e2..7f2cdddfc4ff 100644 --- a/packages/cli/src/cmds/beacon/options.ts +++ b/packages/cli/src/cmds/beacon/options.ts @@ -1,7 +1,7 @@ import {CliCommandOptions, CliOptionDefinition} from "@lodestar/utils"; -import {beaconNodeOptions, paramsOptions, BeaconNodeArgs} from "../../options/index.js"; +import {BeaconNodeArgs, beaconNodeOptions, paramsOptions} from "../../options/index.js"; import {LogArgs, logOptions} from "../../options/logOptions.js"; -import {defaultBeaconPaths, BeaconPaths} from "./paths.js"; +import {BeaconPaths, defaultBeaconPaths} from "./paths.js"; type BeaconExtraArgs = { forceGenesis?: boolean; @@ -33,7 +33,6 @@ export const beaconExtraOptions: CliCommandOptions = { }, genesisStateFile: { - hidden: true, description: "Path or URL to download a genesis state file in ssz-encoded format", type: "string", }, @@ -80,7 +79,6 @@ export const beaconExtraOptions: CliCommandOptions = { ignoreWeakSubjectivityCheck: { description: "Ignore the checkpoint sync state failing the weak subjectivity check. This is relevant in testnets where the weak subjectivity period is too small for even few epochs of non finalization causing last finalized to be out of range. This flag is not recommended for mainnet use.", - hidden: true, type: "boolean", group: "weak subjectivity", }, @@ -120,7 +118,6 @@ export const beaconExtraOptions: CliCommandOptions = { }, persistNetworkIdentity: { - hidden: true, description: "Whether to reuse the same peer-id across restarts", type: "boolean", }, diff --git a/packages/cli/src/cmds/beacon/paths.ts b/packages/cli/src/cmds/beacon/paths.ts index f92732b2a94e..9485bc5fca8a 100644 --- a/packages/cli/src/cmds/beacon/paths.ts +++ b/packages/cli/src/cmds/beacon/paths.ts @@ -1,6 +1,6 @@ import path from "node:path"; import {GlobalArgs} from "../../options/index.js"; -import {getGlobalPaths, GlobalPaths} from "../../paths/global.js"; +import {GlobalPaths, getGlobalPaths} from "../../paths/global.js"; export type BeaconPathsPartial = Partial<{ beaconDir: string; diff --git a/packages/cli/src/cmds/bootnode/handler.ts b/packages/cli/src/cmds/bootnode/handler.ts index 8a262d8f12b7..4dc044a87006 100644 --- a/packages/cli/src/cmds/bootnode/handler.ts +++ b/packages/cli/src/cmds/bootnode/handler.ts @@ -1,21 +1,21 @@ import path from "node:path"; -import {Multiaddr, multiaddr} from "@multiformats/multiaddr"; import {Discv5} from "@chainsafe/discv5"; import {ENR} from "@chainsafe/enr"; -import {ErrorAborted} from "@lodestar/utils"; import {HttpMetricsServer, RegistryMetricCreator, getHttpMetricsServer} from "@lodestar/beacon-node"; +import {ErrorAborted} from "@lodestar/utils"; +import {Multiaddr, multiaddr} from "@multiformats/multiaddr"; -import {GlobalArgs} from "../../options/index.js"; import {getBeaconConfigFromArgs} from "../../config/index.js"; import {getNetworkBootnodes, isKnownNetworkName, readBootnodes} from "../../networks/index.js"; -import {onGracefulShutdown, mkdir, writeFile600Perm} from "../../util/index.js"; -import {getVersionData} from "../../util/version.js"; -import {initPeerIdAndEnr} from "../beacon/initPeerIdAndEnr.js"; import {parseArgs as parseMetricsArgs} from "../../options/beaconNodeOptions/metrics.js"; import {parseArgs as parseNetworkArgs} from "../../options/beaconNodeOptions/network.js"; -import {getBeaconPaths} from "../beacon/paths.js"; -import {BeaconArgs} from "../beacon/options.js"; +import {GlobalArgs} from "../../options/index.js"; +import {mkdir, onGracefulShutdown, writeFile600Perm} from "../../util/index.js"; +import {getVersionData} from "../../util/version.js"; import {initLogger} from "../beacon/handler.js"; +import {initPeerIdAndEnr} from "../beacon/initPeerIdAndEnr.js"; +import {BeaconArgs} from "../beacon/options.js"; +import {getBeaconPaths} from "../beacon/paths.js"; import {BootnodeArgs} from "./options.js"; /** diff --git a/packages/cli/src/cmds/bootnode/index.ts b/packages/cli/src/cmds/bootnode/index.ts index 6fc3c01247d6..3143f7a77ba7 100644 --- a/packages/cli/src/cmds/bootnode/index.ts +++ b/packages/cli/src/cmds/bootnode/index.ts @@ -1,7 +1,7 @@ import {CliCommand, CliCommandOptions} from "@lodestar/utils"; import {GlobalArgs} from "../../options/index.js"; -import {bootnodeOptions, BootnodeArgs} from "./options.js"; import {bootnodeHandler} from "./handler.js"; +import {BootnodeArgs, bootnodeOptions} from "./options.js"; export const bootnode: CliCommand = { command: "bootnode", diff --git a/packages/cli/src/cmds/bootnode/options.ts b/packages/cli/src/cmds/bootnode/options.ts index f3422b4029a1..e4e943bfef0c 100644 --- a/packages/cli/src/cmds/bootnode/options.ts +++ b/packages/cli/src/cmds/bootnode/options.ts @@ -1,7 +1,7 @@ -import {CliOptionDefinition, CliCommandOptions} from "@lodestar/utils"; -import {LogArgs, logOptions} from "../../options/logOptions.js"; +import {CliCommandOptions, CliOptionDefinition} from "@lodestar/utils"; import {MetricsArgs, options as metricsOptions} from "../../options/beaconNodeOptions/metrics.js"; import {defaultListenAddress, defaultP2pPort, defaultP2pPort6} from "../../options/beaconNodeOptions/network.js"; +import {LogArgs, logOptions} from "../../options/logOptions.js"; type BootnodeExtraArgs = { listenAddress?: string; diff --git a/packages/cli/src/cmds/dev/files.ts b/packages/cli/src/cmds/dev/files.ts index 9baf0dc845dd..e5b019c4b48e 100644 --- a/packages/cli/src/cmds/dev/files.ts +++ b/packages/cli/src/cmds/dev/files.ts @@ -2,9 +2,9 @@ import fs from "node:fs"; import path from "node:path"; import {Keystore} from "@chainsafe/bls-keystore"; import {nodeUtils} from "@lodestar/beacon-node"; -import {chainConfigToJson, ChainForkConfig} from "@lodestar/config"; -import {dumpYaml} from "@lodestar/utils"; +import {ChainForkConfig, chainConfigToJson} from "@lodestar/config"; import {interopSecretKey} from "@lodestar/state-transition"; +import {dumpYaml} from "@lodestar/utils"; import {PersistedKeysBackend} from "../validator/keymanager/persistedKeys.js"; /* eslint-disable no-console */ diff --git a/packages/cli/src/cmds/dev/handler.ts b/packages/cli/src/cmds/dev/handler.ts index 3018bb8790a6..43fe12435a9a 100644 --- a/packages/cli/src/cmds/dev/handler.ts +++ b/packages/cli/src/cmds/dev/handler.ts @@ -1,16 +1,16 @@ import fs from "node:fs"; -import {rimraf} from "rimraf"; -import {toHex, fromHex} from "@lodestar/utils"; import {nodeUtils} from "@lodestar/beacon-node"; +import {fromHex, toHex} from "@lodestar/utils"; +import {rimraf} from "rimraf"; +import {getBeaconConfigFromArgs} from "../../config/beaconParams.js"; import {GlobalArgs} from "../../options/index.js"; import {mkdir, onGracefulShutdown} from "../../util/index.js"; -import {getBeaconConfigFromArgs} from "../../config/beaconParams.js"; -import {getBeaconPaths} from "../beacon/paths.js"; -import {getValidatorPaths} from "../validator/paths.js"; import {beaconHandler} from "../beacon/handler.js"; +import {getBeaconPaths} from "../beacon/paths.js"; import {validatorHandler} from "../validator/handler.js"; -import {IDevArgs} from "./options.js"; +import {getValidatorPaths} from "../validator/paths.js"; import {writeTestnetFiles} from "./files.js"; +import {IDevArgs} from "./options.js"; /** * Run a beacon node with validator diff --git a/packages/cli/src/cmds/dev/index.ts b/packages/cli/src/cmds/dev/index.ts index 6c0f73327816..b628d116c526 100644 --- a/packages/cli/src/cmds/dev/index.ts +++ b/packages/cli/src/cmds/dev/index.ts @@ -1,7 +1,7 @@ import {CliCommand, CliCommandOptions} from "@lodestar/utils"; import {GlobalArgs} from "../../options/index.js"; -import {devOptions, IDevArgs} from "./options.js"; import {devHandler} from "./handler.js"; +import {IDevArgs, devOptions} from "./options.js"; export const dev: CliCommand = { command: "dev", diff --git a/packages/cli/src/cmds/dev/options.ts b/packages/cli/src/cmds/dev/options.ts index e442b0605cdc..3bbc32f0ab0e 100644 --- a/packages/cli/src/cmds/dev/options.ts +++ b/packages/cli/src/cmds/dev/options.ts @@ -1,7 +1,7 @@ import {CliCommandOptions, CliOptionDefinition} from "@lodestar/utils"; -import {beaconOptions, BeaconArgs} from "../beacon/options.js"; import {NetworkName} from "../../networks/index.js"; import {beaconNodeOptions, globalOptions} from "../../options/index.js"; +import {BeaconArgs, beaconOptions} from "../beacon/options.js"; import {IValidatorCliArgs, validatorOptions} from "../validator/options.js"; type IDevOwnArgs = { diff --git a/packages/cli/src/cmds/index.ts b/packages/cli/src/cmds/index.ts index 7f701379b097..36217ef1b622 100644 --- a/packages/cli/src/cmds/index.ts +++ b/packages/cli/src/cmds/index.ts @@ -1,10 +1,10 @@ import {CliCommand} from "@lodestar/utils"; import {GlobalArgs} from "../options/index.js"; import {beacon} from "./beacon/index.js"; +import {bootnode} from "./bootnode/index.js"; import {dev} from "./dev/index.js"; -import {validator} from "./validator/index.js"; import {lightclient} from "./lightclient/index.js"; -import {bootnode} from "./bootnode/index.js"; +import {validator} from "./validator/index.js"; export const cmds: Required>>["subcommands"] = [ beacon, diff --git a/packages/cli/src/cmds/lightclient/handler.ts b/packages/cli/src/cmds/lightclient/handler.ts index 5af8f84d8959..b51a7227ce4c 100644 --- a/packages/cli/src/cmds/lightclient/handler.ts +++ b/packages/cli/src/cmds/lightclient/handler.ts @@ -5,9 +5,9 @@ import {LightClientRestTransport} from "@lodestar/light-client/transport"; import {getNodeLogger} from "@lodestar/logger/node"; import {fromHex} from "@lodestar/utils"; import {getBeaconConfigFromArgs} from "../../config/beaconParams.js"; +import {GlobalArgs} from "../../options/index.js"; import {getGlobalPaths} from "../../paths/global.js"; import {parseLoggerArgs} from "../../util/logger.js"; -import {GlobalArgs} from "../../options/index.js"; import {ILightClientArgs} from "./options.js"; export async function lightclientHandler(args: ILightClientArgs & GlobalArgs): Promise { diff --git a/packages/cli/src/cmds/lightclient/index.ts b/packages/cli/src/cmds/lightclient/index.ts index bf85df50800f..55c56697bd0a 100644 --- a/packages/cli/src/cmds/lightclient/index.ts +++ b/packages/cli/src/cmds/lightclient/index.ts @@ -1,7 +1,7 @@ import {CliCommand} from "@lodestar/utils"; import {GlobalArgs} from "../../options/index.js"; -import {ILightClientArgs, lightclientOptions} from "./options.js"; import {lightclientHandler} from "./handler.js"; +import {ILightClientArgs, lightclientOptions} from "./options.js"; export const lightclient: CliCommand = { command: "lightclient", diff --git a/packages/cli/src/cmds/validator/blsToExecutionChange.ts b/packages/cli/src/cmds/validator/blsToExecutionChange.ts index 7fbdbb029bf5..2eeaab846589 100644 --- a/packages/cli/src/cmds/validator/blsToExecutionChange.ts +++ b/packages/cli/src/cmds/validator/blsToExecutionChange.ts @@ -1,13 +1,13 @@ import {SecretKey} from "@chainsafe/blst"; -import {computeSigningRoot} from "@lodestar/state-transition"; -import {DOMAIN_BLS_TO_EXECUTION_CHANGE, ForkName} from "@lodestar/params"; -import {createBeaconConfig} from "@lodestar/config"; -import {ssz, capella} from "@lodestar/types"; import {getClient} from "@lodestar/api"; +import {createBeaconConfig} from "@lodestar/config"; +import {DOMAIN_BLS_TO_EXECUTION_CHANGE, ForkName} from "@lodestar/params"; +import {computeSigningRoot} from "@lodestar/state-transition"; +import {capella, ssz} from "@lodestar/types"; import {CliCommand, fromHex} from "@lodestar/utils"; -import {GlobalArgs} from "../../options/index.js"; import {getBeaconConfigFromArgs} from "../../config/index.js"; +import {GlobalArgs} from "../../options/index.js"; import {IValidatorCliArgs} from "./options.js"; /* eslint-disable no-console */ diff --git a/packages/cli/src/cmds/validator/handler.ts b/packages/cli/src/cmds/validator/handler.ts index 66e66400a3fd..6cb48f862bda 100644 --- a/packages/cli/src/cmds/validator/handler.ts +++ b/packages/cli/src/cmds/validator/handler.ts @@ -1,6 +1,14 @@ -import path from "node:path"; import {setMaxListeners} from "node:events"; +import path from "node:path"; +import {WireFormat, routes} from "@lodestar/api"; +import { + MonitoringService, + RegistryMetricCreator, + collectNodeJSMetrics, + getHttpMetricsServer, +} from "@lodestar/beacon-node"; import {LevelDbController} from "@lodestar/db"; +import {getNodeLogger} from "@lodestar/logger/node"; import { ProcessShutdownCallback, SlashingProtection, @@ -8,29 +16,21 @@ import { ValidatorProposerConfig, defaultOptions, } from "@lodestar/validator"; -import {WireFormat, routes} from "@lodestar/api"; import {getMetrics} from "@lodestar/validator"; -import { - RegistryMetricCreator, - collectNodeJSMetrics, - getHttpMetricsServer, - MonitoringService, -} from "@lodestar/beacon-node"; -import {getNodeLogger} from "@lodestar/logger/node"; import {getBeaconConfigFromArgs} from "../../config/index.js"; import {GlobalArgs} from "../../options/index.js"; import {YargsError, cleanOldLogFiles, mkdir, parseLoggerArgs} from "../../util/index.js"; import {onGracefulShutdown, parseFeeRecipient, parseProposerConfig} from "../../util/index.js"; +import {parseBuilderBoostFactor, parseBuilderSelection} from "../../util/proposerConfig.js"; import {getVersionData} from "../../util/version.js"; -import {parseBuilderSelection, parseBuilderBoostFactor} from "../../util/proposerConfig.js"; -import {getAccountPaths, getValidatorPaths} from "./paths.js"; -import {IValidatorCliArgs, validatorMetricsDefaultOptions, validatorMonitoringDefaultOptions} from "./options.js"; -import {getSignersFromArgs} from "./signers/index.js"; -import {logSigners, warnOrExitNoSigners} from "./signers/logSigners.js"; import {KeymanagerApi} from "./keymanager/impl.js"; -import {PersistedKeysBackend} from "./keymanager/persistedKeys.js"; import {IPersistedKeysBackend} from "./keymanager/interface.js"; +import {PersistedKeysBackend} from "./keymanager/persistedKeys.js"; import {KeymanagerRestApiServer} from "./keymanager/server.js"; +import {IValidatorCliArgs, validatorMetricsDefaultOptions, validatorMonitoringDefaultOptions} from "./options.js"; +import {getAccountPaths, getValidatorPaths} from "./paths.js"; +import {getSignersFromArgs} from "./signers/index.js"; +import {logSigners, warnOrExitNoSigners} from "./signers/logSigners.js"; /** * Runs a validator client. diff --git a/packages/cli/src/cmds/validator/import.ts b/packages/cli/src/cmds/validator/import.ts index 48e5205549f1..2c9343cf71e2 100644 --- a/packages/cli/src/cmds/validator/import.ts +++ b/packages/cli/src/cmds/validator/import.ts @@ -1,13 +1,13 @@ import fs from "node:fs"; import {Keystore} from "@chainsafe/bls-keystore"; import {CliCommand} from "@lodestar/utils"; -import {YargsError, getPubkeyHexFromKeystore} from "../../util/index.js"; import {getBeaconConfigFromArgs} from "../../config/beaconParams.js"; import {GlobalArgs} from "../../options/index.js"; -import {validatorOptions, IValidatorCliArgs} from "./options.js"; +import {YargsError, getPubkeyHexFromKeystore} from "../../util/index.js"; +import {PersistedKeysBackend} from "./keymanager/persistedKeys.js"; +import {IValidatorCliArgs, validatorOptions} from "./options.js"; import {getAccountPaths} from "./paths.js"; import {importKeystoreDefinitionsFromExternalDir, readPassphraseOrPrompt} from "./signers/importExternalKeystores.js"; -import {PersistedKeysBackend} from "./keymanager/persistedKeys.js"; /* eslint-disable no-console */ diff --git a/packages/cli/src/cmds/validator/index.ts b/packages/cli/src/cmds/validator/index.ts index d0c7ea86c042..0c41744e49fd 100644 --- a/packages/cli/src/cmds/validator/index.ts +++ b/packages/cli/src/cmds/validator/index.ts @@ -1,13 +1,13 @@ import {CliCommand} from "@lodestar/utils"; import {GlobalArgs} from "../../options/index.js"; -import {getAccountPaths} from "./paths.js"; -import {slashingProtection} from "./slashingProtection/index.js"; +import {blsToExecutionChange} from "./blsToExecutionChange.js"; +import {validatorHandler} from "./handler.js"; import {importCmd} from "./import.js"; import {list} from "./list.js"; +import {IValidatorCliArgs, validatorOptions} from "./options.js"; +import {getAccountPaths} from "./paths.js"; +import {slashingProtection} from "./slashingProtection/index.js"; import {voluntaryExit} from "./voluntaryExit.js"; -import {blsToExecutionChange} from "./blsToExecutionChange.js"; -import {validatorOptions, IValidatorCliArgs} from "./options.js"; -import {validatorHandler} from "./handler.js"; export const validator: CliCommand = { command: "validator", diff --git a/packages/cli/src/cmds/validator/keymanager/decryptKeystoreDefinitions.ts b/packages/cli/src/cmds/validator/keymanager/decryptKeystoreDefinitions.ts index 7cfaa9768494..2c17f70e8255 100644 --- a/packages/cli/src/cmds/validator/keymanager/decryptKeystoreDefinitions.ts +++ b/packages/cli/src/cmds/validator/keymanager/decryptKeystoreDefinitions.ts @@ -1,13 +1,13 @@ import fs from "node:fs"; import path from "node:path"; -import {SecretKey} from "@chainsafe/blst"; import {Keystore} from "@chainsafe/bls-keystore"; -import {SignerLocal, SignerType} from "@lodestar/validator"; +import {SecretKey} from "@chainsafe/blst"; import {LogLevel, Logger} from "@lodestar/utils"; +import {SignerLocal, SignerType} from "@lodestar/validator"; import {lockFilepath, unlockFilepath} from "../../../util/lockfile.js"; +import {DecryptKeystoresThreadPool} from "./decryptKeystores/index.js"; import {LocalKeystoreDefinition} from "./interface.js"; import {clearKeystoreCache, loadKeystoreCache, writeKeystoreCache} from "./keystoreCache.js"; -import {DecryptKeystoresThreadPool} from "./decryptKeystores/index.js"; export type KeystoreDecryptOptions = { ignoreLockFile?: boolean; diff --git a/packages/cli/src/cmds/validator/keymanager/decryptKeystores/threadPool.ts b/packages/cli/src/cmds/validator/keymanager/decryptKeystores/threadPool.ts index 169ddb74ffda..4203e0640e39 100644 --- a/packages/cli/src/cmds/validator/keymanager/decryptKeystores/threadPool.ts +++ b/packages/cli/src/cmds/validator/keymanager/decryptKeystores/threadPool.ts @@ -1,7 +1,7 @@ import path from "node:path"; -import {spawn, Pool, Worker, ModuleThread, QueuedTask} from "@chainsafe/threads"; -import {DecryptKeystoreArgs, DecryptKeystoreWorkerAPI} from "./types.js"; +import {ModuleThread, Pool, QueuedTask, Worker, spawn} from "@chainsafe/threads"; import {maxPoolSize} from "./poolSize.js"; +import {DecryptKeystoreArgs, DecryptKeystoreWorkerAPI} from "./types.js"; // Worker constructor consider the path relative to the current working directory const workerDir = diff --git a/packages/cli/src/cmds/validator/keymanager/decryptKeystores/worker.ts b/packages/cli/src/cmds/validator/keymanager/decryptKeystores/worker.ts index 711ec4f88b00..9ebebb3a73d9 100644 --- a/packages/cli/src/cmds/validator/keymanager/decryptKeystores/worker.ts +++ b/packages/cli/src/cmds/validator/keymanager/decryptKeystores/worker.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; -import {expose} from "@chainsafe/threads/worker"; -import {Transfer, TransferDescriptor} from "@chainsafe/threads"; import {Keystore} from "@chainsafe/bls-keystore"; +import {Transfer, TransferDescriptor} from "@chainsafe/threads"; +import {expose} from "@chainsafe/threads/worker"; import {DecryptKeystoreArgs, DecryptKeystoreWorkerAPI, isLocalKeystoreDefinition} from "./types.js"; /** diff --git a/packages/cli/src/cmds/validator/keymanager/impl.ts b/packages/cli/src/cmds/validator/keymanager/impl.ts index b4233f3162cd..9a5a8bd72743 100644 --- a/packages/cli/src/cmds/validator/keymanager/impl.ts +++ b/packages/cli/src/cmds/validator/keymanager/impl.ts @@ -1,26 +1,27 @@ import {Keystore} from "@chainsafe/bls-keystore"; import {SecretKey} from "@chainsafe/blst"; import { + BuilderBoostFactorData, DeleteRemoteKeyStatus, DeletionStatus, + FeeRecipientData, + GasLimitData, + GraffitiData, + ImportRemoteKeyStatus, ImportStatus, - ResponseStatus, KeystoreStr, + ProposerConfigResponse, PubkeyHex, - SlashingProtectionData, - SignerDefinition, RemoteSignerDefinition, - ImportRemoteKeyStatus, - FeeRecipientData, - GraffitiData, - GasLimitData, - BuilderBoostFactorData, + ResponseStatus, + SignerDefinition, + SlashingProtectionData, } from "@lodestar/api/keymanager"; import {KeymanagerApiMethods as Api} from "@lodestar/api/keymanager/server"; -import {Interchange, SignerType, Validator} from "@lodestar/validator"; import {ApiError} from "@lodestar/api/server"; import {Epoch} from "@lodestar/types"; import {fromHex, isValidHttpUrl} from "@lodestar/utils"; +import {Interchange, SignerType, Validator} from "@lodestar/validator"; import {getPubkeyHexFromKeystore, isValidatePubkeyHex} from "../../../util/format.js"; import {parseFeeRecipient} from "../../../util/index.js"; import {DecryptKeystoresThreadPool} from "./decryptKeystores/index.js"; @@ -41,11 +42,13 @@ export class KeymanagerApi implements Api { } async listFeeRecipient({pubkey}: {pubkey: PubkeyHex}): ReturnType { + this.assertValidKnownPubkey(pubkey); return {data: {pubkey, ethaddress: this.validator.validatorStore.getFeeRecipient(pubkey)}}; } async setFeeRecipient({pubkey, ethaddress}: FeeRecipientData): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.setFeeRecipient(pubkey, parseFeeRecipient(ethaddress)); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 202}; @@ -53,12 +56,14 @@ export class KeymanagerApi implements Api { async deleteFeeRecipient({pubkey}: {pubkey: PubkeyHex}): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.deleteFeeRecipient(pubkey); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 204}; } async getGraffiti({pubkey}: {pubkey: PubkeyHex}): ReturnType { + this.assertValidKnownPubkey(pubkey); const graffiti = this.validator.validatorStore.getGraffiti(pubkey); if (graffiti === undefined) { throw new ApiError(404, `No graffiti for pubkey ${pubkey}`); @@ -68,6 +73,7 @@ export class KeymanagerApi implements Api { async setGraffiti({pubkey, graffiti}: GraffitiData): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.setGraffiti(pubkey, graffiti); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 202}; @@ -75,18 +81,21 @@ export class KeymanagerApi implements Api { async deleteGraffiti({pubkey}: {pubkey: PubkeyHex}): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.deleteGraffiti(pubkey); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 204}; } async getGasLimit({pubkey}: {pubkey: PubkeyHex}): ReturnType { + this.assertValidKnownPubkey(pubkey); const gasLimit = this.validator.validatorStore.getGasLimit(pubkey); return {data: {pubkey, gasLimit}}; } async setGasLimit({pubkey, gasLimit}: GasLimitData): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.setGasLimit(pubkey, gasLimit); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 202}; @@ -94,18 +103,22 @@ export class KeymanagerApi implements Api { async deleteGasLimit({pubkey}: {pubkey: PubkeyHex}): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.deleteGasLimit(pubkey); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 204}; } async listKeys(): ReturnType { - const pubkeys = this.validator.validatorStore.votingPubkeys(); + const localKeys = this.validator.validatorStore + .votingPubkeys() + .filter((pubkey) => this.validator.validatorStore.getSigner(pubkey)?.type === SignerType.Local); + return { - data: pubkeys.map((pubkey) => ({ + data: localKeys.map((pubkey) => ({ validatingPubkey: pubkey, derivationPath: "", - readonly: this.validator.validatorStore.getSigner(pubkey)?.type !== SignerType.Local, + readonly: false, })), }; } @@ -343,6 +356,7 @@ export class KeymanagerApi implements Api { } async getBuilderBoostFactor({pubkey}: {pubkey: PubkeyHex}): ReturnType { + this.assertValidKnownPubkey(pubkey); const builderBoostFactor = this.validator.validatorStore.getBuilderBoostFactor(pubkey); return {data: {pubkey, builderBoostFactor}}; } @@ -352,6 +366,7 @@ export class KeymanagerApi implements Api { builderBoostFactor, }: BuilderBoostFactorData): ReturnType { this.checkIfProposerWriteEnabled(); + this.assertValidKnownPubkey(pubkey); this.validator.validatorStore.setBuilderBoostFactor(pubkey, builderBoostFactor); this.persistedKeysBackend.writeProposerConfig(pubkey, this.validator.validatorStore.getProposerConfig(pubkey)); return {status: 202}; @@ -364,11 +379,38 @@ export class KeymanagerApi implements Api { return {status: 204}; } + async getProposerConfig({pubkey}: {pubkey: PubkeyHex}): ReturnType { + this.assertValidKnownPubkey(pubkey); + + const config = this.validator.validatorStore.getProposerConfig(pubkey); + + const data: ProposerConfigResponse = { + ...config, + builder: config?.builder + ? { + ...config.builder, + // Default JSON serialization can't handle BigInt + boostFactor: config.builder.boostFactor ? config.builder.boostFactor.toString() : undefined, + } + : undefined, + }; + + return {data}; + } + async signVoluntaryExit({pubkey, epoch}: {pubkey: PubkeyHex; epoch?: Epoch}): ReturnType { + this.assertValidKnownPubkey(pubkey); + return {data: await this.validator.signVoluntaryExit(pubkey, epoch)}; + } + + private assertValidKnownPubkey(pubkey: PubkeyHex): void { if (!isValidatePubkeyHex(pubkey)) { throw new ApiError(400, `Invalid pubkey ${pubkey}`); } - return {data: await this.validator.signVoluntaryExit(pubkey, epoch)}; + + if (!this.validator.validatorStore.hasVotingPubkey(pubkey)) { + throw new ApiError(404, `Validator pubkey ${pubkey} not known`); + } } } diff --git a/packages/cli/src/cmds/validator/keymanager/keystoreCache.ts b/packages/cli/src/cmds/validator/keymanager/keystoreCache.ts index 2997a6b6b113..1f8643621bdc 100644 --- a/packages/cli/src/cmds/validator/keymanager/keystoreCache.ts +++ b/packages/cli/src/cmds/validator/keymanager/keystoreCache.ts @@ -2,8 +2,8 @@ import fs from "node:fs"; import path from "node:path"; import {Keystore} from "@chainsafe/bls-keystore"; import {SecretKey} from "@chainsafe/blst"; -import {SignerLocal, SignerType} from "@lodestar/validator"; import {fromHex, toHex, toPubkeyHex} from "@lodestar/utils"; +import {SignerLocal, SignerType} from "@lodestar/validator"; import {writeFile600Perm} from "../../../util/file.js"; import {lockFilepath, unlockFilepath} from "../../../util/lockfile.js"; import {LocalKeystoreDefinition} from "./interface.js"; diff --git a/packages/cli/src/cmds/validator/keymanager/persistedKeys.ts b/packages/cli/src/cmds/validator/keymanager/persistedKeys.ts index 6a1324dcbaa2..56d508fa4e2f 100644 --- a/packages/cli/src/cmds/validator/keymanager/persistedKeys.ts +++ b/packages/cli/src/cmds/validator/keymanager/persistedKeys.ts @@ -1,15 +1,15 @@ import fs from "node:fs"; import path from "node:path"; import {Keystore} from "@chainsafe/bls-keystore"; -import {ProposerConfig} from "@lodestar/validator"; import {DeletionStatus, ImportStatus, PubkeyHex, SignerDefinition} from "@lodestar/api/keymanager"; +import {ProposerConfig} from "@lodestar/validator"; import { getPubkeyHexFromKeystore, readPassphraseFile, + readProposerConfigDir, rmdirSyncMaybe, unlinkSyncMaybe, writeFile600Perm, - readProposerConfigDir, } from "../../../util/index.js"; import {lockFilepath} from "../../../util/lockfile.js"; import {IPersistedKeysBackend, LocalKeystoreDefinition} from "./interface.js"; diff --git a/packages/cli/src/cmds/validator/keymanager/server.ts b/packages/cli/src/cmds/validator/keymanager/server.ts index e48c708c96a8..4fec2295f293 100644 --- a/packages/cli/src/cmds/validator/keymanager/server.ts +++ b/packages/cli/src/cmds/validator/keymanager/server.ts @@ -1,8 +1,8 @@ import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; -import {RestApiServer, RestApiServerOpts, RestApiServerModules} from "@lodestar/beacon-node"; import {KeymanagerApiMethods, registerRoutes} from "@lodestar/api/keymanager/server"; +import {RestApiServer, RestApiServerModules, RestApiServerOpts} from "@lodestar/beacon-node"; import {ChainForkConfig} from "@lodestar/config"; import {toHex} from "@lodestar/utils"; import {writeFile600Perm} from "../../../util/index.js"; diff --git a/packages/cli/src/cmds/validator/options.ts b/packages/cli/src/cmds/validator/options.ts index 3beb8197793c..b20caeccb268 100644 --- a/packages/cli/src/cmds/validator/options.ts +++ b/packages/cli/src/cmds/validator/options.ts @@ -1,6 +1,6 @@ import {WireFormat, defaultInit} from "@lodestar/api"; -import {defaultOptions} from "@lodestar/validator"; import {CliCommandOptions} from "@lodestar/utils"; +import {defaultOptions} from "@lodestar/validator"; import {LogArgs, logOptions} from "../../options/logOptions.js"; import {ensure0xPrefix} from "../../util/index.js"; import {keymanagerRestApiServerOptsDefault} from "./keymanager/server.js"; diff --git a/packages/cli/src/cmds/validator/signers/index.ts b/packages/cli/src/cmds/validator/signers/index.ts index 950be2db1cf5..ebe3ed72cdba 100644 --- a/packages/cli/src/cmds/validator/signers/index.ts +++ b/packages/cli/src/cmds/validator/signers/index.ts @@ -2,15 +2,15 @@ import path from "node:path"; import {deriveEth2ValidatorKeys, deriveKeyFromMnemonic} from "@chainsafe/bls-keygen"; import {SecretKey} from "@chainsafe/blst"; import {interopSecretKey} from "@lodestar/state-transition"; -import {externalSignerGetKeys, Signer, SignerType} from "@lodestar/validator"; import {LogLevel, Logger, isValidHttpUrl} from "@lodestar/utils"; -import {defaultNetwork, GlobalArgs} from "../../../options/index.js"; -import {assertValidPubkeysHex, parseRange, YargsError} from "../../../util/index.js"; -import {getAccountPaths} from "../paths.js"; -import {IValidatorCliArgs} from "../options.js"; -import {PersistedKeysBackend} from "../keymanager/persistedKeys.js"; -import {decryptKeystoreDefinitions} from "../keymanager/decryptKeystoreDefinitions.js"; +import {Signer, SignerType, externalSignerGetKeys} from "@lodestar/validator"; +import {GlobalArgs, defaultNetwork} from "../../../options/index.js"; +import {YargsError, assertValidPubkeysHex, parseRange} from "../../../util/index.js"; import {showProgress} from "../../../util/progress.js"; +import {decryptKeystoreDefinitions} from "../keymanager/decryptKeystoreDefinitions.js"; +import {PersistedKeysBackend} from "../keymanager/persistedKeys.js"; +import {IValidatorCliArgs} from "../options.js"; +import {getAccountPaths} from "../paths.js"; import {importKeystoreDefinitionsFromExternalDir, readPassphraseOrPrompt} from "./importExternalKeystores.js"; const KEYSTORE_IMPORT_PROGRESS_MS = 10000; diff --git a/packages/cli/src/cmds/validator/signers/logSigners.ts b/packages/cli/src/cmds/validator/signers/logSigners.ts index d245ee75883a..9f65befb1cc7 100644 --- a/packages/cli/src/cmds/validator/signers/logSigners.ts +++ b/packages/cli/src/cmds/validator/signers/logSigners.ts @@ -1,5 +1,5 @@ -import {Signer, SignerLocal, SignerRemote, SignerType} from "@lodestar/validator"; import {LogLevel, Logger, toPrintableUrl} from "@lodestar/utils"; +import {Signer, SignerLocal, SignerRemote, SignerType} from "@lodestar/validator"; import {YargsError} from "../../../util/errors.js"; import {IValidatorCliArgs} from "../options.js"; diff --git a/packages/cli/src/cmds/validator/slashingProtection/export.ts b/packages/cli/src/cmds/validator/slashingProtection/export.ts index f57f9d3ec0bd..be7caae12e49 100644 --- a/packages/cli/src/cmds/validator/slashingProtection/export.ts +++ b/packages/cli/src/cmds/validator/slashingProtection/export.ts @@ -1,16 +1,16 @@ import path from "node:path"; -import {InterchangeFormatVersion} from "@lodestar/validator"; import {getNodeLogger} from "@lodestar/logger/node"; import {CliCommand, toPubkeyHex} from "@lodestar/utils"; -import {YargsError, ensure0xPrefix, isValidatePubkeyHex, writeFile600Perm} from "../../../util/index.js"; -import {parseLoggerArgs} from "../../../util/logger.js"; +import {InterchangeFormatVersion} from "@lodestar/validator"; +import {getBeaconConfigFromArgs} from "../../../config/index.js"; import {GlobalArgs} from "../../../options/index.js"; import {LogArgs} from "../../../options/logOptions.js"; +import {YargsError, ensure0xPrefix, isValidatePubkeyHex, writeFile600Perm} from "../../../util/index.js"; +import {parseLoggerArgs} from "../../../util/logger.js"; import {AccountValidatorArgs} from "../options.js"; -import {getBeaconConfigFromArgs} from "../../../config/index.js"; import {getValidatorPaths} from "../paths.js"; -import {getGenesisValidatorsRoot, getSlashingProtection} from "./utils.js"; import {ISlashingProtectionArgs} from "./options.js"; +import {getGenesisValidatorsRoot, getSlashingProtection} from "./utils.js"; type ExportArgs = { file: string; diff --git a/packages/cli/src/cmds/validator/slashingProtection/import.ts b/packages/cli/src/cmds/validator/slashingProtection/import.ts index 78be9e6126f7..e0e0cb5744c7 100644 --- a/packages/cli/src/cmds/validator/slashingProtection/import.ts +++ b/packages/cli/src/cmds/validator/slashingProtection/import.ts @@ -1,16 +1,16 @@ import fs from "node:fs"; import path from "node:path"; -import {Interchange} from "@lodestar/validator"; import {getNodeLogger} from "@lodestar/logger/node"; import {CliCommand} from "@lodestar/utils"; -import {parseLoggerArgs} from "../../../util/logger.js"; +import {Interchange} from "@lodestar/validator"; +import {getBeaconConfigFromArgs} from "../../../config/index.js"; import {GlobalArgs} from "../../../options/index.js"; import {LogArgs} from "../../../options/logOptions.js"; +import {parseLoggerArgs} from "../../../util/logger.js"; import {AccountValidatorArgs} from "../options.js"; -import {getBeaconConfigFromArgs} from "../../../config/index.js"; import {getValidatorPaths} from "../paths.js"; -import {getGenesisValidatorsRoot, getSlashingProtection} from "./utils.js"; import {ISlashingProtectionArgs} from "./options.js"; +import {getGenesisValidatorsRoot, getSlashingProtection} from "./utils.js"; type ImportArgs = { file: string; diff --git a/packages/cli/src/cmds/validator/slashingProtection/index.ts b/packages/cli/src/cmds/validator/slashingProtection/index.ts index 9c180c59c378..92d8bba619af 100644 --- a/packages/cli/src/cmds/validator/slashingProtection/index.ts +++ b/packages/cli/src/cmds/validator/slashingProtection/index.ts @@ -1,8 +1,8 @@ import {CliCommand} from "@lodestar/utils"; import {AccountValidatorArgs} from "../options.js"; -import {ISlashingProtectionArgs, slashingProtectionOptions} from "./options.js"; -import {importCmd} from "./import.js"; import {exportCmd} from "./export.js"; +import {importCmd} from "./import.js"; +import {ISlashingProtectionArgs, slashingProtectionOptions} from "./options.js"; export const slashingProtection: CliCommand = { command: "slashing-protection ", diff --git a/packages/cli/src/cmds/validator/slashingProtection/utils.ts b/packages/cli/src/cmds/validator/slashingProtection/utils.ts index fe0af1cb2633..48a25b6d83b9 100644 --- a/packages/cli/src/cmds/validator/slashingProtection/utils.ts +++ b/packages/cli/src/cmds/validator/slashingProtection/utils.ts @@ -1,12 +1,12 @@ -import {Root} from "@lodestar/types"; import {getClient} from "@lodestar/api"; -import {fromHex, Logger} from "@lodestar/utils"; -import {genesisData, NetworkName} from "@lodestar/config/networks"; -import {SlashingProtection, MetaDataRepository} from "@lodestar/validator"; +import {NetworkName, genesisData} from "@lodestar/config/networks"; import {LevelDbController} from "@lodestar/db"; +import {Root} from "@lodestar/types"; +import {Logger, fromHex} from "@lodestar/utils"; +import {MetaDataRepository, SlashingProtection} from "@lodestar/validator"; +import {getBeaconConfigFromArgs} from "../../../config/index.js"; import {GlobalArgs} from "../../../options/index.js"; import {getValidatorPaths} from "../paths.js"; -import {getBeaconConfigFromArgs} from "../../../config/index.js"; import {ISlashingProtectionArgs} from "./options.js"; /** diff --git a/packages/cli/src/cmds/validator/voluntaryExit.ts b/packages/cli/src/cmds/validator/voluntaryExit.ts index 5b4cfdf270f0..9b8b33c8601f 100644 --- a/packages/cli/src/cmds/validator/voluntaryExit.ts +++ b/packages/cli/src/cmds/validator/voluntaryExit.ts @@ -1,19 +1,19 @@ -import inquirer from "inquirer"; import {Signature} from "@chainsafe/blst"; +import {ApiClient, getClient} from "@lodestar/api"; +import {BeaconConfig, createBeaconConfig} from "@lodestar/config"; import { computeEpochAtSlot, computeSigningRoot, computeStartSlotAtEpoch, getCurrentSlot, } from "@lodestar/state-transition"; -import {createBeaconConfig, BeaconConfig} from "@lodestar/config"; -import {phase0, ssz, ValidatorIndex, Epoch} from "@lodestar/types"; +import {Epoch, ValidatorIndex, phase0, ssz} from "@lodestar/types"; import {CliCommand, fromHex, toPubkeyHex} from "@lodestar/utils"; -import {externalSignerPostSignature, SignableMessageType, Signer, SignerType} from "@lodestar/validator"; -import {ApiClient, getClient} from "@lodestar/api"; -import {ensure0xPrefix, YargsError, wrapError} from "../../util/index.js"; -import {GlobalArgs} from "../../options/index.js"; +import {SignableMessageType, Signer, SignerType, externalSignerPostSignature} from "@lodestar/validator"; +import inquirer from "inquirer"; import {getBeaconConfigFromArgs} from "../../config/index.js"; +import {GlobalArgs} from "../../options/index.js"; +import {YargsError, ensure0xPrefix, wrapError} from "../../util/index.js"; import {IValidatorCliArgs} from "./options.js"; import {getSignersFromArgs} from "./signers/index.js"; diff --git a/packages/cli/src/config/beaconNodeOptions.ts b/packages/cli/src/config/beaconNodeOptions.ts index edab28e1ed21..f99ced67d40b 100644 --- a/packages/cli/src/config/beaconNodeOptions.ts +++ b/packages/cli/src/config/beaconNodeOptions.ts @@ -1,6 +1,6 @@ +import {IBeaconNodeOptions, defaultOptions} from "@lodestar/beacon-node"; +import {RecursivePartial, isPlainObject} from "@lodestar/utils"; import deepmerge from "deepmerge"; -import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; -import {isPlainObject, RecursivePartial} from "@lodestar/utils"; export class BeaconNodeOptions { /** diff --git a/packages/cli/src/config/beaconParams.ts b/packages/cli/src/config/beaconParams.ts index 54a4155a3914..7abb0e9a5537 100644 --- a/packages/cli/src/config/beaconParams.ts +++ b/packages/cli/src/config/beaconParams.ts @@ -1,19 +1,19 @@ import { ChainConfig, - createChainForkConfig, - createChainConfig, ChainForkConfig, chainConfigFromJson, + createChainConfig, + createChainForkConfig, } from "@lodestar/config"; -import {readFile} from "../util/index.js"; -import {getNetworkBeaconParams, NetworkName} from "../networks/index.js"; +import {NetworkName, getNetworkBeaconParams} from "../networks/index.js"; import { - parseBeaconParamsArgs, - parseTerminalPowArgs, - ITerminalPowArgs, GlobalArgs, + ITerminalPowArgs, defaultNetwork, + parseBeaconParamsArgs, + parseTerminalPowArgs, } from "../options/index.js"; +import {readFile} from "../util/index.js"; import {IBeaconParamsUnparsed} from "./types.js"; type BeaconParamsArgs = { diff --git a/packages/cli/src/config/peerId.ts b/packages/cli/src/config/peerId.ts index 576a99e6980e..dd45ff408d0c 100644 --- a/packages/cli/src/config/peerId.ts +++ b/packages/cli/src/config/peerId.ts @@ -1,10 +1,10 @@ +import {unmarshalPrivateKey, unmarshalPublicKey} from "@libp2p/crypto/keys"; import type {PeerId} from "@libp2p/interface"; import {peerIdFromBytes} from "@libp2p/peer-id"; import {createFromPrivKey, createFromPubKey} from "@libp2p/peer-id-factory"; -import {unmarshalPrivateKey, unmarshalPublicKey} from "@libp2p/crypto/keys"; import {fromString as uint8ArrayFromString} from "uint8arrays/from-string"; import {toString as uint8ArrayToString} from "uint8arrays/to-string"; -import {writeFile600Perm, readFile} from "../util/index.js"; +import {readFile, writeFile600Perm} from "../util/index.js"; // Peer id to / from JSON taken from peer-id-factory // See https://github.com/libp2p/js-libp2p-peer-id/pull/9 for more details diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 0d509af17ab0..bc232bf0cce3 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -2,8 +2,8 @@ // MUST import first to apply preset from args and set ssz hasher import "./applyPreset.js"; -import {YargsError} from "./util/index.js"; import {getLodestarCli, yarg} from "./cli.js"; +import {YargsError} from "./util/index.js"; import "source-map-support/register.js"; const lodestar = getLodestarCli(); diff --git a/packages/cli/src/networks/dev.ts b/packages/cli/src/networks/dev.ts index 6ce87273b3cb..3ae54051ea37 100644 --- a/packages/cli/src/networks/dev.ts +++ b/packages/cli/src/networks/dev.ts @@ -1,7 +1,7 @@ +import {ChainConfig} from "@lodestar/config"; +import {mainnetChainConfig, minimalChainConfig} from "@lodestar/config/configs"; import {gnosisChainConfig} from "@lodestar/config/networks"; -import {minimalChainConfig, mainnetChainConfig} from "@lodestar/config/configs"; import {ACTIVE_PRESET, PresetName} from "@lodestar/params"; -import {ChainConfig} from "@lodestar/config"; let chainConfig: ChainConfig; switch (ACTIVE_PRESET) { diff --git a/packages/cli/src/networks/holesky.ts b/packages/cli/src/networks/holesky.ts index 63bc6e07f8f2..ed1dd7c78462 100644 --- a/packages/cli/src/networks/holesky.ts +++ b/packages/cli/src/networks/holesky.ts @@ -3,7 +3,7 @@ export {holeskyChainConfig as chainConfig} from "@lodestar/config/networks"; export const depositContractDeployBlock = 0; export const genesisFileUrl = "https://media.githubusercontent.com/media/eth-clients/holesky/main/metadata/genesis.ssz"; export const bootnodesFileUrl = - "https://raw.githubusercontent.com/eth-clients/holesky/main/metadata/bootstrap_nodes.txt"; + "https://raw.githubusercontent.com/eth-clients/holesky/main/metadata/bootstrap_nodes.yaml"; export const bootEnrs = [ "enr:-Ku4QFo-9q73SspYI8cac_4kTX7yF800VXqJW4Lj3HkIkb5CMqFLxciNHePmMt4XdJzHvhrCC5ADI4D_GkAsxGJRLnQBh2F0dG5ldHOIAAAAAAAAAACEZXRoMpAhnTT-AQFwAP__________gmlkgnY0gmlwhLKAiOmJc2VjcDI1NmsxoQORcM6e19T1T9gi7jxEZjk_sjVLGFscUNqAY9obgZaxbIN1ZHCCIyk", diff --git a/packages/cli/src/networks/index.ts b/packages/cli/src/networks/index.ts index 13e55685e353..b81fe7094fdd 100644 --- a/packages/cli/src/networks/index.ts +++ b/packages/cli/src/networks/index.ts @@ -1,28 +1,28 @@ import fs from "node:fs"; -import got from "got"; import {ENR} from "@chainsafe/enr"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {HttpHeader, MediaType, WireFormat, getClient} from "@lodestar/api"; import {getStateSlotFromBytes} from "@lodestar/beacon-node"; import {ChainConfig, ChainForkConfig} from "@lodestar/config"; -import {Checkpoint} from "@lodestar/types/phase0"; -import {Slot} from "@lodestar/types"; -import {fromHex, callFnWhenAwait, Logger, formatBytes} from "@lodestar/utils"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; import { BeaconStateAllForks, - getLatestBlockRoot, computeCheckpointEpochAtStateSlot, + getLatestBlockRoot, loadState, } from "@lodestar/state-transition"; +import {Slot} from "@lodestar/types"; +import {Checkpoint} from "@lodestar/types/phase0"; +import {Logger, callFnWhenAwait, formatBytes, fromHex} from "@lodestar/utils"; +import got from "got"; import {parseBootnodesFile} from "../util/format.js"; -import * as mainnet from "./mainnet.js"; +import * as chiado from "./chiado.js"; import * as dev from "./dev.js"; +import * as ephemery from "./ephemery.js"; import * as gnosis from "./gnosis.js"; -import * as sepolia from "./sepolia.js"; import * as holesky from "./holesky.js"; -import * as chiado from "./chiado.js"; -import * as ephemery from "./ephemery.js"; +import * as mainnet from "./mainnet.js"; import * as mekong from "./mekong.js"; +import * as sepolia from "./sepolia.js"; export type NetworkName = "mainnet" | "dev" | "gnosis" | "sepolia" | "holesky" | "chiado" | "ephemery" | "mekong"; export const networkNames: NetworkName[] = [ diff --git a/packages/cli/src/networks/sepolia.ts b/packages/cli/src/networks/sepolia.ts index 9dfd5dc20a0f..6900ca493057 100644 --- a/packages/cli/src/networks/sepolia.ts +++ b/packages/cli/src/networks/sepolia.ts @@ -3,7 +3,7 @@ export {sepoliaChainConfig as chainConfig} from "@lodestar/config/networks"; export const depositContractDeployBlock = 1273020; export const genesisFileUrl = "https://github.com/eth-clients/sepolia/raw/main/metadata/genesis.ssz"; export const bootnodesFileUrl = - "https://raw.githubusercontent.com/eth-clients/sepolia/main/metadata/bootstrap_nodes.txt"; + "https://raw.githubusercontent.com/eth-clients/sepolia/main/metadata/bootstrap_nodes.yaml"; export const bootEnrs = [ "enr:-KO4QP7MmB3juk8rUjJHcUoxZDU9Np4FlW0HyDEGIjSO7GD9PbSsabu7713cWSUWKDkxIypIXg1A-6lG7ySRGOMZHeGCAmuEZXRoMpDTH2GRkAAAc___________gmlkgnY0gmlwhBSoyGOJc2VjcDI1NmsxoQNta5b_bexSSwwrGW2Re24MjfMntzFd0f2SAxQtMj3ueYN0Y3CCIyiDdWRwgiMo", diff --git a/packages/cli/src/options/beaconNodeOptions/api.ts b/packages/cli/src/options/beaconNodeOptions/api.ts index ea4d4ebccf84..7ee3bd9caa17 100644 --- a/packages/cli/src/options/beaconNodeOptions/api.ts +++ b/packages/cli/src/options/beaconNodeOptions/api.ts @@ -1,4 +1,4 @@ -import {defaultOptions, IBeaconNodeOptions, allNamespaces} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, allNamespaces, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; const enabledAll = "*"; diff --git a/packages/cli/src/options/beaconNodeOptions/builder.ts b/packages/cli/src/options/beaconNodeOptions/builder.ts index d0e4089dd81c..01e21125637b 100644 --- a/packages/cli/src/options/beaconNodeOptions/builder.ts +++ b/packages/cli/src/options/beaconNodeOptions/builder.ts @@ -1,4 +1,4 @@ -import {defaultExecutionBuilderHttpOpts, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultExecutionBuilderHttpOpts} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; import {YargsError} from "../../util/index.js"; diff --git a/packages/cli/src/options/beaconNodeOptions/chain.ts b/packages/cli/src/options/beaconNodeOptions/chain.ts index c5f907804a83..21c05545c43d 100644 --- a/packages/cli/src/options/beaconNodeOptions/chain.ts +++ b/packages/cli/src/options/beaconNodeOptions/chain.ts @@ -1,5 +1,5 @@ import * as path from "node:path"; -import {StateArchiveMode, defaultOptions, IBeaconNodeOptions, DEFAULT_STATE_ARCHIVE_MODE} from "@lodestar/beacon-node"; +import {DEFAULT_STATE_ARCHIVE_MODE, IBeaconNodeOptions, StateArchiveMode, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; export type ChainArgs = { diff --git a/packages/cli/src/options/beaconNodeOptions/eth1.ts b/packages/cli/src/options/beaconNodeOptions/eth1.ts index f12a1704dec7..cab090a96781 100644 --- a/packages/cli/src/options/beaconNodeOptions/eth1.ts +++ b/packages/cli/src/options/beaconNodeOptions/eth1.ts @@ -1,5 +1,5 @@ import fs from "node:fs"; -import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; import {extractJwtHexSecret} from "../../util/index.js"; import {ExecutionEngineArgs} from "./execution.js"; diff --git a/packages/cli/src/options/beaconNodeOptions/execution.ts b/packages/cli/src/options/beaconNodeOptions/execution.ts index 2d32ee2ae786..79ea4ade98de 100644 --- a/packages/cli/src/options/beaconNodeOptions/execution.ts +++ b/packages/cli/src/options/beaconNodeOptions/execution.ts @@ -1,5 +1,5 @@ import fs from "node:fs"; -import {defaultExecutionEngineHttpOpts, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultExecutionEngineHttpOpts} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; import {extractJwtHexSecret} from "../../util/index.js"; diff --git a/packages/cli/src/options/beaconNodeOptions/metrics.ts b/packages/cli/src/options/beaconNodeOptions/metrics.ts index ded63b7dc24d..ae4c045fb07c 100644 --- a/packages/cli/src/options/beaconNodeOptions/metrics.ts +++ b/packages/cli/src/options/beaconNodeOptions/metrics.ts @@ -1,4 +1,4 @@ -import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; export type MetricsArgs = { diff --git a/packages/cli/src/options/beaconNodeOptions/monitoring.ts b/packages/cli/src/options/beaconNodeOptions/monitoring.ts index 2143277df2ae..2f35a4a29c5c 100644 --- a/packages/cli/src/options/beaconNodeOptions/monitoring.ts +++ b/packages/cli/src/options/beaconNodeOptions/monitoring.ts @@ -1,4 +1,4 @@ -import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; export type MonitoringArgs = { diff --git a/packages/cli/src/options/beaconNodeOptions/network.ts b/packages/cli/src/options/beaconNodeOptions/network.ts index cfd109bdc50a..56944d90fd0c 100644 --- a/packages/cli/src/options/beaconNodeOptions/network.ts +++ b/packages/cli/src/options/beaconNodeOptions/network.ts @@ -1,7 +1,7 @@ -import {multiaddr} from "@multiformats/multiaddr"; import {ENR} from "@chainsafe/enr"; -import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; +import {multiaddr} from "@multiformats/multiaddr"; import {YargsError} from "../../util/index.js"; export const defaultListenAddress = "0.0.0.0"; diff --git a/packages/cli/src/options/beaconNodeOptions/sync.ts b/packages/cli/src/options/beaconNodeOptions/sync.ts index 789307781ed0..a33fa43db470 100644 --- a/packages/cli/src/options/beaconNodeOptions/sync.ts +++ b/packages/cli/src/options/beaconNodeOptions/sync.ts @@ -1,4 +1,4 @@ -import {defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, defaultOptions} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; export type SyncArgs = { diff --git a/packages/cli/src/options/globalOptions.ts b/packages/cli/src/options/globalOptions.ts index 52a5090c6794..6a6998dc76cc 100644 --- a/packages/cli/src/options/globalOptions.ts +++ b/packages/cli/src/options/globalOptions.ts @@ -2,7 +2,7 @@ import {ACTIVE_PRESET} from "@lodestar/params"; import {CliCommandOptions} from "@lodestar/utils"; import {NetworkName, networkNames} from "../networks/index.js"; import {readFile} from "../util/index.js"; -import {paramsOptions, IParamsArgs} from "./paramsOptions.js"; +import {IParamsArgs, paramsOptions} from "./paramsOptions.js"; type GlobalSingleArgs = { dataDir?: string; @@ -10,6 +10,7 @@ type GlobalSingleArgs = { paramsFile?: string; preset: string; presetFile?: string; + rcConfig?: string; }; export const defaultNetwork: NetworkName = "mainnet"; @@ -44,11 +45,16 @@ const globalSingleOptions: CliCommandOptions = { description: "Preset configuration file to override the active preset with custom values", type: "string", }, + + rcConfig: { + description: "RC file to supplement command line args, accepted formats: .yml, .yaml, .json", + type: "string", + }, }; export const rcConfigOption: [string, string, (configPath: string) => Record] = [ "rcConfig", - "RC file to supplement command line args, accepted formats: .yml, .yaml, .json", + globalSingleOptions.rcConfig.description as string, (configPath: string): Record => readFile(configPath, ["json", "yml", "yaml"]), ]; diff --git a/packages/cli/src/options/logOptions.ts b/packages/cli/src/options/logOptions.ts index 09eb5b1d56cb..5b8c32c3b796 100644 --- a/packages/cli/src/options/logOptions.ts +++ b/packages/cli/src/options/logOptions.ts @@ -1,5 +1,5 @@ -import {LogLevels, CliCommandOptions} from "@lodestar/utils"; import {LogLevel, logFormats} from "@lodestar/logger"; +import {CliCommandOptions, LogLevels} from "@lodestar/utils"; import {LOG_FILE_DISABLE_KEYWORD} from "../util/logger.js"; export type LogArgs = { diff --git a/packages/cli/src/util/gitData/gitDataPath.ts b/packages/cli/src/util/gitData/gitDataPath.ts index 1ad3104aafc6..b4c7f8c7c62c 100644 --- a/packages/cli/src/util/gitData/gitDataPath.ts +++ b/packages/cli/src/util/gitData/gitDataPath.ts @@ -1,5 +1,5 @@ -import path from "node:path"; import fs from "node:fs"; +import path from "node:path"; import {fileURLToPath} from "node:url"; // Global variable __dirname no longer available in ES6 modules. diff --git a/packages/cli/src/util/gitData/index.ts b/packages/cli/src/util/gitData/index.ts index 0720d39d9e30..c5681660f8ce 100644 --- a/packages/cli/src/util/gitData/index.ts +++ b/packages/cli/src/util/gitData/index.ts @@ -2,7 +2,7 @@ import {execSync} from "node:child_process"; // This file is created in the build step and is distributed through NPM // MUST be in sync with `-/gitDataPath.ts` and `package.json` files. -import {readGitDataFile, GitData} from "./gitDataPath.js"; +import {GitData, readGitDataFile} from "./gitDataPath.js"; /** Reads git data from a persisted file or local git data at build time. */ export function readAndGetGitData(): GitData { diff --git a/packages/cli/src/util/logger.ts b/packages/cli/src/util/logger.ts index 7a394c9ce25f..99504ce5d43b 100644 --- a/packages/cli/src/util/logger.ts +++ b/packages/cli/src/util/logger.ts @@ -1,12 +1,12 @@ -import path from "node:path"; import fs from "node:fs"; +import path from "node:path"; import {ChainForkConfig} from "@lodestar/config"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {LogFormat, TimestampFormatCode, logFormats} from "@lodestar/logger"; import {LoggerNodeOpts} from "@lodestar/logger/node"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; import {LogLevel} from "@lodestar/utils"; -import {LogArgs} from "../options/logOptions.js"; import {GlobalArgs} from "../options/globalOptions.js"; +import {LogArgs} from "../options/logOptions.js"; export const LOG_FILE_DISABLE_KEYWORD = "none"; diff --git a/packages/cli/src/util/proposerConfig.ts b/packages/cli/src/util/proposerConfig.ts index 2c12ce8f8524..0aa745bc78af 100644 --- a/packages/cli/src/util/proposerConfig.ts +++ b/packages/cli/src/util/proposerConfig.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; -import {ValidatorProposerConfig} from "@lodestar/validator"; import {routes} from "@lodestar/api"; +import {ValidatorProposerConfig} from "@lodestar/validator"; import {parseFeeRecipient} from "./feeRecipient.js"; @@ -88,11 +88,14 @@ function parseProposerConfigSection( overrideConfig?.strictFeeRecipientCheck ?? (strict_fee_recipient_check ? stringtoBool(strict_fee_recipient_check) : undefined), feeRecipient: overrideConfig?.feeRecipient ?? (fee_recipient ? parseFeeRecipient(fee_recipient) : undefined), - builder: { - gasLimit: overrideConfig?.builder?.gasLimit ?? (gas_limit !== undefined ? Number(gas_limit) : undefined), - selection: overrideConfig?.builder?.selection ?? parseBuilderSelection(builderSelection), - boostFactor: overrideConfig?.builder?.boostFactor ?? parseBuilderBoostFactor(boost_factor), - }, + builder: + overrideConfig?.builder || builder + ? { + gasLimit: overrideConfig?.builder?.gasLimit ?? (gas_limit !== undefined ? Number(gas_limit) : undefined), + selection: overrideConfig?.builder?.selection ?? parseBuilderSelection(builderSelection), + boostFactor: overrideConfig?.builder?.boostFactor ?? parseBuilderBoostFactor(boost_factor), + } + : undefined, }; } diff --git a/packages/cli/src/util/pruneOldFilesInDir.ts b/packages/cli/src/util/pruneOldFilesInDir.ts index 3d5cc2b60bcb..8b8dfe754059 100644 --- a/packages/cli/src/util/pruneOldFilesInDir.ts +++ b/packages/cli/src/util/pruneOldFilesInDir.ts @@ -2,6 +2,10 @@ import fs from "node:fs"; import path from "node:path"; export function pruneOldFilesInDir(dirpath: string, maxAgeMs: number): number { + if (!fs.existsSync(dirpath)) { + return 0; // Nothing to prune + } + let deletedFileCount = 0; for (const entryName of fs.readdirSync(dirpath)) { const entryPath = path.join(dirpath, entryName); diff --git a/packages/cli/test/e2e/blsToExecutionchange.test.ts b/packages/cli/test/e2e/blsToExecutionchange.test.ts index 57f32421d313..ec7322caba00 100644 --- a/packages/cli/test/e2e/blsToExecutionchange.test.ts +++ b/packages/cli/test/e2e/blsToExecutionchange.test.ts @@ -1,11 +1,11 @@ import path from "node:path"; -import {describe, it, vi, onTestFinished} from "vitest"; import {toHexString} from "@chainsafe/ssz"; -import {sleep, retry} from "@lodestar/utils"; import {getClient} from "@lodestar/api"; import {config} from "@lodestar/config/default"; import {interopSecretKey} from "@lodestar/state-transition"; import {execCliCommand, spawnCliCommand, stopChildProcess} from "@lodestar/test-utils"; +import {retry, sleep} from "@lodestar/utils"; +import {describe, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; describe("bLSToExecutionChange cmd", () => { diff --git a/packages/cli/test/e2e/importFromFsDirect.test.ts b/packages/cli/test/e2e/importFromFsDirect.test.ts index 6f612e84afe6..b65ebf74fede 100644 --- a/packages/cli/test/e2e/importFromFsDirect.test.ts +++ b/packages/cli/test/e2e/importFromFsDirect.test.ts @@ -1,8 +1,8 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it, beforeAll, vi} from "vitest"; -import {rimraf} from "rimraf"; import {getKeystoresStr} from "@lodestar/test-utils"; +import {rimraf} from "rimraf"; +import {beforeAll, describe, it, vi} from "vitest"; import {testFilesDir} from "../utils.js"; import {cachedPubkeysHex, cachedSeckeysHex} from "../utils/cachedKeys.js"; import {expectKeys, startValidatorWithKeyManager} from "../utils/validator.js"; diff --git a/packages/cli/test/e2e/importFromFsPreStep.test.ts b/packages/cli/test/e2e/importFromFsPreStep.test.ts index 437180ef07e5..2933b6113a32 100644 --- a/packages/cli/test/e2e/importFromFsPreStep.test.ts +++ b/packages/cli/test/e2e/importFromFsPreStep.test.ts @@ -1,9 +1,9 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it, expect, beforeAll, vi, onTestFinished} from "vitest"; -import {rimraf} from "rimraf"; import {execCliCommand} from "@lodestar/test-utils"; import {getKeystoresStr} from "@lodestar/test-utils"; +import {rimraf} from "rimraf"; +import {beforeAll, describe, expect, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; import {cachedPubkeysHex, cachedSeckeysHex} from "../utils/cachedKeys.js"; import {expectKeys, startValidatorWithKeyManager} from "../utils/validator.js"; diff --git a/packages/cli/test/e2e/importKeystoresFromApi.test.ts b/packages/cli/test/e2e/importKeystoresFromApi.test.ts index 7f71e2977a92..6d15cfe13827 100644 --- a/packages/cli/test/e2e/importKeystoresFromApi.test.ts +++ b/packages/cli/test/e2e/importKeystoresFromApi.test.ts @@ -1,12 +1,12 @@ import path from "node:path"; -import {describe, it, expect, beforeAll, vi, onTestFinished} from "vitest"; -import {rimraf} from "rimraf"; -import {DeletionStatus, getClient, ImportStatus} from "@lodestar/api/keymanager"; -import {config} from "@lodestar/config/default"; -import {Interchange} from "@lodestar/validator"; import {HttpStatusCode} from "@lodestar/api"; +import {DeletionStatus, ImportStatus, getClient} from "@lodestar/api/keymanager"; +import {config} from "@lodestar/config/default"; import {bufferStderr, spawnCliCommand} from "@lodestar/test-utils"; import {getKeystoresStr} from "@lodestar/test-utils"; +import {Interchange} from "@lodestar/validator"; +import {rimraf} from "rimraf"; +import {beforeAll, describe, expect, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; import {cachedPubkeysHex, cachedSeckeysHex} from "../utils/cachedKeys.js"; import {expectDeepEquals} from "../utils/runUtils.js"; diff --git a/packages/cli/test/e2e/importRemoteKeysFromApi.test.ts b/packages/cli/test/e2e/importRemoteKeysFromApi.test.ts index b66611cbf4f4..2f3efea9425e 100644 --- a/packages/cli/test/e2e/importRemoteKeysFromApi.test.ts +++ b/packages/cli/test/e2e/importRemoteKeysFromApi.test.ts @@ -1,9 +1,9 @@ import path from "node:path"; -import {describe, it, expect, beforeAll, vi, onTestFinished} from "vitest"; -import {rimraf} from "rimraf"; -import {ApiClient, DeleteRemoteKeyStatus, getClient, ImportRemoteKeyStatus} from "@lodestar/api/keymanager"; -import {config} from "@lodestar/config/default"; import {HttpStatusCode} from "@lodestar/api"; +import {ApiClient, DeleteRemoteKeyStatus, ImportRemoteKeyStatus, getClient} from "@lodestar/api/keymanager"; +import {config} from "@lodestar/config/default"; +import {rimraf} from "rimraf"; +import {beforeAll, describe, expect, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; import {cachedPubkeysHex} from "../utils/cachedKeys.js"; import {expectDeepEquals} from "../utils/runUtils.js"; diff --git a/packages/cli/test/e2e/propserConfigfromKeymanager.test.ts b/packages/cli/test/e2e/propserConfigfromKeymanager.test.ts index 2f25c82999a7..26bf3e618c2b 100644 --- a/packages/cli/test/e2e/propserConfigfromKeymanager.test.ts +++ b/packages/cli/test/e2e/propserConfigfromKeymanager.test.ts @@ -1,9 +1,9 @@ import path from "node:path"; -import {describe, it, beforeAll, vi, onTestFinished} from "vitest"; -import {rimraf} from "rimraf"; import {ImportStatus} from "@lodestar/api/keymanager"; -import {Interchange} from "@lodestar/validator"; import {getKeystoresStr} from "@lodestar/test-utils"; +import {Interchange} from "@lodestar/validator"; +import {rimraf} from "rimraf"; +import {beforeAll, describe, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; import {cachedPubkeysHex, cachedSeckeysHex} from "../utils/cachedKeys.js"; import {expectDeepEquals} from "../utils/runUtils.js"; diff --git a/packages/cli/test/e2e/runDevCmd.test.ts b/packages/cli/test/e2e/runDevCmd.test.ts index 3beb68393815..e935e5eaf411 100644 --- a/packages/cli/test/e2e/runDevCmd.test.ts +++ b/packages/cli/test/e2e/runDevCmd.test.ts @@ -1,8 +1,8 @@ -import {describe, it, vi, onTestFinished} from "vitest"; import {getClient} from "@lodestar/api"; import {config} from "@lodestar/config/default"; -import {retry} from "@lodestar/utils"; import {spawnCliCommand, stopChildProcess} from "@lodestar/test-utils"; +import {retry} from "@lodestar/utils"; +import {describe, it, onTestFinished, vi} from "vitest"; describe("Run dev command", () => { vi.setConfig({testTimeout: 30_000}); diff --git a/packages/cli/test/e2e/validatorList.test.ts b/packages/cli/test/e2e/validatorList.test.ts index 7f86fb8ef89b..6987006bd26a 100644 --- a/packages/cli/test/e2e/validatorList.test.ts +++ b/packages/cli/test/e2e/validatorList.test.ts @@ -1,13 +1,13 @@ /* eslint-disable no-console */ import fs from "node:fs"; import path from "node:path"; -import {describe, it, beforeAll, vi, expect, afterEach, beforeEach} from "vitest"; -import {rimraf} from "rimraf"; import {Keystore} from "@chainsafe/bls-keystore"; -import {fromHex} from "@lodestar/utils"; import {runCliCommand} from "@lodestar/test-utils"; -import {testFilesDir} from "../utils.js"; +import {fromHex} from "@lodestar/utils"; +import {rimraf} from "rimraf"; +import {afterEach, beforeAll, beforeEach, describe, expect, it, vi} from "vitest"; import {getLodestarCli} from "../../src/cli.js"; +import {testFilesDir} from "../utils.js"; describe("cmds / validator", () => { vi.setConfig({testTimeout: 30_000}); diff --git a/packages/cli/test/e2e/voluntaryExit.test.ts b/packages/cli/test/e2e/voluntaryExit.test.ts index 0abddcab7652..8c17e8ef8c5b 100644 --- a/packages/cli/test/e2e/voluntaryExit.test.ts +++ b/packages/cli/test/e2e/voluntaryExit.test.ts @@ -1,10 +1,10 @@ import path from "node:path"; -import {describe, it, vi, onTestFinished} from "vitest"; -import {retry} from "@lodestar/utils"; import {getClient} from "@lodestar/api"; import {config} from "@lodestar/config/default"; import {interopSecretKey} from "@lodestar/state-transition"; -import {spawnCliCommand, execCliCommand, stopChildProcess} from "@lodestar/test-utils"; +import {execCliCommand, spawnCliCommand, stopChildProcess} from "@lodestar/test-utils"; +import {retry} from "@lodestar/utils"; +import {describe, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; describe("voluntaryExit cmd", () => { diff --git a/packages/cli/test/e2e/voluntaryExitFromApi.test.ts b/packages/cli/test/e2e/voluntaryExitFromApi.test.ts index 97ac06d5fc5c..8421d57658af 100644 --- a/packages/cli/test/e2e/voluntaryExitFromApi.test.ts +++ b/packages/cli/test/e2e/voluntaryExitFromApi.test.ts @@ -1,11 +1,11 @@ import path from "node:path"; -import {describe, it, vi, expect, onTestFinished} from "vitest"; import {getClient} from "@lodestar/api"; import {getClient as getKeymanagerClient} from "@lodestar/api/keymanager"; import {config} from "@lodestar/config/default"; import {interopSecretKey} from "@lodestar/state-transition"; import {spawnCliCommand, stopChildProcess} from "@lodestar/test-utils"; import {retry} from "@lodestar/utils"; +import {describe, expect, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; describe("voluntary exit from api", () => { diff --git a/packages/cli/test/e2e/voluntaryExitRemoteSigner.test.ts b/packages/cli/test/e2e/voluntaryExitRemoteSigner.test.ts index 769380f2053f..172f79c5191d 100644 --- a/packages/cli/test/e2e/voluntaryExitRemoteSigner.test.ts +++ b/packages/cli/test/e2e/voluntaryExitRemoteSigner.test.ts @@ -1,17 +1,17 @@ import path from "node:path"; -import {describe, it, beforeAll, afterAll, vi, onTestFinished} from "vitest"; -import {retry} from "@lodestar/utils"; import {getClient} from "@lodestar/api"; import {config} from "@lodestar/config/default"; import {interopSecretKey, interopSecretKeys} from "@lodestar/state-transition"; import { - spawnCliCommand, - execCliCommand, - startExternalSigner, StartedExternalSigner, + execCliCommand, getKeystoresStr, + spawnCliCommand, + startExternalSigner, stopChildProcess, } from "@lodestar/test-utils"; +import {retry} from "@lodestar/utils"; +import {afterAll, beforeAll, describe, it, onTestFinished, vi} from "vitest"; import {testFilesDir} from "../utils.js"; describe("voluntaryExit using remote signer", () => { diff --git a/packages/cli/test/sim/backupEthProvider.test.ts b/packages/cli/test/sim/backupEthProvider.test.ts index 4ccc131a58bc..8b34d57e4d67 100644 --- a/packages/cli/test/sim/backupEthProvider.test.ts +++ b/packages/cli/test/sim/backupEthProvider.test.ts @@ -1,8 +1,8 @@ import path from "node:path"; import {activePreset} from "@lodestar/params"; -import {Simulation} from "../utils/crucible/simulation.js"; import {nodeAssertion} from "../utils/crucible/assertions/nodeAssertion.js"; -import {Match, BeaconClient, ExecutionClient} from "../utils/crucible/interfaces.js"; +import {BeaconClient, ExecutionClient, Match} from "../utils/crucible/interfaces.js"; +import {Simulation} from "../utils/crucible/simulation.js"; import {defineSimTestConfig, logFilesDir, replaceIpFromUrl} from "../utils/crucible/utils/index.js"; import {connectAllNodes, waitForSlot} from "../utils/crucible/utils/network.js"; diff --git a/packages/cli/test/sim/deneb.test.ts b/packages/cli/test/sim/deneb.test.ts index 865540ae7635..8d3bd3064bc2 100644 --- a/packages/cli/test/sim/deneb.test.ts +++ b/packages/cli/test/sim/deneb.test.ts @@ -1,9 +1,9 @@ import path from "node:path"; -import {Simulation} from "../utils/crucible/simulation.js"; +import {createBlobsAssertion} from "../utils/crucible/assertions/blobsAssertion.js"; import {BeaconClient, ExecutionClient, ValidatorClient} from "../utils/crucible/interfaces.js"; +import {Simulation} from "../utils/crucible/simulation.js"; import {defineSimTestConfig, logFilesDir} from "../utils/crucible/utils/index.js"; import {connectAllNodes, waitForSlot} from "../utils/crucible/utils/network.js"; -import {createBlobsAssertion} from "../utils/crucible/assertions/blobsAssertion.js"; import {assertCheckpointSync, assertRangeSync} from "../utils/crucible/utils/syncing.js"; const runTillEpoch = 6; diff --git a/packages/cli/test/sim/endpoints.test.ts b/packages/cli/test/sim/endpoints.test.ts index 308ac6a0053c..b1492865309a 100644 --- a/packages/cli/test/sim/endpoints.test.ts +++ b/packages/cli/test/sim/endpoints.test.ts @@ -1,10 +1,10 @@ -import path from "node:path"; import assert from "node:assert"; +import path from "node:path"; import {toHexString} from "@chainsafe/ssz"; -import {routes, fetch} from "@lodestar/api"; +import {fetch, routes} from "@lodestar/api"; import {ssz} from "@lodestar/types"; -import {Simulation} from "../utils/crucible/simulation.js"; import {BeaconClient, ExecutionClient} from "../utils/crucible/interfaces.js"; +import {Simulation} from "../utils/crucible/simulation.js"; import {defineSimTestConfig, logFilesDir} from "../utils/crucible/utils/index.js"; import {waitForSlot} from "../utils/crucible/utils/network.js"; diff --git a/packages/cli/test/sim/mixedClient.test.ts b/packages/cli/test/sim/mixedClient.test.ts index 45029a1b26b4..5fe786829cf1 100644 --- a/packages/cli/test/sim/mixedClient.test.ts +++ b/packages/cli/test/sim/mixedClient.test.ts @@ -1,7 +1,7 @@ import path from "node:path"; -import {Simulation} from "../utils/crucible/simulation.js"; import {nodeAssertion} from "../utils/crucible/assertions/nodeAssertion.js"; -import {Match, BeaconClient, ExecutionClient, ValidatorClient} from "../utils/crucible/interfaces.js"; +import {BeaconClient, ExecutionClient, Match, ValidatorClient} from "../utils/crucible/interfaces.js"; +import {Simulation} from "../utils/crucible/simulation.js"; import {defineSimTestConfig, logFilesDir} from "../utils/crucible/utils/index.js"; import {connectAllNodes, waitForSlot} from "../utils/crucible/utils/network.js"; diff --git a/packages/cli/test/sim/multiFork.test.ts b/packages/cli/test/sim/multiFork.test.ts index 047d9196239d..83cb8f234646 100644 --- a/packages/cli/test/sim/multiFork.test.ts +++ b/packages/cli/test/sim/multiFork.test.ts @@ -1,14 +1,14 @@ import path from "node:path"; -import {Match, BeaconClient, ExecutionClient, ValidatorClient} from "../utils/crucible/interfaces.js"; -import {Simulation} from "../utils/crucible/simulation.js"; -import {defineSimTestConfig, logFilesDir} from "../utils/crucible/utils/index.js"; -import {connectAllNodes, waitForSlot} from "../utils/crucible/utils/network.js"; -import {nodeAssertion} from "../utils/crucible/assertions/nodeAssertion.js"; -import {mergeAssertion} from "../utils/crucible/assertions/mergeAssertion.js"; -import {createForkAssertion} from "../utils/crucible/assertions/forkAssertion.js"; import {createAccountBalanceAssertion} from "../utils/crucible/assertions/accountBalanceAssertion.js"; import {createExecutionHeadAssertion} from "../utils/crucible/assertions/executionHeadAssertion.js"; +import {createForkAssertion} from "../utils/crucible/assertions/forkAssertion.js"; +import {mergeAssertion} from "../utils/crucible/assertions/mergeAssertion.js"; +import {nodeAssertion} from "../utils/crucible/assertions/nodeAssertion.js"; import {createWithdrawalAssertions} from "../utils/crucible/assertions/withdrawalsAssertion.js"; +import {BeaconClient, ExecutionClient, Match, ValidatorClient} from "../utils/crucible/interfaces.js"; +import {Simulation} from "../utils/crucible/simulation.js"; +import {defineSimTestConfig, logFilesDir} from "../utils/crucible/utils/index.js"; +import {connectAllNodes, waitForSlot} from "../utils/crucible/utils/network.js"; import {assertCheckpointSync, assertRangeSync, assertUnknownBlockSync} from "../utils/crucible/utils/syncing.js"; const altairForkEpoch = 2; diff --git a/packages/cli/test/unit/cmds/beacon.test.ts b/packages/cli/test/unit/cmds/beacon.test.ts index 6e7b7f389a29..a1dac019a7e8 100644 --- a/packages/cli/test/unit/cmds/beacon.test.ts +++ b/packages/cli/test/unit/cmds/beacon.test.ts @@ -1,16 +1,16 @@ -import path from "node:path"; import fs from "node:fs"; -import {describe, it, expect} from "vitest"; +import path from "node:path"; +import {ENR, SignableENR, createPrivateKeyFromPeerId} from "@chainsafe/enr"; import {createFromJSON, createSecp256k1PeerId} from "@libp2p/peer-id-factory"; -import {multiaddr} from "@multiformats/multiaddr"; -import {createPrivateKeyFromPeerId, ENR, SignableENR} from "@chainsafe/enr"; -import {chainConfig} from "@lodestar/config/default"; import {chainConfigToJson} from "@lodestar/config"; +import {chainConfig} from "@lodestar/config/default"; import {LogLevel} from "@lodestar/utils"; -import {exportToJSON} from "../../../src/config/peerId.js"; +import {multiaddr} from "@multiformats/multiaddr"; +import {describe, expect, it} from "vitest"; import {beaconHandlerInit} from "../../../src/cmds/beacon/handler.js"; import {initPeerIdAndEnr, isLocalMultiAddr} from "../../../src/cmds/beacon/initPeerIdAndEnr.js"; import {BeaconArgs} from "../../../src/cmds/beacon/options.js"; +import {exportToJSON} from "../../../src/config/peerId.js"; import {GlobalArgs} from "../../../src/options/globalOptions.js"; import {testFilesDir, testLogger} from "../../utils.js"; diff --git a/packages/cli/test/unit/cmds/initPeerIdAndEnr.test.ts b/packages/cli/test/unit/cmds/initPeerIdAndEnr.test.ts index a207e0c0f59d..a7b7ed64e743 100644 --- a/packages/cli/test/unit/cmds/initPeerIdAndEnr.test.ts +++ b/packages/cli/test/unit/cmds/initPeerIdAndEnr.test.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; -import {describe, it, expect, beforeEach, afterEach} from "vitest"; import tmp from "tmp"; +import {afterEach, beforeEach, describe, expect, it} from "vitest"; import {initPeerIdAndEnr} from "../../../src/cmds/beacon/initPeerIdAndEnr.js"; import {BeaconArgs} from "../../../src/cmds/beacon/options.js"; import {testLogger} from "../../utils.js"; diff --git a/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts b/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts index 8d3dbb989b5d..a313455f7d8c 100644 --- a/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts +++ b/packages/cli/test/unit/cmds/validator/keymanager/keystoreCache.test.ts @@ -1,13 +1,13 @@ -import fs from "node:fs"; import {randomBytes} from "node:crypto"; -import {describe, it, expect, beforeEach, vi} from "vitest"; -import tmp from "tmp"; +import fs from "node:fs"; import {Keystore} from "@chainsafe/bls-keystore"; import {SecretKey} from "@chainsafe/blst"; import {interopSecretKey} from "@lodestar/state-transition"; import {SignerLocal, SignerType} from "@lodestar/validator"; -import {loadKeystoreCache, writeKeystoreCache} from "../../../../../src/cmds/validator/keymanager/keystoreCache.js"; +import tmp from "tmp"; +import {beforeEach, describe, expect, it, vi} from "vitest"; import {LocalKeystoreDefinition} from "../../../../../src/cmds/validator/keymanager/interface.js"; +import {loadKeystoreCache, writeKeystoreCache} from "../../../../../src/cmds/validator/keymanager/keystoreCache.js"; const numberOfSigners = 10; diff --git a/packages/cli/test/unit/config/beaconNodeOptions.test.ts b/packages/cli/test/unit/config/beaconNodeOptions.test.ts index d35cf06ad1a4..cb21a15ce0af 100644 --- a/packages/cli/test/unit/config/beaconNodeOptions.test.ts +++ b/packages/cli/test/unit/config/beaconNodeOptions.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {defaultOptions} from "@lodestar/beacon-node"; +import {describe, expect, it} from "vitest"; import {BeaconNodeOptions} from "../../../src/config/index.js"; describe("config / beaconNodeOptions", () => { diff --git a/packages/cli/test/unit/config/beaconParams.test.ts b/packages/cli/test/unit/config/beaconParams.test.ts index 2a78d498bf89..1d24cda5dda9 100644 --- a/packages/cli/test/unit/config/beaconParams.test.ts +++ b/packages/cli/test/unit/config/beaconParams.test.ts @@ -1,9 +1,9 @@ import fs from "node:fs"; -import {describe, it, expect, beforeAll, afterAll} from "vitest"; -import yaml from "js-yaml"; import {toHexString} from "@chainsafe/ssz"; -import {getTestdirPath} from "../../utils.js"; +import yaml from "js-yaml"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; import {getBeaconParams} from "../../../src/config/index.js"; +import {getTestdirPath} from "../../utils.js"; describe("config / beaconParams", () => { const GENESIS_FORK_VERSION_MAINNET = "0x00000000"; diff --git a/packages/cli/test/unit/config/peerId.test.ts b/packages/cli/test/unit/config/peerId.test.ts index c0cdc8cff1a9..a85aaf1a5a5c 100644 --- a/packages/cli/test/unit/config/peerId.test.ts +++ b/packages/cli/test/unit/config/peerId.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; import {createSecp256k1PeerId} from "@libp2p/peer-id-factory"; +import {describe, expect, it} from "vitest"; +import {readPeerId, writePeerId} from "../../../src/config/index.js"; import {getTestdirPath} from "../../utils.js"; -import {writePeerId, readPeerId} from "../../../src/config/index.js"; describe("config / peerId", () => { const peerIdFilepath = getTestdirPath("./test-peer-id.json"); diff --git a/packages/cli/test/unit/options/beaconNodeOptions.test.ts b/packages/cli/test/unit/options/beaconNodeOptions.test.ts index 8d295197b541..a94079ee0544 100644 --- a/packages/cli/test/unit/options/beaconNodeOptions.test.ts +++ b/packages/cli/test/unit/options/beaconNodeOptions.test.ts @@ -1,8 +1,8 @@ import fs from "node:fs"; -import {describe, it, expect} from "vitest"; -import {StateArchiveMode, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {IBeaconNodeOptions, StateArchiveMode} from "@lodestar/beacon-node"; import {RecursivePartial} from "@lodestar/utils"; -import {parseBeaconNodeArgs, BeaconNodeArgs} from "../../../src/options/beaconNodeOptions/index.js"; +import {describe, expect, it} from "vitest"; +import {BeaconNodeArgs, parseBeaconNodeArgs} from "../../../src/options/beaconNodeOptions/index.js"; import {getTestdirPath} from "../../utils.js"; describe("options / beaconNodeOptions", () => { diff --git a/packages/cli/test/unit/options/paramsOptions.test.ts b/packages/cli/test/unit/options/paramsOptions.test.ts index d6563203e652..13b3b6e41c6b 100644 --- a/packages/cli/test/unit/options/paramsOptions.test.ts +++ b/packages/cli/test/unit/options/paramsOptions.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {parseBeaconParamsArgs} from "../../../src/options/paramsOptions.js"; +import {describe, expect, it} from "vitest"; import {IBeaconParamsUnparsed} from "../../../src/config/types.js"; +import {parseBeaconParamsArgs} from "../../../src/options/paramsOptions.js"; describe("options / paramsOptions", () => { it("Should parse BeaconParams", () => { diff --git a/packages/cli/test/unit/paths/globalPaths.test.ts b/packages/cli/test/unit/paths/globalPaths.test.ts index 0d301bb56ffb..67655600c25b 100644 --- a/packages/cli/test/unit/paths/globalPaths.test.ts +++ b/packages/cli/test/unit/paths/globalPaths.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {getGlobalPaths} from "../../../src/paths/global.js"; describe("paths / global", () => { diff --git a/packages/cli/test/unit/util/extractJwtHexSecret.test.ts b/packages/cli/test/unit/util/extractJwtHexSecret.test.ts index bb7032390208..9f8543c2b9a1 100644 --- a/packages/cli/test/unit/util/extractJwtHexSecret.test.ts +++ b/packages/cli/test/unit/util/extractJwtHexSecret.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {extractJwtHexSecret} from "../../../src/util/index.js"; describe("parseJwtHexSecret", () => { diff --git a/packages/cli/test/unit/util/format.test.ts b/packages/cli/test/unit/util/format.test.ts index 194cc1dcbde7..f113d400860c 100644 --- a/packages/cli/test/unit/util/format.test.ts +++ b/packages/cli/test/unit/util/format.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {isValidatePubkeyHex, parseRange} from "../../../src/util/index.js"; describe("util / format / parseRange", () => { diff --git a/packages/cli/test/unit/util/gitData.test.ts b/packages/cli/test/unit/util/gitData.test.ts index 9e15fc2f4956..fe1827e58df2 100644 --- a/packages/cli/test/unit/util/gitData.test.ts +++ b/packages/cli/test/unit/util/gitData.test.ts @@ -1,8 +1,8 @@ import fs from "node:fs"; import path from "node:path"; import {fileURLToPath} from "node:url"; -import {describe, it, expect} from "vitest"; import {findUpSync} from "find-up"; +import {describe, expect, it} from "vitest"; import {gitDataPath, readGitDataFile} from "../../../src/util/gitData/gitDataPath.js"; import {getGitData} from "../../../src/util/index.js"; diff --git a/packages/cli/test/unit/util/logger.test.ts b/packages/cli/test/unit/util/logger.test.ts index fa17218bfd1c..dba3a72fda6c 100644 --- a/packages/cli/test/unit/util/logger.test.ts +++ b/packages/cli/test/unit/util/logger.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, vi, beforeEach, afterEach} from "vitest"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {shouldDeleteLogFile} from "../../../src/util/logger.js"; describe("shouldDeleteLogFile", () => { diff --git a/packages/cli/test/unit/util/parseBootnodesFile.test.ts b/packages/cli/test/unit/util/parseBootnodesFile.test.ts index 07338192bc68..87af3c994fb5 100644 --- a/packages/cli/test/unit/util/parseBootnodesFile.test.ts +++ b/packages/cli/test/unit/util/parseBootnodesFile.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {parseBootnodesFile} from "../../../src/util/index.js"; describe("config / bootnodes / parsing", () => { diff --git a/packages/cli/test/unit/util/progress.test.ts b/packages/cli/test/unit/util/progress.test.ts index d04d959d7422..11f443d35678 100644 --- a/packages/cli/test/unit/util/progress.test.ts +++ b/packages/cli/test/unit/util/progress.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect, vi, beforeEach, afterEach} from "vitest"; +import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"; import {showProgress} from "../../../src/util/progress.js"; describe("progress", () => { diff --git a/packages/cli/test/unit/util/pruneOldFilesInDir.test.ts b/packages/cli/test/unit/util/pruneOldFilesInDir.test.ts index 76285afff081..ee5532a358ee 100644 --- a/packages/cli/test/unit/util/pruneOldFilesInDir.test.ts +++ b/packages/cli/test/unit/util/pruneOldFilesInDir.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it, expect, beforeEach, afterEach} from "vitest"; import {rimraf} from "rimraf"; +import {afterEach, beforeEach, describe, expect, it} from "vitest"; import {pruneOldFilesInDir} from "../../../src/util/index.js"; import {testFilesDir} from "../../utils.js"; @@ -55,6 +55,10 @@ describe("pruneOldFilesInDir", () => { expect(fs.existsSync(emptyDir)).toBe(false); }); + it("should handle missing directories", () => { + expect(() => pruneOldFilesInDir(path.join(dataDir, "does-not-exist"), DAYS_TO_MS)).not.toThrowError(); + }); + function createFileWithAge(path: string, ageInDays: number): void { // Create a new empty file fs.closeSync(fs.openSync(path, "w")); diff --git a/packages/cli/test/unit/util/stripOffNewlines.test.ts b/packages/cli/test/unit/util/stripOffNewlines.test.ts index 3a5a5a1f3523..0a118a499e34 100644 --- a/packages/cli/test/unit/util/stripOffNewlines.test.ts +++ b/packages/cli/test/unit/util/stripOffNewlines.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {stripOffNewlines} from "../../../src/util/index.js"; describe("stripOffNewlines", () => { diff --git a/packages/cli/test/unit/validator/decryptKeystoreDefinitions.test.ts b/packages/cli/test/unit/validator/decryptKeystoreDefinitions.test.ts index 10f6b34bd152..5bf19c635139 100644 --- a/packages/cli/test/unit/validator/decryptKeystoreDefinitions.test.ts +++ b/packages/cli/test/unit/validator/decryptKeystoreDefinitions.test.ts @@ -1,16 +1,16 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it, expect, beforeEach, vi} from "vitest"; -import {rimraf} from "rimraf"; import {getKeystoresStr} from "@lodestar/test-utils"; -import {cachedSeckeysHex} from "../../utils/cachedKeys.js"; -import {testFilesDir} from "../../utils.js"; +import {rimraf} from "rimraf"; +import {beforeEach, describe, expect, it, vi} from "vitest"; import { - decryptKeystoreDefinitions, KeystoreDecryptOptions, + decryptKeystoreDefinitions, } from "../../../src/cmds/validator/keymanager/decryptKeystoreDefinitions.js"; import {LocalKeystoreDefinition} from "../../../src/cmds/validator/keymanager/interface.js"; import {LockfileError, unlockFilepath} from "../../../src/util/lockfile.js"; +import {testFilesDir} from "../../utils.js"; +import {cachedSeckeysHex} from "../../utils/cachedKeys.js"; describe("decryptKeystoreDefinitions", () => { vi.setConfig({testTimeout: 100_000, hookTimeout: 50_000}); diff --git a/packages/cli/test/unit/validator/keys.test.ts b/packages/cli/test/unit/validator/keys.test.ts index 6902d17b3883..589e68db7f0d 100644 --- a/packages/cli/test/unit/validator/keys.test.ts +++ b/packages/cli/test/unit/validator/keys.test.ts @@ -1,6 +1,6 @@ import fs from "node:fs"; import path from "node:path"; -import {describe, it, expect, afterEach} from "vitest"; +import {afterEach, describe, expect, it} from "vitest"; import {importKeystoreDefinitionsFromExternalDir} from "../../../src/cmds/validator/signers/importExternalKeystores.js"; describe("validator / signers / importKeystoreDefinitionsFromExternalDir", () => { diff --git a/packages/cli/test/unit/validator/options.test.ts b/packages/cli/test/unit/validator/options.test.ts index 627ee8f59818..85aa0b3f21f7 100644 --- a/packages/cli/test/unit/validator/options.test.ts +++ b/packages/cli/test/unit/validator/options.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {parseFeeRecipient} from "../../../src/util/index.js"; const feeRecipient = Buffer.from(Array.from({length: 20}, () => Math.round(Math.random() * 255))); diff --git a/packages/cli/test/unit/validator/parseProposerConfig.test.ts b/packages/cli/test/unit/validator/parseProposerConfig.test.ts index 83c8c63ef877..f10d5d7cc080 100644 --- a/packages/cli/test/unit/validator/parseProposerConfig.test.ts +++ b/packages/cli/test/unit/validator/parseProposerConfig.test.ts @@ -1,7 +1,7 @@ import path from "node:path"; import {fileURLToPath} from "node:url"; -import {describe, it, expect} from "vitest"; import {routes} from "@lodestar/api"; +import {describe, expect, it} from "vitest"; import {parseProposerConfig} from "../../../src/util/index.js"; @@ -26,8 +26,7 @@ const testValue = { builder: { gasLimit: 35000000, selection: routes.validator.BuilderSelection.BuilderAlways, - // biome-ignore lint/correctness/noPrecisionLoss: - boostFactor: BigInt(18446744073709551616), + boostFactor: 18446744073709551616n, }, }, }, diff --git a/packages/cli/test/utils.ts b/packages/cli/test/utils.ts index 81136c0a18d4..7c20ec0b9c2d 100644 --- a/packages/cli/test/utils.ts +++ b/packages/cli/test/utils.ts @@ -1,9 +1,9 @@ import fs from "node:fs"; import path from "node:path"; -import tmp from "tmp"; import {getEnvLogLevel} from "@lodestar/logger/env"; import {LoggerNode, LoggerNodeOpts, getNodeLogger} from "@lodestar/logger/node"; import {LogLevel} from "@lodestar/utils"; +import tmp from "tmp"; export const networkDev = "dev"; diff --git a/packages/cli/test/utils/crucible/assertions/accountBalanceAssertion.ts b/packages/cli/test/utils/crucible/assertions/accountBalanceAssertion.ts index e6c4f4c744eb..e237bba69dcb 100644 --- a/packages/cli/test/utils/crucible/assertions/accountBalanceAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/accountBalanceAssertion.ts @@ -1,5 +1,5 @@ import {EL_GENESIS_ACCOUNT} from "../constants.js"; -import {Match, AssertionResult, NodePair, Assertion} from "../interfaces.js"; +import {Assertion, AssertionResult, Match, NodePair} from "../interfaces.js"; const transactionAmount = BigInt(2441406250); diff --git a/packages/cli/test/utils/crucible/assertions/blobsAssertion.ts b/packages/cli/test/utils/crucible/assertions/blobsAssertion.ts index 50c9ed13f972..9bea3f1ca1f5 100644 --- a/packages/cli/test/utils/crucible/assertions/blobsAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/blobsAssertion.ts @@ -1,7 +1,7 @@ import {randomBytes} from "node:crypto"; import {fromHex, toHex} from "@lodestar/utils"; -import {Assertion, Match, AssertionResult, NodePair} from "../interfaces.js"; import {EL_GENESIS_ACCOUNT, EL_GENESIS_SECRET_KEY, SIM_ENV_CHAIN_ID} from "../constants.js"; +import {Assertion, AssertionResult, Match, NodePair} from "../interfaces.js"; import {generateBlobsForTransaction} from "../utils/blobs.js"; import {BlobsEIP4844Transaction} from "../web3js/blobsEIP4844Transaction.js"; diff --git a/packages/cli/test/utils/crucible/assertions/defaults/attestationCountAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/attestationCountAssertion.ts index 922ce80ae329..2d0715051fa5 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/attestationCountAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/attestationCountAssertion.ts @@ -1,6 +1,6 @@ import {MAX_COMMITTEES_PER_SLOT} from "@lodestar/params"; -import {Match, AssertionResult, Assertion} from "../../interfaces.js"; -import {inclusionDelayAssertion, expectedMaxInclusionDelay} from "./inclusionDelayAssertion.js"; +import {Assertion, AssertionResult, Match} from "../../interfaces.js"; +import {expectedMaxInclusionDelay, inclusionDelayAssertion} from "./inclusionDelayAssertion.js"; export const expectedMinAttestationCount = MAX_COMMITTEES_PER_SLOT - 1; diff --git a/packages/cli/test/utils/crucible/assertions/defaults/attestationParticipationAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/attestationParticipationAssertion.ts index 01cd6d29d09a..5715392758f1 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/attestationParticipationAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/attestationParticipationAssertion.ts @@ -1,7 +1,7 @@ import {TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX} from "@lodestar/params"; import {isActiveValidator} from "@lodestar/state-transition"; import {altair} from "@lodestar/types"; -import {Match, AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult, Match} from "../../interfaces.js"; const TIMELY_HEAD = 1 << TIMELY_HEAD_FLAG_INDEX; const TIMELY_SOURCE = 1 << TIMELY_SOURCE_FLAG_INDEX; diff --git a/packages/cli/test/utils/crucible/assertions/defaults/connectedPeerCountAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/connectedPeerCountAssertion.ts index 83f308e62789..5304731ee8fc 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/connectedPeerCountAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/connectedPeerCountAssertion.ts @@ -1,4 +1,4 @@ -import {AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult} from "../../interfaces.js"; import {everySlotMatcher} from "../matchers.js"; export const connectedPeerCountAssertion: Assertion<"connectedPeerCount", number> = { diff --git a/packages/cli/test/utils/crucible/assertions/defaults/finalizedAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/finalizedAssertion.ts index f03fc41eb8e9..89998fd87627 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/finalizedAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/finalizedAssertion.ts @@ -1,5 +1,5 @@ import {Slot} from "@lodestar/types"; -import {AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult} from "../../interfaces.js"; import {everySlotMatcher} from "../matchers.js"; export const finalizedAssertion: Assertion<"finalized", Slot> = { diff --git a/packages/cli/test/utils/crucible/assertions/defaults/headAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/headAssertion.ts index 6464067d5d7d..3a3f910a4489 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/headAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/headAssertion.ts @@ -1,6 +1,6 @@ import {RootHex, Slot} from "@lodestar/types"; import {toHexString} from "@lodestar/utils"; -import {AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult} from "../../interfaces.js"; import {everySlotMatcher} from "../matchers.js"; export interface HeadSummary { diff --git a/packages/cli/test/utils/crucible/assertions/defaults/inclusionDelayAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/inclusionDelayAssertion.ts index e3ec467099ba..f0f08c92f202 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/inclusionDelayAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/inclusionDelayAssertion.ts @@ -1,4 +1,4 @@ -import {AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult} from "../../interfaces.js"; import {avg} from "../../utils/index.js"; import {everySlotMatcher} from "../matchers.js"; diff --git a/packages/cli/test/utils/crucible/assertions/defaults/missedBlocksAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/missedBlocksAssertion.ts index 1209a6469ca3..8c8d96451f5e 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/missedBlocksAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/missedBlocksAssertion.ts @@ -1,5 +1,5 @@ import {isNullish} from "../../../../utils.js"; -import {Match, AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult, Match} from "../../interfaces.js"; import {arrayEquals} from "../../utils/index.js"; import {headAssertion} from "./headAssertion.js"; diff --git a/packages/cli/test/utils/crucible/assertions/defaults/syncCommitteeParticipationAssertion.ts b/packages/cli/test/utils/crucible/assertions/defaults/syncCommitteeParticipationAssertion.ts index 83b945da0b0a..a0d6f8328187 100644 --- a/packages/cli/test/utils/crucible/assertions/defaults/syncCommitteeParticipationAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/defaults/syncCommitteeParticipationAssertion.ts @@ -1,6 +1,6 @@ import {ForkName} from "@lodestar/params"; import {altair} from "@lodestar/types"; -import {Match, AssertionResult, Assertion} from "../../interfaces.js"; +import {Assertion, AssertionResult, Match} from "../../interfaces.js"; import {avg} from "../../utils/index.js"; // Until we identity and fix the following issue, reducing the expected sync committee participation rate from 0.9 to 0.75 diff --git a/packages/cli/test/utils/crucible/assertions/executionHeadAssertion.ts b/packages/cli/test/utils/crucible/assertions/executionHeadAssertion.ts index 8ea0be1b445c..3f6fedd139fd 100644 --- a/packages/cli/test/utils/crucible/assertions/executionHeadAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/executionHeadAssertion.ts @@ -1,6 +1,6 @@ -import {toHex} from "@lodestar/utils"; import {bellatrix} from "@lodestar/types"; -import {Match, AssertionResult, Assertion} from "../interfaces.js"; +import {toHex} from "@lodestar/utils"; +import {Assertion, AssertionResult, Match} from "../interfaces.js"; export function createExecutionHeadAssertion({ checkForSlot, diff --git a/packages/cli/test/utils/crucible/assertions/forkAssertion.ts b/packages/cli/test/utils/crucible/assertions/forkAssertion.ts index 8f6372f856f6..aeddff9ab13c 100644 --- a/packages/cli/test/utils/crucible/assertions/forkAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/forkAssertion.ts @@ -1,7 +1,7 @@ import {ForkName} from "@lodestar/params"; import {Epoch} from "@lodestar/types"; import {toHexString} from "@lodestar/utils"; -import {Match, AssertionResult, Assertion} from "../interfaces.js"; +import {Assertion, AssertionResult, Match} from "../interfaces.js"; export function createForkAssertion(fork: ForkName, epoch: Epoch): Assertion { return { diff --git a/packages/cli/test/utils/crucible/assertions/lighthousePeerScoreAssertion.ts b/packages/cli/test/utils/crucible/assertions/lighthousePeerScoreAssertion.ts index 29fa36220b3d..d9dd4e0adc55 100644 --- a/packages/cli/test/utils/crucible/assertions/lighthousePeerScoreAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/lighthousePeerScoreAssertion.ts @@ -1,4 +1,4 @@ -import {AssertionResult, BeaconClient, LighthouseAPI, NodePair, Assertion} from "../interfaces.js"; +import {Assertion, AssertionResult, BeaconClient, LighthouseAPI, NodePair} from "../interfaces.js"; import {neverMatcher} from "./matchers.js"; const MIN_GOSSIPSUB_SCORE = 10; diff --git a/packages/cli/test/utils/crucible/assertions/mergeAssertion.ts b/packages/cli/test/utils/crucible/assertions/mergeAssertion.ts index acd686c87bf7..6e0c1a63d7af 100644 --- a/packages/cli/test/utils/crucible/assertions/mergeAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/mergeAssertion.ts @@ -1,5 +1,5 @@ import {BeaconStateAllForks, isExecutionStateType, isMergeTransitionComplete} from "@lodestar/state-transition"; -import {AssertionResult, Assertion} from "../interfaces.js"; +import {Assertion, AssertionResult} from "../interfaces.js"; import {neverMatcher} from "./matchers.js"; export const mergeAssertion: Assertion<"merge", string> = { diff --git a/packages/cli/test/utils/crucible/assertions/nodeAssertion.ts b/packages/cli/test/utils/crucible/assertions/nodeAssertion.ts index 04c9b393d245..5a951ced89ce 100644 --- a/packages/cli/test/utils/crucible/assertions/nodeAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/nodeAssertion.ts @@ -1,7 +1,7 @@ import {SecretKey} from "@chainsafe/blst"; import {routes} from "@lodestar/api/beacon"; import {toHex} from "@lodestar/utils"; -import {AssertionResult, ValidatorClientKeys, Assertion, ValidatorClient} from "../interfaces.js"; +import {Assertion, AssertionResult, ValidatorClient, ValidatorClientKeys} from "../interfaces.js"; import {arrayEquals} from "../utils/index.js"; import {neverMatcher} from "./matchers.js"; @@ -20,8 +20,13 @@ export const nodeAssertion: Assertion<"node", {health: number; keyManagerKeys: s if (node.validator.client === ValidatorClient.Lighthouse || getAllKeys(node.validator.keys).length === 0) { keyManagerKeys = []; } else { - const keys = (await node.validator.keyManager.listKeys()).value(); - keyManagerKeys = keys.map((k) => k.validatingPubkey); + if (node.validator.keys.type === "local") { + const keys = (await node.validator.keyManager.listKeys()).value(); + keyManagerKeys = keys.map((k) => k.validatingPubkey); + } else { + const keys = (await node.validator.keyManager.listRemoteKeys()).value(); + keyManagerKeys = keys.map((k) => k.pubkey); + } } return {health, keyManagerKeys}; diff --git a/packages/cli/test/utils/crucible/assertions/withdrawalsAssertion.ts b/packages/cli/test/utils/crucible/assertions/withdrawalsAssertion.ts index be256a0b696d..020684682858 100644 --- a/packages/cli/test/utils/crucible/assertions/withdrawalsAssertion.ts +++ b/packages/cli/test/utils/crucible/assertions/withdrawalsAssertion.ts @@ -1,6 +1,6 @@ -import {capella} from "@lodestar/types"; import {MAX_WITHDRAWALS_PER_PAYLOAD} from "@lodestar/params"; -import {Match, AssertionResult, Assertion} from "../interfaces.js"; +import {capella} from "@lodestar/types"; +import {Assertion, AssertionResult, Match} from "../interfaces.js"; type WithdrawalsData = { withdrawalCount: number; diff --git a/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts b/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts index 515418f7e558..725c08389105 100644 --- a/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts +++ b/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts @@ -1,9 +1,9 @@ import {writeFile} from "node:fs/promises"; import path from "node:path"; -import got, {RequestError} from "got"; -import yaml from "js-yaml"; import {getClient} from "@lodestar/api/beacon"; import {chainConfigToJson} from "@lodestar/config"; +import got, {RequestError} from "got"; +import yaml from "js-yaml"; import {BeaconClient, BeaconNodeGenerator, LighthouseAPI, RunnerType} from "../../interfaces.js"; import {getNodeMountedPaths} from "../../utils/paths.js"; import {getNodePorts} from "../../utils/ports.js"; diff --git a/packages/cli/test/utils/crucible/clients/beacon/lodestar.ts b/packages/cli/test/utils/crucible/clients/beacon/lodestar.ts index 2bc7c27ead41..320b9c1fd224 100644 --- a/packages/cli/test/utils/crucible/clients/beacon/lodestar.ts +++ b/packages/cli/test/utils/crucible/clients/beacon/lodestar.ts @@ -1,9 +1,9 @@ import {writeFile} from "node:fs/promises"; import path from "node:path"; -import got from "got"; import {getClient} from "@lodestar/api/beacon"; import {chainConfigToJson} from "@lodestar/config"; import {LogLevel} from "@lodestar/utils"; +import got from "got"; import {BeaconArgs} from "../../../../../src/cmds/beacon/options.js"; import {GlobalArgs} from "../../../../../src/options/globalOptions.js"; import {LODESTAR_BINARY_PATH} from "../../constants.js"; diff --git a/packages/cli/test/utils/crucible/clients/execution/geth.ts b/packages/cli/test/utils/crucible/clients/execution/geth.ts index ca3dee2dcb86..4daa008f0c54 100644 --- a/packages/cli/test/utils/crucible/clients/execution/geth.ts +++ b/packages/cli/test/utils/crucible/clients/execution/geth.ts @@ -9,10 +9,10 @@ import { SHARED_JWT_SECRET, SIM_ENV_NETWORK_ID, } from "../../constants.js"; -import {registerWeb3JsPlugins} from "../../web3js/plugins/index.js"; import {ExecutionClient, ExecutionNodeGenerator, ExecutionStartMode, JobOptions, RunnerType} from "../../interfaces.js"; import {getNodeMountedPaths} from "../../utils/paths.js"; import {getNodePorts} from "../../utils/ports.js"; +import {registerWeb3JsPlugins} from "../../web3js/plugins/index.js"; export const generateGethNode: ExecutionNodeGenerator = (opts, runner) => { if (!process.env.GETH_BINARY_DIR && !process.env.GETH_DOCKER_IMAGE) { diff --git a/packages/cli/test/utils/crucible/clients/execution/index.ts b/packages/cli/test/utils/crucible/clients/execution/index.ts index db6510a7a7d6..b7e83813ce3d 100644 --- a/packages/cli/test/utils/crucible/clients/execution/index.ts +++ b/packages/cli/test/utils/crucible/clients/execution/index.ts @@ -1,5 +1,5 @@ import {writeFile} from "node:fs/promises"; -import {SHARED_JWT_SECRET, CLIQUE_SEALING_PERIOD} from "../../constants.js"; +import {CLIQUE_SEALING_PERIOD, SHARED_JWT_SECRET} from "../../constants.js"; import { AtLeast, ExecutionClient, @@ -8,8 +8,8 @@ import { ExecutionNode, ExecutionStartMode, } from "../../interfaces.js"; -import {getEstimatedForkTime} from "../../utils/index.js"; import {getGethGenesisBlock} from "../../utils/executionGenesis.js"; +import {getEstimatedForkTime} from "../../utils/index.js"; import {ensureDirectories} from "../../utils/paths.js"; import {generateGethNode} from "./geth.js"; import {generateMockNode} from "./mock.js"; diff --git a/packages/cli/test/utils/crucible/clients/execution/nethermind.ts b/packages/cli/test/utils/crucible/clients/execution/nethermind.ts index 1c991afa6189..a59f7e55ece6 100644 --- a/packages/cli/test/utils/crucible/clients/execution/nethermind.ts +++ b/packages/cli/test/utils/crucible/clients/execution/nethermind.ts @@ -2,12 +2,12 @@ import {writeFile} from "node:fs/promises"; import path from "node:path"; import got from "got"; import {Web3} from "web3"; -import {registerWeb3JsPlugins} from "../../web3js/plugins/index.js"; +import {SHARED_JWT_SECRET} from "../../constants.js"; import {ExecutionClient, ExecutionNodeGenerator, JobOptions, RunnerType} from "../../interfaces.js"; import {getNethermindChainSpec} from "../../utils/executionGenesis.js"; import {getNodeMountedPaths} from "../../utils/paths.js"; -import {SHARED_JWT_SECRET} from "../../constants.js"; import {getNodePorts} from "../../utils/ports.js"; +import {registerWeb3JsPlugins} from "../../web3js/plugins/index.js"; export const generateNethermindNode: ExecutionNodeGenerator = (opts, runner) => { if (!process.env.NETHERMIND_DOCKER_IMAGE) { diff --git a/packages/cli/test/utils/crucible/clients/validator/index.ts b/packages/cli/test/utils/crucible/clients/validator/index.ts index 677deca23ff0..74f9734c767a 100644 --- a/packages/cli/test/utils/crucible/clients/validator/index.ts +++ b/packages/cli/test/utils/crucible/clients/validator/index.ts @@ -1,11 +1,11 @@ import {writeFile} from "node:fs/promises"; -import {SHARED_JWT_SECRET, SHARED_VALIDATOR_PASSWORD, BN_REST_BASE_PORT} from "../../constants.js"; +import {BN_REST_BASE_PORT, SHARED_JWT_SECRET, SHARED_VALIDATOR_PASSWORD} from "../../constants.js"; import {AtLeast, BeaconClient, ValidatorClient, ValidatorGeneratorOptions, ValidatorNode} from "../../interfaces.js"; import {makeUniqueArray} from "../../utils/index.js"; import {createKeystores} from "../../utils/keys.js"; import {ensureDirectories} from "../../utils/paths.js"; -import {generateLodestarValidatorNode} from "./lodestar.js"; import {generateLighthouseValidatorNode} from "./lighthouse.js"; +import {generateLodestarValidatorNode} from "./lodestar.js"; export async function createValidatorNode( client: V, diff --git a/packages/cli/test/utils/crucible/clients/validator/lighthouse.ts b/packages/cli/test/utils/crucible/clients/validator/lighthouse.ts index f99310dc7907..a5f137a861d5 100644 --- a/packages/cli/test/utils/crucible/clients/validator/lighthouse.ts +++ b/packages/cli/test/utils/crucible/clients/validator/lighthouse.ts @@ -1,9 +1,9 @@ -import path from "node:path"; import {writeFile} from "node:fs/promises"; -import got, {RequestError} from "got"; -import yaml from "js-yaml"; +import path from "node:path"; import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager"; import {chainConfigToJson} from "@lodestar/config"; +import got, {RequestError} from "got"; +import yaml from "js-yaml"; import {RunnerType, ValidatorClient, ValidatorNodeGenerator} from "../../interfaces.js"; import {updateKeystoresPath} from "../../utils/keys.js"; import {getNodeMountedPaths} from "../../utils/paths.js"; diff --git a/packages/cli/test/utils/crucible/clients/validator/lodestar.ts b/packages/cli/test/utils/crucible/clients/validator/lodestar.ts index a2b928c0a2d5..4e2e88b71cc5 100644 --- a/packages/cli/test/utils/crucible/clients/validator/lodestar.ts +++ b/packages/cli/test/utils/crucible/clients/validator/lodestar.ts @@ -1,10 +1,10 @@ import {writeFile} from "node:fs/promises"; import path from "node:path"; -import got from "got"; import {getClient as keyManagerGetClient} from "@lodestar/api/keymanager"; import {chainConfigToJson} from "@lodestar/config"; import {LogLevel} from "@lodestar/utils"; import {defaultOptions} from "@lodestar/validator"; +import got from "got"; import {IValidatorCliArgs} from "../../../../../src/cmds/validator/options.js"; import {GlobalArgs} from "../../../../../src/options/globalOptions.js"; import {LODESTAR_BINARY_PATH} from "../../constants.js"; diff --git a/packages/cli/test/utils/crucible/externalSignerServer.ts b/packages/cli/test/utils/crucible/externalSignerServer.ts index 4282f1761db9..29789432a0d5 100644 --- a/packages/cli/test/utils/crucible/externalSignerServer.ts +++ b/packages/cli/test/utils/crucible/externalSignerServer.ts @@ -1,6 +1,6 @@ -import {fromHexString} from "@chainsafe/ssz"; -import {fastify, FastifyInstance} from "fastify"; import {SecretKey} from "@chainsafe/blst"; +import {fromHexString} from "@chainsafe/ssz"; +import {FastifyInstance, fastify} from "fastify"; import {EXTERNAL_SIGNER_BASE_PORT} from "./constants.js"; /* eslint-disable no-console */ diff --git a/packages/cli/test/utils/crucible/interfaces.ts b/packages/cli/test/utils/crucible/interfaces.ts index 84b5043ba983..13c56dd5012b 100644 --- a/packages/cli/test/utils/crucible/interfaces.ts +++ b/packages/cli/test/utils/crucible/interfaces.ts @@ -1,12 +1,12 @@ import {ChildProcess} from "node:child_process"; -import {Web3} from "web3"; import {SecretKey} from "@chainsafe/blst"; import {ApiClient} from "@lodestar/api"; import {ApiClient as KeyManagerApi} from "@lodestar/api/keymanager"; import {ChainForkConfig} from "@lodestar/config"; -import {ForkName} from "@lodestar/params"; -import {Slot, Epoch, SignedBeaconBlock} from "@lodestar/types"; import {LogLevel, Logger} from "@lodestar/logger"; +import {ForkName} from "@lodestar/params"; +import {Epoch, SignedBeaconBlock, Slot} from "@lodestar/types"; +import {Web3} from "web3"; import {BeaconArgs} from "../../../src/cmds/beacon/options.js"; import {IValidatorCliArgs} from "../../../src/cmds/validator/options.js"; import {GlobalArgs} from "../../../src/options/index.js"; diff --git a/packages/cli/test/utils/crucible/runner/childProcessRunner.ts b/packages/cli/test/utils/crucible/runner/childProcessRunner.ts index 4c2041d0860f..199d815cc8c3 100644 --- a/packages/cli/test/utils/crucible/runner/childProcessRunner.ts +++ b/packages/cli/test/utils/crucible/runner/childProcessRunner.ts @@ -1,6 +1,6 @@ import {ChildProcess} from "node:child_process"; -import {spawnChildProcess, stopChildProcess, SpawnChildProcessOptions, ChildProcessResolve} from "@lodestar/test-utils"; import {Logger} from "@lodestar/logger"; +import {ChildProcessResolve, SpawnChildProcessOptions, spawnChildProcess, stopChildProcess} from "@lodestar/test-utils"; import {Job, JobOptions, RunnerEnv, RunnerType} from "../interfaces.js"; export class ChildProcessRunner implements RunnerEnv { diff --git a/packages/cli/test/utils/crucible/runner/dockerRunner.ts b/packages/cli/test/utils/crucible/runner/dockerRunner.ts index bc5b97811cf4..33adb5aebbe0 100644 --- a/packages/cli/test/utils/crucible/runner/dockerRunner.ts +++ b/packages/cli/test/utils/crucible/runner/dockerRunner.ts @@ -1,7 +1,7 @@ import {ChildProcess} from "node:child_process"; import {Logger} from "@lodestar/logger"; +import {ChildProcessResolve, SpawnChildProcessOptions, execChildProcess, spawnChildProcess} from "@lodestar/test-utils"; import {sleep} from "@lodestar/utils"; -import {SpawnChildProcessOptions, execChildProcess, spawnChildProcess, ChildProcessResolve} from "@lodestar/test-utils"; import {Job, JobOptions, RunnerEnv, RunnerType} from "../interfaces.js"; const dockerNetworkIpRange = "192.168.0"; diff --git a/packages/cli/test/utils/crucible/simulation.ts b/packages/cli/test/utils/crucible/simulation.ts index c6e58095474a..e9674e5193e2 100644 --- a/packages/cli/test/utils/crucible/simulation.ts +++ b/packages/cli/test/utils/crucible/simulation.ts @@ -1,36 +1,36 @@ import fs from "node:fs"; import {mkdir, writeFile} from "node:fs/promises"; import path from "node:path"; -import tmp from "tmp"; import {fromHexString} from "@chainsafe/ssz"; import {nodeUtils} from "@lodestar/beacon-node"; -import {loadEthereumTrustedSetup, initCKZG} from "@lodestar/beacon-node/util"; +import {initCKZG, loadEthereumTrustedSetup} from "@lodestar/beacon-node/util"; import {ChainForkConfig} from "@lodestar/config"; +import {LogLevel, TimestampFormatCode} from "@lodestar/logger"; +import {LoggerNode, getNodeLogger} from "@lodestar/logger/node"; import {activePreset} from "@lodestar/params"; import {BeaconStateAllForks, interopSecretKey} from "@lodestar/state-transition"; import {prettyMsToTime} from "@lodestar/utils"; -import {LogLevel, TimestampFormatCode} from "@lodestar/logger"; -import {getNodeLogger, LoggerNode} from "@lodestar/logger/node"; -import {EpochClock, MS_IN_SEC} from "./epochClock.js"; -import {ExternalSignerServer} from "./externalSignerServer.js"; -import {SimulationTracker} from "./simulationTracker.js"; +import tmp from "tmp"; import {createBeaconNode} from "./clients/beacon/index.js"; +import {createExecutionNode} from "./clients/execution/index.js"; import {createValidatorNode, getValidatorForBeaconNode} from "./clients/validator/index.js"; import {MOCK_ETH1_GENESIS_HASH} from "./constants.js"; -import {createExecutionNode} from "./clients/execution/index.js"; +import {EpochClock, MS_IN_SEC} from "./epochClock.js"; +import {ExternalSignerServer} from "./externalSignerServer.js"; import { BeaconClient, - ValidatorClientKeys, ExecutionClient, + GeneratorOptions, IRunner, NodePair, NodePairDefinition, SimulationInitOptions, SimulationOptions, ValidatorClient, - GeneratorOptions, + ValidatorClientKeys, } from "./interfaces.js"; import {Runner} from "./runner/index.js"; +import {SimulationTracker} from "./simulationTracker.js"; import {registerProcessHandler, replaceIpFromUrl} from "./utils/index.js"; import {getNodePaths} from "./utils/paths.js"; diff --git a/packages/cli/test/utils/crucible/simulationTracker.ts b/packages/cli/test/utils/crucible/simulationTracker.ts index 778a7ad2a771..3e714ca8950f 100644 --- a/packages/cli/test/utils/crucible/simulationTracker.ts +++ b/packages/cli/test/utils/crucible/simulationTracker.ts @@ -1,25 +1,25 @@ import EventEmitter from "node:events"; -import path from "node:path"; import fs from "node:fs/promises"; -import createDebug from "debug"; +import path from "node:path"; import {routes} from "@lodestar/api/beacon"; import {ChainForkConfig} from "@lodestar/config"; -import {Epoch, Slot} from "@lodestar/types"; import {LoggerNode} from "@lodestar/logger/node"; +import {Epoch, Slot} from "@lodestar/types"; +import createDebug from "debug"; import {isNullish} from "../../utils.js"; +import {defaultAssertions} from "./assertions/defaults/index.js"; import {EpochClock} from "./epochClock.js"; import { - Match, + Assertion, + AssertionError, AtLeast, + Match, NodeId, NodePair, - Assertion, - AssertionError, SimulationReporter, StoreType, StoreTypes, } from "./interfaces.js"; -import {defaultAssertions} from "./assertions/defaults/index.js"; import {TableReporter} from "./tableReporter.js"; import {fetchBlock} from "./utils/network.js"; diff --git a/packages/cli/test/utils/crucible/utils/executionGenesis.ts b/packages/cli/test/utils/crucible/utils/executionGenesis.ts index bd3da4ba7662..02f7d553df16 100644 --- a/packages/cli/test/utils/crucible/utils/executionGenesis.ts +++ b/packages/cli/test/utils/crucible/utils/executionGenesis.ts @@ -1,5 +1,5 @@ import {SIM_ENV_CHAIN_ID, SIM_ENV_NETWORK_ID} from "../constants.js"; -import {ExecutionGenesisOptions, ExecutionStartMode, Eth1GenesisBlock} from "../interfaces.js"; +import {Eth1GenesisBlock, ExecutionGenesisOptions, ExecutionStartMode} from "../interfaces.js"; export const getGethGenesisBlock = ( mode: ExecutionStartMode, diff --git a/packages/cli/test/utils/crucible/utils/index.ts b/packages/cli/test/utils/crucible/utils/index.ts index 0e016778cdce..13b26cfd9318 100644 --- a/packages/cli/test/utils/crucible/utils/index.ts +++ b/packages/cli/test/utils/crucible/utils/index.ts @@ -1,7 +1,7 @@ +import {ChainConfig, ChainForkConfig, createChainForkConfig} from "@lodestar/config"; /* eslint-disable no-console */ import {activePreset} from "@lodestar/params"; import {Epoch} from "@lodestar/types"; -import {ChainConfig, ChainForkConfig, createChainForkConfig} from "@lodestar/config"; import { CLIQUE_SEALING_PERIOD, ETH_TTD_INCREMENT, diff --git a/packages/cli/test/utils/crucible/utils/keys.ts b/packages/cli/test/utils/crucible/utils/keys.ts index 8915e85b529e..1a4da9ffec65 100644 --- a/packages/cli/test/utils/crucible/utils/keys.ts +++ b/packages/cli/test/utils/crucible/utils/keys.ts @@ -1,7 +1,7 @@ import {readFile, writeFile} from "node:fs/promises"; import path from "node:path"; -import yaml from "js-yaml"; import {Keystore} from "@chainsafe/bls-keystore"; +import yaml from "js-yaml"; import {SHARED_VALIDATOR_PASSWORD} from "../constants.js"; import {ValidatorClientKeys, ValidatorPaths} from "../interfaces.js"; diff --git a/packages/cli/test/utils/crucible/utils/paths.ts b/packages/cli/test/utils/crucible/utils/paths.ts index 4ff149d6f308..06ef1bf7fe1f 100644 --- a/packages/cli/test/utils/crucible/utils/paths.ts +++ b/packages/cli/test/utils/crucible/utils/paths.ts @@ -1,6 +1,6 @@ -import path from "node:path"; import fs from "node:fs"; import {mkdir} from "node:fs/promises"; +import path from "node:path"; import { BeaconClient, BeaconPaths, diff --git a/packages/cli/test/utils/crucible/utils/ports.ts b/packages/cli/test/utils/crucible/utils/ports.ts index be430598895e..3b6f51ad1429 100644 --- a/packages/cli/test/utils/crucible/utils/ports.ts +++ b/packages/cli/test/utils/crucible/utils/ports.ts @@ -1,10 +1,10 @@ import { BN_P2P_BASE_PORT, BN_REST_BASE_PORT, - KEY_MANAGER_BASE_PORT, - EL_P2P_BASE_PORT, - EL_ETH_BASE_PORT, EL_ENGINE_BASE_PORT, + EL_ETH_BASE_PORT, + EL_P2P_BASE_PORT, + KEY_MANAGER_BASE_PORT, } from "../constants.js"; export const getNodePorts = ( diff --git a/packages/cli/test/utils/crucible/utils/syncing.ts b/packages/cli/test/utils/crucible/utils/syncing.ts index b720c6bf6ccc..e0232ae7b5ba 100644 --- a/packages/cli/test/utils/crucible/utils/syncing.ts +++ b/packages/cli/test/utils/crucible/utils/syncing.ts @@ -1,9 +1,9 @@ import {routes} from "@lodestar/api"; +import {ForkBlobs} from "@lodestar/params"; import {SignedBeaconBlock, Slot} from "@lodestar/types"; import {sleep, toHex} from "@lodestar/utils"; -import {ForkBlobs} from "@lodestar/params"; -import type {Simulation} from "../simulation.js"; import {BeaconClient, ExecutionClient, NodePair} from "../interfaces.js"; +import type {Simulation} from "../simulation.js"; import {connectNewCLNode, connectNewELNode, connectNewNode, waitForHead, waitForSlot} from "./network.js"; export async function assertRangeSync(env: Simulation): Promise { diff --git a/packages/cli/test/utils/crucible/web3js/blobsEIP4844Transaction.ts b/packages/cli/test/utils/crucible/web3js/blobsEIP4844Transaction.ts index a5dbf9408b7d..b61814e6ae1e 100644 --- a/packages/cli/test/utils/crucible/web3js/blobsEIP4844Transaction.ts +++ b/packages/cli/test/utils/crucible/web3js/blobsEIP4844Transaction.ts @@ -1,4 +1,5 @@ import {RLP} from "@ethereumjs/rlp"; +import {fromHex} from "@lodestar/utils"; import {keccak256} from "ethereum-cryptography/keccak.js"; import { FeeMarketEIP1559Transaction, @@ -7,7 +8,6 @@ import { bigIntToUnpaddedUint8Array, uint8ArrayToBigInt, } from "web3-eth-accounts"; -import {fromHex} from "@lodestar/utils"; function uint8ArrayConcat(...arrays: Uint8Array[]): Uint8Array { const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0); diff --git a/packages/cli/test/utils/mockBeaconApiServer.ts b/packages/cli/test/utils/mockBeaconApiServer.ts index e7e80338686f..24b8b9c7473b 100644 --- a/packages/cli/test/utils/mockBeaconApiServer.ts +++ b/packages/cli/test/utils/mockBeaconApiServer.ts @@ -1,6 +1,6 @@ -import {RestApiServer, RestApiServerOpts, RestApiServerModules} from "@lodestar/beacon-node"; -import {BeaconApiMethods, registerRoutes} from "@lodestar/api/beacon/server"; import {allNamespaces} from "@lodestar/api"; +import {BeaconApiMethods, registerRoutes} from "@lodestar/api/beacon/server"; +import {RestApiServer, RestApiServerModules, RestApiServerOpts} from "@lodestar/beacon-node"; import {ChainForkConfig} from "@lodestar/config"; import {config} from "@lodestar/config/default"; import {ssz} from "@lodestar/types"; diff --git a/packages/cli/test/utils/validator.ts b/packages/cli/test/utils/validator.ts index 139683d5dd6b..fbecf6900d28 100644 --- a/packages/cli/test/utils/validator.ts +++ b/packages/cli/test/utils/validator.ts @@ -1,8 +1,8 @@ import childProcess from "node:child_process"; -import {retry} from "@lodestar/utils"; import {ApiClient, getClient} from "@lodestar/api/keymanager"; import {config} from "@lodestar/config/default"; -import {spawnCliCommand, gracefullyStopChildProcess} from "@lodestar/test-utils"; +import {gracefullyStopChildProcess, spawnCliCommand} from "@lodestar/test-utils"; +import {retry} from "@lodestar/utils"; import {getMockBeaconApiServer} from "./mockBeaconApiServer.js"; import {expectDeepEqualsUnordered, findApiToken} from "./runUtils.js"; diff --git a/packages/config/package.json b/packages/config/package.json index 5a4edcf7879c..c421d8802f08 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/config", - "version": "1.23.1", + "version": "1.24.0", "description": "Chain configuration required for lodestar", "author": "ChainSafe Systems", "license": "Apache-2.0", @@ -65,8 +65,8 @@ ], "dependencies": { "@chainsafe/ssz": "^0.18.0", - "@lodestar/params": "^1.23.1", - "@lodestar/types": "^1.23.1", - "@lodestar/utils": "^1.23.1" + "@lodestar/params": "^1.24.0", + "@lodestar/types": "^1.24.0", + "@lodestar/utils": "^1.24.0" } } diff --git a/packages/config/src/beaconConfig.ts b/packages/config/src/beaconConfig.ts index 634bdc8b5047..7c84dbaeeb8d 100644 --- a/packages/config/src/beaconConfig.ts +++ b/packages/config/src/beaconConfig.ts @@ -1,6 +1,6 @@ import {Root} from "@lodestar/types"; -import {createChainConfig, ChainConfig} from "./chainConfig/index.js"; -import {createForkConfig, ForkConfig} from "./forkConfig/index.js"; +import {ChainConfig, createChainConfig} from "./chainConfig/index.js"; +import {ForkConfig, createForkConfig} from "./forkConfig/index.js"; import {createCachedGenesis} from "./genesisConfig/index.js"; import {CachedGenesis} from "./genesisConfig/types.js"; diff --git a/packages/config/src/chainConfig/configs/mainnet.ts b/packages/config/src/chainConfig/configs/mainnet.ts index 5da5f8d2acb0..a4adc04a1756 100644 --- a/packages/config/src/chainConfig/configs/mainnet.ts +++ b/packages/config/src/chainConfig/configs/mainnet.ts @@ -1,5 +1,5 @@ -import {fromHex as b} from "@lodestar/utils"; import {PresetName} from "@lodestar/params"; +import {fromHex as b} from "@lodestar/utils"; import {ChainConfig} from "../types.js"; // Mainnet config @@ -101,6 +101,10 @@ export const chainConfig: ChainConfig = { // Deneb // `2**12` (= 4096 epochs, ~18 days) MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096, + BLOB_SIDECAR_SUBNET_COUNT: 6, + MAX_BLOBS_PER_BLOCK: 6, + // MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK + MAX_REQUEST_BLOB_SIDECARS: 768, // Electra // 2**8 * 10**9 (= 256,000,000,000) diff --git a/packages/config/src/chainConfig/configs/minimal.ts b/packages/config/src/chainConfig/configs/minimal.ts index f1a52e956f4d..d16b03e82c28 100644 --- a/packages/config/src/chainConfig/configs/minimal.ts +++ b/packages/config/src/chainConfig/configs/minimal.ts @@ -1,5 +1,5 @@ -import {fromHex as b} from "@lodestar/utils"; import {PresetName} from "@lodestar/params"; +import {fromHex as b} from "@lodestar/utils"; import {ChainConfig} from "../types.js"; // Minimal config @@ -98,6 +98,10 @@ export const chainConfig: ChainConfig = { // Deneb // `2**12` (= 4096 epochs, ~18 days) MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096, + BLOB_SIDECAR_SUBNET_COUNT: 6, + MAX_BLOBS_PER_BLOCK: 6, + // MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK + MAX_REQUEST_BLOB_SIDECARS: 768, // Electra // 2**7 * 10**9 (= 128,000,000,000) diff --git a/packages/config/src/chainConfig/default.ts b/packages/config/src/chainConfig/default.ts index ef2b9743a1d2..8f8acc37a9f3 100644 --- a/packages/config/src/chainConfig/default.ts +++ b/packages/config/src/chainConfig/default.ts @@ -1,7 +1,7 @@ import {ACTIVE_PRESET, PresetName} from "@lodestar/params"; -import {ChainConfig} from "./types.js"; import {chainConfig as mainnet} from "./configs/mainnet.js"; import {chainConfig as minimal} from "./configs/minimal.js"; +import {ChainConfig} from "./types.js"; let defaultChainConfig: ChainConfig; diff --git a/packages/config/src/chainConfig/index.ts b/packages/config/src/chainConfig/index.ts index b202021b0337..cd7d2d9c29f0 100644 --- a/packages/config/src/chainConfig/index.ts +++ b/packages/config/src/chainConfig/index.ts @@ -1,6 +1,6 @@ import {ACTIVE_PRESET} from "@lodestar/params"; -import {ChainConfig} from "./types.js"; import {defaultChainConfig} from "./default.js"; +import {ChainConfig} from "./types.js"; export {chainConfigToJson, chainConfigFromJson, specValuesToJson} from "./json.js"; export * from "./types.js"; diff --git a/packages/config/src/chainConfig/json.ts b/packages/config/src/chainConfig/json.ts index 78db9230c836..de5214d96416 100644 --- a/packages/config/src/chainConfig/json.ts +++ b/packages/config/src/chainConfig/json.ts @@ -1,5 +1,5 @@ import {fromHex, toHex} from "@lodestar/utils"; -import {ChainConfig, chainConfigTypes, SpecValue, SpecValueTypeName} from "./types.js"; +import {ChainConfig, SpecValue, SpecValueTypeName, chainConfigTypes} from "./types.js"; const MAX_UINT64_JSON = "18446744073709551615"; diff --git a/packages/config/src/chainConfig/networks/ephemery.ts b/packages/config/src/chainConfig/networks/ephemery.ts index d1c17c36f0ab..f6349afe1e9a 100644 --- a/packages/config/src/chainConfig/networks/ephemery.ts +++ b/packages/config/src/chainConfig/networks/ephemery.ts @@ -1,6 +1,6 @@ import {fromHex as b} from "@lodestar/utils"; -import {ChainConfig} from "../types.js"; import {chainConfig as mainnet} from "../configs/mainnet.js"; +import {ChainConfig} from "../types.js"; // Ephemery dynamic beacon chain config: // https://github.com/ephemery-testnet/ephemery-genesis/blob/master/cl-config.yaml diff --git a/packages/config/src/chainConfig/networks/gnosis.ts b/packages/config/src/chainConfig/networks/gnosis.ts index a25162ae5028..a3b2679bd080 100644 --- a/packages/config/src/chainConfig/networks/gnosis.ts +++ b/packages/config/src/chainConfig/networks/gnosis.ts @@ -1,7 +1,7 @@ -import {fromHex as b} from "@lodestar/utils"; import {PresetName} from "@lodestar/params"; -import {ChainConfig} from "../types.js"; +import {fromHex as b} from "@lodestar/utils"; import {chainConfig as mainnet} from "../configs/mainnet.js"; +import {ChainConfig} from "../types.js"; // Gnosis beacon chain config: // https://github.com/gnosischain/configs/blob/main/mainnet/config.yaml diff --git a/packages/config/src/chainConfig/networks/holesky.ts b/packages/config/src/chainConfig/networks/holesky.ts index 46c32606931f..18f356d6bc03 100644 --- a/packages/config/src/chainConfig/networks/holesky.ts +++ b/packages/config/src/chainConfig/networks/holesky.ts @@ -1,6 +1,6 @@ import {fromHex as b} from "@lodestar/utils"; -import {ChainConfig} from "../types.js"; import {chainConfig as mainnet} from "../configs/mainnet.js"; +import {ChainConfig} from "../types.js"; // Holesky beacon chain config: // https://github.com/eth-clients/holesky/blob/main/metadata/config.yaml diff --git a/packages/config/src/chainConfig/networks/mainnet.ts b/packages/config/src/chainConfig/networks/mainnet.ts index 13225b463da9..d10e3209243b 100644 --- a/packages/config/src/chainConfig/networks/mainnet.ts +++ b/packages/config/src/chainConfig/networks/mainnet.ts @@ -1,6 +1,6 @@ import {fromHex as b} from "@lodestar/utils"; -import {ChainConfig} from "../types.js"; import {chainConfig as mainnet} from "../configs/mainnet.js"; +import {ChainConfig} from "../types.js"; export const mainnetChainConfig: ChainConfig = { ...mainnet, diff --git a/packages/config/src/chainConfig/networks/mekong.ts b/packages/config/src/chainConfig/networks/mekong.ts index 106c2abe67fa..194956c0d6c0 100644 --- a/packages/config/src/chainConfig/networks/mekong.ts +++ b/packages/config/src/chainConfig/networks/mekong.ts @@ -1,6 +1,6 @@ import {fromHex as b} from "@lodestar/utils"; -import {ChainConfig} from "../types.js"; import {chainConfig as mainnet} from "../configs/mainnet.js"; +import {ChainConfig} from "../types.js"; // Mekong beacon chain config: // https://github.com/ethpandaops/mekong-devnets/blob/master/network-configs/devnet-0/metadata/config.yaml diff --git a/packages/config/src/chainConfig/networks/sepolia.ts b/packages/config/src/chainConfig/networks/sepolia.ts index e7e5dc76f691..f47d73436702 100644 --- a/packages/config/src/chainConfig/networks/sepolia.ts +++ b/packages/config/src/chainConfig/networks/sepolia.ts @@ -1,6 +1,6 @@ import {fromHex as b} from "@lodestar/utils"; -import {ChainConfig} from "../types.js"; import {chainConfig as mainnet} from "../configs/mainnet.js"; +import {ChainConfig} from "../types.js"; // Sepolia beacon chain config: // https://github.com/eth-clients/sepolia/blob/main/metadata/config.yaml diff --git a/packages/config/src/chainConfig/types.ts b/packages/config/src/chainConfig/types.ts index 5c06b205c2f6..291dcc8601a7 100644 --- a/packages/config/src/chainConfig/types.ts +++ b/packages/config/src/chainConfig/types.ts @@ -72,6 +72,9 @@ export type ChainConfig = { // Networking MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: number; + BLOB_SIDECAR_SUBNET_COUNT: number; + MAX_BLOBS_PER_BLOCK: number; + MAX_REQUEST_BLOB_SIDECARS: number; }; export const chainConfigTypes: SpecTypes = { @@ -136,6 +139,9 @@ export const chainConfigTypes: SpecTypes = { // Networking MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: "number", + BLOB_SIDECAR_SUBNET_COUNT: "number", + MAX_BLOBS_PER_BLOCK: "number", + MAX_REQUEST_BLOB_SIDECARS: "number", }; /** Allows values in a Spec file */ diff --git a/packages/config/src/forkConfig/index.ts b/packages/config/src/forkConfig/index.ts index 513cd7559ee3..725e0a3af572 100644 --- a/packages/config/src/forkConfig/index.ts +++ b/packages/config/src/forkConfig/index.ts @@ -1,17 +1,17 @@ import { - GENESIS_EPOCH, + ForkAll, + ForkBlobs, + ForkExecution, + ForkLightClient, ForkName, - SLOTS_PER_EPOCH, ForkSeq, - isForkLightClient, - isForkExecution, + GENESIS_EPOCH, + SLOTS_PER_EPOCH, isForkBlobs, - ForkExecution, - ForkAll, - ForkLightClient, - ForkBlobs, + isForkExecution, + isForkLightClient, } from "@lodestar/params"; -import {Slot, Version, SSZTypesFor, sszTypesFor, Epoch} from "@lodestar/types"; +import {Epoch, SSZTypesFor, Slot, Version, sszTypesFor} from "@lodestar/types"; import {ChainConfig} from "../chainConfig/index.js"; import {ForkConfig, ForkInfo} from "./types.js"; diff --git a/packages/config/src/genesisConfig/index.ts b/packages/config/src/genesisConfig/index.ts index d2dfae2a8e08..992185461b58 100644 --- a/packages/config/src/genesisConfig/index.ts +++ b/packages/config/src/genesisConfig/index.ts @@ -1,8 +1,8 @@ -import {ForkName, SLOTS_PER_EPOCH, DOMAIN_VOLUNTARY_EXIT} from "@lodestar/params"; -import {DomainType, ForkDigest, phase0, Root, Slot, ssz, Version} from "@lodestar/types"; -import {toHex} from "@lodestar/utils"; +import {DOMAIN_VOLUNTARY_EXIT, ForkName, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {DomainType, ForkDigest, Root, Slot, Version, phase0, ssz} from "@lodestar/types"; +import {strip0xPrefix, toHex} from "@lodestar/utils"; import {ChainForkConfig} from "../beaconConfig.js"; -import {ForkDigestHex, CachedGenesis} from "./types.js"; +import {CachedGenesis, ForkDigestHex} from "./types.js"; export type {ForkDigestContext} from "./types.js"; export function createCachedGenesis(chainForkConfig: ChainForkConfig, genesisValidatorsRoot: Root): CachedGenesis { @@ -142,10 +142,6 @@ function toHexStringNoPrefix(hex: string | Uint8Array): string { return strip0xPrefix(typeof hex === "string" ? hex : toHex(hex)); } -function strip0xPrefix(hex: string): string { - return hex.startsWith("0x") ? hex.slice(2) : hex; -} - function computeForkDigest(currentVersion: Version, genesisValidatorsRoot: Root): ForkDigest { return computeForkDataRoot(currentVersion, genesisValidatorsRoot).slice(0, 4); } diff --git a/packages/config/src/networks.ts b/packages/config/src/networks.ts index df39ae15d09e..5e377e86a974 100644 --- a/packages/config/src/networks.ts +++ b/packages/config/src/networks.ts @@ -1,11 +1,11 @@ import {ChainConfig} from "./chainConfig/index.js"; -import {mainnetChainConfig} from "./chainConfig/networks/mainnet.js"; -import {gnosisChainConfig} from "./chainConfig/networks/gnosis.js"; -import {sepoliaChainConfig} from "./chainConfig/networks/sepolia.js"; -import {holeskyChainConfig} from "./chainConfig/networks/holesky.js"; import {chiadoChainConfig} from "./chainConfig/networks/chiado.js"; import {ephemeryChainConfig} from "./chainConfig/networks/ephemery.js"; +import {gnosisChainConfig} from "./chainConfig/networks/gnosis.js"; +import {holeskyChainConfig} from "./chainConfig/networks/holesky.js"; +import {mainnetChainConfig} from "./chainConfig/networks/mainnet.js"; import {mekongChainConfig} from "./chainConfig/networks/mekong.js"; +import {sepoliaChainConfig} from "./chainConfig/networks/sepolia.js"; export { mainnetChainConfig, diff --git a/packages/config/test/unit/index.test.ts b/packages/config/test/unit/index.test.ts index bde31f6b1477..9c6e94978504 100644 --- a/packages/config/test/unit/index.test.ts +++ b/packages/config/test/unit/index.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; import {toHexString} from "@chainsafe/ssz"; import {ForkName} from "@lodestar/params"; -import {config, chainConfig} from "../../src/default.js"; +import {describe, expect, it} from "vitest"; +import {chainConfig, config} from "../../src/default.js"; import {createForkConfig} from "../../src/index.js"; describe("forks", () => { diff --git a/packages/config/test/unit/json.test.ts b/packages/config/test/unit/json.test.ts index 96ffd050a088..970a40048540 100644 --- a/packages/config/test/unit/json.test.ts +++ b/packages/config/test/unit/json.test.ts @@ -1,6 +1,6 @@ -import {describe, it, expect} from "vitest"; -import {chainConfigFromJson, chainConfigToJson} from "../../src/index.js"; +import {describe, expect, it} from "vitest"; import {chainConfig} from "../../src/default.js"; +import {chainConfigFromJson, chainConfigToJson} from "../../src/index.js"; describe("chainConfig JSON", () => { it("Convert to and from JSON", () => { diff --git a/packages/db/package.json b/packages/db/package.json index a332d316185b..c71fae529350 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/db", - "version": "1.23.1", + "version": "1.24.0", "description": "DB modules of Lodestar", "author": "ChainSafe Systems", "homepage": "https://github.com/ChainSafe/lodestar#readme", @@ -36,12 +36,12 @@ }, "dependencies": { "@chainsafe/ssz": "^0.18.0", - "@lodestar/config": "^1.23.1", - "@lodestar/utils": "^1.23.1", + "@lodestar/config": "^1.24.0", + "@lodestar/utils": "^1.24.0", "classic-level": "^1.4.1", "it-all": "^3.0.4" }, "devDependencies": { - "@lodestar/logger": "^1.23.1" + "@lodestar/logger": "^1.24.0" } } diff --git a/packages/db/src/controller/level.ts b/packages/db/src/controller/level.ts index 82fbf631f7ae..ac3688a161ab 100644 --- a/packages/db/src/controller/level.ts +++ b/packages/db/src/controller/level.ts @@ -1,6 +1,6 @@ -import {ClassicLevel} from "classic-level"; import {Logger} from "@lodestar/utils"; -import {DbReqOpts, DatabaseController, DatabaseOptions, FilterOptions, KeyValue} from "./interface.js"; +import {ClassicLevel} from "classic-level"; +import {DatabaseController, DatabaseOptions, DbReqOpts, FilterOptions, KeyValue} from "./interface.js"; import {LevelDbControllerMetrics} from "./metrics.js"; enum Status { diff --git a/packages/db/test/unit/controller/level.test.ts b/packages/db/test/unit/controller/level.test.ts index 16f20e770c93..af9de5a04e46 100644 --- a/packages/db/test/unit/controller/level.test.ts +++ b/packages/db/test/unit/controller/level.test.ts @@ -1,8 +1,8 @@ import {execSync} from "node:child_process"; import os from "node:os"; -import {describe, it, expect, beforeAll, afterAll} from "vitest"; -import all from "it-all"; import {getEnvLogger} from "@lodestar/logger/env"; +import all from "it-all"; +import {afterAll, beforeAll, describe, expect, it} from "vitest"; import {LevelDbController} from "../../../src/controller/index.js"; describe("LevelDB controller", () => { diff --git a/packages/db/test/unit/schema.test.ts b/packages/db/test/unit/schema.test.ts index c72611453e4f..7488e9f5aaef 100644 --- a/packages/db/test/unit/schema.test.ts +++ b/packages/db/test/unit/schema.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {intToBytes} from "@lodestar/utils"; +import {describe, expect, it} from "vitest"; import {BUCKET_LENGTH, encodeKey} from "../../src/index.js"; describe("encodeKey", () => { diff --git a/packages/flare/package.json b/packages/flare/package.json index c3d262173321..a4fa6ca96399 100644 --- a/packages/flare/package.json +++ b/packages/flare/package.json @@ -1,6 +1,6 @@ { "name": "@lodestar/flare", - "version": "1.23.1", + "version": "1.24.0", "description": "Beacon chain debugging tool", "author": "ChainSafe Systems", "license": "Apache-2.0", @@ -60,12 +60,12 @@ "dependencies": { "@chainsafe/bls-keygen": "^0.4.0", "@chainsafe/blst": "^2.1.0", - "@lodestar/api": "^1.23.1", - "@lodestar/config": "^1.23.1", - "@lodestar/params": "^1.23.1", - "@lodestar/state-transition": "^1.23.1", - "@lodestar/types": "^1.23.1", - "@lodestar/utils": "^1.23.1", + "@lodestar/api": "^1.24.0", + "@lodestar/config": "^1.24.0", + "@lodestar/params": "^1.24.0", + "@lodestar/state-transition": "^1.24.0", + "@lodestar/types": "^1.24.0", + "@lodestar/utils": "^1.24.0", "source-map-support": "^0.5.21", "yargs": "^17.7.1" }, diff --git a/packages/flare/src/cli.ts b/packages/flare/src/cli.ts index 91c4ef83ca09..9b29d22629de 100644 --- a/packages/flare/src/cli.ts +++ b/packages/flare/src/cli.ts @@ -1,7 +1,7 @@ +import {registerCommandToYargs} from "@lodestar/utils"; // Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131 import yargs from "yargs"; import {hideBin} from "yargs/helpers"; -import {registerCommandToYargs} from "@lodestar/utils"; import {cmds} from "./cmds/index.js"; const topBanner = `Beacon chain multi-purpose and debugging tool. diff --git a/packages/flare/src/cmds/index.ts b/packages/flare/src/cmds/index.ts index 63e1f316b3b6..58d882040e8a 100644 --- a/packages/flare/src/cmds/index.ts +++ b/packages/flare/src/cmds/index.ts @@ -1,6 +1,6 @@ import {CliCommand} from "@lodestar/utils"; -import {selfSlashProposer} from "./selfSlashProposer.js"; import {selfSlashAttester} from "./selfSlashAttester.js"; +import {selfSlashProposer} from "./selfSlashProposer.js"; export const cmds: Required, Record>>["subcommands"] = [ selfSlashProposer, diff --git a/packages/flare/src/cmds/selfSlashAttester.ts b/packages/flare/src/cmds/selfSlashAttester.ts index 174535ba2e7d..78c10b6451a3 100644 --- a/packages/flare/src/cmds/selfSlashAttester.ts +++ b/packages/flare/src/cmds/selfSlashAttester.ts @@ -1,12 +1,12 @@ import {SecretKey, aggregateSignatures} from "@chainsafe/blst"; import {getClient} from "@lodestar/api"; -import {AttesterSlashing, phase0, ssz} from "@lodestar/types"; +import {BeaconConfig, createBeaconConfig} from "@lodestar/config"; import {config as chainConfig} from "@lodestar/config/default"; -import {createBeaconConfig, BeaconConfig} from "@lodestar/config"; import {DOMAIN_BEACON_ATTESTER, MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params"; -import {CliCommand, toPubkeyHex} from "@lodestar/utils"; import {computeSigningRoot} from "@lodestar/state-transition"; -import {deriveSecretKeys, SecretKeysArgs, secretKeysOptions} from "../util/deriveSecretKeys.js"; +import {AttesterSlashing, phase0, ssz} from "@lodestar/types"; +import {CliCommand, toPubkeyHex} from "@lodestar/utils"; +import {SecretKeysArgs, deriveSecretKeys, secretKeysOptions} from "../util/deriveSecretKeys.js"; /* eslint-disable no-console */ diff --git a/packages/flare/src/cmds/selfSlashProposer.ts b/packages/flare/src/cmds/selfSlashProposer.ts index dd9580232e71..83992aae7d82 100644 --- a/packages/flare/src/cmds/selfSlashProposer.ts +++ b/packages/flare/src/cmds/selfSlashProposer.ts @@ -1,12 +1,12 @@ import {SecretKey} from "@chainsafe/blst"; import {getClient} from "@lodestar/api"; -import {phase0, ssz} from "@lodestar/types"; +import {BeaconConfig, createBeaconConfig} from "@lodestar/config"; import {config as chainConfig} from "@lodestar/config/default"; -import {createBeaconConfig, BeaconConfig} from "@lodestar/config"; import {DOMAIN_BEACON_PROPOSER} from "@lodestar/params"; -import {CliCommand, toPubkeyHex} from "@lodestar/utils"; import {computeSigningRoot} from "@lodestar/state-transition"; -import {deriveSecretKeys, SecretKeysArgs, secretKeysOptions} from "../util/deriveSecretKeys.js"; +import {phase0, ssz} from "@lodestar/types"; +import {CliCommand, toPubkeyHex} from "@lodestar/utils"; +import {SecretKeysArgs, deriveSecretKeys, secretKeysOptions} from "../util/deriveSecretKeys.js"; /* eslint-disable no-console */ diff --git a/packages/flare/src/index.ts b/packages/flare/src/index.ts index 5f3b85b459c1..b2ef85ce4c10 100644 --- a/packages/flare/src/index.ts +++ b/packages/flare/src/index.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node -import {YargsError} from "./util/errors.js"; import {getCli, yarg} from "./cli.js"; +import {YargsError} from "./util/errors.js"; import "source-map-support/register.js"; const flare = getCli(); diff --git a/packages/flare/test/unit/utils/format.test.ts b/packages/flare/test/unit/utils/format.test.ts index c6ef8805fe7b..846793175d9d 100644 --- a/packages/flare/test/unit/utils/format.test.ts +++ b/packages/flare/test/unit/utils/format.test.ts @@ -1,4 +1,4 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import {parseRange} from "../../../src/util/format.js"; describe("utils / format", () => { diff --git a/packages/fork-choice/package.json b/packages/fork-choice/package.json index cc86cd75b45f..a3d0470b21d2 100644 --- a/packages/fork-choice/package.json +++ b/packages/fork-choice/package.json @@ -11,7 +11,7 @@ "bugs": { "url": "https://github.com/ChainSafe/lodestar/issues" }, - "version": "1.23.1", + "version": "1.24.0", "type": "module", "exports": "./lib/index.js", "types": "./lib/index.d.ts", @@ -37,11 +37,11 @@ }, "dependencies": { "@chainsafe/ssz": "^0.18.0", - "@lodestar/config": "^1.23.1", - "@lodestar/params": "^1.23.1", - "@lodestar/state-transition": "^1.23.1", - "@lodestar/types": "^1.23.1", - "@lodestar/utils": "^1.23.1" + "@lodestar/config": "^1.24.0", + "@lodestar/params": "^1.24.0", + "@lodestar/state-transition": "^1.24.0", + "@lodestar/types": "^1.24.0", + "@lodestar/utils": "^1.24.0" }, "keywords": [ "ethereum", diff --git a/packages/fork-choice/src/forkChoice/errors.ts b/packages/fork-choice/src/forkChoice/errors.ts index 43d209106eed..cd0e0cd25274 100644 --- a/packages/fork-choice/src/forkChoice/errors.ts +++ b/packages/fork-choice/src/forkChoice/errors.ts @@ -1,4 +1,4 @@ -import {Slot, Epoch, RootHex} from "@lodestar/types"; +import {Epoch, RootHex, Slot} from "@lodestar/types"; import {LodestarError} from "@lodestar/utils"; export enum InvalidBlockCode { diff --git a/packages/fork-choice/src/forkChoice/forkChoice.ts b/packages/fork-choice/src/forkChoice/forkChoice.ts index dcc76441865e..2b803c3553a4 100644 --- a/packages/fork-choice/src/forkChoice/forkChoice.ts +++ b/packages/fork-choice/src/forkChoice/forkChoice.ts @@ -1,47 +1,47 @@ -import {Logger, MapDef, fromHex, toRootHex} from "@lodestar/utils"; -import {SLOTS_PER_HISTORICAL_ROOT, SLOTS_PER_EPOCH, INTERVALS_PER_SLOT} from "@lodestar/params"; -import {bellatrix, Slot, ValidatorIndex, phase0, ssz, RootHex, Epoch, Root, BeaconBlock} from "@lodestar/types"; +import {ChainConfig, ChainForkConfig} from "@lodestar/config"; +import {INTERVALS_PER_SLOT, SLOTS_PER_EPOCH, SLOTS_PER_HISTORICAL_ROOT} from "@lodestar/params"; import { + CachedBeaconStateAllForks, + EffectiveBalanceIncrements, + ZERO_HASH, + computeEpochAtSlot, computeSlotsSinceEpochStart, computeStartSlotAtEpoch, - computeEpochAtSlot, - ZERO_HASH, - EffectiveBalanceIncrements, - CachedBeaconStateAllForks, + getAttesterSlashableIndices, isExecutionBlockBodyType, - isExecutionStateType, isExecutionEnabled, - getAttesterSlashableIndices, + isExecutionStateType, } from "@lodestar/state-transition"; import {computeUnrealizedCheckpoints} from "@lodestar/state-transition/epoch"; -import {ChainConfig, ChainForkConfig} from "@lodestar/config"; +import {BeaconBlock, Epoch, Root, RootHex, Slot, ValidatorIndex, bellatrix, phase0, ssz} from "@lodestar/types"; +import {Logger, MapDef, fromHex, toRootHex} from "@lodestar/utils"; import {computeDeltas} from "../protoArray/computeDeltas.js"; +import {ProtoArrayError, ProtoArrayErrorCode} from "../protoArray/errors.js"; import { - HEX_ZERO_HASH, - VoteTracker, - ProtoBlock, + DataAvailabilityStatus, ExecutionStatus, - MaybeValidExecutionStatus, + HEX_ZERO_HASH, LVHExecResponse, + MaybeValidExecutionStatus, + ProtoBlock, ProtoNode, - DataAvailabilityStatus, + VoteTracker, } from "../protoArray/interface.js"; import {ProtoArray} from "../protoArray/protoArray.js"; -import {ProtoArrayError, ProtoArrayErrorCode} from "../protoArray/errors.js"; -import {ForkChoiceError, ForkChoiceErrorCode, InvalidBlockCode, InvalidAttestationCode} from "./errors.js"; +import {ForkChoiceError, ForkChoiceErrorCode, InvalidAttestationCode, InvalidBlockCode} from "./errors.js"; import { - IForkChoice, - LatestMessage, - PowBlockHex, - EpochDifference, AncestorResult, AncestorStatus, + EpochDifference, ForkChoiceMetrics, + IForkChoice, + LatestMessage, NotReorgedReason, + PowBlockHex, } from "./interface.js"; -import {IForkChoiceStore, CheckpointWithHex, toCheckpointWithHex, JustifiedBalances} from "./store.js"; +import {CheckpointWithHex, IForkChoiceStore, JustifiedBalances, toCheckpointWithHex} from "./store.js"; export type ForkChoiceOpts = { proposerBoost?: boolean; diff --git a/packages/fork-choice/src/forkChoice/interface.ts b/packages/fork-choice/src/forkChoice/interface.ts index 9ac8cdfac81b..05c803b50dc8 100644 --- a/packages/fork-choice/src/forkChoice/interface.ts +++ b/packages/fork-choice/src/forkChoice/interface.ts @@ -1,15 +1,15 @@ import {EffectiveBalanceIncrements} from "@lodestar/state-transition"; import {CachedBeaconStateAllForks} from "@lodestar/state-transition"; -import {Epoch, Slot, ValidatorIndex, phase0, Root, RootHex, BeaconBlock, IndexedAttestation} from "@lodestar/types"; +import {BeaconBlock, Epoch, IndexedAttestation, Root, RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types"; import { - ProtoBlock, - MaybeValidExecutionStatus, + DataAvailabilityStatus, LVHExecResponse, + MaybeValidExecutionStatus, + ProtoBlock, ProtoNode, - DataAvailabilityStatus, } from "../protoArray/interface.js"; -import {CheckpointWithHex} from "./store.js"; import {UpdateAndGetHeadOpt} from "./forkChoice.js"; +import {CheckpointWithHex} from "./store.js"; export type CheckpointHex = { epoch: Epoch; diff --git a/packages/fork-choice/src/forkChoice/store.ts b/packages/fork-choice/src/forkChoice/store.ts index 2cd4da512870..fda01689f96c 100644 --- a/packages/fork-choice/src/forkChoice/store.ts +++ b/packages/fork-choice/src/forkChoice/store.ts @@ -1,7 +1,7 @@ +import {CachedBeaconStateAllForks, EffectiveBalanceIncrements} from "@lodestar/state-transition"; +import {RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; -import {EffectiveBalanceIncrements, CachedBeaconStateAllForks} from "@lodestar/state-transition"; -import {phase0, Slot, RootHex, ValidatorIndex} from "@lodestar/types"; -import {CheckpointHexWithTotalBalance, CheckpointHexWithBalance} from "./interface.js"; +import {CheckpointHexWithBalance, CheckpointHexWithTotalBalance} from "./interface.js"; /** * Stores checkpoints in a hybrid format: diff --git a/packages/fork-choice/src/protoArray/computeDeltas.ts b/packages/fork-choice/src/protoArray/computeDeltas.ts index c921e12f751e..928cef8487cb 100644 --- a/packages/fork-choice/src/protoArray/computeDeltas.ts +++ b/packages/fork-choice/src/protoArray/computeDeltas.ts @@ -1,7 +1,7 @@ -import {ValidatorIndex} from "@lodestar/types"; import {EffectiveBalanceIncrements} from "@lodestar/state-transition"; -import {VoteTracker} from "./interface.js"; +import {ValidatorIndex} from "@lodestar/types"; import {ProtoArrayError, ProtoArrayErrorCode} from "./errors.js"; +import {VoteTracker} from "./interface.js"; // reuse arrays to avoid memory reallocation and gc const deltas = new Array(); diff --git a/packages/fork-choice/src/protoArray/interface.ts b/packages/fork-choice/src/protoArray/interface.ts index d60305a6ff72..5e36593697f6 100644 --- a/packages/fork-choice/src/protoArray/interface.ts +++ b/packages/fork-choice/src/protoArray/interface.ts @@ -1,4 +1,4 @@ -import {Epoch, Slot, RootHex, UintNum64} from "@lodestar/types"; +import {Epoch, RootHex, Slot, UintNum64} from "@lodestar/types"; // RootHex is a root as a hex string // Used for lightweight and easy comparison diff --git a/packages/fork-choice/src/protoArray/protoArray.ts b/packages/fork-choice/src/protoArray/protoArray.ts index 82a8b2620880..e1cbf4970920 100644 --- a/packages/fork-choice/src/protoArray/protoArray.ts +++ b/packages/fork-choice/src/protoArray/protoArray.ts @@ -1,11 +1,11 @@ -import {Epoch, RootHex, Slot} from "@lodestar/types"; -import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; import {GENESIS_EPOCH} from "@lodestar/params"; +import {computeEpochAtSlot, computeStartSlotAtEpoch} from "@lodestar/state-transition"; +import {Epoch, RootHex, Slot} from "@lodestar/types"; import {toRootHex} from "@lodestar/utils"; import {ForkChoiceError, ForkChoiceErrorCode} from "../forkChoice/errors.js"; -import {ProtoBlock, ProtoNode, HEX_ZERO_HASH, ExecutionStatus, LVHExecResponse} from "./interface.js"; -import {ProtoArrayError, ProtoArrayErrorCode, LVHExecError, LVHExecErrorCode} from "./errors.js"; +import {LVHExecError, LVHExecErrorCode, ProtoArrayError, ProtoArrayErrorCode} from "./errors.js"; +import {ExecutionStatus, HEX_ZERO_HASH, LVHExecResponse, ProtoBlock, ProtoNode} from "./interface.js"; export const DEFAULT_PRUNE_THRESHOLD = 0; type ProposerBoost = {root: RootHex; score: number}; diff --git a/packages/fork-choice/test/perf/forkChoice/onAttestation.test.ts b/packages/fork-choice/test/perf/forkChoice/onAttestation.test.ts index ae3b10b45d63..db344de96c57 100644 --- a/packages/fork-choice/test/perf/forkChoice/onAttestation.test.ts +++ b/packages/fork-choice/test/perf/forkChoice/onAttestation.test.ts @@ -1,9 +1,9 @@ -import {itBench} from "@dapplion/benchmark"; import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {AttestationData, IndexedAttestation} from "@lodestar/types/phase0"; +import {itBench} from "@dapplion/benchmark"; import {ATTESTATION_SUBNET_COUNT} from "@lodestar/params"; -import {ssz} from "@lodestar/types"; import {computeEpochAtSlot} from "@lodestar/state-transition"; +import {ssz} from "@lodestar/types"; +import {AttestationData, IndexedAttestation} from "@lodestar/types/phase0"; import {initializeForkChoice} from "./util.js"; describe("ForkChoice onAttestation", () => { diff --git a/packages/fork-choice/test/perf/forkChoice/updateHead.test.ts b/packages/fork-choice/test/perf/forkChoice/updateHead.test.ts index 850215f5a844..892135b4eb34 100644 --- a/packages/fork-choice/test/perf/forkChoice/updateHead.test.ts +++ b/packages/fork-choice/test/perf/forkChoice/updateHead.test.ts @@ -1,7 +1,7 @@ import {itBench} from "@dapplion/benchmark"; import {computeEpochAtSlot} from "@lodestar/state-transition"; import {ForkChoice, ProtoBlock} from "../../../src/index.js"; -import {initializeForkChoice, Opts} from "./util.js"; +import {Opts, initializeForkChoice} from "./util.js"; describe("forkchoice updateHead", () => { for (const initialValidatorCount of [100_000, 600_000, 1_000_000]) { diff --git a/packages/fork-choice/test/perf/forkChoice/util.ts b/packages/fork-choice/test/perf/forkChoice/util.ts index 6c04ac817fb2..4376ce047727 100644 --- a/packages/fork-choice/test/perf/forkChoice/util.ts +++ b/packages/fork-choice/test/perf/forkChoice/util.ts @@ -1,14 +1,14 @@ import {fromHexString} from "@chainsafe/ssz"; import {config} from "@lodestar/config/default"; +import {computeTotalBalance} from "../../../src/forkChoice/store.js"; import { + DataAvailabilityStatus, ExecutionStatus, ForkChoice, IForkChoiceStore, - ProtoBlock, ProtoArray, - DataAvailabilityStatus, + ProtoBlock, } from "../../../src/index.js"; -import {computeTotalBalance} from "../../../src/forkChoice/store.js"; const genesisSlot = 0; const genesisEpoch = 0; diff --git a/packages/fork-choice/test/perf/protoArray/computeDeltas.test.ts b/packages/fork-choice/test/perf/protoArray/computeDeltas.test.ts index 9b51f640d949..cb99d8b566d4 100644 --- a/packages/fork-choice/test/perf/protoArray/computeDeltas.test.ts +++ b/packages/fork-choice/test/perf/protoArray/computeDeltas.test.ts @@ -1,7 +1,7 @@ import {itBench, setBenchOpts} from "@dapplion/benchmark"; import {EffectiveBalanceIncrements, getEffectiveBalanceIncrementsZeroed} from "@lodestar/state-transition"; -import {VoteTracker} from "../../../src/protoArray/interface.js"; import {computeDeltas} from "../../../src/protoArray/computeDeltas.js"; +import {VoteTracker} from "../../../src/protoArray/interface.js"; describe("computeDeltas", () => { let oldBalances: EffectiveBalanceIncrements; diff --git a/packages/fork-choice/test/unit/forkChoice/forkChoice.test.ts b/packages/fork-choice/test/unit/forkChoice/forkChoice.test.ts index f47849136bff..db7482f30cde 100644 --- a/packages/fork-choice/test/unit/forkChoice/forkChoice.test.ts +++ b/packages/fork-choice/test/unit/forkChoice/forkChoice.test.ts @@ -1,18 +1,18 @@ -import {describe, it, expect, beforeEach, beforeAll} from "vitest"; import {fromHexString} from "@chainsafe/ssz"; import {config} from "@lodestar/config/default"; +import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {computeEpochAtSlot} from "@lodestar/state-transition"; import {RootHex, Slot} from "@lodestar/types"; import {toHex} from "@lodestar/utils"; -import {computeEpochAtSlot} from "@lodestar/state-transition"; -import {SLOTS_PER_EPOCH} from "@lodestar/params"; +import {beforeAll, beforeEach, describe, expect, it} from "vitest"; import { + DataAvailabilityStatus, + EpochDifference, + ExecutionStatus, ForkChoice, IForkChoiceStore, - ProtoBlock, ProtoArray, - ExecutionStatus, - EpochDifference, - DataAvailabilityStatus, + ProtoBlock, } from "../../../src/index.js"; import {getBlockRoot, getStateRoot} from "../../utils/index.js"; diff --git a/packages/fork-choice/test/unit/forkChoice/getProposerHead.test.ts b/packages/fork-choice/test/unit/forkChoice/getProposerHead.test.ts index 187834e6d63a..ba225756733d 100644 --- a/packages/fork-choice/test/unit/forkChoice/getProposerHead.test.ts +++ b/packages/fork-choice/test/unit/forkChoice/getProposerHead.test.ts @@ -1,18 +1,18 @@ -import {describe, it, expect, beforeEach} from "vitest"; import {fromHexString} from "@chainsafe/ssz"; import {config} from "@lodestar/config/default"; +import {INTERVALS_PER_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params"; import {Slot} from "@lodestar/types"; import {toHex} from "@lodestar/utils"; -import {INTERVALS_PER_SLOT, SLOTS_PER_EPOCH} from "@lodestar/params"; +import {beforeEach, describe, expect, it} from "vitest"; +import {NotReorgedReason} from "../../../src/forkChoice/interface.js"; import { + DataAvailabilityStatus, + ExecutionStatus, ForkChoice, IForkChoiceStore, ProtoArray, - ExecutionStatus, ProtoBlock, - DataAvailabilityStatus, } from "../../../src/index.js"; -import {NotReorgedReason} from "../../../src/forkChoice/interface.js"; import {getBlockRoot, getStateRoot} from "../../utils/index.js"; type ProtoBlockWithWeight = ProtoBlock & {weight: number}; // weight of the block itself diff --git a/packages/fork-choice/test/unit/forkChoice/utils.test.ts b/packages/fork-choice/test/unit/forkChoice/utils.test.ts index 44b0eb8b719b..b3bea1020544 100644 --- a/packages/fork-choice/test/unit/forkChoice/utils.test.ts +++ b/packages/fork-choice/test/unit/forkChoice/utils.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; import {createChainForkConfig} from "@lodestar/config"; import {ssz} from "@lodestar/types"; -import {assertValidTerminalPowBlock, ExecutionStatus} from "../../../src/index.js"; +import {describe, expect, it} from "vitest"; +import {ExecutionStatus, assertValidTerminalPowBlock} from "../../../src/index.js"; describe("assertValidTerminalPowBlock", () => { const config = createChainForkConfig({TERMINAL_TOTAL_DIFFICULTY: BigInt(10)}); diff --git a/packages/fork-choice/test/unit/protoArray/computeDeltas.test.ts b/packages/fork-choice/test/unit/protoArray/computeDeltas.test.ts index 4428807bd13d..af5d42f834b9 100644 --- a/packages/fork-choice/test/unit/protoArray/computeDeltas.test.ts +++ b/packages/fork-choice/test/unit/protoArray/computeDeltas.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; import {getEffectiveBalanceIncrementsZeroed} from "@lodestar/state-transition"; +import {describe, expect, it} from "vitest"; import {computeDeltas} from "../../../src/protoArray/computeDeltas.js"; diff --git a/packages/fork-choice/test/unit/protoArray/executionStatusUpdates.test.ts b/packages/fork-choice/test/unit/protoArray/executionStatusUpdates.test.ts index cefb2b07df02..4fcc6c79d190 100644 --- a/packages/fork-choice/test/unit/protoArray/executionStatusUpdates.test.ts +++ b/packages/fork-choice/test/unit/protoArray/executionStatusUpdates.test.ts @@ -1,10 +1,10 @@ -import {describe, it, expect} from "vitest"; +import {describe, expect, it} from "vitest"; import { - ProtoBlock, - ProtoArray, + BlockExtraMeta, ExecutionStatus, MaybeValidExecutionStatus, - BlockExtraMeta, + ProtoArray, + ProtoBlock, } from "../../../src/index.js"; import {LVHExecErrorCode} from "../../../src/protoArray/errors.js"; import {DataAvailabilityStatus} from "../../../src/protoArray/interface.js"; diff --git a/packages/fork-choice/test/unit/protoArray/getCommonAncestor.test.ts b/packages/fork-choice/test/unit/protoArray/getCommonAncestor.test.ts index b9b7f9c37b43..3bc322112332 100644 --- a/packages/fork-choice/test/unit/protoArray/getCommonAncestor.test.ts +++ b/packages/fork-choice/test/unit/protoArray/getCommonAncestor.test.ts @@ -1,5 +1,5 @@ -import {describe, it, expect} from "vitest"; -import {ProtoArray, ExecutionStatus, DataAvailabilityStatus} from "../../../src/index.js"; +import {describe, expect, it} from "vitest"; +import {DataAvailabilityStatus, ExecutionStatus, ProtoArray} from "../../../src/index.js"; describe("getCommonAncestor", () => { const blocks: {slot: number; root: string; parent: string}[] = [ diff --git a/packages/fork-choice/test/unit/protoArray/protoArray.test.ts b/packages/fork-choice/test/unit/protoArray/protoArray.test.ts index 92dfc61d61b2..5e87504dc455 100644 --- a/packages/fork-choice/test/unit/protoArray/protoArray.test.ts +++ b/packages/fork-choice/test/unit/protoArray/protoArray.test.ts @@ -1,7 +1,7 @@ -import {describe, it, expect} from "vitest"; import {RootHex} from "@lodestar/types"; +import {describe, expect, it} from "vitest"; -import {ProtoArray, ExecutionStatus, DataAvailabilityStatus} from "../../../src/index.js"; +import {DataAvailabilityStatus, ExecutionStatus, ProtoArray} from "../../../src/index.js"; describe("ProtoArray", () => { it("finalized descendant", () => { diff --git a/packages/light-client/README.md b/packages/light-client/README.md index 0323e8fc4326..f9af65f23f98 100644 --- a/packages/light-client/README.md +++ b/packages/light-client/README.md @@ -18,7 +18,7 @@ The evolution of light clients is emblematic of the broader trajectory of Ethere ## Requirements for Running a Light-Client -Access to an beacon node that supports the light client specification is necessary. The client must support the following routes from the [consensus API spec](https://github.com/ethereum/beacon-APIs/tree/v2.5.0/apis/beacon/light_client): +Access to a beacon node that supports the light client specification is necessary. The client must support the following routes from the [consensus API spec](https://github.com/ethereum/beacon-APIs/tree/v2.5.0/apis/beacon/light_client): - [`GET /eth/v1/beacon/light_client/updates`](https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.5.0#/Beacon/getLightClientUpdatesByRange) - [`GET /eth/v1/beacon/light_client/optimistic_update`](https://ethereum.github.io/beacon-APIs/?urls.primaryName=v2.5.0#/Beacon/getLightClientOptimisticUpdate) @@ -31,8 +31,8 @@ You can find more information about the light-client protocol in the [specificat ## Getting started -- Follow the [installation guide](https://chainsafe.github.io/lodestar/getting-started/installation) or [Docker install](https://chainsafe.github.io/lodestar/getting-started/installation/#docker-installation) to install Lodestar. -- Quickly try out the whole stack by [starting a local testnet](https://chainsafe.github.io/lodestar/advanced-topics/setting-up-a-testnet). +- Follow the [installation guide](https://chainsafe.github.io/lodestar/run/getting-started/installation) to install Lodestar. +- Quickly try out the whole stack by [starting a local testnet](https://chainsafe.github.io/lodestar/contribution/advanced-topics/setting-up-a-testnet). ## Light-Client CLI Example @@ -92,7 +92,7 @@ lightclient.emitter.on(LightclientEvent.lightClientOptimisticHeader, async (opti ## Browser Integration -If you want to use Lightclient in browser and facing some issues in building it with bundlers like webpack, vite. We suggest to use our distribution build. The support for single distribution build is started from `1.20.0` version. +If you want to use Lightclient in browser and are facing some issues in building it with bundlers like webpack, vite. We suggest using our distribution build. The support for single distribution build is started from `1.20.0` version. Directly link the dist build with the `