From 2e2f4f26cd361119d5f1217edf686d2c15c67f85 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 26 Jul 2019 08:29:41 -0700 Subject: [PATCH] Display tendermint::consensus::State height/round/step --- src/session.rs | 12 ++++++------ tendermint-rs/src/consensus/state.rs | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/session.rs b/src/session.rs index aff49b7..eb3f61d 100644 --- a/src/session.rs +++ b/src/session.rs @@ -186,8 +186,8 @@ where let height = request.height().unwrap(); warn!( - "[{}:{}] attempt to double sign at height: {}", - &self.chain_id, &self.peer_addr, height + "[{}:{}] attempt to double sign at height/round/step: {}", + &self.chain_id, &self.peer_addr, request_state ); let remote_err = RemoteError::double_sign(height); @@ -242,8 +242,8 @@ where /// Write an INFO logline about a signing request fn log_signing_request(&self, request: &T, started_at: Instant) { - let height = request - .height() + let consensus_state = request + .consensus_state() .map(|h| h.to_string()) .unwrap_or_else(|| "none".to_owned()); @@ -253,11 +253,11 @@ where .unwrap_or_else(|| "Unknown".to_owned()); info!( - "[{}@{}] signed {:?} at height: {} ({} ms)", + "[{}@{}] signed {:?} at height/round/step: {} ({} ms)", &self.chain_id, &self.peer_addr, msg_type, - height, + consensus_state, started_at.elapsed().as_millis() ); } diff --git a/tendermint-rs/src/consensus/state.rs b/tendermint-rs/src/consensus/state.rs index ef67cb7..aa525c1 100644 --- a/tendermint-rs/src/consensus/state.rs +++ b/tendermint-rs/src/consensus/state.rs @@ -1,7 +1,7 @@ //! Tendermint consensus state pub use crate::block; -pub use std::cmp::Ordering; +pub use std::{cmp::Ordering, fmt}; #[cfg(feature = "serde")] use { crate::serializers, @@ -32,6 +32,12 @@ pub struct State { pub block_id: Option, } +impl fmt::Display for State { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}/{}/{}", self.height, self.round, self.step) + } +} + impl Ord for State { fn cmp(&self, other: &State) -> Ordering { if self.height < other.height {