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:
Max Inden
2020-08-28 17:34:25 +02:00
committed by GitHub
parent ff1e8150e1
commit 8fd343e39d
16 changed files with 87 additions and 76 deletions
+2 -2
View File
@@ -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)
}