Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/node/p2p/src/rpc/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
/// Whether to only return connected peers.
connected: bool,
},

/// Request to connect the specified peer.
ConnectPeer {
/// The peer id to connect.
peer_id: PeerId,
},
/// Request to disconnect the specified peer.
DisconnectPeer {
/// The peer id to disconnect.
Comment on lines +46 to 51
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

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

[nitpick] In the doc comment, consider changing "peer id" to "peer ID" for consistency with other code and logs.

Suggested change
/// The peer id to connect.
peer_id: PeerId,
},
/// Request to disconnect the specified peer.
DisconnectPeer {
/// The peer id to disconnect.
/// The peer ID to connect.
peer_id: PeerId,
},
/// Request to disconnect the specified peer.
DisconnectPeer {
/// The peer ID to disconnect.

Copilot uses AI. Check for mistakes.
Expand All @@ -63,6 +69,7 @@
Self::PeerInfo(s) => Self::handle_peer_info(s, gossip, disc),
Self::Peers { out, connected } => Self::handle_peers(out, connected, gossip, disc),
Self::DisconnectPeer { peer_id } => Self::disconnect_peer(peer_id, gossip),
Self::ConnectPeer { peer_id } => Self::connect_peer(peer_id, gossip),

Check warning on line 72 in crates/node/p2p/src/rpc/request.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/p2p/src/rpc/request.rs#L72

Added line #L72 was not covered by tests
Self::PeerStats(s) => Self::handle_peer_stats(s, gossip, disc),
}
}
Expand All @@ -74,6 +81,14 @@
info!(target: "p2p::rpc", "Disconnected peer {}", peer_id);
}
}

fn connect_peer(peer_id: PeerId, gossip: &mut GossipDriver) {
Copy link

Copilot AI Jun 6, 2025

Choose a reason for hiding this comment

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

[nitpick] Logging targets differ between the RPC server (target: "rpc") and this handler (target: "p2p::rpc"); consider unifying or documenting the distinction for consistent observability.

Copilot uses AI. Check for mistakes.
if let Err(e) = gossip.swarm.dial(peer_id) {
warn!(target: "p2p::rpc", "Failed to connect to peer {}: {:?}", peer_id, e);

Check warning on line 87 in crates/node/p2p/src/rpc/request.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/p2p/src/rpc/request.rs#L85-L87

Added lines #L85 - L87 were not covered by tests
} else {
info!(target: "p2p::rpc", "Connected peer {}", peer_id);

Check warning on line 89 in crates/node/p2p/src/rpc/request.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/p2p/src/rpc/request.rs#L89

Added line #L89 was not covered by tests
}
}

Check warning on line 91 in crates/node/p2p/src/rpc/request.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/p2p/src/rpc/request.rs#L91

Added line #L91 was not covered by tests

fn handle_discovery_table(sender: Sender<Vec<String>>, disc: &Discv5Handler) {
let enrs = disc.table_enrs();
Expand Down
17 changes: 14 additions & 3 deletions crates/node/rpc/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,21 @@
Err(ErrorObject::from(ErrorCode::MethodNotFound))
}

async fn opp2p_connect_peer(&self, _peer: String) -> RpcResult<()> {
async fn opp2p_connect_peer(&self, peer_id: String) -> RpcResult<()> {

Check warning on line 145 in crates/node/rpc/src/p2p.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/rpc/src/p2p.rs#L145

Added line #L145 was not covered by tests
kona_macros::inc!(gauge, kona_p2p::Metrics::RPC_CALLS, "method" => "opp2p_connectPeer");
// Method not supported yet.
Err(ErrorObject::from(ErrorCode::MethodNotFound))

let peer_id = match peer_id.parse() {
Ok(id) => id,
Err(err) => {
warn!(target: "rpc", ?err, ?peer_id, "Failed to parse peer ID");
return Err(ErrorObject::from(ErrorCode::InvalidParams))

Check warning on line 152 in crates/node/rpc/src/p2p.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/rpc/src/p2p.rs#L148-L152

Added lines #L148 - L152 were not covered by tests
}
};

self.sender
.send(P2pRpcRequest::ConnectPeer { peer_id })
.await
.map_err(|_| ErrorObject::from(ErrorCode::InternalError))

Check warning on line 159 in crates/node/rpc/src/p2p.rs

View check run for this annotation

Codecov / codecov/patch

crates/node/rpc/src/p2p.rs#L156-L159

Added lines #L156 - L159 were not covered by tests
}

async fn opp2p_disconnect_peer(&self, peer_id: String) -> RpcResult<()> {
Expand Down
Loading