How limechain/fruzhin works
Main Components
• Node & Bootstrap: At the entry point is Main.java that initializes and wires the node services.
• Chain Manager: Packages under “com.limechain.chain” and “com.limechain/chain/spec” contain the logic for chain specs, genesis configuration (including reading from the genesis folder), and maintaining chain state.
• Consensus Engines: Multiple consensus modules exist:
– The “consensus/babe” package for block production and slot coordination.
– “consensus/grandpa” handling finality proofs.
– “consensus/beefy” for additional finality and vote aggregation.
• Networking: Several layers of network protocols are implemented (look under “network”, “network/protocol”, and “network/kad”). These handle peer discovery, connection management, message encoding/decoding, block announcement, syncing, and light client message protocols.
• Sync Module: The “sync” packages provide both full sync and warp sync mechanisms. These interact with the chain state and network to update the node with new blocks.
• RPC & PubSub: Under “rpc” packages, you find both the server and client implementations to support public API methods (chain, state, system, offchain, and author endpoints) and subscribe to updates.
• Runtime and Host API: “runtime” packages implement the WASM runtime, its memory management, host APIs, and version handling. This is key for executing runtime logic and smart contract-like operations.
• Storage & Trie: The “storage” and “trie” packages handle block storage, state persistence, and efficient lookup via trie data structures.
• CLI and Configuration: The “cli” package offers a command-line interface, while the “config” packages load system settings and host configurations.
• Monitoring and Utilities: Integration with “prometheus” supports metrics, and there are many utility and exception packages for managing errors, encoding/decoding, scales, and asynchronous tasks.
Establish Relationships and Interactions
• The Main Node component creates a NodeService that wires together:
• Chain Manager – for processing and validating block headers and chain specification files.
• Consensus engines (Babe, Grandpa, Beefy) that manage consensus state and block finalization.
• Sync module that drives block execution and synchronization with the peer network.
• Networking protocols interface with the Consensus and Sync modules to receive new blocks, disseminate messages (block announcements, votes, sync requests), and maintain peer connections.
• The RPC subsystem exposes data from the Chain Manager, Consensus state, and Storage layer so that external clients (or the node operator via CLI) can query the system.
• The Runtime subsystem, with its host API modules, interacts with the Storage layer and State management to execute WASM code.
• Storage/Trie components are used throughout the system to persist chain and state data, maintaining a consistent view required by syncing and runtime evaluations.
• Monitoring via Prometheus gathers metrics across node components.
Architectural Patterns and Technical Stack
• Modular design: Each functional area (chain, consensus, network, runtime, storage) is clearly separated into its own package.
• Layered architecture: Low-level storage/trie components feed into higher-level chain and runtime modules.
• Service orchestration: The NodeService coordinates startup and lifecycle management of consensus engines, network, and RPC components.
• Exception handling and asynchronous programming: The extensive exception and async utility packages indicate attention to reliability and concurrent processing.
• Use of Gradle builds, Docker deployment (with a provided Dockerfile), and extensive testing under “src/test” further support modern development practices.