-
Notifications
You must be signed in to change notification settings - Fork 225
feat: implement Direct RPC mode for Smart Router #2199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
avitenzer
commented
Jan 22, 2026
- Support for JSON-RPC, REST, gRPC, and WebSocket protocols
- Implement connection pooling and health tracking for endpoints
- Add WebSocket streaming subscription management
Modified the RPC consumer command in the init_lava_only_with_node_three_providers.sh script to include the --enable-selection-stats flag, enhancing the functionality of the consumer setup.
This update introduces a composition-based design for session connections, allowing for better type safety and flexibility. The `SingleConsumerSession` now utilizes a `SessionConnection` interface, which can be either a `ProviderRelayConnection` or a `DirectRPCSessionConnection`. Key changes include: - Updated methods to handle both connection types. - Added new methods for retrieving connections based on session type. - Improved session management logic to ensure proper handling of connection states. Additionally, comprehensive tests have been added to validate the new structure and ensure compliance with the expected interface behavior.
This commit introduces a new mechanism for handling direct RPC connections within the smart router. Key changes include: - Added `DirectRPCRelaySender` to facilitate sending relay requests directly to RPC endpoints, bypassing the provider-relay protocol. - Implemented error mapping for direct RPC errors, providing user-friendly error messages for common issues such as connection refusals and timeouts. - Enhanced session management to support both direct RPC and provider-relay modes, ensuring seamless operation based on session type. - Comprehensive tests added to validate the new functionality and ensure robustness in various scenarios. These updates improve the flexibility and reliability of the RPC smart router, particularly under high load conditions.
This commit introduces improved logging and session management for the direct RPC relay functionality. Key changes include: - Added detailed logging for responses received from nodes and results being returned, aiding in debugging and monitoring. - Integrated a `chainTracker` into the `RPCSmartRouterServer` to track the latest block, enhancing the accuracy of session management. - Implemented a new method to handle direct RPC sessions, ensuring they bypass the provider-relay flow correctly. - Updated the smart router initialization to include the `chainTracker`, improving overall performance and reliability. These enhancements aim to provide better insights during operation and ensure robust handling of direct RPC connections.
This commit refines the logging mechanism and enhances the session management within the RPC smart router. Key changes include: - Removed redundant debug logging statements to streamline the code and reduce noise in logs. - Integrated a `chainTracker` into the `ServeRPCRequests` method, improving session tracking and management. - Updated the `sendRelayToDirectEndpoints` function to ensure proper response handling without unnecessary logging. These modifications aim to improve code clarity and maintainability while ensuring efficient session handling in the RPC smart router.
This commit introduces improvements to the tracking of direct RPC sessions and the synchronization of block information. Key changes include: - Added a direct reference to the endpoint in `DirectRPCSessionConnection` for better per-endpoint tracking. - Implemented a method to extract the latest block number from RPC responses, enhancing the accuracy of block synchronization. - Updated the `sendRelayToDirectEndpoints` function to utilize the extracted block information and calculate synchronization gaps, improving endpoint performance monitoring. These enhancements aim to provide more robust session management and ensure accurate tracking of block updates across endpoints.
This commit introduces REST support for direct RPC connections, enhancing the functionality of the `DirectRPCRelaySender`. Key changes include: - Added `HTTPRequestParams` and `HTTPDirectRPCResponse` types to facilitate HTTP request handling and response management. - Implemented the `DoHTTPRequest` method for executing HTTP requests, including robust error handling and response parsing. - Updated the `SendDirectRelay` method to route requests based on the API interface, supporting both JSON-RPC and REST protocols. - Removed the `minimal_state_tracker_mock.go` file as it was no longer needed. These enhancements aim to improve the flexibility and reliability of the RPC smart router, ensuring seamless operation across different API interfaces.
This commit introduces a new test file for the `DirectRPCRelaySender`, implementing various integration tests to validate REST functionality. Key additions include: - Tests for GET requests with path and query parameters, ensuring correct handling and response validation. - Tests for POST requests with JSON bodies, verifying content type and body presence. - Handling of various HTTP status codes, including 404, 429, and 503, to ensure proper error management. - Verification of response headers to confirm correct metadata capture. These tests enhance the reliability and robustness of the REST integration within the RPC smart router, ensuring seamless operation across different scenarios.
This commit introduces significant improvements to the error handling logic in the REST integration of the DirectRPCRelaySender. Key changes include: - Updated the `CheckResponseError` method to correctly classify 5xx and 429 HTTP status codes as node errors, triggering appropriate retry logic. - Enhanced the extraction of error messages from REST responses, providing clearer feedback for various error scenarios. - Added comprehensive integration tests to validate the handling of different HTTP status codes, including 404, 429, and 503, ensuring robust error management. - Refactored existing tests to utilize a mock server setup, improving the reliability and clarity of test cases. These enhancements aim to improve the reliability and robustness of the REST integration within the RPC smart router, ensuring seamless operation across different scenarios.
This commit introduces a new configuration file, `smartrouter_lava.yml`, for the Smart Router, enabling direct RPC connections to local Lava endpoints. The configuration includes three static providers pointing to the same local node, facilitating testing and failover logic. Additionally, the initialization script `init_lava_smartrouter_lava.sh` has been updated to handle multiple specification files, improving error handling for missing spec files during setup.
This commit updates the `CreateSmartRouterEndpoint` function to create a minimal `RPCProviderEndpoint` for the ChainTracker, which only requires the latest block information. The changes include removing unnecessary addons and ensuring that the endpoint is correctly utilized in the chain router and fetcher creation processes. This enhancement optimizes the ChainTracker's functionality by streamlining its endpoint configuration.
Resolve conflicts: - consumer_types.go: Keep dual session matching logic (provider-relay vs direct RPC), remove DataReliabilitySessionId check, keep composition-based connection types - rpcsmartrouter_server.go: Combine chainTracker (primary) with latestBlockEstimator (secondary) for getLatestBlock(), remove data reliability code Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit enhances the `sendRelayToDirectEndpoints` function by adding logic to update the global latest block height and estimator. This update ensures that the latest block information is accurately maintained for fallback scenarios, improving the reliability of the RPCSmartRouter's operations.
This commit introduces the GetNodeUrl method to the DirectRPCConnection interface and its implementations in HTTP, WebSocket, and gRPC connections. This addition allows retrieval of NodeUrl configurations, enabling timeout overrides and improved connection management in the RPC relay process. Additionally, the sendJSONRPCRelay method has been updated to utilize NodeUrl for context timeout management, enhancing flexibility in handling RPC requests.
This commit refactors the WebSocket subscription management by introducing a new `WSSubscriptionManager` interface, which standardizes the subscription handling across different components. The existing `ConsumerWSSubscriptionManager` has been updated to implement this interface, and a new `DirectWSSubscriptionManager` has been added to facilitate direct RPC endpoint connections. This change enhances flexibility and allows for better management of WebSocket subscriptions, supporting both provider-based and direct models. Additionally, various components have been updated to utilize the new interface, ensuring consistent behavior across the system.
… IDs This commit introduces comprehensive tests and enhancements to the DirectWSSubscriptionManager, ensuring that multiple clients can subscribe to the same parameters while receiving unique router IDs. This change addresses a critical bug where clients shared a single router ID, leading to unintended unsubscribe behavior. The implementation includes new tests for deduplication, active subscription tracking, unsubscribe rate limiting, and validation of router ID ownership. Additionally, the subscription manager now properly handles reconnections and message routing, ensuring robust multi-client support.
…ooling This commit introduces a new `GrpcConfig` structure to manage gRPC-specific configurations, including descriptor sources and connection settings. The `GRPCDirectRPCConnection` implementation now supports dynamic protobuf handling via reflection or file descriptors, enhancing flexibility for gRPC endpoints. Additionally, comprehensive tests have been added to validate gRPC connection creation, URL validation, and error handling, ensuring robust functionality for various gRPC scenarios. This enhancement improves the overall capability of the RPC system to interact with gRPC-based services.
…n pooling This commit introduces the `DirectGRPCSubscriptionManager`, which manages gRPC streaming subscriptions directly to upstream endpoints. It includes features such as active subscription tracking, client connection management, and rate limiting for subscription creation and unsubscription requests. The implementation supports dynamic message handling and ensures robust reconnection logic for maintaining active streams. Additionally, a new `GRPCStreamingConfig` structure is added to manage configuration parameters for gRPC streaming, enhancing the overall capability of the RPC system to handle gRPC-based services efficiently.
…flection support This commit introduces a new configuration file `smartrouter_eth.yml` for direct RPC connections to Ethereum endpoints, including Infura and a secondary QuikNode endpoint. It also enhances the gRPC support by implementing a `GRPCReflectionProvider` interface, allowing tools like grpcurl to discover services through the smart router. Additionally, the `DirectRPCConnection` interface has been updated to support an optional `apiInterface` parameter for better protocol detection, improving the overall functionality and flexibility of the RPC system.
…ter mode This commit adds a new method, `probeDirectRPCEndpoints`, to the `ConsumerSessionManager` for health checking direct RPC endpoints. It distinguishes between direct RPC and provider-relay endpoints, ensuring proper health status checks without encountering "nil client" errors. The implementation tracks healthy endpoints, measures latency, and logs detailed probe results, enhancing the reliability of direct RPC connections in the system.
…scription handling This commit introduces comprehensive tests and functionality for managing subscriptions in the DirectWSSubscriptionManager, specifically for Tendermint and EVM protocols. It adds methods to extract and rewrite subscription IDs based on the protocol, ensuring correct handling of subscription requests and notifications. The implementation includes tests for subscription ID extraction, unsubscribe parameter handling, and proper notification formatting, enhancing the robustness and flexibility of the subscription management system.
…ing for EVM and Tendermint This commit introduces new tests and functionality for extracting block heights from JSON-RPC responses, accommodating both EVM and Tendermint protocols. It refines the `extractBlockHeightFromJSONResponse` method to utilize spec-driven parsing, with a fallback to EVM-specific parsing for compatibility. Additionally, it updates the `DirectWSSubscriptionManager` to preserve original response formats for Tendermint subscriptions, ensuring clients receive the expected query structure. Comprehensive tests validate these enhancements, improving the robustness of subscription management and block height extraction.
…ints This commit modifies the `init_lava_smartrouter_lava.sh` script to include support for gRPC endpoints alongside existing REST configurations. It updates the output messages to reflect the addition of gRPC, introduces local gRPC URL handling, and generates configurations for three upstream gRPC endpoints. Additionally, it enhances the test command section to include gRPC-specific commands, improving the overall functionality and usability of the smart router setup.
…t RPC endpoints This commit updates the `init_lava_smartrouter_lava.sh` script to include support for Tendermint RPC endpoints alongside existing REST and gRPC configurations. It modifies output messages to reflect the addition of Tendermint RPC, introduces local Tendermint RPC URL handling, and generates configurations for three upstream Tendermint RPC endpoints. Additionally, it enhances the test command section with Tendermint-specific commands, improving the overall functionality and usability of the smart router setup.
…int RPC endpoints This commit enhances the `smartrouter_lava.yml` configuration by adding support for three upstream Tendermint RPC endpoints, allowing for both HTTP and WebSocket connections. Additionally, it refactors the `chainlib` to replace instances of `ConsumerWSSubscriptionManager` with the more generic `WSSubscriptionManager` interface, improving flexibility in subscription management across different protocols.
This commit introduces the `NoOpWSSubscriptionManager`, which provides clear error handling for WebSocket subscription attempts when no endpoints are configured. Additionally, it adds the `LAVA_RELAY_PROTOCOL_HEADER_NAME` constant to the endpoints definition, improving the clarity and extensibility of the protocol's header management.
This commit removes unnecessary emoji indicators and corrections from log messages and comments across various files, enhancing readability and maintaining a consistent logging format. Key areas of change include the `restMessage.go`, `subscription_test.go`, and `consumer_session_manager.go` files, among others. The updates aim to streamline the codebase and improve the clarity of logging outputs.
…ed components This commit introduces a suite of tests for the `DirectGRPCSubscriptionManager`, `UpstreamGRPCPool`, and related configurations, ensuring robust functionality and error handling. Key additions include tests for subscription management, rate limiting, context cancellation, and connection handling. Additionally, it implements tests for the `NoOpWSSubscriptionManager` and various configuration defaults, enhancing overall test coverage and reliability of the smart router components.
This commit renames the `TestRelayInner_DirectRPCBranching` function to `TestDirectRPCSession_IsDirectRPC` for clarity, reflecting its purpose of verifying direct RPC session identification. Additionally, it removes the `rpcsmartrouter_compression_test.go` file, which contained tests that are no longer relevant, streamlining the test suite and improving maintainability.
…outerServer This commit refactors the `RPCSmartRouterServer` code to replace instances of "providers" with "endpoints" for improved clarity and consistency. The changes include updates to comments, error messages, and function names related to relay handling, ensuring that the terminology accurately reflects the system's architecture and functionality. This enhances code readability and aligns with the recent enhancements to endpoint management.
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 187 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Test Results 6 files - 1 83 suites - 2 33m 41s ⏱️ +14s For more details on these failures, see this check. Results for commit 180ef1e. ± Comparison against base commit f0e3d53. This pull request removes 181 and adds 265 tests. Note that renamed tests count towards both. |