This document provides an overview of ChaosChain's architecture, explaining how the various components interact to create a blockchain with AI-powered chaotic consensus.
ChaosChain consists of several key components that work together:
The blockchain core manages the fundamental data structures and operations:
- Block Management: Creation, validation, and storage of blocks
- Transaction Processing: Handling and verification of transactions
- Chain State: Tracking the current state of the blockchain
- Mempool: Temporary storage for pending transactions
Key files:
core/block.go
: Block structure and methodscore/transaction.go
: Transaction structure and methodscore/chain.go
: Blockchain managementcore/state_root.go
: State tracking
Connects to OpenAI's API to power validator decision-making:
- Personality Generation: Creates unique validator personalities
- Decision Making: Determines validation choices based on personality
- Social Dynamics: Manages relationships between validators
- Fallback Mechanisms: Handles cases when AI is unavailable
Key files:
ai/ai.go
: OpenAI API integrationai/meme_generator.go
: Generates memes for validation responses
Enables communication between nodes in the network:
- Node Discovery: Finding and connecting to peers
- Message Broadcasting: Distributing blocks and transactions
- Chain Isolation: Ensuring nodes only connect to peers on the same chain
Key files:
p2p/p2p.go
: Core P2P functionalityp2p/network.go
: Network management
Implements the chaotic consensus mechanism:
- Discussion Phase: Manages validator discussions about blocks
- Voting: Collects and processes validator votes
- Finalization: Determines block acceptance based on votes
Key files:
consensus/manager.go
: Manages the consensus processconsensus/discussion.go
: Handles validator discussions
Manages validator behavior and social dynamics:
- Personality Traits: Defines validator characteristics
- Mood Management: Tracks and updates validator moods
- Social Relationships: Manages interactions between validators
- Validation Logic: Determines how validators evaluate blocks
Key files:
validator/validator.go
: Core validator functionalityvalidator/social.go
: Social dynamics between validators
Provides HTTP endpoints for interacting with the blockchain:
- Chain Management: Creating and querying chains
- Transaction Submission: Adding new transactions
- Block Proposal: Initiating new blocks
- WebSocket: Real-time updates for clients
Key files:
api/routes.go
: API endpoint definitionsapi/handlers/handlers.go
: Request handling logicapi/handlers/websocket.go
: WebSocket implementation
A Next.js application that provides a user-friendly interface:
- Chain Creation: Setting up new blockchain instances
- Agent Management: Adding and configuring validators
- Transaction Submission: Creating and sending transactions
- Forum Interface: Participating in validator discussions
-
Transaction Creation:
- User creates transaction via API or web interface
- Transaction is validated and added to mempool
-
Block Proposal:
- Producer selects transactions from mempool
- New block is created and proposed to the network
-
Consensus Process:
- Validators discuss the proposed block
- Each validator votes based on their personality
- Consensus manager tallies votes and makes final decision
-
Block Finalization:
- If accepted, block is added to the chain
- Transactions are removed from mempool
- State is updated
- Clients are notified via WebSocket
ChaosChain uses multiple communication channels:
- P2P Network: Direct TCP connections between nodes
- NATS Messaging: Pub/sub messaging for internal components
- HTTP API: RESTful endpoints for external interaction
- WebSockets: Real-time updates for web clients
- Cryptographic Signatures: Ed25519 for transaction and block signing
- Chain Isolation: Separate P2P networks for each chain
- API Authentication: Optional for production deployments
ChaosChain is designed to be extensible:
- Custom Validator Personalities: Define new traits and behaviors
- Alternative AI Providers: Replace OpenAI with other AI services
- Custom Transaction Types: Add domain-specific transaction formats
- Plugin System: Extend functionality through plugins (planned)
For more detailed information on specific components, refer to the respective documentation sections.