Skip to content

Commit f572e80

Browse files
authored
fix: disable message limit (#2)
1 parent ed2ada9 commit f572e80

File tree

2 files changed

+4
-61
lines changed

2 files changed

+4
-61
lines changed

relay_rpc/src/rpc.rs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ pub const JSON_RPC_VERSION_STR: &str = "2.0";
1616
pub static JSON_RPC_VERSION: once_cell::sync::Lazy<Arc<str>> =
1717
once_cell::sync::Lazy::new(|| Arc::from(JSON_RPC_VERSION_STR));
1818

19-
/// The maximum message length in bytes.
20-
///
21-
/// See <https://github.com/WalletConnect/walletconnect-docs/blob/main/docs/specs/servers/relay/relay-server-rpc.md>
22-
pub const MAX_MESSAGE_LENGTH: usize = 20000;
23-
2419
/// The maximum number of topics allowed for a batch subscribe request.
2520
///
2621
/// See <https://github.com/WalletConnect/walletconnect-docs/blob/main/docs/specs/servers/relay/relay-server-rpc.md>
@@ -40,12 +35,6 @@ pub enum ValidationError {
4035
#[error("Invalid JSON RPC version")]
4136
JsonRpcVersion,
4237

43-
#[error(
44-
"Message is too long. Maximum message length is {} characters",
45-
MAX_MESSAGE_LENGTH
46-
)]
47-
MessageLength,
48-
4938
#[error(
5039
"The batch contains too many items. Maximum number of subscriptions is {}",
5140
MAX_SUBSCRIPTION_BATCH_SIZE
@@ -258,16 +247,7 @@ impl ErrorResponse {
258247
/// Validates the parameters.
259248
pub fn validate(&self) -> Result<(), ValidationError> {
260249
if self.jsonrpc.as_ref() != JSON_RPC_VERSION_STR {
261-
return Err(ValidationError::JsonRpcVersion);
262-
}
263-
264-
let data_len = self.error.data.as_deref().map(str::len).unwrap_or(0);
265-
let total_len = data_len + self.error.message.len();
266-
267-
// Make sure the combined length of error message and the optional `data` param
268-
// do not exceed the `MAX_MESSAGE_LENGTH` limit.
269-
if total_len > MAX_MESSAGE_LENGTH {
270-
Err(ValidationError::MessageLength)
250+
Err(ValidationError::JsonRpcVersion)
271251
} else {
272252
Ok(())
273253
}
@@ -487,11 +467,7 @@ impl RequestPayload for Publish {
487467
.decode()
488468
.map_err(ValidationError::TopicDecoding)?;
489469

490-
if self.message.len() > MAX_MESSAGE_LENGTH {
491-
Err(ValidationError::MessageLength)
492-
} else {
493-
Ok(())
494-
}
470+
Ok(())
495471
}
496472

497473
fn into_params(self) -> Params {
@@ -530,11 +506,7 @@ impl RequestPayload for Subscription {
530506
.decode()
531507
.map_err(ValidationError::TopicDecoding)?;
532508

533-
if self.data.message.len() > MAX_MESSAGE_LENGTH {
534-
Err(ValidationError::MessageLength)
535-
} else {
536-
Ok(())
537-
}
509+
Ok(())
538510
}
539511

540512
fn into_params(self) -> Params {

relay_rpc/src/rpc/tests.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn validation() {
195195
// Valid data.
196196
let id = MessageId::from(1);
197197
let jsonrpc: Arc<str> = "2.0".into();
198-
let message: Arc<str> = "0".repeat(MAX_MESSAGE_LENGTH).into();
198+
let message: Arc<str> = "0".repeat(512).into();
199199
let topic = Topic::from("c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9840");
200200
let subscription_id =
201201
SubscriptionId::from("c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9841");
@@ -245,20 +245,6 @@ fn validation() {
245245
Err(ValidationError::TopicDecoding(DecodingError::Length))
246246
);
247247

248-
// Publish: invalid message.
249-
let request = Request {
250-
id,
251-
jsonrpc: jsonrpc.clone(),
252-
params: Params::Publish(Publish {
253-
topic: topic.clone(),
254-
message: "0".repeat(MAX_MESSAGE_LENGTH + 1).into(),
255-
ttl_secs: 0,
256-
tag: 0,
257-
prompt: false,
258-
}),
259-
};
260-
assert_eq!(request.validate(), Err(ValidationError::MessageLength));
261-
262248
// Subscribe: valid.
263249
let request = Request {
264250
id,
@@ -360,21 +346,6 @@ fn validation() {
360346
Err(ValidationError::TopicDecoding(DecodingError::Length))
361347
);
362348

363-
// Subscription: invalid message.
364-
let request = Request {
365-
id,
366-
jsonrpc: jsonrpc.clone(),
367-
params: Params::Subscription(Subscription {
368-
id: subscription_id.clone(),
369-
data: SubscriptionData {
370-
topic: topic.clone(),
371-
message: "0".repeat(MAX_MESSAGE_LENGTH + 1).into(),
372-
published_at: 123,
373-
},
374-
}),
375-
};
376-
assert_eq!(request.validate(), Err(ValidationError::MessageLength));
377-
378349
// Batch subscription: valid.
379350
let request = Request {
380351
id,

0 commit comments

Comments
 (0)