diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index 6256cdd64d..c4b6d97909 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -713,6 +713,17 @@ impl NetworkService { pub fn num_connected(&self) -> usize { self.num_connected.load(Ordering::Relaxed) } + + /// This function should be called when blocks are added to the chain by something other + /// than the import queue. + /// + /// > **Important**: This function is a hack and can be removed at any time. Do **not** use it. + pub fn update_chain(&self) { + let _ = self + .to_worker + .unbounded_send(ServiceToWorkerMsg::UpdateChain); + } + } impl sp_consensus::SyncOracle @@ -778,6 +789,7 @@ enum ServiceToWorkerMsg { protocol_name: Cow<'static, [u8]>, }, DisconnectPeer(PeerId), + UpdateChain, } /// Main network worker. Must be polled in order for the network to advance. @@ -1106,6 +1118,8 @@ impl Future for NetworkWorker { }, ServiceToWorkerMsg::DisconnectPeer(who) => this.network_service.user_protocol_mut().disconnect_peer(&who), + ServiceToWorkerMsg::UpdateChain => + this.network_service.user_protocol_mut().update_chain(), } } diff --git a/substrate/client/service/test/src/lib.rs b/substrate/client/service/test/src/lib.rs index 63c7e0795d..2061530825 100644 --- a/substrate/client/service/test/src/lib.rs +++ b/substrate/client/service/test/src/lib.rs @@ -457,6 +457,7 @@ pub fn sync( make_block_and_import(&first_service.get(), first_user_data); } + (network.full_nodes[0].1).0.lock().unwrap().network().update_chain(); network.full_nodes[0].3.clone() };