Skip to content

feat: add HTTP API server with stats and health check endpoints#3

Draft
priyashuu wants to merge 1 commit intomasterfrom
http_api
Draft

feat: add HTTP API server with stats and health check endpoints#3
priyashuu wants to merge 1 commit intomasterfrom
http_api

Conversation

@priyashuu
Copy link
Copy Markdown
Contributor

  • 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.

- 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.
@priyashuu priyashuu requested a review from Copilot January 19, 2026 15:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/stats and /api/health endpoints using Axum
  • Implemented MiningStats module 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.

Comment thread src/main.rs
let mut stratum = StratumClient::connect(config, coordinator).await?;
stratum.run().await
}

Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing whitespace on empty line.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread src/stats.rs
Comment on lines +156 to +158
if share.is_block_candidate {
self.inner.blocks_found.fetch_add(1, Ordering::Relaxed);
}
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if share.is_block_candidate {
self.inner.blocks_found.fetch_add(1, Ordering::Relaxed);
}

Copilot uses AI. Check for mistakes.
Comment thread src/api.rs
Comment on lines +31 to +34
let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
.allow_headers(Any);
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/stats.rs
.map(|id| WorkerInfo {
id,
status: "mining".to_string(),
hashes_computed: hashes / state.threads as u64,
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
hashes_computed: hashes / state.threads as u64,
hashes_computed: 0,

Copilot uses AI. Check for mistakes.
@priyashuu priyashuu marked this pull request as draft January 19, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants