Add peer info on P2Pool Status#24
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds P2Pool peer/chain visibility to the TUI by introducing a small HTTP client, wiring async fetches into app state, and rendering the results in a new tabbed P2Pool Status view.
Changes:
- Introduces
P2PoolClient(reqwest) with/chain_infoand/peersendpoints plus tests. - Extends
Appwith P2Pool status tabs + async channels and triggers background fetches when entering P2Pool Status. - Updates UI (tabs, status bar hints, snapshots) and enables left/right switching on P2Pool Status.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ui.rs | Updates snapshot test setup for the P2Pool Status screen. |
| src/snapshots/pdm__ui__tests__p2pool_status_screen_render.snap | Updates snapshot output for the new P2Pool Status tab UI. |
| src/snapshots/pdm__ui__tests__p2pool_screen_render.snap.new | Removes obsolete generated snapshot file. |
| src/snapshots/pdm__ui__tests__p2pool_screen_render.snap | Snapshot metadata update. |
| src/snapshots/pdm__ui__tests__bitcoin_screen_render.snap.new | Removes obsolete generated snapshot file. |
| src/snapshots/pdm__ui__tests__bitcoin_screen_render.snap | Snapshot metadata update. |
| src/main.rs | Makes main async (Tokio), polls async results, and adds left/right tab switching for P2Pool Status. |
| src/lib.rs | Exposes the new config module. |
| src/config.rs | Adds API config loading (host/port/auth) via config crate. |
| src/components/status_bar.rs | Shows tab-switching hints on P2Pool Status. |
| src/components/p2pool_status_view.rs | Renders P2Pool Status as a tab view (Chain Info / Peers Info). |
| src/components/p2pool_client.rs | New HTTP client for P2Pool API endpoints with tests. |
| src/components/mod.rs | Exports the new p2pool_client module. |
| src/app.rs | Stores P2Pool client + state, spawns fetches on screen entry, and drains results via channels. |
| config/config.toml | Adds a default API config file. |
| Cargo.toml | Adds reqwest/tokio + test deps (mockito/serde_json). |
| Cargo.lock | Locks new dependency graph. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| loop { | ||
| app.poll_chain_info(); | ||
| app.poll_peer_info(); | ||
| terminal.draw(|f| ui::ui(f, app))?; | ||
|
|
||
| if let Event::Key(key) = event::read()? { |
There was a problem hiding this comment.
Fixed! Replaced the blocking event::read() call with event::poll() using a short timeout.
| #[test] | ||
| fn test_p2pool_status_screen_render() { | ||
| let mut server = Server::new(); | ||
| let _mock = server | ||
| .mock("GET", "/chain_info") | ||
| .with_status(200) | ||
| .with_header("content-type", "application/json") | ||
| .with_body( | ||
| serde_json::json!({ | ||
| "genesis_blockhash": null, | ||
| "chain_tip_height": 1, | ||
| "total_work": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", | ||
| "chain_tip_blockhash": null | ||
| }) | ||
| .to_string(), | ||
| ) | ||
| .create(); | ||
|
|
||
| let client = P2PoolClient::with_base_url(server.url()); | ||
| let mut app = App::new_with_client(client); | ||
| let mut terminal = make_terminal(); |
There was a problem hiding this comment.
Fixed. Removed the mock HTTP server setup from the UI snapshot test since this test only verifies rendering.
| use crate::app::App; | ||
| use crate::components::p2pool_client::P2PoolClient; | ||
| use mockito::Server; | ||
| use ratatui::Terminal; | ||
| use ratatui::backend::TestBackend; |
| let host: String = settings.get("api.host").unwrap_or("127.0.0.1".into()); | ||
| let port: u16 = settings.get("api.port").unwrap_or(9332); | ||
| let auth_user: Option<String> = settings.get("api.auth_user").ok(); |
| [api] | ||
| host = "127.0.0.1" | ||
| port = 46884 | ||
| auth_user = "p2pool" | ||
| auth_pass = "p2pool" |
There was a problem hiding this comment.
Fixed! Added config.sample.toml
| reqwest = { version = "0.12", features = ["json", "rustls-tls", "blocking"] } | ||
| tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "time"] } |
| Line::from(format!( | ||
| "Chain Tip Height : {}", | ||
| info.chain_tip_height.unwrap_or(0) | ||
| )), |
Refactor terminal input handling to improve testability and add coverage for keyboard-driven interactions. Introduce additional test cases and update the event loop to support periodic polling so background updates can be reflected without requiring user input.
Changes: