How koma2211/go-ethereum works
Project type and purpose
• From the README and file tree, this is “go-ethereum” (geth), a Go-based execution-layer client for the Ethereum protocol. It can run as a full/archival/light node, offers JSON-RPC, WS and IPC APIs, P2P networking, consensus engines, transaction pool, EVM execution, state DB, and command-line utilities (geth, abigen, evm, clef, etc.).
File structure
• Top-level directories:
• cmd – entrypoint executables (geth, clef, devp2p, abigen, evm, rlpdump, workload, etc.)
• node – core node bootstrap, lifecycle, RPC stack
• p2p – low-level peer discovery, RLPx transport, server
• eth – Ethereum protocol handlers: sync, downloader, filters, tracer interfaces
• consensus – plug-in consensus rules (ethash, clique, beacon)
• core – blockchain insertion & validation logic, gas, fork rules, chain state
• state, trie, triedb, ethdb – database layers (key/value stores, trie, history, snapshots)
• core/vm – the Ethereum Virtual Machine
• txpool – transaction pool & mempool logic
• rpc, ethclient, graphql – JSON-RPC server and client implementations
• accounts, signer, keystore – account management & signing backends
• crypto – cryptographic primitives (secp256k1, bn256, KZG, etc.)
• metrics, log – instrumentation, logging
• internal – build tooling, debug, testing helpers
README for additional insights
• The geth binary hosts the P2P node, downloads blocks, validates & executes them, maintains state, and exposes APIs. Other binaries wrap portions of this (abigen for contract codegen, evm for EVM sandbox, clef for signing).
Main components and interactions
a. Node Core (node/node.go) – initializes all submodules and ties them together
b. P2P Network (p2p/) – connects to peers, discovery, secure RLPx transport
c. Sync & Downloader (eth/downloader, eth/sync.go) – fetches blocks from peers, verifies headers & bodies
d. Consensus & Fork Rules (consensus/, core/forkid/) – determines valid forks, block acceptance
e. Chain Manager (core/, trie/, triedb/) – stores blocks, executes transactions via VM, updates Merkle trie state
f. Transaction Pool (core/txpool/) – holds pending transactions for inclusion by miner
g. Miner (miner/) – assembles blocks, signs (for proof-of-work) or payload (for proof-of-stake), injects to chain
h. RPC/API Layer (node/rpcstack.go, rpc/, eth/api_*.go, graphql/) – exposes JSON-RPC over HTTP, WS, IPC for external clients
i. Account & Signing (accounts/, signer/) – manages private keys & signs transactions
j. Utilities & CLI (cmd/) – CLI wrappers around the core node or isolated tools
• Startup: CLI → Node Core
• Node Core ↔ P2P Network
• P2P Network → Downloader → Chain Manager → State DB
• Chain Manager → VM → Execution results back into State DB
• Chain Manager emits events → Filters & Tracers → API Layer
• Transaction Pool ← API Layer ← Client → Transaction Pool → Miner
• Miner → Chain Manager to commit new block → Broadcast via P2P
• Account/Signer used by RPC & CLI for signing transactions
Architectural patterns and principles
• Layered architecture: network → sync → consensus → execution → storage → API
• Dependency injection via the Node package, enabling swapping consensus engines or DB backends
• Clear separation of concerns: core (blockchain logic), eth (protocol), p2p (network), rpc (interface)
• Use of interfaces for state DB, transaction sources, backends (in ethclient, accounts)