Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small cleanups #3384

Merged
merged 3 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions crates/relayer-types/src/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

use core::fmt::{Display, Error as FmtError, Formatter};
use core::hash::{Hash, Hasher};
use core::hash::Hash;
use core::num::ParseIntError;
use core::ops::{Add, Sub};
use core::str::FromStr;
Expand All @@ -21,29 +21,21 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0);
/// a `u64` value and a raw timestamp. In protocol buffer, the timestamp is
/// represented as a `u64` Unix timestamp in nanoseconds, with 0 representing the absence
/// of timestamp.
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, Deserialize, Serialize, PartialOrd, Ord)]
#[derive(
Copy, Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash,
)]
pub struct Timestamp {
time: Option<Time>,
}

// TODO: derive when tendermint::Time supports it:
// https://github.com/informalsystems/tendermint-rs/pull/1054
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for Timestamp {
fn hash<H: Hasher>(&self, state: &mut H) {
let odt: Option<OffsetDateTime> = self.time.map(Into::into);
odt.hash(state);
}
}

/// The expiry result when comparing two timestamps.
/// - If either timestamp is invalid (0), the result is `InvalidTimestamp`.
/// - If the left timestamp is strictly after the right timestamp, the result is `Expired`.
/// - Otherwise, the result is `NotExpired`.
///
/// User of this result may want to determine whether error should be raised,
/// when either of the timestamp being compared is invalid.
#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize, Hash)]
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub enum Expiry {
Expired,
NotExpired,
Expand Down Expand Up @@ -169,9 +161,9 @@ impl Display for Timestamp {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
write!(
f,
"Timestamp({})",
"{}",
self.time
.map_or("NoTimestamp".to_string(), |time| time.to_rfc3339())
.map_or_else(|| "NoTimestamp".to_string(), |time| time.to_rfc3339())
)
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/relayer/src/link/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::thread;
use std::time::{Duration, Instant};

use ibc_relayer_types::core::ics04_channel::packet::Sequence;
use itertools::Itertools;
use tracing::{error_span, info};

use ibc_relayer_types::events::IbcEvent;
Expand All @@ -23,6 +24,7 @@ use crate::link::relay_path::RelayPath;
use crate::link::relay_sender::SyncSender;
use crate::link::Link;
use crate::path::PathIdentifiers;
use crate::util::collate::CollatedIterExt;
use crate::util::pretty::{PrettyDuration, PrettySlice};

impl<ChainA: ChainHandle, ChainB: ChainHandle> RelayPath<ChainA, ChainB> {
Expand Down Expand Up @@ -150,7 +152,7 @@ impl<ChainA: ChainHandle, ChainB: ChainHandle> Link<ChainA, ChainB> {
info!(
"{} unreceived acknowledgements found: {} ",
sequences.len(),
PrettySlice(&sequences)
sequences.iter().copied().collated().format(", "),
);

let query_height = match packet_data_query_height {
Expand Down