From 1aba9812c701dbdddc84485cc8589e3f788bbd96 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 16 Jan 2023 16:55:16 +0100 Subject: [PATCH] node: Request recent messages on connection Instead of only being interested in messages from "now", we request messages from one hour in the past up to now. This lets nodes catch up on state more quickly, without having to wait for new announcements. Signed-off-by: Alexis Sellier --- radicle-node/src/service.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/radicle-node/src/service.rs b/radicle-node/src/service.rs index 11a25a6f..17e90603 100644 --- a/radicle-node/src/service.rs +++ b/radicle-node/src/service.rs @@ -65,6 +65,8 @@ pub const KEEP_ALIVE_DELTA: LocalDuration = LocalDuration::from_secs(30); pub const MAX_TIME_DELTA: LocalDuration = LocalDuration::from_mins(60); /// Maximum attempts to connect to a peer before we give up. pub const MAX_CONNECTION_ATTEMPTS: usize = 3; +/// How far back from the present time should we request gossip messages when connecting to a peer. +pub const SUBSCRIBE_BACKLOG_DELTA: LocalDuration = LocalDuration::from_mins(60); /// Maximum external address limit imposed by message size limits. pub use message::ADDRESS_LIMIT; @@ -1287,7 +1289,7 @@ mod gossip { } pub fn handshake( - timestamp: Timestamp, + now: Timestamp, storage: &S, signer: &G, filter: Filter, @@ -1305,10 +1307,14 @@ mod gossip { let mut msgs = vec![ Message::init(), - Message::inventory(gossip::inventory(timestamp, inventory), signer), - Message::subscribe(filter, timestamp, Timestamp::MAX), + Message::inventory(gossip::inventory(now, inventory), signer), + Message::subscribe( + filter, + now - SUBSCRIBE_BACKLOG_DELTA.as_secs(), + Timestamp::MAX, + ), ]; - if let Some(m) = gossip::node(timestamp, config) { + if let Some(m) = gossip::node(now, config) { msgs.push(Message::node(m, signer)); };