ChainOS Architecture

Architecture Overview

ChainOS is built on a multi-layered architecture designed for high performance, security, and scalability. This document provides a comprehensive overview of the system's components and their interactions.

Architectural Layers

ChainOS implements a modular architecture with four primary layers:


┌───────────────────────────────────────────────────────────┐
│                    Application Layer                      │
│   ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐   │
│   │ Transaction │  │   Smart     │  │State Transition │   │
│   │  Execution  │  │  Contracts  │  │     Engine      │   │
│   └─────────────┘  └─────────────┘  └─────────────────┘   │
├───────────────────────────────────────────────────────────┤
│                    Consensus Layer                        │
│   ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐   │
│   │  Modified   │  │Probabilistic│  │ Byzantine Fault │   │
│   │  Tendermint │  │  Finality   │  │     Tolerance   │   │
│   └─────────────┘  └─────────────┘  └─────────────────┘   │
├───────────────────────────────────────────────────────────┤
│                    Networking Layer                       │
│   ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐   │
│   │  P2P Mesh   │  │  Libp2p     │  │  Gossip Protocol│   │
│   │  Network    │  │  Subsystem  │  │  Implementation │   │
│   └─────────────┘  └─────────────┘  └─────────────────┘   │
├───────────────────────────────────────────────────────────┤
│                    Persistence Layer                      │
│   ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐   │
│   │  LevelDB    │  │ Merkleized  │  │  IAVL+ Tree     │   │
│   │  Storage    │  │   State     │  │  Implementation │   │
│   └─────────────┘  └─────────────┘  └─────────────────┘   │
└───────────────────────────────────────────────────────────┘

Application Layer

The Application Layer is responsible for transaction execution, state transitions, and business logic:

Key Components

  • Transaction Execution Engine: Processes and validates transactions according to the protocol rules
  • Smart Contract VM: Executes deterministic smart contracts with sandboxed execution environment
  • State Transition Engine: Manages the application state and applies state transitions based on transaction results
  • Module System: Pluggable modules for specific functionality (staking, governance, etc.)

The Application Layer communicates with the Consensus Layer through the Application Blockchain Interface (ABI), which provides a standardized way for the consensus engine to deliver transactions to the application and receive results.

Consensus Layer

The Consensus Layer ensures that all nodes in the network agree on the state of the blockchain:

Key Components

  • Modified Tendermint BFT: ChainOS uses a modified version of Tendermint Byzantine Fault Tolerance consensus with optimizations for higher throughput
  • Validator Set Management: Manages the active set of validators based on stake and performance
  • Block Production: Coordinates the creation and validation of new blocks
  • Finality Gadget: Provides fast probabilistic finality (4.5 seconds) with eventual absolute finality

The consensus mechanism can tolerate up to 1/3 of validators being Byzantine (malicious or faulty) while still maintaining safety and liveness properties.

Consensus Optimizations

ChainOS has implemented several optimizations to the consensus layer that enable 2.37-second block times and up to 8,750 transactions per second:

  • Parallel transaction validation
  • Optimized signature verification with batch processing
  • Pipelined block production and propagation
  • Adaptive gossip protocol for efficient block distribution

Networking Layer

The Networking Layer facilitates communication between nodes in the network:

Key Components

  • P2P Mesh Network: Connects nodes in a resilient peer-to-peer topology
  • Libp2p Subsystem: Provides transport, discovery, and routing capabilities
  • Gossip Protocol: Efficiently propagates blocks, transactions, and consensus messages
  • Connection Management: Handles peer discovery, connection establishment, and maintenance

The networking layer includes optimizations for reducing latency and maximizing throughput, such as prioritized message queues, adaptive peer selection, and bandwidth management.

Persistence Layer

The Persistence Layer handles data storage and retrieval:

Key Components

  • LevelDB Storage: Fast key-value store for blockchain data
  • Merkleized State: Efficient state representation with cryptographic verification
  • IAVL+ Tree: Optimized Merkle tree implementation for state storage
  • Pruning System: Manages historical data retention and state pruning

The persistence layer is designed for high performance and data integrity, with optimizations for both read and write operations.

Node Types

ChainOS supports several types of nodes with different roles in the network:

Validator Nodes

Validator nodes participate in consensus by proposing and validating blocks:

Full Nodes

Full nodes maintain a complete copy of the blockchain but do not participate in consensus:

Archive Nodes

Archive nodes maintain the complete historical state of the blockchain:

Light Clients

Light clients provide minimal functionality for resource-constrained environments:

Transaction Flow

The following diagram illustrates the flow of a transaction through the ChainOS architecture:

┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐     ┌─────────┐
│  Client  │────▶│  Mempool │────▶│ Consensus│────▶│   Block  │────▶│  State   │
│          │     │          │     │  Engine  │     │ Producer │     │ Transition│
└─────────┘     └─────────┘     └─────────┘     └─────────┘     └─────────┘
     │                                                                 │
     │                                                                 │
     │                                                                 ▼
     │                                                           ┌─────────┐
     │                                                           │ Commit  │
     │                                                           │         │
     │                                                           └─────────┘
     │                                                                 │
     ▼                                                                 │
┌─────────┐                                                            │
│ Response│◀───────────────────────────────────────────────────────────┘
│         │
└─────────┘
  1. Transaction Creation: A client creates and signs a transaction
  2. Mempool Submission: The transaction is submitted to a node's mempool
  3. Mempool Validation: Basic validation checks are performed
  4. Consensus Processing: The consensus engine selects transactions for inclusion in a block
  5. Block Production: A validator proposes a block containing the transaction
  6. Block Validation: Other validators verify the block
  7. State Transition: The transaction is executed, and state changes are applied
  8. Commit: The new state is committed to the database
  9. Response: The client receives confirmation of the transaction

Consensus Mechanism

ChainOS uses a modified Tendermint BFT consensus algorithm with several optimizations:

Consensus Rounds

Each block production cycle consists of several steps:

  1. Propose: The designated proposer creates and broadcasts a block proposal
  2. Prevote: Validators vote on whether the proposal is valid
  3. Precommit: If 2/3+ of validators prevote for the same block, they precommit to it
  4. Commit: If 2/3+ of validators precommit to the same block, it is committed

Consensus Performance

  • Block Time: 2.37 seconds average
  • Finality Time: 4.5 seconds
  • Transaction Throughput: Up to 8,750 TPS
  • Fault Tolerance: Can withstand up to 1/3 of validators being Byzantine

Validator Selection

ChainOS uses a Delegated Proof of Stake (DPoS) mechanism for validator selection:

State Management

ChainOS uses a sophisticated state management system to maintain the blockchain state:

State Structure

The state is organized as a Merkleized key-value store with the following properties:

State Pruning

To manage storage requirements, ChainOS implements several pruning strategies:

Security Model

ChainOS implements a comprehensive security model to protect the network:

Cryptographic Primitives

Economic Security

Scalability Approach

ChainOS addresses scalability through several approaches:

Horizontal Scaling

Future Scaling Solutions

The ChainOS roadmap includes several advanced scaling solutions:

Developer Resources

For more detailed information about the ChainOS architecture, check out these resources: