LES Peer Info (#4195)
* connected peers function for network service * get LES peer info in sync API * new peer info in RPC
This commit is contained in:
committed by
Arkadiy Paronyan
parent
35666f718b
commit
3ff9324ec0
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use util::{H256, RwLock};
|
||||
use ethsync::{SyncProvider, SyncStatus, SyncState, PeerInfo, TransactionStats};
|
||||
use ethsync::{SyncProvider, EthProtocolInfo, SyncStatus, SyncState, PeerInfo, TransactionStats};
|
||||
|
||||
/// TestSyncProvider config.
|
||||
pub struct Config {
|
||||
@@ -78,9 +78,12 @@ impl SyncProvider for TestSyncProvider {
|
||||
capabilities: vec!["eth/62".to_owned(), "eth/63".to_owned()],
|
||||
remote_address: "127.0.0.1:7777".to_owned(),
|
||||
local_address: "127.0.0.1:8888".to_owned(),
|
||||
eth_version: 62,
|
||||
eth_difficulty: Some(40.into()),
|
||||
eth_head: 50.into()
|
||||
eth_info: Some(EthProtocolInfo {
|
||||
version: 62,
|
||||
difficulty: Some(40.into()),
|
||||
head: 50.into(),
|
||||
}),
|
||||
les_info: None,
|
||||
},
|
||||
PeerInfo {
|
||||
id: None,
|
||||
@@ -88,9 +91,12 @@ impl SyncProvider for TestSyncProvider {
|
||||
capabilities: vec!["eth/63".to_owned(), "eth/64".to_owned()],
|
||||
remote_address: "Handshake".to_owned(),
|
||||
local_address: "127.0.0.1:3333".to_owned(),
|
||||
eth_version: 64,
|
||||
eth_difficulty: None,
|
||||
eth_head: 60.into()
|
||||
eth_info: Some(EthProtocolInfo {
|
||||
version: 64,
|
||||
difficulty: None,
|
||||
head: 60.into()
|
||||
}),
|
||||
les_info: None,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ fn rpc_parity_net_peers() {
|
||||
let io = deps.default_client();
|
||||
|
||||
let request = r#"{"jsonrpc": "2.0", "method": "parity_netPeers", "params":[], "id": 1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"active":0,"connected":120,"max":50,"peers":[{"caps":["eth/62","eth/63"],"id":"node1","name":"Parity/1","network":{"localAddress":"127.0.0.1:8888","remoteAddress":"127.0.0.1:7777"},"protocols":{"eth":{"difficulty":"0x28","head":"0000000000000000000000000000000000000000000000000000000000000032","version":62}}},{"caps":["eth/63","eth/64"],"id":null,"name":"Parity/2","network":{"localAddress":"127.0.0.1:3333","remoteAddress":"Handshake"},"protocols":{"eth":{"difficulty":null,"head":"000000000000000000000000000000000000000000000000000000000000003c","version":64}}}]},"id":1}"#;
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"active":0,"connected":120,"max":50,"peers":[{"caps":["eth/62","eth/63"],"id":"node1","name":"Parity/1","network":{"localAddress":"127.0.0.1:8888","remoteAddress":"127.0.0.1:7777"},"protocols":{"eth":{"difficulty":"0x28","head":"0000000000000000000000000000000000000000000000000000000000000032","version":62},"les":null}},{"caps":["eth/63","eth/64"],"id":null,"name":"Parity/2","network":{"localAddress":"127.0.0.1:3333","remoteAddress":"Handshake"},"protocols":{"eth":{"difficulty":null,"head":"000000000000000000000000000000000000000000000000000000000000003c","version":64},"les":null}}]},"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ pub use self::hash::{H64, H160, H256, H512, H520, H2048};
|
||||
pub use self::index::Index;
|
||||
pub use self::log::Log;
|
||||
pub use self::sync::{
|
||||
SyncStatus, SyncInfo, Peers, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo, PeerEthereumProtocolInfo,
|
||||
TransactionStats, ChainStatus
|
||||
SyncStatus, SyncInfo, Peers, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo,
|
||||
TransactionStats, ChainStatus, EthProtocolInfo, LesProtocolInfo,
|
||||
};
|
||||
pub use self::transaction::{Transaction, RichRawTransaction, LocalTransactionStatus};
|
||||
pub use self::transaction_request::TransactionRequest;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use ethsync::{PeerInfo as SyncPeerInfo, TransactionStats as SyncTransactionStats};
|
||||
use ethsync::{self, PeerInfo as SyncPeerInfo, TransactionStats as SyncTransactionStats};
|
||||
use serde::{Serialize, Serializer};
|
||||
use v1::types::{U256, H512};
|
||||
|
||||
@@ -82,12 +82,14 @@ pub struct PeerNetworkInfo {
|
||||
#[derive(Default, Debug, Serialize)]
|
||||
pub struct PeerProtocolsInfo {
|
||||
/// Ethereum protocol information
|
||||
pub eth: Option<PeerEthereumProtocolInfo>,
|
||||
pub eth: Option<EthProtocolInfo>,
|
||||
/// LES protocol information.
|
||||
pub les: Option<LesProtocolInfo>,
|
||||
}
|
||||
|
||||
/// Peer Ethereum protocol information
|
||||
#[derive(Default, Debug, Serialize)]
|
||||
pub struct PeerEthereumProtocolInfo {
|
||||
pub struct EthProtocolInfo {
|
||||
/// Negotiated ethereum protocol version
|
||||
pub version: u32,
|
||||
/// Peer total difficulty if known
|
||||
@@ -96,6 +98,37 @@ pub struct PeerEthereumProtocolInfo {
|
||||
pub head: String,
|
||||
}
|
||||
|
||||
impl From<ethsync::EthProtocolInfo> for EthProtocolInfo {
|
||||
fn from(info: ethsync::EthProtocolInfo) -> Self {
|
||||
EthProtocolInfo {
|
||||
version: info.version,
|
||||
difficulty: info.difficulty.map(Into::into),
|
||||
head: info.head.hex(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Peer LES protocol information
|
||||
#[derive(Default, Debug, Serialize)]
|
||||
pub struct LesProtocolInfo {
|
||||
/// Negotiated LES protocol version
|
||||
pub version: u32,
|
||||
/// Peer total difficulty
|
||||
pub difficulty: U256,
|
||||
/// SHA3 of peer best block hash
|
||||
pub head: String,
|
||||
}
|
||||
|
||||
impl From<ethsync::LesProtocolInfo> for LesProtocolInfo {
|
||||
fn from(info: ethsync::LesProtocolInfo) -> Self {
|
||||
LesProtocolInfo {
|
||||
version: info.version,
|
||||
difficulty: info.difficulty.into(),
|
||||
head: info.head.hex(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sync status
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum SyncStatus {
|
||||
@@ -137,11 +170,8 @@ impl From<SyncPeerInfo> for PeerInfo {
|
||||
local_address: p.local_address,
|
||||
},
|
||||
protocols: PeerProtocolsInfo {
|
||||
eth: Some(PeerEthereumProtocolInfo {
|
||||
version: p.eth_version,
|
||||
difficulty: p.eth_difficulty.map(|d| d.into()),
|
||||
head: p.eth_head.hex(),
|
||||
})
|
||||
eth: p.eth_info.map(Into::into),
|
||||
les: p.les_info.map(Into::into),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user