-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add HTTP subscription support via polling #32
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
Draft
smartprogrammer93
wants to merge
6
commits into
OpenZeppelin:main
Choose a base branch
from
smartprogrammer93:feat/http-subscription
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: add HTTP subscription support via polling #32
smartprogrammer93
wants to merge
6
commits into
OpenZeppelin:main
from
smartprogrammer93:feat/http-subscription
+1,662
−36
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implements OpenZeppelin#23 - Support HTTP Subscription This PR adds the ability for HTTP providers to participate in block subscriptions via polling, enabling use cases where WebSocket connections are not available (e.g., behind load balancers). ## Changes ### New Feature (behind `http-subscription` feature flag) - Add `HttpPollingSubscription` that polls `eth_getBlockByNumber(latest)` at configurable intervals - Add `SubscriptionBackend` enum to handle both WebSocket and HTTP backends - Add `poll_interval()` and `allow_http_subscriptions()` builder methods - Seamless failover between mixed WS/HTTP provider chains ### Files - `src/robust_provider/http_subscription.rs` - New HTTP polling module - `src/robust_provider/subscription.rs` - Unified backend handling - `src/robust_provider/builder.rs` - New configuration options - `src/robust_provider/provider.rs` - Updated subscribe_blocks() - `Cargo.toml` - Added `http-subscription` feature flag ## Usage ```rust let robust = RobustProviderBuilder::new(http_provider) .allow_http_subscriptions(true) .poll_interval(Duration::from_secs(12)) .build() .await?; let mut sub = robust.subscribe_blocks().await?; ``` ## Trade-offs (documented) - Latency: up to `poll_interval` delay for block detection - RPC Load: one call per `poll_interval` - Feature-gated to ensure explicit opt-in Closes OpenZeppelin#23
64ba47c to
3a73de3
Compare
Add comprehensive integration tests in tests/http_subscription.rs: - test_http_subscription_basic_flow - test_http_subscription_multiple_blocks - test_http_subscription_as_stream - test_failover_from_ws_to_http - test_failover_from_http_to_ws - test_mixed_provider_chain_failover - test_http_reconnects_to_ws_primary - test_http_only_no_ws_providers - test_http_subscription_disabled_falls_back_to_ws - test_custom_poll_interval All tests gated behind #[cfg(feature = "http-subscription")]
Audit findings addressed: Unit tests (http_subscription.rs): - Improved test_http_polling_deduplication with better verification - Renamed test_http_polling_handles_drop → test_http_polling_stops_on_drop with clearer verification logic - Added test_http_subscription_error_types for all error variants - Added test_http_polling_close_method for close() functionality Integration tests (tests/http_subscription.rs) - rewritten: - Removed broken test_http_reconnects_to_ws_primary (was meaningless) - Removed flawed test_custom_poll_interval, replaced with test_poll_interval_is_respected (measures correctly) - Renamed tests for clarity on what they actually verify - Added test_http_disabled_no_ws_fails (negative test case) - Added test_all_providers_fail_returns_error (error handling) - Added test_http_subscription_survives_temporary_errors - Added test_http_polling_deduplication (integration level) - Fixed failover tests to verify behavior correctly - Removed fragile 'pre-mine to distinguish providers' hacks Test count: 73 total (19 unit + 12 http integration + 24 subscription + 18 eth)
Tests verify that RPC calls (not just subscriptions) properly: - Failover to fallback providers when primary dies - Cycle through multiple fallbacks - Return errors when all providers exhausted - Don't retry non-retryable errors (BlockNotFound) - Complete within bounded time when providers unavailable - Work correctly for various RPC methods (get_accounts, get_balance, get_block)
Fixes two bugs in HTTP subscription handling: 1. http_config now uses configured values from RobustProviderBuilder instead of defaults when a WebSocket subscription is created first. This ensures poll_interval, call_timeout, and buffer_capacity are respected when failing over to HTTP. 2. HTTP reconnection now validates the provider is reachable before claiming success. Uses a short 50ms timeout to quickly fail and not block the failover process. Also fixes test timing in test_failover_http_to_ws_on_provider_death to mine before subscription timeout instead of after. Adds two new tests: - test_poll_interval_propagated_from_builder: verifies config propagation - test_http_reconnect_validates_provider: verifies reconnect validation
f94c84d to
b6001af
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements HTTP subscription support via polling, allowing HTTP providers to participate in block subscriptions alongside WebSocket providers. This addresses issue #23.
Changes
Core Feature (
http-subscriptionfeature flag)HttpPollingSubscription: New subscription backend that pollseth_getBlockByNumber("latest")at configurable intervalsRobustSubscriptionAPI - callers use the samesubscribe_blocks()andrecv()interfaceBuilder API
Failover Behavior
Files Added/Modified
src/robust_provider/http_subscription.rssrc/robust_provider/subscription.rsSubscriptionBackendenum, HTTP failover logicsrc/robust_provider/builder.rspoll_interval(),allow_http_subscriptions()methodssrc/robust_provider/provider.rssubscribe_blocks()tests/http_subscription.rstests/rpc_failover.rsTest Coverage
Usage
Breaking Changes
None. Feature is behind
http-subscriptionflag and disabled by default.Closes #23