diff --git a/core/client/db/src/lib.rs b/core/client/db/src/lib.rs index 15a71344a5b4a2953a320b82883fdde2e672a0f8..9427e28c902973c41aa18b1bd440d49db1a6bb45 100644 --- a/core/client/db/src/lib.rs +++ b/core/client/db/src/lib.rs @@ -56,7 +56,7 @@ use crate::storage_cache::{CachingState, SharedCache, new_shared_cache}; use log::{trace, debug, warn}; pub use state_db::PruningMode; -const CANONICALIZATION_DELAY: u64 = 256; +const CANONICALIZATION_DELAY: u64 = 4096; const MIN_BLOCKS_TO_KEEP_CHANGES_TRIES_FOR: u64 = 32768; const STATE_CACHE_SIZE_BYTES: usize = 16 * 1024 * 1024; diff --git a/core/consensus/aura/src/lib.rs b/core/consensus/aura/src/lib.rs index a531bd8bba1c8b67f7218d9606165ceaf568ee74..154bc214f6d8340f599bbc696e051507b8b9e970 100644 --- a/core/consensus/aura/src/lib.rs +++ b/core/consensus/aura/src/lib.rs @@ -272,6 +272,11 @@ pub fn start_aura<B, C, E, I, SO, Error>( } }; + if sync_oracle.is_offline() && authorities.len() > 1 { + debug!(target: "aura", "Skipping proposal slot. Waiting for the netork."); + return Either::B(future::ok(())); + } + let proposal_work = match slot_author(slot_num, &authorities) { None => return Either::B(future::ok(())), Some(author) => if author.0 == public_key.0 { diff --git a/core/consensus/common/src/lib.rs b/core/consensus/common/src/lib.rs index ccbafdb86369a8e4f8d33c764654840c0374a06c..904e01325666a2771a179aa7094fab08386c9f68 100644 --- a/core/consensus/common/src/lib.rs +++ b/core/consensus/common/src/lib.rs @@ -88,6 +88,9 @@ pub trait SyncOracle { /// Whether the synchronization service is undergoing major sync. /// Returns true if so. fn is_major_syncing(&self) -> bool; + /// Whether the synchronization service is offline. + /// Returns true if so. + fn is_offline(&self) -> bool; } /// A synchronization oracle for when there is no network. @@ -96,10 +99,14 @@ pub struct NoNetwork; impl SyncOracle for NoNetwork { fn is_major_syncing(&self) -> bool { false } + fn is_offline(&self) -> bool { false } } impl<T: SyncOracle> SyncOracle for Arc<T> { fn is_major_syncing(&self) -> bool { T::is_major_syncing(&*self) } + fn is_offline(&self) -> bool { + T::is_offline(&*self) + } } diff --git a/core/network/src/protocol.rs b/core/network/src/protocol.rs index 2506dcd5462abf3f1c755aa3589ee977ee2d34c0..b2e02ea4e31dae87c206643450a811abc5fe6bc4 100644 --- a/core/network/src/protocol.rs +++ b/core/network/src/protocol.rs @@ -433,7 +433,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> { } debug!(target: "sync", "{} clogging messages:", clogging_messages.len()); - for msg_bytes in clogging_messages { + for msg_bytes in clogging_messages.take(5) { if let Some(msg) = <Message<B> as Decode>::decode(&mut Cursor::new(msg_bytes)) { debug!(target: "sync", "{:?}", msg); } else { diff --git a/core/network/src/service.rs b/core/network/src/service.rs index 05b455aead06a5d76cc167de7fca4ecc28777ef9..7e74c19ff58c4f0306be24743c2cd99a4513b3c6 100644 --- a/core/network/src/service.rs +++ b/core/network/src/service.rs @@ -234,6 +234,9 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> ::consensus:: fn is_major_syncing(&self) -> bool { self.handler.sync().read().status().is_major_syncing() } + fn is_offline(&self) -> bool { + self.handler.sync().read().status().is_offline() + } } impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H:ExHashT> Drop for Service<B, S, H> { diff --git a/core/network/src/sync.rs b/core/network/src/sync.rs index dc929899c53577483180d17442092520cad26886..b9fd2d289c44e99aa20eed21709aa82fe73f4864 100644 --- a/core/network/src/sync.rs +++ b/core/network/src/sync.rs @@ -263,6 +263,8 @@ pub struct Status<B: BlockT> { pub state: SyncState, /// Target sync block number. pub best_seen_block: Option<NumberFor<B>>, + /// Number of peers participating in syncing. + pub num_peers: u32, } impl<B: BlockT> Status<B> { @@ -274,6 +276,11 @@ impl<B: BlockT> Status<B> { SyncState::Downloading => true, } } + + /// Are we all alone? + pub fn is_offline(&self) -> bool { + self.num_peers == 0 + } } impl<B: BlockT> ChainSync<B> { @@ -315,6 +322,7 @@ impl<B: BlockT> ChainSync<B> { Status { state: state, best_seen_block: best_seen, + num_peers: self.peers.len() as u32, } } diff --git a/core/rpc/src/system/tests.rs b/core/rpc/src/system/tests.rs index 1f13abd7ec398d35ab5c1e29d9d4c089308ea3ff..5f6214de4f969ae8913d39ec3d3cbfe35dd6e359 100644 --- a/core/rpc/src/system/tests.rs +++ b/core/rpc/src/system/tests.rs @@ -33,6 +33,7 @@ impl network::SyncProvider<Block> for Status { 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,