Skip to content

Commit 4f4e042

Browse files
committed
relay-pool: disable the default event max size limit
By default, enable only the max message size limit (5MB) and keep the max event size limit disabled (previously 70kb). This will prevent issues with NWC or similar protocols, which may often receive events above 70kb. Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent fecadbd commit 4f4e042

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

crates/nostr-relay-pool/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- Simplify received message logging (https://github.com/rust-nostr/nostr/pull/945)
3737
- Trim incoming relay messages before processing
3838
- Verify that the received events belong to a subscription (https://github.com/rust-nostr/nostr/pull/979)
39+
- Disable the default event max size limit (TBD)
3940

4041
### Added
4142

crates/nostr-relay-pool/src/relay/constants.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ pub const DEFAULT_NOTIFICATION_CHANNEL_SIZE: usize = 2048;
1616

1717
/// Max relay size
1818
pub const MAX_MESSAGE_SIZE: u32 = 5 * 1024 * 1024; // 5 MB
19-
/// Max event size
20-
pub const MAX_EVENT_SIZE: u32 = 70 * 1024; // 70 kB
21-
/// Max event size for contact list kind
22-
pub const MAX_CONTACT_LIST_EVENT_SIZE: u32 = 840 * 1024; // 840 kB
2319

2420
pub(super) const DEFAULT_RETRY_INTERVAL: Duration = Duration::from_secs(10);
2521
// Not increase the max retry interval too much.

crates/nostr-relay-pool/src/relay/limits.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::collections::HashMap;
88

99
use nostr::Kind;
1010

11-
use super::constants::{MAX_CONTACT_LIST_EVENT_SIZE, MAX_EVENT_SIZE, MAX_MESSAGE_SIZE};
11+
use super::constants::MAX_MESSAGE_SIZE;
1212

1313
/// Relay limits
1414
#[derive(Debug, Clone, Default, PartialEq, Eq)]
@@ -55,7 +55,7 @@ impl RelayMessageLimits {
5555
/// Events limits
5656
#[derive(Debug, Clone, PartialEq, Eq)]
5757
pub struct RelayEventLimits {
58-
/// Maximum size of normalised JSON, in bytes (default: [`MAX_EVENT_SIZE`])
58+
/// Maximum size of the normalized JSON, in bytes (default: None)
5959
pub max_size: Option<u32>,
6060
/// Maximum size of normalized JSON per [Kind], in bytes.
6161
pub max_size_per_kind: HashMap<Kind, Option<u32>>,
@@ -67,15 +67,12 @@ pub struct RelayEventLimits {
6767

6868
impl Default for RelayEventLimits {
6969
fn default() -> Self {
70-
let mut max_size_per_kind: HashMap<Kind, Option<u32>> = HashMap::with_capacity(1);
71-
max_size_per_kind.insert(Kind::ContactList, Some(MAX_CONTACT_LIST_EVENT_SIZE));
72-
7370
let mut max_num_tags_per_kind: HashMap<Kind, Option<u16>> = HashMap::with_capacity(1);
7471
max_num_tags_per_kind.insert(Kind::ContactList, Some(10_000));
7572

7673
Self {
77-
max_size: Some(MAX_EVENT_SIZE),
78-
max_size_per_kind,
74+
max_size: None,
75+
max_size_per_kind: HashMap::new(),
7976
max_num_tags: Some(2_000),
8077
max_num_tags_per_kind,
8178
}
@@ -134,13 +131,7 @@ mod tests {
134131
fn test_event_limits_get_max_size() {
135132
let limits = RelayLimits::default();
136133

137-
assert_eq!(
138-
limits.events.get_max_size(&Kind::TextNote),
139-
Some(MAX_EVENT_SIZE)
140-
);
141-
assert_eq!(
142-
limits.events.get_max_size(&Kind::ContactList),
143-
Some(MAX_CONTACT_LIST_EVENT_SIZE)
144-
);
134+
assert_eq!(limits.events.get_max_size(&Kind::TextNote), None,);
135+
assert_eq!(limits.events.get_max_size(&Kind::ContactList), None,);
145136
}
146137
}

0 commit comments

Comments
 (0)