pallet-beefy-mmr: better logging on BEEFY key to ETH address conversion (#1520)

# Description

Each time the validator set changes, BEEFY validator keys are converted
to ETH addresses and merkelised into a `keyset_commitment` to be used by
light clients.

This commit downgrades `error` to `debug` when individual conversions
from BEEFY keys to ETH addresses fail, and adds cumulative check that
reports total number of failed conversions, if any, on `error`
log-level.

Fixes https://github.com/paritytech/polkadot-sdk/issues/1305

Signed-off-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Adrian Catangiu
2023-09-13 10:33:12 +03:00
committed by GitHub
parent f204e3264f
commit 35de1f2769
+14 -1
View File
@@ -79,7 +79,7 @@ impl Convert<sp_consensus_beefy::ecdsa_crypto::AuthorityId, Vec<u8>> for BeefyEc
.to_eth_address() .to_eth_address()
.map(|v| v.to_vec()) .map(|v| v.to_vec())
.map_err(|_| { .map_err(|_| {
log::error!(target: "runtime::beefy", "Failed to convert BEEFY PublicKey to ETH address!"); log::debug!(target: "runtime::beefy", "Failed to convert BEEFY PublicKey to ETH address!");
}) })
.unwrap_or_default() .unwrap_or_default()
} }
@@ -199,7 +199,20 @@ impl<T: Config> Pallet<T> {
.cloned() .cloned()
.map(T::BeefyAuthorityToMerkleLeaf::convert) .map(T::BeefyAuthorityToMerkleLeaf::convert)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let default_eth_addr = [0u8; 20];
let len = beefy_addresses.len() as u32; let len = beefy_addresses.len() as u32;
let uninitialized_addresses = beefy_addresses
.iter()
.filter(|&addr| addr.as_slice().eq(&default_eth_addr))
.count();
if uninitialized_addresses > 0 {
log::error!(
target: "runtime::beefy",
"Failed to convert {} out of {} BEEFY PublicKeys to ETH addresses!",
uninitialized_addresses,
len,
);
}
let keyset_commitment = binary_merkle_tree::merkle_root::< let keyset_commitment = binary_merkle_tree::merkle_root::<
<T as pallet_mmr::Config>::Hashing, <T as pallet_mmr::Config>::Hashing,
_, _,