Skip to content

feat(l2): show peer count in monitor when in based mode #3668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

iovoid
Copy link
Contributor

@iovoid iovoid commented Jul 16, 2025

Motivation

Currently peer count is a placeholder ('NaN') so we want an actual implementations.

The peer count of the L2 should only be shown in based bode, because in other (non-based) modes peers aren't needed and having more isn't necessarily better.

Description

Adds a EthClient method to query net_peerCount, and uses it to get the peer count from the local node. Only displays the value if based mode is enabled.

Closes #3516

@iovoid iovoid requested a review from a team as a code owner July 16, 2025 21:25
@github-actions github-actions bot added the L2 Rollup client label Jul 16, 2025
@iovoid iovoid moved this to In Review in ethrex_l2 Jul 16, 2025
Copy link

github-actions bot commented Jul 16, 2025

Lines of code report

Total lines added: 44
Total lines removed: 0
Total lines changed: 44

Detailed view
+----------------------------------------------------+-------+------+
| File                                               | Lines | Diff |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/monitor/app.rs                    | 411   | +2   |
+----------------------------------------------------+-------+------+
| ethrex/crates/l2/monitor/widget/node_status.rs     | 89    | +14  |
+----------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/errors.rs | 273   | +9   |
+----------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/clients/eth/mod.rs    | 1291  | +19  |
+----------------------------------------------------+-------+------+

@@ -40,7 +50,7 @@ impl NodeStatusTable {
.get_latest_block_number()
.await
.map_err(|_| MonitorError::GetLatestBlock)?;
let follower_nodes = "NaN"; // TODO: Implement follower nodes retrieval
let follower_nodes = l2_client.peer_count().await?;
Copy link
Contributor

@tomip01 tomip01 Jul 17, 2025

Choose a reason for hiding this comment

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

nit: peers could also be syncing.
Maybe active_peers is more accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved.

Copy link
Contributor

@tomip01 tomip01 left a comment

Choose a reason for hiding this comment

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

Works well!

@@ -53,7 +63,11 @@ impl NodeStatusTable {
"Last Known Block:".to_string(),
last_known_block.to_string(),
),
("Peers:".to_string(), follower_nodes.to_string()),
if is_based {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this needed? In general it seems an antipattern to have a is_based flag spread across the codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, part of the problem is due to the fact that the table rows are rendered (read rows elements are formatted into String) in refresh_items instead of in the SatefulWidget implementation, where we have the state of the widget that knows whether we are on based or not, and can render the Peers row or not, reducing all the flag spread thought this code to a single if.

We could either file an issue or tackle this in this PR, what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's ok to add a ticket and fix later

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @iovoid file an issue explaining this and link this thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened issue #3839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L2 Rollup client
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

L2 Monitor: Display number of peers only in based
5 participants