Skip to content
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

Add client id to admin_peers RPC API #7706

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 11 additions & 2 deletions src/Nethermind/Nethermind.JsonRpc/Modules/Admin/PeerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.Net;
using Nethermind.Network;
using Nethermind.Stats.Model;
using Nethermind.Core.Crypto;

namespace Nethermind.JsonRpc.Modules.Admin
{
public class PeerInfo
{
public string ClientId { get; set; }
public string Name { get; set; }
public string Id { get; }
public string Host { get; set; }
public int Port { get; set; }
public string Address { get; set; }
Expand All @@ -36,7 +38,8 @@ public PeerInfo(Peer peer, bool includeDetails)
$"{nameof(PeerInfo)} cannot be created for a {nameof(Peer)} with an unknown {peer.Node}");
}

ClientId = peer.Node.ClientId;
Name = peer.Node.ClientId;
Id = CalculateClientId(peer.Node.Id);
Copy link
Member

Choose a reason for hiding this comment

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

Btw do we need to calculate it here, we have already peer.Node.IdHash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, let me check again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see that IdHash is calculated by PrefixedBytes, this isn’t the clientId.

IdHash = Keccak.Compute(PublicKey.PrefixedBytes);

I think we should use new CalculateClientId function, right?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure, it is your PR ;)
Best to check with Geth code.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah IdHash should be fine

Host = peer.Node.Host is null ? null : IPAddress.Parse(peer.Node.Host).MapToIPv4().ToString();
Port = peer.Node.Port;
Address = peer.Node.Address.ToString();
Expand All @@ -51,5 +54,11 @@ public PeerInfo(Peer peer, bool includeDetails)
LastSignal = (peer.InSession ?? peer.OutSession)?.LastPingUtc.ToString(CultureInfo.InvariantCulture);
}
}

private string CalculateClientId(PublicKey nodeKey)
{
byte[] publicKeyBytes = nodeKey.Bytes;
return (publicKeyBytes is null ? Keccak.Zero.ValueHash256 : ValueKeccak.Compute(publicKeyBytes)).ToString(false);
}
}
}