Files
lodestar/.gitignore
guha-rahul 4584616eeb feat: add Era File Reading and Writing (#8035)
**Motivation**

- tracks #7048 
-
[era](https://github.com/eth-clients/e2store-format-specs/blob/main/formats/era.md)
specs.

**Description**

- Adds functionality to read/write to
[e2s](613f4a9a50/docs/e2store.md (era-files))
files
```ts
import {open} from "node:fs/promises";
import {e2s} from "@lodestar/era";

const fh = await open("mainnet-xxxxxx-xxxxxxxx.era");
const entry = await e2s.readEntry(fh, 0);
entry.type == e2s.EntryType.Version
```
- Adds functionality to read/write era files
```ts
import {era} from "@lodestar/era";
import {config} from "@lodestar/config/default";
// open reader
const reader = await era.EraReader.open(config, "mainnet-xxxxx-xxxxxxxx.era");

// check number of groups
reader.groups.length === 1;

// read blocks
const slot = reader.groups[0].startSlot;

 // return snappy-frame compressed, ssz-serialized block at slot or null if a skip slot
 // throws if out of range
await reader.readCompressedBlock(slot);
// same, but for ssz-serialized block
await reader.readSerializedBlock(slot);
// same but for deserialized block
await reader.readBlock(slot);

// read state(s), one per group
// similar api to blocks, but with an _optional_ eraNumber param for specifying which group's state to read
await reader.readCompressedState(); 
await reader.readSerializedState();
await reader.readState();

// write era files
const writer = await era.EraWriter.create(config, "path/to/era");

// similar api to reader, can write compressed, serialized, or deserialized items
// first write all blocks for the era
await writer.writeBlock(block);
// ...
// then write the state
await writer.writeState(state);
// if applicable, continue writing eras of blocks and state (an era file can contain multiple eras, or "groups" as the spec states)
// when finished, must call `finish`, which will close the file handler and _rename_ the file to the spec-compliant name
await writer.finish();
```

- e2e test reads an era file, does all validation, writes an era fila,
does validation on that freshly created file
- requires the era file fixture to be downloaded (`cd packages/era/test
&& ./download_era_file.sh`)
  - e2e test is skipped (`test:e2e` is not defined for the era package)

---------

Co-authored-by: Cayman <caymannava@gmail.com>
2025-11-07 11:42:31 -05:00

86 lines
1.3 KiB
Plaintext

.__testdb*
node_modules/
lib
dist
.nyc_output/
coverage/**
.DS_Store
*.swp
.idea
beaconchain
lodestar-config.toml
keys/
keystores/
test-db
yarn-error.log
package-lock.json
LodestarValidatorDB/
*.log
data
validators
*.tsbuildinfo
**/coverage
**/node_modules
**/lib
**/dist
**/.nyc_output
.tmp
.npmrc
.vscode/launch.json
!.vscode/settings.json
.vscode/tasks.json
.claude/
# Tests artifacts
packages/*/spec-tests*
packages/*/benchmark_data
packages/beacon-node/test-logs/
packages/cli/test-logs/
packages/state-transition/test-cache
benchmark_data
invalidSszObjects/
packages/beacon-node/mainnet_pubkeys.csv
packages/api/oapi-schemas
test-logs/
# Autogenerated docs
packages/**/docs
packages/**/typedocs
docs/pages/**/*-cli.md
docs/pages/assets
docs/pages/images
docs/pages/security.md
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/
# Testnet artifacts
.lodestar
*.ssz
.pyrmont
.tmpdb
docker/grafana_dev/dashboards
# Wallet CLI artifacts
.pass
# docker-compose .env file
.env
# Grafana secret
.secrets.env
# Git artifacts
packages/cli/.git-data.json
# Build artifacts
.last_build_unixsec
dictionary.dic
temp/