How stader-labs/stader-node works
Project Type and Purpose
• This is a Go-based CLI and supporting library ecosystem for running and managing “ETHx” permissionless staking nodes on Ethereum.
• The stader-cli binary (user-facing) orchestrates node registration, reward claiming, config generation, and interactions with smart contracts.
• Underneath, a set of core libraries (shared/…), a service-oriented CLI app (stader/…), and a companion guardian module provide actual blockchain, state, wallet, and monitoring logic.
High-Level Architecture Overview
A. User Layer
• stader-cli (CLI): the entry point.
B. Application Layer
• CLI App (“stader-cli” package) uses:
– Shared Services (shared/services)
– Shared Types & Utils (shared/types, shared/utils)
• Main application binary (“stader” package) & “ec_migrate” scripts
• Guardian module (stader/guardian): metrics collector & exporter
C. Services Layer
• Config Manager (shared/services/config): reads/overrides YAML templates
• API Client (shared/services/stader): talks to Stader backend for pool data
• Blockchain Manager (shared/services/bc-manager & beacon client)
• Execution Client Manager (shared/services/ec-manager)
• Wallet Manager (shared/services/wallet): keystore per consensus client
• Gas Oracle (shared/services/gas): Etherchain & Etherscan
• State Manager (shared/services/state): tracks network & local node state
D. Infrastructure & External Systems
• Ethereum Consensus & Execution RPC Endpoints (e.g., Geth, Nethermind, Lighthouse, Prysm, Teku)
• Smart Contracts on Ethereum (abis/*.json + stader-lib/contracts)
• Monitoring & Metrics (Prometheus + Grafana + guardian exporter)
• Docker & Install Scripts (docker/, install/…): deployment artifacts
Component Relationships & Data Flows
• The CLI invokes the Application Layer, passing user commands.
• Configuration Manager loads templates, user overrides → passes config objects to Services.
• API Client retrieves pool/contract addresses & params from Stader backend.
• Blockchain Manager & EC Manager launch or talk to local Ethereum clients via JSON-RPC.
• Wallet Manager manages validator keys in consensus client format, feeds deposit data to smart contracts via RPC.
• Gas Oracle provides gas‐price suggestions before on-chain tx.
• State Manager tracks local node health & on-chain state.
• Guardian periodically pulls metrics from all Managers & Clients, exposes Prometheus endpoint.
• Monitoring stack scrapes Guardian + node exporters and displays on Grafana.
Important Patterns & Principles
• Layered architecture: CLI → Core Services → External Systems
• Dependency injection via “shared/services” interfaces—swapable clients (e.g., Lighthouse vs Prysm)
• Template-driven config generation for different client implementations
• Modularization: each blockchain service, gas oracle, wallet provider implemented as pluggable module
Essential Elements
• Sequence of interactions for a typical command (e.g., “deposit-sd”):
1) CLI reads config →
2) API Client fetches contract data →
3) Wallet Manager constructs deposit TX →
4) Gas Oracle suggests gas →
5) EC Manager submits TX to execution client →
6) State Manager confirms inclusion
• “stader-lib” usage as the in-process abstraction of smart-contract ABIs and proofs.