From d808ab29eb8cb7944c1ee14e56118a599f4a0488 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Tue, 14 Feb 2023 07:47:34 +0100 Subject: [PATCH] fix: disable message limit --- relay_rpc/src/rpc.rs | 34 +++------------------------------- relay_rpc/src/rpc/tests.rs | 31 +------------------------------ 2 files changed, 4 insertions(+), 61 deletions(-) diff --git a/relay_rpc/src/rpc.rs b/relay_rpc/src/rpc.rs index 95667f0..0758193 100644 --- a/relay_rpc/src/rpc.rs +++ b/relay_rpc/src/rpc.rs @@ -16,11 +16,6 @@ pub const JSON_RPC_VERSION_STR: &str = "2.0"; pub static JSON_RPC_VERSION: once_cell::sync::Lazy> = once_cell::sync::Lazy::new(|| Arc::from(JSON_RPC_VERSION_STR)); -/// The maximum message length in bytes. -/// -/// See -pub const MAX_MESSAGE_LENGTH: usize = 20000; - /// The maximum number of topics allowed for a batch subscribe request. /// /// See @@ -40,12 +35,6 @@ pub enum ValidationError { #[error("Invalid JSON RPC version")] JsonRpcVersion, - #[error( - "Message is too long. Maximum message length is {} characters", - MAX_MESSAGE_LENGTH - )] - MessageLength, - #[error( "The batch contains too many items. Maximum number of subscriptions is {}", MAX_SUBSCRIPTION_BATCH_SIZE @@ -258,16 +247,7 @@ impl ErrorResponse { /// Validates the parameters. pub fn validate(&self) -> Result<(), ValidationError> { if self.jsonrpc.as_ref() != JSON_RPC_VERSION_STR { - return Err(ValidationError::JsonRpcVersion); - } - - let data_len = self.error.data.as_deref().map(str::len).unwrap_or(0); - let total_len = data_len + self.error.message.len(); - - // Make sure the combined length of error message and the optional `data` param - // do not exceed the `MAX_MESSAGE_LENGTH` limit. - if total_len > MAX_MESSAGE_LENGTH { - Err(ValidationError::MessageLength) + Err(ValidationError::JsonRpcVersion) } else { Ok(()) } @@ -487,11 +467,7 @@ impl RequestPayload for Publish { .decode() .map_err(ValidationError::TopicDecoding)?; - if self.message.len() > MAX_MESSAGE_LENGTH { - Err(ValidationError::MessageLength) - } else { - Ok(()) - } + Ok(()) } fn into_params(self) -> Params { @@ -530,11 +506,7 @@ impl RequestPayload for Subscription { .decode() .map_err(ValidationError::TopicDecoding)?; - if self.data.message.len() > MAX_MESSAGE_LENGTH { - Err(ValidationError::MessageLength) - } else { - Ok(()) - } + Ok(()) } fn into_params(self) -> Params { diff --git a/relay_rpc/src/rpc/tests.rs b/relay_rpc/src/rpc/tests.rs index bfef15f..e83088d 100644 --- a/relay_rpc/src/rpc/tests.rs +++ b/relay_rpc/src/rpc/tests.rs @@ -195,7 +195,7 @@ fn validation() { // Valid data. let id = MessageId::from(1); let jsonrpc: Arc = "2.0".into(); - let message: Arc = "0".repeat(MAX_MESSAGE_LENGTH).into(); + let message: Arc = "0".repeat(512).into(); let topic = Topic::from("c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9840"); let subscription_id = SubscriptionId::from("c4163cf65859106b3f5435fc296e7765411178ed452d1c30337a6230138c9841"); @@ -245,20 +245,6 @@ fn validation() { Err(ValidationError::TopicDecoding(DecodingError::Length)) ); - // Publish: invalid message. - let request = Request { - id, - jsonrpc: jsonrpc.clone(), - params: Params::Publish(Publish { - topic: topic.clone(), - message: "0".repeat(MAX_MESSAGE_LENGTH + 1).into(), - ttl_secs: 0, - tag: 0, - prompt: false, - }), - }; - assert_eq!(request.validate(), Err(ValidationError::MessageLength)); - // Subscribe: valid. let request = Request { id, @@ -360,21 +346,6 @@ fn validation() { Err(ValidationError::TopicDecoding(DecodingError::Length)) ); - // Subscription: invalid message. - let request = Request { - id, - jsonrpc: jsonrpc.clone(), - params: Params::Subscription(Subscription { - id: subscription_id.clone(), - data: SubscriptionData { - topic: topic.clone(), - message: "0".repeat(MAX_MESSAGE_LENGTH + 1).into(), - published_at: 123, - }, - }), - }; - assert_eq!(request.validate(), Err(ValidationError::MessageLength)); - // Batch subscription: valid. let request = Request { id,