From a889347fbb7fc10bd371cd3f241874ca7d1d2b60 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 24 Feb 2023 13:28:28 -0800 Subject: [PATCH] debug: improve Debug impl for Ed25519 VerificationKeys (#1272) Since the `ed25519_consensus::VerificationKey` is no longer used, the `VerificationKey`s go back to having raw debug output that's hard to read when it appears in logs. This commit restores the hex-formatting previously inherited from `ed25519_consensus`, allowing nice output like (in use in `pd` downstream): ``` 2023-02-24T03:34:57.002766Z DEBUG abci:EndBlock{height=187}:end_block:staking:build_tendermint_validator_updates: updates=[Update { pub_key: Ed25519(7423aa71eb844cdde4dc0b8c72ef1225931dc54c21a102cbe2fded2645d4e814), power: Power(50000000000) }] ``` In the future, another option could be to have the key be base64-encoded, to match Tendermint's data structures, but this is a less obtrusive change (not requiring a base64 encoder) to restore functionality first. --- .../unreleased/bug-fixes/1272-ed25519-debug.md | 2 ++ .../src/crypto/ed25519/verification_key.rs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changelog/unreleased/bug-fixes/1272-ed25519-debug.md diff --git a/.changelog/unreleased/bug-fixes/1272-ed25519-debug.md b/.changelog/unreleased/bug-fixes/1272-ed25519-debug.md new file mode 100644 index 000000000..af8ed5239 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/1272-ed25519-debug.md @@ -0,0 +1,2 @@ +- `[tendermint]` Restore hex-formatting in debug output of Ed25519 keys. + ([#1272](https://github.com/informalsystems/tendermint-rs/pull/1272)) diff --git a/tendermint/src/crypto/ed25519/verification_key.rs b/tendermint/src/crypto/ed25519/verification_key.rs index 52cc49dd2..305614f07 100644 --- a/tendermint/src/crypto/ed25519/verification_key.rs +++ b/tendermint/src/crypto/ed25519/verification_key.rs @@ -1,8 +1,23 @@ use crate::Error; -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Copy, Clone, Eq, PartialEq)] pub struct VerificationKey([u8; 32]); +impl core::fmt::Display for VerificationKey { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + for byte in &self.0 { + write!(f, "{byte:02x}")?; + } + Ok(()) + } +} + +impl core::fmt::Debug for VerificationKey { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + ::fmt(self, f) + } +} + impl VerificationKey { #[allow(dead_code)] pub(super) fn new(bytes: [u8; 32]) -> Self {