Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Added peers details to ethcore_netPeers RPC #2580

Merged
merged 5 commits into from
Oct 12, 2016
Merged

Added peers details to ethcore_netPeers RPC #2580

merged 5 commits into from
Oct 12, 2016

Conversation

svyatonik
Copy link
Collaborator

closes ethcore/parity#2433

I've tried to make returned data to look exactly like Geth' admin.peers output. However, protocols.eth.difficulty is returned as decimal number in Geth, while in ethcore_* APIs all bigints are returned as hex numbers (at my first glance). Not sure if I should break this rule here => difficulty is also returned as hex number here.
I'm still not sure whether it is ok to alter existing RPC - Parity already had ethcore_netPeers RPC before - I've just added another member to the returned value. Hope this won't break any clients.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.423% when pulling aba99ab on svyatonik:master into 327f5e0 on ethcore:master.

@jacogr
Copy link
Contributor

jacogr commented Oct 11, 2016

It should be ok with the Parity UI in master (accessed via localhost:8080/home/ -> status) and will be for the new UI as well (js branch) since in both cases we only look at the active/connected/max members.

Once merged however I will update the JS branch (specifically the new Parity.js JSAPI to do proper formatting of the newly returned structure as well as update the documentation). Issue to be logged.

@jacogr jacogr added the M4-core ⛓ Core client code / Rust. label Oct 11, 2016
@keorn keorn added the A0-pleasereview 🤓 Pull request needs code review. label Oct 11, 2016
@jacogr
Copy link
Contributor

jacogr commented Oct 11, 2016

@tomusdrw There are some errors with the current UI on the props validation side. We need to get those sorted in conjunction with this if this is good to go. So please take a peek at this one to make sure you are happy and it is valid to make the (minor) changes to adjust to the new format.

Copy link
Contributor

@rphmeier rphmeier left a comment

Choose a reason for hiding this comment

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

A couple of style concerns, looks good generally.

I'm not particularly concerned about the backwards compatibility aspect of this change, but I have a couple things to note:

  • This is additive, so it won't break backwards compatibility. Once we commit to this format, though, we have to support it (at least after we make an official release containing it -- unstable can change at-will). Consider the case of supporting an arbitrary number of protocols, each with their own data.
  • Parity will probably support LES soon, which means that we'll have to have nullable subprotocol fields for each protocol. A more extensible format might just have an array of { name, props } objects for each peer.

/// Remote endpoint address
pub remote_address: String,
/// Local endpoint address
pub local_address: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

extra spaces before client_version, remote_address, and local_address


/// Peer connection information
#[derive(Binary)]
pub struct PeerInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

public-facing types should derive Debug as well.

self.peers.iter()
.filter_map(|(&peer_id, ref peer_data)| {
if let Some(session_info) = io.peer_session_info(peer_id) {
return Some(PeerInfoDigest {
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like a good use-case for Option::map

fn peer_info(&self, peer_id: PeerId) -> String {
peer_id.to_string()
}
/// Returns peer client identifier string
fn peer_session_info(&self, peer_id: PeerId) -> Option<SessionInfo>;
Copy link
Contributor

Choose a reason for hiding this comment

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

doc seems wrong here

match host.as_ref() {
Some(ref host) => Some(host.with_context_eval(protocol, &io, action)),
None => None
}
Copy link
Contributor

Choose a reason for hiding this comment

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

host.as_ref().map(|ref host| ...)

let net_config = take_weak!(self.net).network_config();
let peers = sync.peers().into_iter().map(|s| s.into()).collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

map(Into::into) is a little more idiomatic

pub struct PeerProtocolsInfo {
/// Ethereum protocol information
pub eth: PeerEthereumProtocolInfo
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct doesn't seem to be particularly extensible -- we might soon see cases where peers are connected either on eth, les, or both. Maybe the fields on this struct could be Optional? Or maybe that would be a premature refactoring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. I personally think that { name, props } isn't a good pattern for public APIs - it is hard to document, hard to use (in long term) & hard to maintain. Do you think this will be better than strictly typed struct's for each protocol?
  2. as for converting eth to an Option<> - I could do that right now. But when you'll met some code which has return type Option<> and unconditionally returns Some(...) - isn't it a bad pattern?
    @rphmeier Could you, please, comment so we could agree on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@svyatonik I agree that strictly typed is better. For now, I think it can be left as is, since the only peers we'll find will be connected to eth, but it should be documented as a nullable/optional field in the JSON structure so we can accommodate future subprotocols without breaking backwards compatibility.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d02d67c on svyatonik:master into * on ethcore:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d02d67c on svyatonik:master into * on ethcore:master*.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.462% when pulling f1fe17a on svyatonik:master into eb40750 on ethcore:master.

@@ -368,6 +369,25 @@ impl ChainSync {
}
}

/// @returns Information on peers connections
Copy link
Contributor

Choose a reason for hiding this comment

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

rustdoc doesn't do anything with the @ symbol like doxygen does, so it's probably unnecessary here.

@rphmeier rphmeier added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Oct 12, 2016
@rphmeier
Copy link
Contributor

LGTM modulo tiny docs format issue.

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Oct 12, 2016
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.458% when pulling 5aca0e3 on svyatonik:master into eb40750 on ethcore:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 86.427% when pulling 5aca0e3 on svyatonik:master into eb40750 on ethcore:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 86.472% when pulling 5aca0e3 on svyatonik:master into eb40750 on ethcore:master.

@arkpar arkpar merged commit c9ce25c into openethereum:master Oct 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants