Skip to content

feat: expose stratum mining stats via Owner API#3897

Open
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:feat/mining-status-api
Open

feat: expose stratum mining stats via Owner API#3897
iho wants to merge 1 commit into
mimblewimble:stagingfrom
iho:feat/mining-status-api

Conversation

@iho

@iho iho commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Adds an Owner API endpoint for stratum mining statistics so operators running headless (no TUI) can inspect connected workers and share stats — the same data shown on the TUI mining tab.

Closes #3201

Changes

  • New get_mining_status method on Owner JSON-RPC (/v2/owner)
  • New types: MiningStatus / WorkerInfo in the API crate
  • Server wires live StratumStats into the Owner API via a provider callback
  • CLI: grin client miningstatus
  • Brief docs in doc/api/api.md

Example

{
  "jsonrpc": "2.0",
  "method": "get_mining_status",
  "params": [],
  "id": 1
}

Returns whether stratum is enabled/running, worker count, block height, network difficulty/hashrate, blocks found, and per-worker share stats. When stratum is disabled (or no provider is wired), returns a disabled default rather than an error.

Test plan

  • Unit tests: MiningStatus serde roundtrip, default disabled state
  • Unit tests: Owner::get_mining_status with/without provider
  • Unit tests: StratumStatsMiningStatus conversion
  • cargo check -p grin --bin grin
  • Manually: enable stratum, connect a miner, run grin client miningstatus

Add get_mining_status to the Owner JSON-RPC API so headless operators
can query the same stratum/worker stats shown on the TUI mining tab.
Wire live StratumStats into node_apis and add `grin client miningstatus`.

Closes mimblewimble#3201

@wiesche89 wiesche89 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a nice and useful feature, and the endpoint is wired to the live StratumStats correctly. Before merging, I’d clarify whether the API should return only active workers, avoid masking a missing provider as disabled, and preserve the public node_apis signature.

blocks_found: stats.blocks_found,
network_hashrate: stats.network_hashrate,
minimum_share_difficulty: stats.minimum_share_difficulty,
worker_stats: stats.worker_stats.iter().map(WorkerInfo::from).collect(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

worker_stats keeps every disconnected worker, so this response grows for the lifetime of the node while the CLI only shows connected workers. Should the API filter to active workers too?

Comment thread api/src/owner.rs
pub fn get_mining_status(&self) -> Result<MiningStatus, Error> {
match &self.mining_stats {
Some(provider) => Ok(provider()),
None => Ok(MiningStatus::default()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A disabled server already has a provider returning is_enabled, false. Could a missing provider return an internal error instead of silently looking disabled?

Comment thread api/src/handlers.rs
tls_config: Option<TLSConfig>,
api_chan: &'static mut (oneshot::Sender<()>, oneshot::Receiver<()>),
stop_state: Arc<StopState>,
mining_stats: Option<MiningStatsProvider>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

node_apis is publicly re-exported, so this required argument breaks external callers. Could we preserve the existing wrapper and add a provider-aware variant?

Comment thread api/src/types.rs
/// Whether the stratum server is enabled in config
pub is_enabled: bool,
/// Whether the stratum server is currently running
pub is_running: bool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The source flag is set on startup but never cleared on listener failure or shutdown. Is “currently running” too strong for the API contract?

Comment thread api/src/owner.rs
/// * or [`Error`](struct.Error.html) if an error is encountered.
///

pub fn get_mining_status(&self) -> Result<MiningStatus, Error> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we trim the empty doc line and shorten the returns section to match the neighboring methods?

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