Skip to content

Conversation

@nimrod-teich
Copy link
Contributor

@nimrod-teich nimrod-teich commented Jan 20, 2026

Summary

Replace the grpc-web/h2c/HTTP hybrid server with a cleaner architecture using pure gRPC and native compression.

Background

The previous implementation used grpc-web and h2c HTTP wrappers to support the Lava SDK (lava-sdk/lavajs), which allowed browser-based JavaScript clients to communicate with providers. Since SDK support has been removed (see #2186), this infrastructure is no longer needed.

Changes

1. Pure gRPC Provider Listener

Replace the hybrid server with a cleaner architecture:

  • Use cmux to multiplex HTTP health checks and native gRPC on the same port
  • Remove grpcweb.WrapServer and h2c.NewHandler complexity
  • Add gRPC health checking protocol support (grpc_health_v1)
  • Keep HTTP health endpoint for Kubernetes probes compatibility
  • Optimize cmux matching: HTTP1Fast() first, then Any() for gRPC (avoids expensive HTTP/2 header parsing at high scale)

Benefits:

  • Native gRPC connection management (keepalives, stream limits)
  • Proper graceful shutdown via grpcServer.GracefulStop()
  • Simpler, more maintainable code
  • Better performance at scale (no protocol translation overhead)

2. Native gRPC Compression

Replace manual application-level compression with native gRPC gzip:

  • Remove common.CompressData() / common.DecompressData() from relay path
  • Remove custom headers (LavaCompressionHeader, LavaCompressionSupportHeader)
  • Register gzip compressor on provider via import _ "google.golang.org/grpc/encoding/gzip"
  • Consumer already uses grpc.UseCompressor(gzip.Name) when flag is enabled

3. Flag Rename

  • --enable-application-level-compression--enable-grpc-compression
  • Updated description: "enable gzip compression for gRPC messages between consumer and provider (reduces bandwidth, adds CPU overhead)"

BREAKING CHANGES

gRPC-web Protocol Removed

gRPC-web protocol is no longer supported. Browser-based clients that relied on grpc-web to communicate directly with providers will no longer work. Only native gRPC clients are supported.

Who is affected: Only the deprecated lava-sdk (browser clients) which has already been removed.

Compression Flag Renamed

The --enable-application-level-compression flag has been renamed to --enable-grpc-compression.

Migration: Update any scripts, configurations, or Kubernetes manifests using the old flag name.

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 83.05085% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
protocol/rpcprovider/provider_listener.go 89.09% 4 Missing and 2 partials ⚠️
protocol/rpcconsumer/rpcconsumer.go 0.00% 2 Missing ⚠️
protocol/rpcsmartrouter/rpcsmartrouter.go 0.00% 2 Missing ⚠️
Flag Coverage Δ
consensus 8.54% <ø> (ø)
protocol 34.14% <83.05%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
protocol/lavasession/consumer_types.go 71.34% <ø> (ø)
protocol/rpcconsumer/rpcconsumer_server.go 30.55% <ø> (+0.20%) ⬆️
protocol/rpcprovider/rpcprovider_server.go 1.92% <ø> (+0.03%) ⬆️
protocol/rpcsmartrouter/rpcsmartrouter_server.go 31.23% <ø> (-0.43%) ⬇️
protocol/rpcconsumer/rpcconsumer.go 0.00% <0.00%> (ø)
protocol/rpcsmartrouter/rpcsmartrouter.go 4.55% <0.00%> (ø)
protocol/rpcprovider/provider_listener.go 88.28% <89.09%> (+53.76%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nimrod-teich nimrod-teich force-pushed the refactor/provider-listener-pure-grpc branch from 603a3fc to cadf97a Compare January 20, 2026 11:22
@github-actions
Copy link

github-actions bot commented Jan 20, 2026

Test Results

    7 files  ± 0     85 suites  ±0   30m 53s ⏱️ -53s
3 332 tests +12  3 331 ✅ +12  1 💤 ±0  0 ❌ ±0 
3 525 runs  +12  3 524 ✅ +12  1 💤 ±0  0 ❌ ±0 

Results for commit 88bb60e. ± Comparison against base commit e4f7444.

This pull request removes 7 and adds 19 tests. Note that renamed tests count towards both.
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterCompressionHeaderLogic
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterCompressionHeaderLogic/Flag_disabled_-_no_header
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterCompressionHeaderLogic/Flag_enabled_-_header_should_be_added
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterCompressionRoundTrip
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterHandlesDecompressionError
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterNoCompressionWhenBelowThreshold
github.com/lavanet/lava/v5/protocol/rpcsmartrouter ‑ TestSmartRouterUncompressedResponseHandling
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestGRPCCompressionBidirectional
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestGRPCCompressionDisabled
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestGRPCCompressionEnabled
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestGRPCCompressionSmallPayload
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestGRPCCompressionWithConnectGRPCClient
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestNewProviderListener
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestProviderListener_ConcurrentRequests
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestProviderListener_CustomHealthPath
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestProviderListener_GRPCHealthService
github.com/lavanet/lava/v5/protocol/rpcprovider ‑ TestProviderListener_GRPCProbe
…

♻️ This comment has been updated with latest results.

BREAKING CHANGE: gRPC-web protocol is no longer supported. Browser-based
clients that relied on grpc-web to communicate directly with providers
will no longer work. Only native gRPC clients are supported.

The previous implementation used grpc-web and h2c HTTP wrappers to support
the Lava SDK (lava-sdk/lavajs) which allowed browser-based JavaScript clients
to communicate with providers. Since SDK support has been removed (see #2186),
this infrastructure is no longer needed.

Replace the grpc-web/h2c/HTTP hybrid server with a cleaner architecture:

- Use cmux to multiplex HTTP health checks and native gRPC on same port
- Remove grpcweb.WrapServer and h2c.NewHandler complexity
- Add gRPC health checking protocol support (grpc_health_v1)
- Keep HTTP health endpoint for Kubernetes probes compatibility
- Optimize cmux matching: HTTP1Fast() first, then Any() for gRPC
  (avoids expensive HTTP/2 header parsing at high scale)

Benefits:
- Native gRPC connection management (keepalives, stream limits)
- Proper graceful shutdown via grpcServer.GracefulStop()
- Simpler, more maintainable code
- Better performance at scale (no protocol translation overhead)

Also adds comprehensive test suite for provider_listener.go with
14 tests and 2 benchmarks covering HTTP health, gRPC health,
relay/probe RPCs, concurrent requests, and error handling.
gRPC handles compression automatically when the gzip compressor is
registered (via import) and the client uses grpc.UseCompressor(gzip.Name).

Removed:
- Manual compression in provider (common.CompressData)
- Manual decompression in consumer/smartrouter (common.DecompressData)
- Custom LavaCompressionSupportHeader and LavaCompressionHeader headers
- Obsolete rpcsmartrouter_compression_test.go

The --enable-application-level-compression flag still works, but now
uses native gRPC compression instead of manual application-level
compression. This is simpler, more efficient, and follows gRPC best
practices.

Note: common.CompressData/DecompressData utilities are kept as they're
still used for cache storage compression.
- Renamed from --enable-application-level-compression to
  --enable-grpc-compression (more accurate now that we use native gRPC
  compression)
- Updated flag description to explain the trade-off (bandwidth vs CPU)
- Improved log message when compression is enabled
Add comprehensive tests verifying native gRPC compression works
correctly between consumer and provider:

- TestGRPCCompressionEnabled: verifies data is compressed (99%+ reduction)
- TestGRPCCompressionDisabled: verifies no compression without flag
- TestGRPCCompressionBidirectional: verifies both request and response compression
- TestGRPCCompressionWithConnectGRPCClient: tests via actual ConnectGRPCClient function
- TestGRPCCompressionSmallPayload: verifies small payload handling
- BenchmarkGRPCWithCompression/WithoutCompression: performance comparison

Uses gRPC stats handler to measure actual wire vs logical payload sizes.
@NadavLevi NadavLevi force-pushed the refactor/provider-listener-pure-grpc branch from df807cf to 88bb60e Compare January 29, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants