• Matthew Slipper's avatar
    op-node: Add wrapper to support EthSubscribe in HTTP clients (#3629) · 775d9ff9
    Matthew Slipper authored
    The Geth RPC client does not support subscriptions for HTTP endpoints. As a result, users who set an HTTP endpoint for the op-node were unable to sync since the driver never got any L1 head updates. This PR adds a wrapper around `client.RPC` that makes `newHeads` subscriptions work over HTTP. It does this by layering a notifications system that mimicks what Geth does under the hood on top of an HTTP polling loop.
    
    The interface is the same as the one exposed by the raw RPC client. I tried my best to match Geth's subscription semantics, including:
    
    - Closing the client causes all subscribers to get a nil error on their error channels.
    - Unsubscribing closes each subscriber's error channel.
    - Calling `Unsubscribe` multiple times is safe.
    
    The poll rate is configurable. It default to 250ms, which should be fine for both L1 and L2. I tried at first to use Geth's underlying libraries, but found that it was impossible to do so without making changes to Geth itself to export more fields. This system is also simpler, and gives us room to instrument the polling loop in the future.
    
    The wrapper is not integrated with the rest of the system in this PR. I'll stack those changes on top of this one so we can review this in isolation.
    
    Totally open to different solutions here - marking as draft to reflect the fact that if there's a better way to do this, I'm happy o close this + the dependent PRs and go a different route.
    
    Meta:
    
    - Fixes ENG-2490
    775d9ff9
polling.go 4.84 KB