This file helps understand and navigate the Mina codebase structure.
Mina is a Rust implementation of the Mina Protocol, a lightweight blockchain using zero-knowledge proofs. It follows a Redux-style state machine architecture for predictable, debuggable behavior.
For detailed architecture documentation, see
docs/handover/
The codebase follows Redux principles:
- State - Centralized, immutable data structure
- Actions - Events that trigger state changes
- Enabling Conditions - Guards that prevent invalid state transitions
- Reducers - Functions that update state and dispatch new actions
- Effects - Thin wrappers for service calls
- Services - Separate threads handling I/O and heavy computation
- New Style: Unified reducers that handle both state updates and action dispatch
- Old Style: Separate reducer and effects files (being migrated)
node/ - Main node logic
block_producer/- Block productiontransaction_pool/- Transaction mempooltransition_frontier/- Consensus and blockchain statesnark_pool/- SNARK work managementledger/- Ledger operationsrpc/- External APIevent_source/- Event routingservice/- Service implementations
p2p/ - Networking layer
- Dual transport: libp2p and WebRTC
- Channel abstractions for message types
- Peer discovery and connection management
snark/ - Proof verification orchestration
ledger/ - Ledger implementation, transaction logic, core transaction pool logic, staged ledger, scan state, and proof verification
core/ - Shared types and utilities
*_state.rs- State definitions*_actions.rs- Action types*_reducer.rs- State transitions*_effects.rs- Service interactions*_service.rs- Service interfacessummary.md- Component documentation and technical debt notes
node/src/state.rs- Global state structurenode/src/action.rs- Top-level action enumnode/src/reducer.rs- Main reducer dispatch
- Actions flow through the system as events
- Enabling conditions check if actions are valid
- Reducers process actions to update state
- Effects trigger service calls when needed
- Services handle async operations and send events back
bug_condition!macro marks theoretically unreachable code paths- Used after enabling condition checks for invariant validation
- Complex logic extracted from reducers into state methods
- Keeps reducers focused on orchestration
- Enable decoupled component communication
- Used for async operation completion
# Find specific actions
rg "YourAction" --type rust
# Find reducers
rg "reducer.*Substate" --type rust
# Find services
rg "impl.*Service" --type rust
# Check component documentation
find . -name "summary.md" -path "*/component/*"Each component directory contains a summary.md file documenting:
- Component purpose and responsibilities
- Known technical debt
- Implementation notes
- Refactoring plans
Mina includes a comprehensive documentation website built with Docusaurus:
# Start local documentation server
make docs-serve
# Build documentation
make docs-build
# Other documentation commands
make help | grep docsThe website is available at http://localhost:3000 when running locally.
- Node Runners (
website/docs/node-runners/) - Installation and operation guides - Developers (
website/docs/developers/) - Architecture and contribution guides - Researchers (
website/docs/researchers/) - Protocol and cryptography documentation
- Create markdown files in the appropriate
website/docs/subdirectory - Add frontmatter with title, description, and sidebar position
- Update
website/sidebars.tsif needed for navigation
The website supports versioning and will be automatically deployed when commits
are made to develop or when tags are created.
The Rust codebase maintains references to the corresponding OCaml implementation to track correspondence and detect when updates are needed.
Comment format:
/// OCaml: <https://github.com/MinaProtocol/mina/blob/5da42ccd72e791f164d4d200cf1ce300262873b3/src/lib/mina_base/transaction_status.ml#L9-L51>
pub enum TransactionFailure {
// ...
}Validation:
# Check all OCaml references
./.github/scripts/check-ocaml-refs.sh
# Update stale commit hashes
./.github/scripts/check-ocaml-refs.sh --update
# Check against specific branch
./.github/scripts/check-ocaml-refs.sh --branch developThe validation script verifies that referenced OCaml files exist, line ranges are valid, code at the referenced commit matches the current branch, and tracks commit staleness. A GitHub Actions workflow runs weekly to automatically update references and create PRs.
docs/handover/- Comprehensive architecture documentationARCHITECTURE.md- Migration guide for old vs new style- Component-specific
summary.mdfiles throughout the codebase website/- Docusaurus documentation website
This section contains specific instructions for Claude when working on this project.
After making any code modifications, run the appropriate formatting commands:
- Format: Run
make format-mdafter modifying any markdown (.md) or MDX (.mdx) files - Check: Run
make check-mdto verify markdown and MDX files are formatted correctly
- Format: Run
make formatafter modifying any Rust (.rs) or TOML (.toml) files - Check: Run
make check-formatto verify Rust and TOML files are formatted correctly
NEVER add Claude as a co-author in commit messages. Do not include:
Co-Authored-By: Claude <noreply@anthropic.com>- Any other co-author attribution for Claude
NEVER use emojis in commit messages.
Always wrap commit message titles at 80 characters and body text at 80 characters.
Always verify commit messages before committing and remove any co-author lines referencing Claude.
- Make your code changes
- Run the appropriate formatting command based on file types modified
- ALWAYS run
make fix-trailing-whitespacebefore committing or ending any task - Verify formatting with check commands if needed
- Verify commit message does not include Claude as co-author
- Verify commit message contains no emojis and follows 80-character wrap
- Proceed with testing or committing changes
When adding scripts to documentation, always use Docusaurus CodeBlock imports:
import CodeBlock from "@theme/CodeBlock";
import ScriptName from "!!raw-loader!./path/to/script.sh";
<CodeBlock language="bash" title="path/to/script.sh">
{ScriptName}
</CodeBlock>This ensures scripts are displayed accurately and stay in sync with the actual files.
Capitalization in headings and bullet points:
- Use lowercase for section headings (e.g., "Test design", "Resource management")
- Use lowercase for bullet point labels (e.g., "Connection policies", "State inspection")
- Maintain proper capitalization for proper nouns and technical terms
- Apply this style consistently across all documentation files
Docusaurus admonitions (:::note, :::caution, :::info, etc.):
-
Always wrap Docusaurus admonitions with
<!-- prettier-ignore-start -->and<!-- prettier-ignore-stop -->comments -
This prevents prettier from reformatting the admonition blocks
-
Example:
<!-- prettier-ignore-start --> :::note Content of the note here ::: <!-- prettier-ignore-stop -->
When modifying developer setup scripts in website/docs/developers/scripts/,
always test them using the documentation testing workflow:
The project includes automated testing of developer setup scripts to ensure they work correctly across different platforms. This prevents developers from encountering broken installation instructions.
When to test:
- After modifying any script in
website/docs/developers/scripts/setup/ - When adding new dependencies or tools to the setup process
- When changing installation procedures
- When adding support for a new distribution or platform
How to trigger tests:
- For PRs: Add the
test-doc-scriptslabel to your pull request - Manual testing: Use GitHub CLI:
gh pr edit <PR_NUMBER> --add-label test-doc-scripts - Remove and re-add: If tests need to be re-run, remove the label first:
gh pr edit <PR_NUMBER> --remove-label test-doc-scripts gh pr edit <PR_NUMBER> --add-label test-doc-scripts
What gets tested:
- System dependencies installation (Ubuntu/macOS)
- Rust toolchain setup (including taplo, wasm-pack, etc.)
- Node.js installation
- Docker installation
- Build processes and formatting tools
- Tool version verification
Why this matters:
- Ensures documentation stays current with actual requirements
- Prevents "command not found" errors for new developers
- Tests across multiple platforms (Ubuntu 22.04, 24.04, macOS)
- Catches environment drift and dependency changes
- Runs nightly to detect breaking changes early
The tests are designed to run on-demand via labels to avoid slowing down regular development workflow, as they can take significant time to complete.
When making significant changes that affect users or developers, update the CHANGELOG.md file:
The CHANGELOG follows Keep a Changelog format
with these sections under ## [Unreleased]:
- OCaml node - Changes related to OCaml node compatibility
- Added - New features and functionality
- Changed - Changes to existing functionality
- Fixed - Bug fixes
- Dependencies - Dependency updates
- Use this format:
- **Category**: Description ([#PR](github-link)) - Wrap entries at 80 characters with proper indentation
- Categories include: CI, Build System, Documentation, Development Tools, etc.
- Always reference the PR number
- Commit message:
CHANGELOG: add entry for patch XXXX - Where XXXX is the PR number
- Keep the commit message simple and consistent with existing pattern
Example entry:
- **CI**: Generalized build jobs to support multiple platforms (Ubuntu 22.04,
Ubuntu 24.04, Ubuntu 24.04 ARM, macOS latest) and updated test execution to
ubuntu-latest ([#1249](https://github.com/o1-labs/openmina/pull/1249))When modifying CI workflows, especially for performance improvements:
-
Separate "builds for tests" from "builds for verification": Create dedicated single-platform build jobs that produce only the artifacts needed for testing. This allows tests to start as soon as required artifacts are available, not waiting for all cross-platform builds to complete.
-
Use selective dependencies: Instead of depending on matrix build jobs (which include all platforms), create specific build jobs that tests can depend on. For example:
# Before: Tests wait for all platforms needs: [build, build-tests] # Matrix across 7 platforms # After: Tests wait for specific artifact-producing builds needs: [build-for-tests, build-tests-for-tests] # Single platform
-
Maintain cross-platform coverage: Keep matrix builds for platform verification but don't let them block test execution. They should run in parallel for verification purposes.
-
Artifact consistency: Ensure dedicated build jobs produce the same artifact names that test jobs expect. Use patterns like
bin-${{ github.sha }}andtests-${{ github.sha }}consistently.
- Tests typically only need artifacts from ubuntu-22.04 builds (for container compatibility)
- macOS builds often take longest and shouldn't block Linux-based test execution
- Use ubuntu-22.04 for artifact production to ensure GLIBC compatibility with Debian-based test containers
- MANDATORY: Run
make fix-trailing-whitespacebefore every commit - MANDATORY: Run
make check-trailing-whitespaceto verify no trailing whitespaces remain - This applies to ALL file modifications, regardless of file type
- Trailing whitespaces are strictly prohibited in the codebase