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
2022-01-31 11:49:02 -06:00
2020-03-30 20:24:46 -04:00
2021-03-07 12:50:58 +01:00
2024-02-08 16:59:25 +01:00
2025-10-20 14:09:58 -04:00

Lodestar Ethereum Consensus Implementation

GitHub release (latest by date) Docker Image Version (latest by date) Eth Consensus Spec v1.5.0 ES Version Node Version codecov gitpoap badge

Lodestar is a TypeScript implementation of the Ethereum Consensus specification developed by ChainSafe Systems.

Getting started

Prerequisites

Developer Quickstart:
yarn install
yarn build
./lodestar --help

Architecture Overview

  • 📦 This mono-repository contains a suite of Ethereum Consensus packages.
  • ⚖️ The mono-repository is released under Apache-2.0 license. Note, that the packages contain their own licenses.
Package Version License Docs Description
@chainsafe/lodestar npm License documentation 💻 Command-line tool for Lodestar
@lodestar/api npm License documentation 📋 REST Client for the Ethereum Beacon API
@lodestar/beacon-node npm License documentation 🚨 Beacon-chain client
@lodestar/config npm License documentation 🗒️ Eth Consensus types and params bundled together
@lodestar/db npm License documentation 💾 Read/write persistent Eth Consensus data
@lodestar/flare npm License documentation 💥 Command tool for triggering non-standard actions
@lodestar/fork-choice npm License documentation 🍴 Beacon-chain fork choice
@lodestar/light-client npm License documentation 🐦 Ethereum Light client
@lodestar/logger npm License documentation 📝 NodeJS logger for Lodestar binaries
@lodestar/params npm License documentation 🕸️ Eth Consensus network parameters
@lodestar/prover npm License documentation Ethereum Light client verifier for execution JSON-RPC calls
@lodestar/reqresp npm License documentation 📞 Eth Consensus Req/Resp protocol
@lodestar/spec-test-util npm License documentation 🧪 Test harness for Eth Consensus spec tests
@lodestar/state-transition npm License documentation 🔎 Eth Consensus beacon-state transition
@lodestar/types npm License documentation 🗒️ Eth Consensus TypeScript and SSZ types
@lodestar/utils npm License documentation 🧰 Miscellaneous utility functions used across Lodestar
@lodestar/validator npm License documentation 🏦 Validator client

Contributors

Read our contributors document, submit an issue or talk to us on our Discord!

Meetings

Weekly contributor meetings are posted under 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. Post-September 2021, meeting notes can be found on the Lodestar Wiki Page.

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 find the ETH address under "Sponsor this project" on this repository.

Description
No description provided
Readme 507 MiB
Languages
TypeScript 98.9%
JavaScript 0.6%
Shell 0.4%