|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Rollkit is a sovereign rollup framework built in Go that allows developers to build rollups on any DA layer. It provides a modular architecture where components like the data availability layer, executor, and sequencer can be plugged in. |
| 8 | + |
| 9 | +## Build and Development Commands |
| 10 | + |
| 11 | +### Building |
| 12 | +- `make build` - Builds the Testapp CLI to `./build/testapp` |
| 13 | +- `make install` - Installs Testapp CLI to your Go bin directory |
| 14 | +- `make build-all` - Builds all Rollkit binaries |
| 15 | +- `make docker-build` - Builds Docker image tagged as `rollkit:local-dev` |
| 16 | + |
| 17 | +### Testing |
| 18 | +- `make test` - Runs unit tests for all go.mod files |
| 19 | +- `make test-integration` - Runs integration tests (15m timeout) |
| 20 | +- `make test-e2e` - Runs end-to-end tests (requires building binaries first) |
| 21 | +- `make test-cover` - Generates code coverage report |
| 22 | +- `make test-all` - Runs all tests including Docker E2E tests |
| 23 | + |
| 24 | +### Linting and Code Quality |
| 25 | +- `make lint` - Runs all linters (golangci-lint, markdownlint, hadolint, yamllint, goreleaser check, actionlint) |
| 26 | +- `make lint-fix` - Auto-fixes linting issues where possible |
| 27 | +- `make vet` - Runs go vet |
| 28 | + |
| 29 | +### Development Utilities |
| 30 | +- `make deps` - Downloads dependencies and runs go mod tidy for all modules |
| 31 | +- `make proto-gen` - Generates protobuf files (requires Docker) |
| 32 | +- `make mock-gen` - Generates mocks using mockery |
| 33 | +- `make run-n NODES=3` - Run multiple nodes locally (default: 1) |
| 34 | + |
| 35 | +## Code Architecture |
| 36 | + |
| 37 | +### Core Package Structure |
| 38 | +The project uses a zero-dependency core package pattern: |
| 39 | +- **core/** - Contains only interfaces and types, no external dependencies |
| 40 | +- **block/** - Block management, creation, validation, and synchronization |
| 41 | +- **p2p/** - Networking layer built on libp2p |
| 42 | +- **sequencing/** - Modular sequencer implementations |
| 43 | +- **testapp/** - Reference implementation for testing |
| 44 | + |
| 45 | +### Key Interfaces |
| 46 | +- **Executor** (core/executor.go) - Handles state transitions |
| 47 | +- **Sequencer** (core/sequencer.go) - Orders transactions |
| 48 | +- **DA** (core/da.go) - Data availability layer abstraction |
| 49 | + |
| 50 | +### Modular Design |
| 51 | +- Each component has an interface in the core package |
| 52 | +- Implementations are in separate packages |
| 53 | +- Components are wired together via dependency injection |
| 54 | +- Multiple go.mod files enable modular builds |
| 55 | + |
| 56 | +### P2P Architecture |
| 57 | +- Built on libp2p with GossipSub and Kademlia DHT |
| 58 | +- Nodes advertise capabilities (full/light, DA layers) |
| 59 | +- Automatic peer discovery with rendezvous points |
| 60 | + |
| 61 | +## Testing Patterns |
| 62 | + |
| 63 | +### Test Organization |
| 64 | +- Unit tests: `*_test.go` files alongside code |
| 65 | +- Integration tests: `test/integration/` |
| 66 | +- E2E tests: `test/e2e/` |
| 67 | + |
| 68 | +### Running Specific Tests |
| 69 | +```bash |
| 70 | +# Run a single test |
| 71 | +go test -run TestSpecificFunction ./package/... |
| 72 | + |
| 73 | +# Run with verbose output |
| 74 | +go test -v ./package/... |
| 75 | + |
| 76 | +# Run with race detection |
| 77 | +go test -race ./package/... |
| 78 | +``` |
| 79 | + |
| 80 | +### Mock Generation |
| 81 | +- Mocks are defined in `.mockery.yaml` |
| 82 | +- Generate with `make mock-gen` |
| 83 | +- Mocks are placed in `mocks/` directories |
| 84 | + |
| 85 | +## Code Style Guidelines |
| 86 | + |
| 87 | +### Go Conventions |
| 88 | +- Follow standard Go formatting (enforced by golangci-lint) |
| 89 | +- Use meaningful variable names |
| 90 | +- Keep functions small and focused |
| 91 | +- Document exported types and functions |
| 92 | +- Use context.Context for cancellation |
| 93 | + |
| 94 | +### Error Handling |
| 95 | +- Wrap errors with context using `fmt.Errorf` |
| 96 | +- Return errors early |
| 97 | +- Use custom error types for domain-specific errors |
| 98 | + |
| 99 | +### Logging |
| 100 | +- Use structured logging (look for existing patterns) |
| 101 | +- Include relevant context in log messages |
| 102 | +- Use appropriate log levels |
| 103 | + |
| 104 | +## Common Development Tasks |
| 105 | + |
| 106 | +### Adding a New DA Layer |
| 107 | +1. Implement the `DA` interface from `core/da.go` |
| 108 | +2. Add configuration in the appropriate config package |
| 109 | +3. Wire it up in the initialization code |
| 110 | +4. Add tests following existing patterns |
| 111 | + |
| 112 | +### Modifying Protobuf Definitions |
| 113 | +1. Edit `.proto` files in `types/pb/` |
| 114 | +2. Run `make proto-gen` to regenerate Go code |
| 115 | +3. Update any affected code |
| 116 | +4. Run tests to ensure compatibility |
| 117 | + |
| 118 | +### Adding New Tests |
| 119 | +1. Place unit tests next to the code being tested |
| 120 | +2. Use table-driven tests where appropriate |
| 121 | +3. Mock external dependencies using mockery |
| 122 | +4. Ensure tests are deterministic |
| 123 | + |
| 124 | +## Security Considerations |
| 125 | + |
| 126 | +- Never expose private keys in logs or errors |
| 127 | +- Validate all inputs from external sources |
| 128 | +- Use secure random number generation |
| 129 | +- Follow the principle of least privilege |
| 130 | +- Be careful with concurrent access to shared state |
| 131 | + |
| 132 | +## Performance Considerations |
| 133 | + |
| 134 | +- The project uses concurrent processing extensively |
| 135 | +- Be mindful of goroutine leaks |
| 136 | +- Use buffered channels appropriately |
| 137 | +- Profile before optimizing |
| 138 | +- Consider memory allocation in hot paths |
| 139 | + |
| 140 | +## Debugging Tips |
| 141 | + |
| 142 | +- Use `make run-n NODES=2` to test multi-node scenarios locally |
| 143 | +- Check logs for error messages and stack traces |
| 144 | +- Use Go's built-in profiling tools for performance issues |
| 145 | +- The testapp provides a simple way to test changes |
| 146 | + |
| 147 | +## Contributing Guidelines |
| 148 | + |
| 149 | +- All code must pass linting (`make lint`) |
| 150 | +- All tests must pass (`make test-all`) |
| 151 | +- Follow the existing code patterns |
| 152 | +- Update tests when changing functionality |
| 153 | +- Keep commits focused and atomic |
0 commit comments