This document provides guidelines for developers and AI agents working on the Bounty Challenge codebase.
Bounty Challenge is a decentralized issue reward system on the Bittensor network. Miners earn TAO rewards by discovering and reporting valid issues.
| Component | Path | Description |
|---|---|---|
| Server | src/main.rs |
HTTP server entry point |
| Challenge | src/challenge.rs |
Core challenge implementation |
| Storage | src/pg_storage.rs |
PostgreSQL data layer |
| Auth | src/auth.rs |
SS58/sr25519 signature verification |
| GitHub API | src/github.rs |
GitHub API client |
| GitHub CLI | src/gh_cli.rs |
gh CLI wrapper for reliable sync |
| Config | src/config.rs |
Configuration loading |
| Server Routes | src/server.rs |
HTTP routes and handlers |
| Metagraph | src/metagraph.rs |
Metagraph caching |
| CLI | src/bin/bounty/ |
Command-line interface |
-
Error Handling
- Use
Resulttypes and the?operator for propagation - Use
unwrap_or_elsewith fallbacks, never bareunwrap()in production code - Log errors with
tracingbefore returning them
- Use
-
Async Code
- All database and network operations are async
- Use
tokioruntime withasync-traitfor trait implementations - Respect timeouts (30s default for DB queries)
-
Security
- Never hardcode secrets - use environment variables
- All user inputs must be validated before use
- Use parameterized SQL queries only
bounty-challenge/
├── src/
│ ├── main.rs # Server entry point
│ ├── lib.rs # Library exports
│ ├── auth.rs # Signature verification
│ ├── challenge.rs # Challenge implementation
│ ├── config.rs # Configuration loading
│ ├── server.rs # HTTP routes and handlers
│ ├── pg_storage.rs # PostgreSQL storage
│ ├── github.rs # GitHub API client
│ ├── gh_cli.rs # GitHub CLI (gh) wrapper
│ ├── github_oauth.rs # GitHub Device Flow OAuth
│ ├── metagraph.rs # Metagraph caching
│ └── bin/
│ ├── bounty/ # CLI application
│ │ ├── main.rs # CLI entry point
│ │ ├── client.rs # Bridge API client
│ │ ├── style.rs # Terminal styling
│ │ ├── wizard/ # Registration wizard
│ │ └── commands/ # CLI commands
│ └── bounty-health-server.rs # Health check server
├── migrations/ # SQL migrations
├── docs/
│ ├── anti-abuse.md # Anti-abuse documentation
│ ├── miner/ # Miner guides
│ ├── reference/ # API & scoring references
│ └── validator/ # Validator guides
├── examples/ # Example code
├── config.toml # Configuration file
└── Dockerfile # Container build
Configuration is loaded from config.toml:
[github]- OAuth client ID and target repositories[server]- Host and port bindings[rewards]- Points system parameters
Environment variables take precedence:
DATABASE_URL- PostgreSQL connection stringGITHUB_TOKEN- API authenticationPLATFORM_URL- Platform server URL
# Run all tests
cargo test
# Run with logging
RUST_LOG=debug cargo test
# Check code quality
cargo clippy
cargo fmt --check# Development build
cargo build
# Release build
cargo build --release
# Docker build
docker build -t bounty-challenge .| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check |
| GET | /config |
Challenge configuration |
| POST | /register |
Register GitHub account |
| GET | /status/:hotkey |
Get miner status |
| GET | /leaderboard |
Current standings |
| GET | /stats |
Challenge statistics |
Points are calculated as:
- 1 point per valid issue
- 0.25 points per starred repository (max 5 repos)
- Dynamic penalty: max(0, invalid_count - valid_count)
Weight formula: min(points × 0.02, 1.0)
Key tables:
github_registrations- Hotkey ↔ GitHub username mappingsresolved_issues- Valid issues credited to minersinvalid_issues- Invalid issues (for penalty tracking)target_repos- Repositories to monitor
- Define handler function in
src/server.rs - Add route in
create_router() - Update API documentation in
docs/reference/api-reference.md
- Create new migration in
migrations/ - Update
PgStoragemethods insrc/pg_storage.rs - Add migration check in
run_migrations()
- Add command variant to
Commandsenum insrc/bin/bounty/main.rs - Implement handler in
src/bin/bounty/commands/ - Update CLI documentation in README
- All signatures use sr25519 (Substrate standard)
- Timestamps must be within 5 minutes (replay protection)
- Each GitHub username can only link to one hotkey
- Only maintainers can add the
validlabel