Skip to content

Commit

Permalink
Added on_block_imported on NetworkService
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Mar 12, 2020
1 parent c31d416 commit ba360ca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
pub fn num_connected(&self) -> usize {
self.num_connected.load(Ordering::Relaxed)
}

/// You must call this when a new block is imported by the client.
pub fn on_block_imported(&self, header: B::Header, data: Vec<u8>, is_best: bool) {
let _ = self.to_worker.unbounded_send(ServiceToWorkerMsg::OnBlockImported(header, data, is_best));
}
}

impl<B: BlockT + 'static, H: ExHashT> sp_consensus::SyncOracle
Expand Down Expand Up @@ -739,6 +744,7 @@ enum ServiceToWorkerMsg<B: BlockT, H: ExHashT> {
protocol_name: Cow<'static, [u8]>,
},
DisconnectPeer(PeerId),
OnBlockImported(B::Header, Vec<u8>, bool),
}

/// Main network worker. Must be polled in order for the network to advance.
Expand Down Expand Up @@ -929,6 +935,8 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
},
ServiceToWorkerMsg::DisconnectPeer(who) =>
this.network_service.user_protocol_mut().disconnect_peer(&who),
ServiceToWorkerMsg::OnBlockImported(header, data, is_best) =>
this.network_service.user_protocol_mut().on_block_imported(&header, data, is_best),
}
}

Expand Down

0 comments on commit ba360ca

Please sign in to comment.