Skip to content

Commit 11f6cce

Browse files
committed
allow a wider range of last-seen timestamps
With the current validation rules we drop most of the addresses while they still might be useful since it doesn't necessarily mean they are offline. We should still keep more addresses to have at least some addresses to try to connect to.
1 parent 5525c29 commit 11f6cce

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

dash-spv/src/network/addrv2.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use dashcore::network::message::NetworkMessage;
1313

1414
use crate::network::constants::{MAX_ADDR_TO_SEND, MAX_ADDR_TO_STORE};
1515

16+
const ONE_WEEK: u32 = 7 * 24 * 60 * 60;
17+
const TEN_MINUTES: u32 = 600;
18+
1619
/// Evict oldest entries if the map exceeds capacity, keeping the freshest addresses.
1720
fn evict_if_needed(peers: &mut HashMap<SocketAddr, AddrV2Message>) {
1821
if peers.len() > MAX_ADDR_TO_STORE {
@@ -62,9 +65,9 @@ impl AddrV2Handler {
6265
let mut updated = 0;
6366

6467
for msg in messages {
65-
// Validate timestamp
66-
// Accept addresses from up to 3 hours ago and up to 10 minutes in the future
67-
if msg.time <= now.saturating_sub(10800) || msg.time > now + 600 {
68+
// Accept addresses seen within the last week. Older addresses are likely stale.
69+
// Also, reject timestamps more than 10 minutes in the future which are invalid.
70+
if msg.time < now.saturating_sub(ONE_WEEK) || msg.time > now + TEN_MINUTES {
6871
log::trace!("Ignoring AddrV2 with invalid timestamp: {}", msg.time);
6972
continue;
7073
}

0 commit comments

Comments
 (0)