Add network field to GlobalInfo (GET /api/v1/global)#367
Open
vnprc wants to merge 3 commits intostratum-mining:mainfrom
Open
Add network field to GlobalInfo (GET /api/v1/global)#367vnprc wants to merge 3 commits intostratum-mining:mainfrom
network field to GlobalInfo (GET /api/v1/global)#367vnprc wants to merge 3 commits intostratum-mining:mainfrom
Conversation
Add `network: Option<String>` to `GlobalInfo` so the Bitcoin network is machine-readable from `GET /api/v1/global` without consulting Prometheus or config files. - `GlobalInfo` gets `pub network: Option<String>` - `ServerState.network`: `Option<String>` → `Arc<RwLock<Option<String>>>` - `MonitoringServer::with_network(self, Option<String>)` writes into the existing Arc so any handle obtained via `network_handle()` remains valid after the call - `MonitoringServer::network_handle()` returns a clone of the Arc for background tasks that need to update network after `run()` consumes self - `handle_global` reads via `.read().unwrap().clone()` - Tests: `global_endpoint_with_no_sources` asserts network is null; new `global_endpoint_network_field` asserts null and populated cases
Pool is the authoritative source of network identity — it is directly connected to the Bitcoin node via the template provider. Pool: - `PoolConfig` gains `network: Option<String>` with `#[serde(default)]` - Pool calls `.with_network(config.network())` on its `MonitoringServer` Translator: - `TranslatorConfig` gains `upstream_monitoring_url: Option<String>` with `#[serde(default)]` and `with_upstream_monitoring_url()` builder - After building `MonitoringServer`, calls `.network_handle()` - Spawns `poll_network_from_pool()` background task: fetches `GET <upstream_monitoring_url>/api/v1/global` immediately then every 60s, writes `global.network` into the Arc; trims trailing slash; shuts down cleanly on cancellation token - Applied to both startup and fallback-restart code paths - `reqwest` added as a dep Integration test `global_info_exposes_network`: - Starts pool with `network = "regtest"` - Starts translator with `upstream_monitoring_url` pointing at pool - Asserts pool `/api/v1/global` immediately returns `network = "regtest"` - Polls translator `/api/v1/global` up to 10s for propagation - `start_pool_with_network` and `start_sv2_translator_with_upstream_monitoring` helpers added; existing helpers unchanged - `serde_json` added to integration-tests `Cargo.toml`
Long lines in the new test exceeded the stable rustfmt line limit. Break up start_pool_with_network, start_sv2_translator_with_upstream_monitoring, assert_eq!, and panic! calls to match the project's formatting style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
network: Option<String>toGlobalInfoso the Bitcoin network is machine-readable from the monitoring REST API without inspecting config files or Prometheus metrics[pool]TOML config (network = "regtest")GET <upstream_monitoring_url>/api/v1/globalevery 60 seconds in a background taskMotivation
Downstream consumers of the monitoring API (dashboards, alerting tools, and same for translator proxy) need to know which Bitcoin network the pool is operating on. Today this requires reading config files out-of-band. Exposing it in
GlobalInfomakes it a first-class, machine-readable API field.Changes
stratum-appsGlobalInfo.network: Option<String>(serializes tonullwhen not configured)ServerState.network: Arc<RwLock<Option<String>>>for runtime updatesMonitoringServer::with_network()— builder method for static configurationMonitoringServer::network_handle()— returns anArcclone for background tasks that need to update the field afterrun()consumesselfpool-apps/poolPoolConfig.network: Option<String>with#[serde(default)](backward-compatible).with_network(config.network())on startupminer-apps/translatorTranslatorConfig.upstream_monitoring_url: Option<String>with#[serde(default)]monitoring_server.network_handle()then spawnspoll_network_from_pool(): fetches pool's/api/v1/globalimmediately, then every 60 seconds; exits cleanly on cancellationreqwestadded as a dependency (default-features = false, features = ["json"])integration-testsstart_pool_with_networkandstart_sv2_translator_with_upstream_monitoringhelpers added (existing helpers unchanged, delegate to new ones)global_info_exposes_networktest: starts pool withnetwork = "regtest", starts translator pointing at pool's monitoring server, asserts pool exposes"regtest"immediately and translator propagates it within 10 secondsNetwork value convention
Values follow
bitcoin-cli -getinfo/bitcoin-cli getblockchaininfoconvention:"main","test","testnet4","regtest","signet". The field isnullif not configured.Test plan
cargo clippy --manifest-path stratum-apps/Cargo.toml -- -D warnings -A dead-code— cleancargo test --manifest-path stratum-apps/Cargo.toml— 29/29 passcargo fmt --manifest-path stratum-apps/Cargo.toml -- --check— cleanreqwestaddedglobal_info_exposes_networkintegration test passes end-to-end