Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
protocol: provide more information for invalid timestamps
Open fintohaps opened 4 months ago

The invalid timestamp error will only tell the timestamp of the offending node’s message.

Currently, there are issues where that error is occurring but the timestamp seems legitimate. This patch adds the running node’s timestamp to help debug the issue.

3 files changed +16 -4 37d4ae4a 91002ad5
modified crates/radicle-node/src/tests.rs
@@ -447,8 +447,8 @@ fn test_inventory_relay_bad_timestamp() {
    );
    assert_matches!(
        alice.outbox().next(),
-
        Some(Io::Disconnect(addr, DisconnectReason::Session(session::Error::InvalidTimestamp(t))))
-
        if addr == bob.id() && t == timestamp
+
        Some(Io::Disconnect(addr, DisconnectReason::Session(session::Error::InvalidTimestamp(session::InvalidTimestamp::Future { theirs, .. }))))
+
        if addr == bob.id() && theirs == timestamp
    );
}

modified crates/radicle-protocol/src/service.rs
@@ -1524,7 +1524,7 @@ where

        // Don't allow messages from too far in the future.
        if timestamp.saturating_sub(now.as_millis()) > MAX_TIME_DELTA.as_millis() as u64 {
-
            return Err(session::Error::InvalidTimestamp(timestamp));
+
            return Err(session::Error::future_timestamp(timestamp, now.into()));
        }

        // We don't process announcements from nodes we don't know, since the node announcement is
modified crates/radicle-protocol/src/service/session.rs
@@ -22,7 +22,7 @@ pub enum Error {
    /// The remote peer sent an invalid announcement timestamp,
    /// for eg. a timestamp far in the future.
    #[error("invalid announcement timestamp: {0}")]
-
    InvalidTimestamp(Timestamp),
+
    InvalidTimestamp(InvalidTimestamp),
    /// The remote peer sent git protocol messages while we were expecting
    /// gossip messages. Or vice-versa.
    #[error("protocol mismatch")]
@@ -36,6 +36,18 @@ pub enum Error {
}

impl Error {
+
    pub(crate) fn future_timestamp(theirs: Timestamp, ours: Timestamp) -> Self {
+
        Self::InvalidTimestamp(InvalidTimestamp::Future { theirs, ours })
+
    }
+
}
+

+
#[derive(thiserror::Error, Debug, Clone, Copy)]
+
pub enum InvalidTimestamp {
+
    #[error("{theirs} appears too far in the future compared to {ours}")]
+
    Future { theirs: Timestamp, ours: Timestamp },
+
}
+

+
impl Error {
    /// Return the severity for this error.
    pub fn severity(&self) -> Severity {
        match self {