Move block announcement protocol config out of Protocol (#12441)

* Move Role(s) to `sc-network-common`

* Introduce `NotificationHandshake` type

* Move block announce protocol config creation to `ChainSync`

* Include block announcement into `notification_protocols`

* Apply review comments

* Remove unneeded include

* Add missing include

* Apply review comments
This commit is contained in:
Aaro Altonen
2022-10-10 10:10:53 +03:00
committed by GitHub
parent 0b77060986
commit ce9ce49bc6
23 changed files with 439 additions and 263 deletions
@@ -19,10 +19,12 @@
//! Network packet message types. These get serialized and put into the lower level protocol
//! payload.
use crate::protocol::role::Roles;
use bitflags::bitflags;
use codec::{Decode, Encode, Error, Input, Output};
pub use generic::{BlockAnnounce, FromBlock};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
/// Type alias for using the block request type using block type parameters.
pub type BlockRequest<B> =
@@ -218,3 +220,27 @@ pub mod generic {
}
}
}
/// Handshake sent when we open a block announces substream.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
pub struct BlockAnnouncesHandshake<B: BlockT> {
/// Roles of the node.
pub roles: Roles,
/// Best block number.
pub best_number: NumberFor<B>,
/// Best block hash.
pub best_hash: B::Hash,
/// Genesis block hash.
pub genesis_hash: B::Hash,
}
impl<B: BlockT> BlockAnnouncesHandshake<B> {
pub fn build(
roles: Roles,
best_number: NumberFor<B>,
best_hash: B::Hash,
genesis_hash: B::Hash,
) -> Self {
Self { genesis_hash, roles, best_number, best_hash }
}
}