How axieinfinity/ronin works
Main Components
• Node & Networking: The “node” component (node/, p2p/, enode/, dnsdisc/) is responsible for managing peer-to-peer communication, discovery, and network interactions. Represent a “P2P Networking” block which includes discovery protocols, node communication, and transport management.
• Consensus Engine: Inside folders like consensus/ (with sub-folders for clique, ethash, consortium, etc.), the project implements multiple consensus algorithms. Include a “Consensus” module that shows how blocks are validated and finalized using mechanisms like Delegated Proof of Stake (as described in the README) and other protocols.
• Blockchain & State Management: The core blockchain logic is found in folders such as core/ (blockchain, state, rawdb, trie, rlp) and common/. This module manages the chain of blocks, state transitions, and the storage layer (both the state trie and raw data stored in databases). Label these modules accordingly – e.g. “Blockchain Core”, “State Database & Trie Storage”, and “RLP (data encoding).”
• Virtual Machine Execution: The EVM and its associated virtual machine logic are encapsulated in core/vm/ and cmd/evm. Indicate an “EVM Execution Engine” which processes smart contract bytecode and opcode instructions.
• Cryptographic & Account Management: There are dedicated folders for cryptography (crypto/, accounts/, keystore, bls, bn256, secp256k1, etc.) and account management (including wallet and signature utilities). Represent a “Cryptography & Account Services” component.
• Auxiliary tools & Utilities: Other modules, including debugging tools, metrics (metrics/), logging (log/), and additional utilities, form supporting infrastructure. Represent these as peripheral components which support monitoring, diagnostics, and build operations.
Relationships and Data Flows
• The CLI (ronin executable) serves as the orchestrator: it starts the node, sets up RPC servers, and integrates with the consensus and state layers.
• Data flow from the “P2P Networking” module feeds into the “Consensus” layer where incoming blocks are validated.
• The “Blockchain Core” uses data provided by consensus, and updates the "State Database" when new blocks are applied.
• The “EVM Execution Engine” interacts with the blockchain core to process transactions and smart contracts.
• The “RPC API” layer sits on top and provides programmatic access to the core components (node, blockchain, state, and EVM).
• Cryptographic modules support account management, signing via “clef” and the transaction signing processes needed by other components.
Architectural Patterns and Design Principles
• Layered Architecture: Show how the lower-level components (network, consensus, storage) feed upward into higher-level services (EVM, APIs, command interfaces).
Technologies and Frameworks
• Golang is the primary language.
• JSON-RPC interfaces (HTTP, WS, IPC).
• Standard crypto libraries and specialized crypto (BLS, secp256k1, BN256).
• RLP encoding for data serialization.
• The consensus mechanisms include both Ethash (for PoW experiments) and Delegated Proof of Stake (for Ronin’s production).