Keep peer info up to date (#2067)

* Keep peer info up to date

* Docs

Co-Authored-By: arkpar <arkady.paronyan@gmail.com>
This commit is contained in:
Arkadiy Paronyan
2019-03-21 12:55:30 +01:00
committed by GitHub
parent e6c73e8951
commit b31bcdfcc3
2 changed files with 38 additions and 1 deletions
+19
View File
@@ -58,6 +58,15 @@ struct PeerSync<B: BlockT> {
pub recently_announced: VecDeque<B::Hash>,
}
#[derive(Debug)]
/// Peer sync status.
pub(crate) struct PeerInfo<B: BlockT> {
/// Their best block hash.
pub best_hash: B::Hash,
/// Their best block number.
pub best_number: NumberFor<B>,
}
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
enum AncestorSearchState<B: BlockT> {
/// Use exponential backoff to find an ancestor, then switch to binary search.
@@ -408,6 +417,16 @@ impl<B: BlockT> ChainSync<B> {
}
}
/// Returns peer sync status (if any).
pub(crate) fn peer_info(&self, who: NodeIndex) -> Option<PeerInfo<B>> {
self.peers.get(&who).map(|peer| {
PeerInfo {
best_hash: peer.best_hash,
best_number: peer.best_number,
}
})
}
/// Returns sync status.
pub(crate) fn status(&self) -> Status<B> {
let best_seen = self.best_seen_block();