Skip to content

Commit

Permalink
debug: improve Debug impl for Ed25519 VerificationKeys
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hdevalence committed Feb 24, 2023
1 parent 0c37d3a commit 7325b10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/1272-ed25519-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[tendermint]` Restore hex-formatting in debug output of Ed25519 keys.
([#1272](https://github.com/informalsystems/tendermint-rs/pull/1272))
17 changes: 16 additions & 1 deletion tendermint/src/crypto/ed25519/verification_key.rs
Original file line number Diff line number Diff line change
@@ -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 {
<Self as core::fmt::Display>::fmt(self, f)
}
}

impl VerificationKey {
#[allow(dead_code)]
pub(super) fn new(bytes: [u8; 32]) -> Self {
Expand Down

0 comments on commit 7325b10

Please sign in to comment.