|
| 1 | +# GitHub Copilot Instructions for Mina Rust Repository |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Mina is a Rust implementation of the Mina Protocol, a lightweight blockchain |
| 6 | +using zero-knowledge proofs. It follows a Redux-style state machine architecture |
| 7 | +for predictable, debuggable behavior. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +### State Machine Pattern |
| 12 | + |
| 13 | +The codebase follows Redux principles: |
| 14 | + |
| 15 | +- **State** - Centralized, immutable data structure |
| 16 | +- **Actions** - Events that trigger state changes |
| 17 | +- **Enabling Conditions** - Guards that prevent invalid state transitions |
| 18 | +- **Reducers** - Functions that update state and dispatch new actions |
| 19 | +- **Effects** - Thin wrappers for service calls |
| 20 | +- **Services** - Separate threads handling I/O and heavy computation |
| 21 | + |
| 22 | +### Key Components |
| 23 | + |
| 24 | +- **node/** - Main node logic (block production, transaction pool, consensus) |
| 25 | +- **p2p/** - Networking layer (libp2p and WebRTC transports) |
| 26 | +- **snark/** - Proof verification orchestration |
| 27 | +- **ledger/** - Ledger implementation and transaction logic |
| 28 | +- **core/** - Shared types and utilities |
| 29 | + |
| 30 | +## Code Patterns |
| 31 | + |
| 32 | +### File Organization |
| 33 | + |
| 34 | +- `*_state.rs` - State definitions |
| 35 | +- `*_actions.rs` - Action types |
| 36 | +- `*_reducer.rs` - State transitions |
| 37 | +- `*_effects.rs` - Service interactions |
| 38 | +- `*_service.rs` - Service interfaces |
| 39 | + |
| 40 | +### Defensive Programming |
| 41 | + |
| 42 | +- Use `bug_condition!` macro for theoretically unreachable code paths |
| 43 | +- Always add enabling condition checks before state transitions |
| 44 | +- Extract complex logic from reducers into state methods |
| 45 | + |
| 46 | +## Development Workflow |
| 47 | + |
| 48 | +### Before Making Changes |
| 49 | + |
| 50 | +1. Understand the Redux-style architecture |
| 51 | +2. Identify the correct component and layer for your changes |
| 52 | +3. Check existing patterns in similar files |
| 53 | +4. Run tests to understand current behavior |
| 54 | + |
| 55 | +### Code Changes |
| 56 | + |
| 57 | +1. Make minimal, surgical modifications |
| 58 | +2. Follow existing patterns and conventions |
| 59 | +3. Update documentation if directly related to changes |
| 60 | +4. Preserve working functionality |
| 61 | + |
| 62 | +### Formatting and Quality |
| 63 | + |
| 64 | +**MANDATORY before any commit:** |
| 65 | + |
| 66 | +```bash |
| 67 | +# Format Rust and TOML files |
| 68 | +make format |
| 69 | + |
| 70 | +# Format markdown and MDX files |
| 71 | +make format-md |
| 72 | + |
| 73 | +# Fix trailing whitespaces (CRITICAL) |
| 74 | +make fix-trailing-whitespace |
| 75 | + |
| 76 | +# Verify formatting |
| 77 | +make check-format |
| 78 | +make check-md |
| 79 | +make check-trailing-whitespace |
| 80 | +``` |
| 81 | + |
| 82 | +### Testing |
| 83 | + |
| 84 | +```bash |
| 85 | +# Run all tests |
| 86 | +make test |
| 87 | + |
| 88 | +# Run specific test suites |
| 89 | +make test-p2p |
| 90 | +make test-ledger |
| 91 | +make nextest # Faster test execution |
| 92 | + |
| 93 | +# Build project |
| 94 | +make build |
| 95 | +make build-release |
| 96 | +``` |
| 97 | + |
| 98 | +### Documentation |
| 99 | + |
| 100 | +- Update `CHANGELOG.md` for significant user-facing changes |
| 101 | +- Use format: `- **Category**: Description ([#PR](github-link))` |
| 102 | +- Component docs are in individual `summary.md` files |
| 103 | +- Website docs are in `website/docs/` |
| 104 | + |
| 105 | +## Commit Guidelines |
| 106 | + |
| 107 | +**CRITICAL RULES:** |
| 108 | + |
| 109 | +- **NEVER** add any AI assistant as co-author in commit messages |
| 110 | +- **NEVER** use emojis in commit messages |
| 111 | +- **ALWAYS** wrap commit titles at 80 characters |
| 112 | +- **ALWAYS** run `make fix-trailing-whitespace` before committing |
| 113 | + |
| 114 | +### Commit Message Format |
| 115 | + |
| 116 | +``` |
| 117 | +Brief description of change (80 chars max) |
| 118 | +
|
| 119 | +Longer description if needed, wrapped at 80 characters. |
| 120 | +Reference issues/PRs when relevant. |
| 121 | +``` |
| 122 | + |
| 123 | +## Code Style |
| 124 | + |
| 125 | +### Rust Code |
| 126 | + |
| 127 | +- Follow existing `rustfmt` configuration |
| 128 | +- Use `clippy` suggestions: `make lint` |
| 129 | +- Prefer explicit error handling over panics |
| 130 | +- Use descriptive variable names |
| 131 | +- Add comments only when they add value beyond the code |
| 132 | + |
| 133 | +### Documentation Style |
| 134 | + |
| 135 | +- Use lowercase for section headings ("test design", "resource management") |
| 136 | +- Use lowercase for bullet point labels |
| 137 | +- Wrap Docusaurus admonitions with prettier-ignore comments: |
| 138 | + |
| 139 | + ```mdx |
| 140 | + <!-- prettier-ignore-start --> |
| 141 | + |
| 142 | + :::note Content here ::: |
| 143 | + |
| 144 | + <!-- prettier-ignore-stop --> |
| 145 | + ``` |
| 146 | + |
| 147 | +## Common Tasks |
| 148 | + |
| 149 | +### Adding New Features |
| 150 | + |
| 151 | +1. Define actions in appropriate `*_actions.rs` |
| 152 | +2. Add state transitions in `*_reducer.rs` |
| 153 | +3. Implement effects in `*_effects.rs` if needed |
| 154 | +4. Add service methods in `*_service.rs` if needed |
| 155 | +5. Update tests and documentation |
| 156 | + |
| 157 | +### Debugging |
| 158 | + |
| 159 | +- Use existing test scenarios in `node/testing/` |
| 160 | +- Check component `summary.md` files for known issues |
| 161 | +- Follow the Redux flow: Action → Reducer → Effect → Service |
| 162 | + |
| 163 | +### Dependencies |
| 164 | + |
| 165 | +- Update `Cargo.toml` files carefully |
| 166 | +- Run `make check` after dependency changes |
| 167 | +- Consider impact on WebAssembly build (`make build-wasm`) |
| 168 | + |
| 169 | +## Important Files |
| 170 | + |
| 171 | +- `node/src/state.rs` - Global state structure |
| 172 | +- `node/src/action.rs` - Top-level action enum |
| 173 | +- `node/src/reducer.rs` - Main reducer dispatch |
| 174 | +- `Makefile` - Build and development commands |
| 175 | +- `CLAUDE.md` - Comprehensive codebase navigation guide |
| 176 | +- `ARCHITECTURE.md` - Migration guide for old vs new style |
| 177 | + |
| 178 | +## Resources |
| 179 | + |
| 180 | +- Architecture docs: `docs/handover/` |
| 181 | +- Component docs: Find `summary.md` in component directories |
| 182 | +- Website: `make docs-serve` (http://localhost:3000) |
| 183 | +- Build commands: `make help` |
| 184 | + |
| 185 | +Remember: This is a complex blockchain implementation. Take time to understand |
| 186 | +the Redux architecture and existing patterns before making changes. |
0 commit comments