How layertwo-labs/thunder-rust works
Thunder is a Rust workspace organized around a core node/library, an application shell, and a separate RPC client. The architecture is centered on a shared domain library that implements the actual blockchain/node behavior, while the app layer mainly orchestrates presentation and remote control.
1. Core domain engine: lib/
This is the main backend subsystem. It contains the node logic (lib/node), network peer management (lib/net/peer), state handling and rollback (lib/state), mempool and mining (lib/mempool.rs, lib/miner.rs), wallet/authorization/archive logic, and shared domain types (lib/types). This crate is where consensus/state transitions and peer-to-peer behavior live.
2. Node runtime split into tasks
The lib/node folder suggests a task-based runtime boundary: mainchain_task.rs and net_task.rs separate mainchain/block-processing responsibilities from network I/O. That separation is important for diagramming internal data flow: peer messages feed network tasks, which then drive state updates and mainchain processing.
3. Network and peer layer
lib/net and lib/net/peer implement the transport-facing side of the node. The peer subsystem is decomposed into mailbox, channel pool, request queue, task, and message handling, indicating asynchronous message passing between peers and internal node logic rather than direct synchronous calls.
4. State and chain data model
lib/state holds the canonical chain/block state, rollback support, and two-way peg data. This is the persistence/consensus boundary: incoming blocks, transactions, and withdrawals are validated and applied here, with rollback support for reorgs or invalid transitions.
5. Shared protocol and type layer
lib/types and proto/ define the shared data structures used across node, RPC, and UI boundaries: addresses, hashes, transactions, and schema/proto definitions. lib/types/proto.rs and rpc-api/schema.rs indicate schema-driven serialization across component boundaries.
6. Application shell and UI: app/
The app crate is the executable frontend/orchestrator. It contains the main binary entrypoint, CLI/bootstrap logic, a GUI subsystem, and an embedded RPC server. This crate does not appear to own consensus logic; it consumes the core library and exposes user-facing control surfaces.
7. GUI as a set of functional panels
app/gui is organized by task domain rather than by generic windowing: coins/transfer/tx creation/UTXO selection, block explorer, mempool explorer, miner controls, withdrawals, parent-chain info/transfer, seed management, and console logs. That implies a dashboard-style client that calls into backend services rather than directly manipulating state.
8. RPC server boundary
app/rpc_server.rs is the primary integration point between the app/UI and the backend. The README explicitly says the app can run with an embedded JSON-RPC server, so the UI and the external CLI both talk to the same RPC surface rather than accessing the node internals directly.
9. External CLI client
The cli/ crate is a separate binary (thunder_app_cli) for interacting with the JSON-RPC server. Architecturally, this is a thin remote client that depends on the shared RPC API definitions, allowing headless control of the node/app.
10. Shared RPC contract
rpc-api/ contains the schema and types used by both server and client. This crate is the contract boundary for all remote operations, and it likely prevents drift between the app’s embedded server and the external CLI.
11. Testing and lifecycle coverage
integration_tests/ contains end-to-end tests such as IBD and unknown withdrawal scenarios. These tests indicate the system is validated at the protocol/state boundary, not just at unit level. The presence of an example.env suggests tests depend on environment-driven runtime setup.
12. Packaging and delivery
The repository is designed for reproducible builds via Cargo workspaces, with Docker and CI workflows in .github/workflows. That affects deployment architecture: the node/app can be built and run as a containerized binary, with automated lint/build checks in CI.
13. Architectural summary of data flow
The main flow is: peer/network messages and local actions enter the core lib node, which updates mempool/state/miner logic; results are exposed through the RPC server; the GUI and CLI consume the RPC API; integration tests exercise the same external interfaces. The key boundaries are between core consensus/state, RPC contract, and presentation/client layers.
Main entry points: lib.rs lib · rpc_server.rs RPC server · mod.rs State core · Dockerfile CI/Docker
Components 19
Core engine
Shared node, state, network, and domain logic.
- lib · Core backend crate for node behavior and shared domain logic.
lib/lib.rs - Node runtime · Orchestrates node execution as separate mainchain and network tasks.
lib/node/mod.rs - Mainchain task · Handles block processing, chain updates, and consensus-facing work.
lib/node/mainchain_task.rs - Net task · Drives network I/O and peer message flow into the node.
lib/node/net_task.rs - Network layer · Network-facing module that hosts peer communication primitives.
lib/net/mod.rs - Peer stack · Asynchronous peer messaging, queues, and mailbox coordination.
lib/net/peer/mod.rs - State core · Canonical block/state storage with rollback and peg data.
lib/state/mod.rs - Mempool · Pending transaction pool used by node and miner logic.
lib/mempool.rs - Miner · Mining and block production logic built on shared state.
lib/miner.rs - Wallet · Wallet and authorization-facing domain logic.
lib/wallet.rs
App shell
Executable frontend, GUI, and embedded RPC server.
- app · Main application crate that orchestrates UI and RPC.
app/app.rs - GUI · Panel-based user interface for node control and explorers.
app/gui/mod.rs - RPC server · Embedded JSON-RPC server exposing backend control and queries.
app/rpc_server.rs
Remote clients
External command-line access to the RPC surface.
- CLI · Separate command-line client for remote control via RPC.
cli/main.rs
Shared contracts
Schema and types shared across process boundaries.
Tests and delivery
Integration coverage and build/deployment tooling.
- Integration tests · Protocol and lifecycle tests exercising public interfaces.
integration_tests/integration_test.rs - CI/Docker · Workspace build, lint, and container packaging workflows.
Dockerfile
Connections 27
- lib → Node runtime: contains · Core crate includes the node runtime boundary.
- lib → Network layer: contains · Core crate includes transport-facing networking code.
- lib → State core: contains · Core crate owns canonical state management.
- lib → Mempool: contains · Core crate includes pending transaction handling.
- lib → Miner: contains · Core crate includes block production logic.
- lib → Wallet: contains · Core crate includes wallet and authorization domain logic.
- Node runtime → Mainchain task: splits into · Node runtime separates chain processing into a dedicated task.
- Node runtime → Net task: splits into · Node runtime separates network I/O into a dedicated task.
- Network layer → Peer stack: hosts · Transport layer is implemented through peer coordination primitives.
- Peer stack → State core: drives updates · Peer messages eventually feed validated state transitions.
- Mainchain task → State core: applies blocks · Chain-processing task updates canonical state.
- Mainchain task → Mempool: consumes · Block processing interacts with pending transactions.
- Mempool → Miner: feeds · Miner draws from the transaction pool.
- State core → Types: uses · State logic relies on shared domain types.
- Wallet → Types: uses · Wallet logic uses shared addresses and transaction types.
- Proto → Types: aligns · Protocol schemas are backed by shared domain types.
- app → GUI: contains · Application crate includes the user-facing GUI.
- app → RPC server: hosts · Application crate embeds the RPC server boundary.
- GUI → RPC server: controls via · GUI invokes backend actions through RPC rather than directly.
- CLI → RPC API: depends on · CLI uses the shared RPC contract.
- RPC server → RPC API: implements · RPC server exposes the shared contract.
- RPC server → lib: calls into · Server bridges UI/client requests to core backend logic.
- Integration tests → RPC API: exercises · End-to-end tests validate public RPC-facing behavior.
- Integration tests → lib: exercises · Integration tests cover core protocol/state behavior.
- CI/Docker → app: builds · Delivery pipeline packages the application binary.
- CI/Docker → CLI: builds · Delivery pipeline packages the CLI client.
- CI/Docker → Integration tests: runs · CI validates the workspace through automated tests.