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:
Gregory Terzian
2019-03-02 21:35:16 +08:00
committed by Gav Wood
parent 828cd9580a
commit a81f7f48a0
9 changed files with 90 additions and 54 deletions
+22 -18
View File
@@ -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
}
}