Skip to content

Add peer info on P2Pool Status#24

Open
R27-pixel wants to merge 4 commits into
p2poolv2:mainfrom
R27-pixel:peer_info
Open

Add peer info on P2Pool Status#24
R27-pixel wants to merge 4 commits into
p2poolv2:mainfrom
R27-pixel:peer_info

Conversation

@R27-pixel

@R27-pixel R27-pixel commented May 6, 2026

Copy link
Copy Markdown
Contributor

Changes:

  • Added GET /peers support in p2pool_client.rs .
  • Fetches peers when opening P2Pool Status and polls async results in app.rs.
  • Renders connected peers in the Peers Info tab in p2pool_status_view.rs.
  • Enabled left/right tab switching for P2Pool Status in main.rs .
  • Updated the status bar and snapshot for the P2Pool tab UI.
image

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.99065% with 45 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/main.rs 93.21% 27 Missing ⚠️
src/app.rs 40.00% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_info and /peers endpoints plus tests.
  • Extends App with 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.

Comment thread src/main.rs Outdated
Comment on lines 73 to 78
loop {
app.poll_chain_info();
app.poll_peer_info();
terminal.draw(|f| ui::ui(f, app))?;

if let Event::Key(key) = event::read()? {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed! Replaced the blocking event::read() call with event::poll() using a short timeout.

Comment thread src/ui.rs
Comment on lines 195 to 215
#[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();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Removed the mock HTTP server setup from the UI snapshot test since this test only verifies rendering.

Comment thread src/ui.rs
Comment on lines 114 to 118
use crate::app::App;
use crate::components::p2pool_client::P2PoolClient;
use mockito::Server;
use ratatui::Terminal;
use ratatui::backend::TestBackend;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed!.

Comment thread src/config.rs
Comment on lines +22 to +24
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();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Comment thread config/config.toml
Comment on lines +1 to +5
[api]
host = "127.0.0.1"
port = 46884
auth_user = "p2pool"
auth_pass = "p2pool"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed! Added config.sample.toml

Comment thread Cargo.toml Outdated
Comment on lines +20 to +21
reqwest = { version = "0.12", features = ["json", "rustls-tls", "blocking"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "time"] }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed!

Comment on lines +51 to +54
Line::from(format!(
"Chain Tip Height : {}",
info.chain_tip_height.unwrap_or(0)
)),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!.

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