|
| 1 | +# OpenMina Handover Documentation |
| 2 | + |
| 3 | +This directory contains comprehensive documentation for understanding and working with the OpenMina codebase. The documents are designed to provide a structured onboarding experience for developers new to the project. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### 👋 New to OpenMina? |
| 8 | +**Start here**: [Architecture Walkthrough](architecture-walkthrough.md) → [State Machine Structure](state-machine-structure.md) → [State Machine Patterns](state-machine-patterns.md) → [Project Organization](organization.md) |
| 9 | + |
| 10 | +### 🔍 Looking for Something Specific? |
| 11 | +- **Add new features**: [State Machine Development Guide](state-machine-development-guide.md) - includes quick reference checklists |
| 12 | +- **Add RPC endpoints**: [Adding RPC Endpoints](adding-rpc-endpoints.md) - HTTP routing and service patterns |
| 13 | +- **Testing framework**: [Testing Infrastructure](testing-infrastructure.md) - scenario-based testing with extensive examples |
| 14 | +- **Ledger implementation overview**: [Ledger Crate](ledger-crate.md) - OCaml port with Rust adaptations |
| 15 | +- **Service integration**: [Services](services.md) - complete service inventory and patterns |
| 16 | + |
| 17 | +### 📚 Quick Reference |
| 18 | +- **Architecture**: Redux pattern, actions, reducers, effects - see [Glossary](#glossary-of-key-terms) for definitions |
| 19 | +- **Services**: External I/O, threading, event-driven communication - see [Services](services.md) for complete inventory |
| 20 | +- **Technical Debt**: [Services](services-technical-debt.md) (blocking operations, error handling) | [State Machine](state-machine-technical-debt.md) (architecture migration, anti-patterns) |
| 21 | +- **Testing**: Scenario-based, multi-node simulation, fuzzing - see [Testing Infrastructure](testing-infrastructure.md) for extensive test scenarios |
| 22 | + |
| 23 | +## Document Overview |
| 24 | + |
| 25 | +- [Architecture Walkthrough](#architecture-walkthrough) |
| 26 | +- [State Machine Structure](#state-machine-structure) |
| 27 | +- [State Machine Patterns](#state-machine-patterns) |
| 28 | +- [Project Organization](#project-organization) |
| 29 | +- [Services](#services) |
| 30 | +- [Ledger Crate](#ledger-crate) |
| 31 | +- [Testing Infrastructure](#testing-infrastructure) |
| 32 | +- [State Machine Development Guide](#state-machine-development-guide) |
| 33 | +- [State Machine Debugging Guide](#state-machine-debugging-guide) |
| 34 | +- [Adding RPC Endpoints](#adding-rpc-endpoints) |
| 35 | +- [Fuzzing Infrastructure](#fuzzing-infrastructure) |
| 36 | +- [Services Technical Debt](#services-technical-debt) |
| 37 | +- [State Machine Technical Debt](#state-machine-technical-debt) |
| 38 | +- [Circuits](#circuits) |
| 39 | +- [Debug Block Proof Generation](#debug-block-proof-generation) |
| 40 | +- [Persistence](#persistence) |
| 41 | +- [Mainnet Readiness](#mainnet-readiness) |
| 42 | +- [Release Process](#release-process) |
| 43 | +- [Component Summaries](#component-summaries) |
| 44 | +- [Git Workflow](#git-workflow) |
| 45 | +- [P2P Evolution Plan](#p2p-evolution-plan) |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +### [Architecture Walkthrough](architecture-walkthrough.md) |
| 50 | +**Start here** - Provides a high-level overview of the OpenMina architecture, including: |
| 51 | +- Architecture philosophy and design principles |
| 52 | +- Redux-style state machine architecture |
| 53 | +- Core concepts (actions, enabling conditions, reducers, effects) |
| 54 | +- Network configuration system (devnet/mainnet) |
| 55 | +- Key component overview |
| 56 | +- Development guidelines |
| 57 | + |
| 58 | +### [State Machine Structure](state-machine-structure.md) |
| 59 | +Deep dive into the state machine implementation details: |
| 60 | +- Action types and hierarchies |
| 61 | +- Reducer patterns (new vs old style) |
| 62 | +- Substate contexts and access control |
| 63 | +- Callback systems |
| 64 | +- Migration from old to new architecture |
| 65 | + |
| 66 | +### [State Machine Patterns](state-machine-patterns.md) |
| 67 | +Analysis of common patterns across OpenMina's state machines: |
| 68 | +- Lifecycle Pattern (Init/Pending/Success/Error) - Most common for async operations |
| 69 | +- Request/Response Pattern - For communication-heavy components |
| 70 | +- Custom Domain-Specific Patterns - For complex workflows |
| 71 | +- Pattern selection guide and implementation best practices |
| 72 | + |
| 73 | +### [Project Organization](organization.md) |
| 74 | +Overview of the codebase structure and component purposes: |
| 75 | +- Entry points and CLI structure |
| 76 | +- Major components (node, p2p, snark, ledger) |
| 77 | +- Supporting libraries and cryptographic primitives |
| 78 | +- Development tools and utilities |
| 79 | +- Dependency hierarchy |
| 80 | + |
| 81 | +### [Services](services.md) |
| 82 | +Detailed documentation of all system services: |
| 83 | +- Service architecture principles |
| 84 | +- Complete inventory of services |
| 85 | +- Service trait definitions vs implementations |
| 86 | +- Threading and communication patterns |
| 87 | +- Service lifecycle management |
| 88 | + |
| 89 | +### [Ledger Crate](ledger-crate.md) |
| 90 | +High-level overview of the ledger implementation: |
| 91 | +- Direct port from OCaml with Rust adaptations |
| 92 | +- Core components (BaseLedger, Mask, Database) |
| 93 | +- Transaction processing and validation |
| 94 | +- Proof system integration |
| 95 | +- Future refactoring plans |
| 96 | + |
| 97 | +### [Testing Infrastructure](testing-infrastructure.md) |
| 98 | +Comprehensive testing approaches and tools: |
| 99 | +- Scenario-based testing |
| 100 | +- Multi-node simulation |
| 101 | +- Fuzz testing and differential testing |
| 102 | +- Debugging capabilities |
| 103 | +- Testing best practices |
| 104 | + |
| 105 | +### [State Machine Development Guide](state-machine-development-guide.md) |
| 106 | +Practical guide for implementing features with Redux patterns: |
| 107 | +- Making changes to existing components |
| 108 | +- Adding new state machines and actions |
| 109 | +- Component communication patterns |
| 110 | + |
| 111 | +### [State Machine Debugging Guide](state-machine-debugging-guide.md) |
| 112 | +Comprehensive troubleshooting and investigation tools: |
| 113 | +- ActionEvent macro and structured logging |
| 114 | +- Recording, replay, and testing frameworks |
| 115 | +- Common error patterns and solutions |
| 116 | + |
| 117 | +### [Adding RPC Endpoints](adding-rpc-endpoints.md) |
| 118 | +Focused guide for RPC-specific implementation patterns: |
| 119 | +- RPC request/response type system |
| 120 | +- HTTP routing with Warp framework |
| 121 | +- Service interface integration |
| 122 | +- WASM API exposure patterns |
| 123 | + |
| 124 | +### [Fuzzing Infrastructure](fuzzing.md) |
| 125 | +Basic fuzzing infrastructure for transaction processing (documentation incomplete): |
| 126 | +- Differential testing setup against OCaml implementation |
| 127 | +- Limited mutation strategies and reproduction capabilities |
| 128 | +- Basic debugging tools for fuzzer |
| 129 | +- Note: Document is incomplete and contains unverified claims |
| 130 | + |
| 131 | +### [Services Technical Debt](services-technical-debt.md) |
| 132 | +Analysis of technical debt in the services layer: |
| 133 | +- Service-by-service debt inventory |
| 134 | +- Cross-cutting concerns (error handling, blocking operations) |
| 135 | +- Prioritized recommendations for improvements |
| 136 | +- Critical issues including intentional panics and synchronous operations |
| 137 | + |
| 138 | +### [State Machine Technical Debt](state-machine-technical-debt.md) |
| 139 | +Systemic architectural issues in state machine implementations: |
| 140 | +- Architecture migration status (old vs new style) |
| 141 | +- Anti-patterns and monolithic reducers |
| 142 | +- Enabling conditions and service integration issues |
| 143 | +- Safety and linting improvements (including clippy lints) |
| 144 | +- Prioritized refactoring roadmap |
| 145 | + |
| 146 | +### [Circuits](circuits.md) |
| 147 | +Circuit generation process and distribution: |
| 148 | +- Circuit generation requires OCaml (OpenMina fork) |
| 149 | +- Circuit blob repository and GitHub releases |
| 150 | +- On-demand downloading and caching system |
| 151 | +- Network-specific circuit configuration |
| 152 | +- Verifier index loading and validation |
| 153 | + |
| 154 | +### [Debug Block Proof Generation](debug-block-proof-generation.md) |
| 155 | +Technical procedure for debugging failed block proofs: |
| 156 | +- Decrypting and preparing failed proof dumps |
| 157 | +- Running proof generation in both Rust and OCaml |
| 158 | +- Comparing outputs for debugging discrepancies |
| 159 | + |
| 160 | +### [Persistence](persistence.md) |
| 161 | +Design for ledger persistence (not yet implemented): |
| 162 | +- Memory reduction strategy for mainnet scale |
| 163 | +- Fast restart capabilities |
| 164 | +- SNARK verification result caching |
| 165 | +- Critical for webnode browser constraints |
| 166 | + |
| 167 | +### [Mainnet Readiness](mainnet-readiness.md) |
| 168 | +Requirements and gaps for mainnet deployment: |
| 169 | +- Critical missing features (persistence, wide merkle queries) |
| 170 | +- Security audit requirements and error sink service integration |
| 171 | +- Protocol compliance gaps |
| 172 | +- Webnode-specific requirements |
| 173 | +- Future compatibility considerations |
| 174 | +- Rollout plan with testing requirements and deployment phases |
| 175 | + |
| 176 | +### [Release Process](release-process.md) |
| 177 | +Comprehensive release workflow: |
| 178 | +- Monthly release cadence during active development |
| 179 | +- Version management across all Cargo.toml files |
| 180 | +- Changelog and Docker image updates |
| 181 | +- CI/CD automation for multi-architecture builds |
| 182 | + |
| 183 | +### [Component Summaries](component-summaries.md) |
| 184 | +Tree view of all component technical debt documentation: |
| 185 | +- Complete hierarchy of summary.md files |
| 186 | +- Links to refactoring plans where available |
| 187 | +- Organized by node, p2p, and snark subsystems |
| 188 | + |
| 189 | +### [Git Workflow](git-workflow.md) |
| 190 | +Git workflow and pull request policy used in the repository: |
| 191 | +- Branch naming conventions and management |
| 192 | +- PR development workflow and commit squashing policy |
| 193 | +- Merge strategy and best practices |
| 194 | +- Commit message format and examples |
| 195 | + |
| 196 | +### [P2P Evolution Plan](p2p-evolution.md) |
| 197 | +Evolution plan for Mina's P2P networking layer: |
| 198 | +- Unified pull-based P2P design for the entire Mina ecosystem |
| 199 | +- Current dual P2P architecture challenges (WebRTC + libp2p) |
| 200 | +- Four-phase implementation strategy with QUIC transport integration |
| 201 | +- Migration from libp2p to unified protocol across OCaml and Rust nodes |
| 202 | +- Requires coordination with OCaml Mina team for ecosystem adoption |
| 203 | + |
| 204 | +## Recommended Reading Order |
| 205 | + |
| 206 | +### For New Developers |
| 207 | +- **Architecture Walkthrough** - Get the big picture |
| 208 | +- **State Machine Structure** - Learn the core programming model |
| 209 | +- **State Machine Patterns** - Understand common patterns and when to use them |
| 210 | +- **Project Organization** - Understand the codebase layout |
| 211 | +- **Services** - Understand external interactions |
| 212 | +- **State Machine Development Guide** - Learn practical development patterns |
| 213 | +- **Adding RPC Endpoints** - Learn to implement new API endpoints |
| 214 | +- **Testing Infrastructure** - Learn how to test your changes |
| 215 | +- **State Machine Technical Debt** - Understand known architectural issues and ongoing improvements |
| 216 | + |
| 217 | +### For Protocol Developers |
| 218 | +- **Architecture Walkthrough** - Understand the system design |
| 219 | +- **Ledger Crate** - High-level overview of ledger implementation |
| 220 | +- **State Machine Structure** - Learn state management patterns |
| 221 | +- **Services** - Understand proof verification and block production |
| 222 | +- **Services Technical Debt** - Be aware of service layer limitations |
| 223 | + |
| 224 | +### For Quick Reference |
| 225 | +- **Project Organization** - Find where components are located |
| 226 | +- **Services** - Look up specific service interfaces |
| 227 | +- **State Machine Structure** - Reference for action/reducer patterns |
| 228 | +- **Technical Debt Documents** - Check current known issues and planned improvements |
| 229 | + |
| 230 | +## Glossary of Key Terms |
| 231 | + |
| 232 | +### Core Architecture Terms |
| 233 | + |
| 234 | +**Redux Pattern** - State management architecture where all state changes happen through actions processed by reducers. Provides predictable state updates and easy debugging. |
| 235 | + |
| 236 | +**Action** - Data structure representing a state change request. Can be stateful (handled by reducers) or effectful (handled by effects). |
| 237 | + |
| 238 | +**Reducer** - Pure function that takes current state and an action, returns new state. In new-style components, also handles action dispatching. |
| 239 | + |
| 240 | +**Effect** - Side-effect handler that interacts with external services. Should be thin wrappers around service calls. |
| 241 | + |
| 242 | +**Enabling Condition** - Function that determines if an action is valid in the current state. Prevents invalid state transitions. |
| 243 | + |
| 244 | +**State Machine** - Component that manages a specific domain's state through actions and reducers (e.g., P2P, block producer). |
| 245 | + |
| 246 | +**Stateful Action** - Action that modifies state and is processed by reducers. |
| 247 | + |
| 248 | +**Effectful Action** - Action that triggers side effects (service calls) and is processed by effects. |
| 249 | + |
| 250 | +### State Management Terms |
| 251 | + |
| 252 | +**Substate** - Abstraction that gives components access to their specific portion of global state without coupling to global state structure. |
| 253 | + |
| 254 | +**Dispatcher** - Interface for dispatching new actions from within reducers. |
| 255 | + |
| 256 | +**Callback** - Mechanism for components to respond to async operations without tight coupling. |
| 257 | + |
| 258 | +**bug_condition!** - Macro for defensive programming that marks code paths that should be unreachable if enabling conditions work correctly. |
| 259 | + |
| 260 | +### Service Architecture Terms |
| 261 | + |
| 262 | +**Service** - Component that handles external I/O, heavy computation, or async operations. Runs in separate threads. |
| 263 | + |
| 264 | +**Event** - Result from a service operation that gets converted to an action and fed back to the state machine. |
| 265 | + |
| 266 | +**EventSource** - Central service that aggregates events from all other services and forwards them to the state machine. |
| 267 | + |
| 268 | +**Deterministic Execution** - Principle that given the same inputs, the system behaves identically. Achieved by isolating non-determinism to services. |
| 269 | + |
| 270 | +### Development Terms |
| 271 | + |
| 272 | +**New Style** - Current architecture pattern with unified reducers that handle both state updates and action dispatching. |
| 273 | + |
| 274 | +**Old Style** - Legacy architecture pattern with separate reducer and effects files. Still used in transition frontier. For migration instructions, see [ARCHITECTURE.md](../../ARCHITECTURE.md). |
| 275 | + |
| 276 | +**Component** - Self-contained state machine handling a specific domain (e.g., transaction pool, P2P networking). |
| 277 | + |
| 278 | +**Summary.md** - File in each component directory documenting purpose, technical debt, and implementation notes. |
| 279 | + |
| 280 | +**ActionEvent** - Derive macro that generates structured logging for actions. |
| 281 | + |
| 282 | +### Network and Protocol Terms |
| 283 | + |
| 284 | +**Network Configuration** - System supporting multiple networks (devnet/mainnet) with different parameters. |
| 285 | + |
| 286 | +**OCaml Compatibility** - Many components are direct ports from the OCaml Mina implementation. |
| 287 | + |
| 288 | +**P2P** - Peer-to-peer networking layer using libp2p with custom WebRTC transport. |
| 289 | + |
| 290 | +**SNARK** - Zero-knowledge proof system used for blockchain verification. |
| 291 | + |
| 292 | +**Ledger** - Blockchain account state management system. |
| 293 | + |
| 294 | +**Transition Frontier** - Core consensus and blockchain state management component. |
| 295 | + |
| 296 | +### Testing Terms |
| 297 | + |
| 298 | +**Scenario** - Structured test case that can be recorded, saved, and replayed deterministically. |
| 299 | + |
| 300 | +**Recording/Replay** - System for capturing execution traces and replaying them exactly for debugging. |
| 301 | + |
| 302 | +**Differential Testing** - Comparing OpenMina behavior against the OCaml implementation. |
| 303 | + |
| 304 | +**Fuzzing** - Automated testing with random inputs to find edge cases. |
| 305 | + |
| 306 | +## Key Concepts to Understand |
| 307 | + |
| 308 | +Before diving into the documentation, familiarize yourself with these core concepts: |
| 309 | + |
| 310 | +1. **Redux Pattern** - State management through actions and reducers |
| 311 | +2. **Deterministic Execution** - Separation of pure state logic from side effects |
| 312 | +3. **Network Configuration** - Support for multiple networks (devnet/mainnet) with different parameters |
| 313 | +4. **OCaml Compatibility** - Many components are direct ports from the OCaml implementation |
| 314 | +5. **Service Architecture** - External interactions handled by services, not state machines |
| 315 | + |
| 316 | +## Additional Resources |
| 317 | + |
| 318 | +- **Source Code Comments** - Many modules have detailed inline documentation |
| 319 | +- **Summary Files** - Look for `summary.md` files in component directories for technical debt and implementation notes |
| 320 | +- **P2P WebRTC Documentation** - See [p2p/readme.md](../../p2p/readme.md) for details on the WebRTC implementation |
| 321 | +- **Technical Debt Analysis** - See the technical debt documents for comprehensive analysis of known issues |
| 322 | + |
0 commit comments