Skip to content

Commit

Permalink
fix(admin): id in NodeInfo is string instead of B256 (alloy-rs#1038)
Browse files Browse the repository at this point in the history
* fix(admin): id in NodeInfo is string instead of B256

Signed-off-by: jsvisa <[email protected]>

* fix testcase

Signed-off-by: jsvisa <[email protected]>

* apply code review

Signed-off-by: jsvisa <[email protected]>

---------

Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa authored and j75689 committed Aug 1, 2024
1 parent 3a2e126 commit e6f2d6c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions crates/node-bindings/src/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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(());
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/provider/src/ext/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions crates/rpc-types-admin/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e6f2d6c

Please sign in to comment.