Conversation
- Introduced `ApiServer` using Axum for handling HTTP requests. - Added routes for fetching mining statistics and health checks. - Integrated CORS support for the API. - Updated `MiningCoordinator` to manage mining statistics. - Enhanced CLI with new configuration options for API server. - Implemented `MiningStats` to track and serialize mining performance metrics. - Updated `StratumClient` to utilize new stats tracking. - Added `.gitignore` to exclude target directory.
There was a problem hiding this comment.
Pull request overview
This PR introduces an HTTP API server using Axum to expose mining statistics and health check endpoints. The implementation adds comprehensive stats tracking for mining operations, including hashrate, share acceptance rates, and connection status, all accessible via REST endpoints with CORS support.
Changes:
- Added HTTP API server with
/api/statsand/api/healthendpoints using Axum - Implemented
MiningStatsmodule to track and serialize mining performance metrics - Enhanced CLI with configuration options for API server, pool timeout, and share history
- Removed hardcoded timeout constant in favor of configurable pool timeout
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/api.rs | New API server implementation with stats and health endpoints |
| src/stats.rs | New stats tracking module with comprehensive mining metrics |
| src/mining.rs | Integrated stats tracking into coordinator and made structs serializable |
| src/stratum.rs | Updated to record share events and use configurable pool timeout |
| src/main.rs | Modified to launch API server alongside stratum client |
| src/cli.rs | Added CLI arguments for API configuration and timeouts |
| Cargo.toml | Added dependencies for chrono, axum, and tower-http |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let mut stratum = StratumClient::connect(config, coordinator).await?; | ||
| stratum.run().await | ||
| } | ||
|
|
There was a problem hiding this comment.
Remove trailing whitespace on empty line.
| if share.is_block_candidate { | ||
| self.inner.blocks_found.fetch_add(1, Ordering::Relaxed); | ||
| } |
There was a problem hiding this comment.
Block candidates are counted when submitted, but may be rejected by the pool. This leads to inaccurate block count. Consider only incrementing blocks_found when a share is both a block candidate AND accepted.
| if share.is_block_candidate { | |
| self.inner.blocks_found.fetch_add(1, Ordering::Relaxed); | |
| } |
| let cors = CorsLayer::new() | ||
| .allow_origin(Any) | ||
| .allow_methods(Any) | ||
| .allow_headers(Any); |
There was a problem hiding this comment.
CORS is configured to allow any origin, methods, and headers. This is overly permissive and could expose the API to cross-origin attacks. Consider restricting origins to trusted domains or making this configurable.
| .map(|id| WorkerInfo { | ||
| id, | ||
| status: "mining".to_string(), | ||
| hashes_computed: hashes / state.threads as u64, |
There was a problem hiding this comment.
Hash distribution across worker threads is evenly divided, but this doesn't reflect actual work done per thread. This creates misleading per-worker statistics. Consider tracking hashes per worker individually or removing per-worker hash counts if not accurately tracked.
| hashes_computed: hashes / state.threads as u64, | |
| hashes_computed: 0, |
ApiServerusing Axum for handling HTTP requests.MiningCoordinatorto manage mining statistics.MiningStatsto track and serialize mining performance metrics.StratumClientto utilize new stats tracking..gitignoreto exclude target directory.