feat: expose stratum mining stats via Owner API#3897
Conversation
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
left a comment
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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?
| pub fn get_mining_status(&self) -> Result<MiningStatus, Error> { | ||
| match &self.mining_stats { | ||
| Some(provider) => Ok(provider()), | ||
| None => Ok(MiningStatus::default()), |
There was a problem hiding this comment.
A disabled server already has a provider returning is_enabled, false. Could a missing provider return an internal error instead of silently looking disabled?
| tls_config: Option<TLSConfig>, | ||
| api_chan: &'static mut (oneshot::Sender<()>, oneshot::Receiver<()>), | ||
| stop_state: Arc<StopState>, | ||
| mining_stats: Option<MiningStatsProvider>, |
There was a problem hiding this comment.
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?
| /// Whether the stratum server is enabled in config | ||
| pub is_enabled: bool, | ||
| /// Whether the stratum server is currently running | ||
| pub is_running: bool, |
There was a problem hiding this comment.
The source flag is set on startup but never cleared on listener failure or shutdown. Is “currently running” too strong for the API contract?
| /// * or [`Error`](struct.Error.html) if an error is encountered. | ||
| /// | ||
|
|
||
| pub fn get_mining_status(&self) -> Result<MiningStatus, Error> { |
There was a problem hiding this comment.
Could we trim the empty doc line and shorten the returns section to match the neighboring methods?
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
get_mining_statusmethod on Owner JSON-RPC (/v2/owner)MiningStatus/WorkerInfoin the API crateStratumStatsinto the Owner API via a provider callbackgrin client miningstatusdoc/api/api.mdExample
{ "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
MiningStatusserde roundtrip, default disabled stateOwner::get_mining_statuswith/without providerStratumStats→MiningStatusconversioncargo check -p grin --bin gringrin client miningstatus