mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user