mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 16:17:59 +00:00
Refactor Sync status updates into a stream of updates (#1858)
* refactor sync provider * relative use of interval * typo * set propagate timeout to 2500ms * address comments * fix instant calc * update intervals
This commit is contained in:
committed by
Gav Wood
parent
828cd9580a
commit
a81f7f48a0
@@ -109,10 +109,9 @@ impl<B: traits::Block> SystemApi<B::Hash, <B::Header as HeaderT>::Number> for Sy
|
||||
}
|
||||
|
||||
fn system_health(&self) -> Result<Health> {
|
||||
let status = self.sync.status();
|
||||
Ok(Health {
|
||||
peers: status.num_peers,
|
||||
is_syncing: status.sync.is_major_syncing(),
|
||||
peers: self.sync.peers().len(),
|
||||
is_syncing: self.sync.is_major_syncing(),
|
||||
should_have_peers: self.should_have_peers,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use network::{self, SyncState, SyncStatus, ProtocolStatus, NodeIndex, PeerId, PeerInfo as NetworkPeerInfo};
|
||||
use network::{self, ProtocolStatus, NodeIndex, PeerId, PeerInfo as NetworkPeerInfo};
|
||||
use network::config::Roles;
|
||||
use test_client::runtime::Block;
|
||||
use assert_matches::assert_matches;
|
||||
use futures::sync::mpsc;
|
||||
|
||||
struct Status {
|
||||
pub peers: usize,
|
||||
@@ -40,16 +41,9 @@ impl Default for Status {
|
||||
}
|
||||
|
||||
impl network::SyncProvider<Block> for Status {
|
||||
fn status(&self) -> ProtocolStatus<Block> {
|
||||
ProtocolStatus {
|
||||
sync: SyncStatus {
|
||||
state: if self.is_syncing { SyncState::Downloading } else { SyncState::Idle },
|
||||
best_seen_block: None,
|
||||
num_peers: self.peers as u32,
|
||||
},
|
||||
num_peers: self.peers,
|
||||
num_active_peers: 0,
|
||||
}
|
||||
fn status(&self) -> mpsc::UnboundedReceiver<ProtocolStatus<Block>> {
|
||||
let (_sink, stream) = mpsc::unbounded();
|
||||
stream
|
||||
}
|
||||
|
||||
fn network_state(&self) -> network::NetworkState {
|
||||
@@ -67,13 +61,23 @@ impl network::SyncProvider<Block> for Status {
|
||||
}
|
||||
|
||||
fn peers(&self) -> Vec<(NodeIndex, NetworkPeerInfo<Block>)> {
|
||||
vec![(1, NetworkPeerInfo {
|
||||
peer_id: self.peer_id.clone(),
|
||||
roles: Roles::FULL,
|
||||
protocol_version: 1,
|
||||
best_hash: Default::default(),
|
||||
best_number: 1
|
||||
})]
|
||||
let mut peers = vec![];
|
||||
for _peer in 0..self.peers {
|
||||
peers.push(
|
||||
(1, NetworkPeerInfo {
|
||||
peer_id: self.peer_id.clone(),
|
||||
roles: Roles::FULL,
|
||||
protocol_version: 1,
|
||||
best_hash: Default::default(),
|
||||
best_number: 1
|
||||
})
|
||||
);
|
||||
}
|
||||
peers
|
||||
}
|
||||
|
||||
fn is_major_syncing(&self) -> bool {
|
||||
self.is_syncing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user