protocol: provide more information for invalid timestamps

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.
This commit is contained in:
Fintan Halpenny 2025-12-03 11:44:08 +00:00 committed by Lorenz Leutgeb
parent ac5fc67428
commit 1f40b32b6a
3 changed files with 16 additions and 4 deletions

View File

@ -457,8 +457,8 @@ fn test_inventory_relay_bad_timestamp() {
); );
assert_matches!( assert_matches!(
alice.outbox().next(), alice.outbox().next(),
Some(Io::Disconnect(addr, DisconnectReason::Session(session::Error::InvalidTimestamp(t)))) Some(Io::Disconnect(addr, DisconnectReason::Session(session::Error::InvalidTimestamp(session::InvalidTimestamp::Future { theirs, .. }))))
if addr == bob.id() && t == timestamp if addr == bob.id() && theirs == timestamp
); );
} }

View File

@ -1461,7 +1461,7 @@ where
// Don't allow messages from too far in the future. // Don't allow messages from too far in the future.
if timestamp.saturating_sub(now.as_millis()) > MAX_TIME_DELTA.as_millis() as u64 { 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 // We don't process announcements from nodes we don't know, since the node announcement is

View File

@ -21,7 +21,7 @@ pub enum Error {
/// The remote peer sent an invalid announcement timestamp, /// The remote peer sent an invalid announcement timestamp,
/// for eg. a timestamp far in the future. /// for eg. a timestamp far in the future.
#[error("invalid announcement timestamp: {0}")] #[error("invalid announcement timestamp: {0}")]
InvalidTimestamp(Timestamp), InvalidTimestamp(InvalidTimestamp),
/// The remote peer sent git protocol messages while we were expecting /// The remote peer sent git protocol messages while we were expecting
/// gossip messages. Or vice-versa. /// gossip messages. Or vice-versa.
#[error("protocol mismatch")] #[error("protocol mismatch")]
@ -34,6 +34,18 @@ pub enum Error {
Timeout, Timeout,
} }
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 { impl Error {
/// Return the severity for this error. /// Return the severity for this error.
pub fn severity(&self) -> Severity { pub fn severity(&self) -> Severity {