mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
client/*: Treat protocol name as str and not [u8] (#6967)
* client/*: Treat protocol name as str and not [u8] Notification protocol names are in practice always valid utf8 strings. Instead of treating them as such in the type system, thus far they were casted to a [u8] at creation time. With this commit protocol names are instead treated as valid utf8 strings throughout the codebase and passed as `Cow<'static, str>` instead of `Cow<'static, [u8]>`. Among other things this eliminates the need for string casting when logging. * client/network: Don't allocate when protocol name is borrowed
This commit is contained in:
@@ -69,7 +69,7 @@ impl<B: BlockT> GossipEngine<B> {
|
||||
pub fn new<N: Network<B> + Send + Clone + 'static>(
|
||||
network: N,
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: impl Into<Cow<'static, [u8]>>,
|
||||
protocol_name: impl Into<Cow<'static, str>>,
|
||||
validator: Arc<dyn Validator<B>>,
|
||||
) -> Self where B: 'static {
|
||||
// We grab the event stream before registering the notifications protocol, otherwise we
|
||||
@@ -333,7 +333,7 @@ mod tests {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn register_notifications_protocol(&self, _: ConsensusEngineId, _: Cow<'static, [u8]>) {}
|
||||
fn register_notifications_protocol(&self, _: ConsensusEngineId, _: Cow<'static, str>) {}
|
||||
|
||||
fn announce(&self, _: B::Hash, _: Vec<u8>) {
|
||||
unimplemented!();
|
||||
@@ -362,7 +362,7 @@ mod tests {
|
||||
let mut gossip_engine = GossipEngine::<Block>::new(
|
||||
network.clone(),
|
||||
[1, 2, 3, 4],
|
||||
"my_protocol".as_bytes(),
|
||||
"my_protocol",
|
||||
Arc::new(AllowAll{}),
|
||||
);
|
||||
|
||||
@@ -390,7 +390,7 @@ mod tests {
|
||||
let mut gossip_engine = GossipEngine::<Block>::new(
|
||||
network.clone(),
|
||||
engine_id.clone(),
|
||||
"my_protocol".as_bytes(),
|
||||
"my_protocol",
|
||||
Arc::new(AllowAll{}),
|
||||
);
|
||||
|
||||
@@ -525,7 +525,7 @@ mod tests {
|
||||
let mut gossip_engine = GossipEngine::<Block>::new(
|
||||
network.clone(),
|
||||
engine_id.clone(),
|
||||
"my_protocol".as_bytes(),
|
||||
"my_protocol",
|
||||
Arc::new(TestValidator{}),
|
||||
);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ pub trait Network<B: BlockT> {
|
||||
fn register_notifications_protocol(
|
||||
&self,
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: Cow<'static, [u8]>,
|
||||
protocol_name: Cow<'static, str>,
|
||||
);
|
||||
|
||||
/// Notify everyone we're connected to that we have the given block.
|
||||
@@ -117,7 +117,7 @@ impl<B: BlockT, H: ExHashT> Network<B> for Arc<NetworkService<B, H>> {
|
||||
fn register_notifications_protocol(
|
||||
&self,
|
||||
engine_id: ConsensusEngineId,
|
||||
protocol_name: Cow<'static, [u8]>,
|
||||
protocol_name: Cow<'static, str>,
|
||||
) {
|
||||
NetworkService::register_notifications_protocol(self, engine_id, protocol_name)
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ mod tests {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn register_notifications_protocol(&self, _: ConsensusEngineId, _: Cow<'static, [u8]>) {}
|
||||
fn register_notifications_protocol(&self, _: ConsensusEngineId, _: Cow<'static, str>) {}
|
||||
|
||||
fn announce(&self, _: B::Hash, _: Vec<u8>) {
|
||||
unimplemented!();
|
||||
|
||||
Reference in New Issue
Block a user