From e6f2d6c22d44778a6dd2860c1f10cba09522fc66 Mon Sep 17 00:00:00 2001 From: Delweng Date: Sat, 13 Jul 2024 21:46:06 +0800 Subject: [PATCH] fix(admin): id in NodeInfo is string instead of B256 (#1038) * fix(admin): id in NodeInfo is string instead of B256 Signed-off-by: jsvisa * fix testcase Signed-off-by: jsvisa * apply code review Signed-off-by: jsvisa --------- Signed-off-by: jsvisa --- crates/node-bindings/src/geth.rs | 8 ++++---- crates/provider/src/ext/admin.rs | 2 +- crates/rpc-types-admin/src/admin.rs | 7 +++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/node-bindings/src/geth.rs b/crates/node-bindings/src/geth.rs index 79942a0f936..4c61b153a86 100644 --- a/crates/node-bindings/src/geth.rs +++ b/crates/node-bindings/src/geth.rs @@ -2,7 +2,7 @@ use crate::unused_port; use alloy_genesis::{CliqueConfig, Genesis}; -use alloy_primitives::{hex, Address, B256}; +use alloy_primitives::Address; use k256::ecdsa::SigningKey; use std::{ borrow::Cow, @@ -121,7 +121,7 @@ impl GethInstance { /// Blocks until geth adds the specified peer, using 20s as the timeout. /// /// Requires the stderr to be present in the `GethInstance`. - pub fn wait_to_add_peer(&mut self, id: B256) -> Result<(), GethInstanceError> { + pub fn wait_to_add_peer(&mut self, id: &str) -> Result<(), GethInstanceError> { let mut stderr = self.pid.stderr.as_mut().ok_or(GethInstanceError::NoStderr)?; let mut err_reader = BufReader::new(&mut stderr); let mut line = String::new(); @@ -132,8 +132,8 @@ impl GethInstance { err_reader.read_line(&mut line).map_err(GethInstanceError::ReadLineError)?; // geth ids are truncated - let truncated_id = hex::encode(&id.0[..8]); - if line.contains("Adding p2p peer") && line.contains(&truncated_id) { + let truncated_id = if id.len() > 16 { &id[..16] } else { id }; + if line.contains("Adding p2p peer") && line.contains(truncated_id) { return Ok(()); } } diff --git a/crates/provider/src/ext/admin.rs b/crates/provider/src/ext/admin.rs index 158f9598d37..b81d4701111 100644 --- a/crates/provider/src/ext/admin.rs +++ b/crates/provider/src/ext/admin.rs @@ -116,7 +116,7 @@ mod test { let added = provider2.add_peer(&node1_enode).await.unwrap(); assert!(added); - geth2.wait_to_add_peer(node1_id).unwrap(); + geth2.wait_to_add_peer(&node1_id).unwrap(); let peers = provider2.peers().await.unwrap(); assert_eq!(peers[0].enode, node1_enode); } diff --git a/crates/rpc-types-admin/src/admin.rs b/crates/rpc-types-admin/src/admin.rs index 2814f16160e..d227d117670 100644 --- a/crates/rpc-types-admin/src/admin.rs +++ b/crates/rpc-types-admin/src/admin.rs @@ -10,10 +10,13 @@ use std::{ /// This includes general information about a running node, spanning networking and protocol /// details. +/// +/// See [geth's `NodeInfo` struct](https://github.com/ethereum/go-ethereum/blob/v1.14.0/p2p/server.go#L1078) +/// for the source of each field. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NodeInfo { - /// Unique node identifier. - pub id: B256, + /// Unique node identifier(also the encryption key). + pub id: String, /// The node's user agent, containing a client name, version, OS, and other metadata. pub name: String, /// The enode URL of the connected node.