mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 12:37:57 +00:00
Add block announce validator. (#3346)
* Add `BlockAnnounceValidator` trait. * Add associated data to block announcement. * Make tests compile. * Move validator into `sync.rs`. * Smaller changes. * Update core/network/src/protocol.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update core/network/src/protocol.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update core/network/src/test/sync.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Formatting. * Remove assoc. data from `BlockImportNotification`. * Use `Option<Vec<u8>>` for associated data. * Update core/network/src/protocol/sync.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Fix type error.
This commit is contained in:
committed by
Bastian Köcher
parent
4888c253a3
commit
af0d71d389
@@ -113,9 +113,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkWorker
|
||||
/// Returns a `NetworkWorker` that implements `Future` and must be regularly polled in order
|
||||
/// for the network processing to advance. From it, you can extract a `NetworkService` using
|
||||
/// `worker.service()`. The `NetworkService` can be shared through the codebase.
|
||||
pub fn new(
|
||||
params: Params<B, S, H>,
|
||||
) -> Result<NetworkWorker<B, S, H>, Error> {
|
||||
pub fn new(params: Params<B, S, H>) -> Result<NetworkWorker<B, S, H>, Error> {
|
||||
let (to_worker, from_worker) = mpsc::unbounded();
|
||||
|
||||
if let Some(ref path) = params.network_config.net_config_path {
|
||||
@@ -178,6 +176,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkWorker
|
||||
params.finality_proof_request_builder,
|
||||
params.protocol_id,
|
||||
peerset_config,
|
||||
params.block_announce_validator
|
||||
)?;
|
||||
|
||||
// Build the swarm.
|
||||
@@ -297,8 +296,8 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkWorker
|
||||
}
|
||||
|
||||
/// You must call this when a new block is imported by the client.
|
||||
pub fn on_block_imported(&mut self, hash: B::Hash, header: B::Header, is_best: bool) {
|
||||
self.network_service.user_protocol_mut().on_block_imported(hash, &header, is_best);
|
||||
pub fn on_block_imported(&mut self, hash: B::Hash, header: B::Header, data: Vec<u8>, is_best: bool) {
|
||||
self.network_service.user_protocol_mut().on_block_imported(hash, &header, data, is_best);
|
||||
}
|
||||
|
||||
/// You must call this when a new block is finalized by the client.
|
||||
@@ -394,8 +393,8 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> NetworkServic
|
||||
///
|
||||
/// In chain-based consensus, we often need to make sure non-best forks are
|
||||
/// at least temporarily synced. This function forces such an announcement.
|
||||
pub fn announce_block(&self, hash: B::Hash) {
|
||||
let _ = self.to_worker.unbounded_send(ServerToWorkerMsg::AnnounceBlock(hash));
|
||||
pub fn announce_block(&self, hash: B::Hash, data: Vec<u8>) {
|
||||
let _ = self.to_worker.unbounded_send(ServerToWorkerMsg::AnnounceBlock(hash, data));
|
||||
}
|
||||
|
||||
/// Send a consensus message through the gossip
|
||||
@@ -580,7 +579,7 @@ impl<B, S, H> NetworkStateInfo for NetworkService<B, S, H>
|
||||
enum ServerToWorkerMsg<B: BlockT, S: NetworkSpecialization<B>> {
|
||||
PropagateExtrinsics,
|
||||
RequestJustification(B::Hash, NumberFor<B>),
|
||||
AnnounceBlock(B::Hash),
|
||||
AnnounceBlock(B::Hash, Vec<u8>),
|
||||
ExecuteWithSpec(Box<dyn FnOnce(&mut S, &mut dyn Context<B>) + Send>),
|
||||
ExecuteWithGossip(Box<dyn FnOnce(&mut ConsensusGossip<B>, &mut dyn Context<B>) + Send>),
|
||||
GossipConsensusMessage(B::Hash, ConsensusEngineId, Vec<u8>, GossipMessageRecipient),
|
||||
@@ -653,8 +652,8 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> Stream for Ne
|
||||
}
|
||||
ServerToWorkerMsg::GossipConsensusMessage(topic, engine_id, message, recipient) =>
|
||||
self.network_service.user_protocol_mut().gossip_consensus_message(topic, engine_id, message, recipient),
|
||||
ServerToWorkerMsg::AnnounceBlock(hash) =>
|
||||
self.network_service.user_protocol_mut().announce_block(hash),
|
||||
ServerToWorkerMsg::AnnounceBlock(hash, data) =>
|
||||
self.network_service.user_protocol_mut().announce_block(hash, data),
|
||||
ServerToWorkerMsg::RequestJustification(hash, number) =>
|
||||
self.network_service.user_protocol_mut().request_justification(&hash, number),
|
||||
ServerToWorkerMsg::PropagateExtrinsics =>
|
||||
|
||||
Reference in New Issue
Block a user