Skip to content

Conversation

@preston-evans98
Copy link
Member

Description

This PR adds support for gzipping messages on the events and transactions websockets using the ?compression=gzip query param. When gzip is enabled...

  • Messages are chunked and encoded into a json array with at most 128 messages before being compressed and sent
  • Errors json encoded, gzipped, and sent immediately

@preston-evans98 preston-evans98 marked this pull request as ready for review January 28, 2026 21:31
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

Added gzip compression support for WebSocket subscriptions via ?compression=gzip query parameter. When enabled, messages are batched (max 128), JSON-encoded into arrays, gzip-compressed, and sent as binary frames.

Key Changes:

  • Added CompressionMode enum and CompressionQuery struct to parse query params
  • Implemented serve_generic_ws_subscription_with_config with conditional compression logic
  • Updated /sequencer/events/ws and /sequencer/txs/ws endpoints to accept compression param
  • Added comprehensive tests validating gzip magic bytes, batching, and backward compatibility
  • Used flate2 with rust_backend for compression

Observations:

  • Other WebSocket endpoints (/sequencer/txs/:tx_hash/ws, /sequencer/txs/submit/ws, and test-utils endpoints) were not updated with compression support
  • Implementation maintains backward compatibility (default is no compression)
  • Proper error handling: errors are flushed before sending compressed, and non-recoverable errors terminate connection

Confidence Score: 4/5

  • Safe to merge with minor considerations about endpoint coverage
  • Well-implemented feature with comprehensive tests and proper error handling. Score of 4 (not 5) due to inconsistent application across WebSocket endpoints - some endpoints support compression while others don't, which may confuse users
  • Consider whether rest_api.rs:425 (axum_get_tx_ws) should also support compression for consistency

Important Files Changed

Filename Overview
crates/full-node/sov-sequencer/src/rest_api.rs Added compression query param to events and transactions endpoints; other WS endpoints not updated
crates/utils/sov-rest-utils/src/lib.rs Implemented gzip compression with batching, proper error handling, and backward compatibility
crates/utils/sov-rest-utils/src/ws_tests.rs Added comprehensive tests for compression mode, gzip roundtrip, and backward compatibility

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Additional Comments (1)

crates/full-node/sov-sequencer/src/rest_api.rs
Consider adding compression support to axum_get_tx_ws for consistency with other subscription endpoints

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/full-node/sov-sequencer/src/rest_api.rs
Line: 425:425

Comment:
Consider adding compression support to `axum_get_tx_ws` for consistency with other subscription endpoints

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 77.43363% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.8%. Comparing base (4f8c280) to head (17c07cb).
⚠️ Report is 16 commits behind head on dev.

Files with missing lines Patch % Lines
crates/utils/sov-rest-utils/src/lib.rs 60.2% 39 Missing ⚠️
crates/utils/sov-rest-utils/src/ws_tests.rs 88.4% 12 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
crates/full-node/sov-sequencer/src/rest_api.rs 73.3% <100.0%> (-3.3%) ⬇️
crates/utils/sov-rest-utils/src/ws_tests.rs 84.4% <88.4%> (ø)
crates/utils/sov-rest-utils/src/lib.rs 61.3% <60.2%> (-13.7%) ⬇️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@preston-evans98 preston-evans98 changed the title Draft: Add support for gzipping messages in ws subscriptions Add support for gzipping messages in ws subscriptions Jan 29, 2026
break 'outer;
}

if !err.is_recoverable() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send_compressed_bytes calls socket.feed(..), so this error might not be sent in some cases (in the uncompressed branch, we call socket.send) is that ok? Let's rename send_compressed_bytes to feed_compressed_bytes?

Some(Ok(_)) => {
// Client sent an unexpected message - notify them it was ignored
trace!("Incoming WebSocket message but none was expected; notifying client");
if let Err(err) = send_json(&mut socket, &ErrorObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we send an uncompressed error even if config.compress == true

Copy link
Member

@bkolad bkolad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, provided my comments are addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants