BEEFY and GRANDPA protocol names should use full genesis hash (#10974)

std::fmt::Display shows formats as reduced hash (e.g. 0xb0a8…dafe)

Use hex::encode to format full hash.

Signed-off-by: acatangiu <adrian@parity.io>
This commit is contained in:
Adrian Catangiu
2022-03-04 18:22:52 +02:00
committed by GitHub
parent 6cfdbe5caa
commit d41838076e
6 changed files with 103 additions and 6 deletions
@@ -77,13 +77,13 @@ pub mod grandpa_protocol_name {
/// Name of the notifications protocol used by GRANDPA.
///
/// Must be registered towards the networking in order for GRANDPA to properly function.
pub fn standard_name<Hash: std::fmt::Display>(
pub fn standard_name<Hash: AsRef<[u8]>>(
genesis_hash: &Hash,
chain_spec: &Box<dyn ChainSpec>,
) -> std::borrow::Cow<'static, str> {
let chain_prefix = match chain_spec.fork_id() {
Some(fork_id) => format!("/{}/{}", genesis_hash, fork_id),
None => format!("/{}", genesis_hash),
Some(fork_id) => format!("/{}/{}", hex::encode(genesis_hash), fork_id),
None => format!("/{}", hex::encode(genesis_hash)),
};
format!("{}{}", chain_prefix, NAME).into()
}