How chainsafe/lodestar works
Major Components
• Core Client (Beacon Node): Represented by the “@lodestar/beacon-node” package. This component is responsible for running the beacon chain client, including processing blocks, managing state, handling fork choice, and interacting with the network.
• Communication/API Layer: The “@lodestar/api” package exposes REST endpoints while “@lodestar/reqresp” and “@lodestar/light-client” handle protocol-level messaging (request/response, light client sync, etc.).
• CLI and User Interface: The main CLI tool is in “@chainsafe/lodestar” (also under packages/cli). It ties together and provides command-line access to the underlying services.
• State Transition & Consensus: The “@lodestar/state-transition” package covers all the logic for state transition and processing blocks (deposits, attestation processing, slashing, fork-choice integration, etc.). It forms the core engine for checking consensus rules.
• Supporting Modules: Several packages provide supporting functionality like:
• Configuration: “@lodestar/config” (for consensus parameters and config management)
• Database/Persistence: “@lodestar/db” (for reading/writing persistent consensus data)
• Logging: “@lodestar/logger” (for a unified logging interface)
• Consensus Parameters & Types: “@lodestar/params”, “@lodestar/types” (to shout about Ethereum-specific types, SSZ, chain constants, etc.)
• Fork Choice: “@lodestar/fork-choice” (with its fork-choice algorithms and proto-array implementations)
• Proving & Verification: “@lodestar/prover” (for verifying execution payloads and JSON-RPC calls)
• Utilities: “@lodestar/utils” (miscellaneous functions used across the project)
• Validator functionality: “@lodestar/validator” (for client side validator tools, slashing protection, duties, external signer integration)
• Other specialized modules such as “@lodestar/flare”, which handles non-standard actions or triggering events.
• The beacon node (the main execution engine) will have internal dependencies on:
• The state-transition module (processing block transitions and protocol rules),
• The fork-choice module (ensuring chain selection is correct),
• The database module for state persistence,
• The network modules (reqresp and light-client) for peer-to-peer communications.
• Configuration and parameters modules providing settings/information to multiple components (for example, passing consensus specs to state transition, database, and API).
• Logging and monitoring systems (embedded within modules such as “@lodestar/logger”) and highlight that metrics (possibly exposed by the metrics server in the beacon node package) flow from core operations to external dashboards (Grafana or Prometheus, as indicated by the docker-compose and dashboards directories).
• For network communication, show the “reqresp” layer encapsulating requests/responses between nodes; these exchange data with the beacon node and interact with external Ethereum networks (e.g., via ETH1 bridges in certain modules).
Architectural Patterns and Design Principles
• Separation of concerns: Each package is responsible for a distinct aspect of Ethereum consensus (e.g., state transitions, configuration, network communication, logging).
• That the system is extensible—new modules or updates to a module (for example, updated state-transition logic, fork-choice protocol, or new network communication strategies) can be developed relatively independently.