From 261b8c700126d55d37a2a091cf520067f48464bf Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 12 Sep 2018 22:07:28 +0200 Subject: [PATCH 1/2] net_version caches network_id to avoid redundant aquire of sync read lock, #8746 --- rpc/src/v1/impls/net.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rpc/src/v1/impls/net.rs b/rpc/src/v1/impls/net.rs index 74521d81356..d1224ec1b75 100644 --- a/rpc/src/v1/impls/net.rs +++ b/rpc/src/v1/impls/net.rs @@ -22,7 +22,12 @@ use v1::traits::Net; /// Net rpc implementation. pub struct NetClient { - sync: Arc + sync: Arc, + /// Cached `network_id`. + /// + /// We cache it to avoid redundant aquire of sync read lock. + /// https://github.com/paritytech/parity-ethereum/issues/8746 + network_id: u64, } impl NetClient where S: SyncProvider { @@ -30,17 +35,18 @@ impl NetClient where S: SyncProvider { pub fn new(sync: &Arc) -> Self { NetClient { sync: sync.clone(), + network_id: sync.status().network_id, } } } impl Net for NetClient where S: SyncProvider + 'static { fn version(&self) -> Result { - Ok(format!("{}", self.sync.status().network_id).to_owned()) + Ok(format!("{}", self.network_id)) } fn peer_count(&self) -> Result { - Ok(format!("0x{:x}", self.sync.status().num_peers as u64).to_owned()) + Ok(format!("0x{:x}", self.sync.status().num_peers as u64)) } fn is_listening(&self) -> Result { From cf96a03775ebedba5cf1d7766cc29b092825c8fe Mon Sep 17 00:00:00 2001 From: debris Date: Thu, 13 Sep 2018 09:01:42 +0200 Subject: [PATCH 2/2] use lower_hex display formatting for net_peerCount rpc method --- rpc/src/v1/impls/net.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/src/v1/impls/net.rs b/rpc/src/v1/impls/net.rs index d1224ec1b75..e86bd253f7a 100644 --- a/rpc/src/v1/impls/net.rs +++ b/rpc/src/v1/impls/net.rs @@ -46,7 +46,7 @@ impl Net for NetClient where S: SyncProvider + 'static { } fn peer_count(&self) -> Result { - Ok(format!("0x{:x}", self.sync.status().num_peers as u64)) + Ok(format!("{:#x}", self.sync.status().num_peers as u64)) } fn is_listening(&self) -> Result {