-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add a JsonRpcWebSocketProvider #141
Comments
I had totally overlooked this, as I use the default provider for the most part. But yes, this is an incredibly useful feature which I'll add this week. |
Any updates on this issue? Anything I could help with? |
Hi, I would also love to see such a feature. I am willing to implement the websocket version. I would probably just need a bid of guidance. Thank you for your great work. |
Sorry, I've been busy. I will try to look at it this weekend during my downtime mentoring at the CryptoChicks Hackthon. If I had to focus on one, which is more important to you more immediately, WebSockets or IPC? |
For me personally WebSocket's. I don't mind todo it :) I guess the send function would need to be changed right? I see some polling JSON RPC provider in the code but I am not sure for what exactly it's used. Geth and Parity both have an way to subscribe to new transaction's and block's https://github.com/ethereum/go-ethereum/wiki/RPC-PUB-SUB |
I added the websocket provider: https://github.com/florianlenz/ethers.js/blob/feature/websocket_provider/providers/web-socket-provider.js. Works quite well till now. I will test him for a few day's. |
I have added the first incarnation of the IpcProvider. It is obviously only available in Node.js and not from the browser dist files. Please try it out. :) |
Definitely WebSocket oven IPC. The IPC protocol with Geth/Parity is both terrible and non-standard between the two. For 99% of use cases, WebSocket will be pragmatically as fast as IPC, your bottleneck when talking to a local Ethereum node is almost certainly not the networking stack. |
The goal of ethers.js is to support as much of the ecosystem as is reasonable, while remaining highly compatible and compact. The main advantage of IPC is not speed, but security. WebScokets are certainly useful, but require a lot more work. The IpcProvider is already complete and has been included for quite some time. Both provide a very different abilities. @MicahZoltu What incompatibilities have you found between Geth and Parity over IPC (that aren't present over http)? I also want to smooth out incompatibilities. :) |
The one that bugged me the most is the fact that they terminate their lines differently. Both of them are delimited JSON, but one of them includes newlines between payloads while the other does not (I think it does comma or something). In general I really detest delimited JSON because tooling for parsing it correctly is difficult to write (not impossible though). On top of that, IIRC, named pipes on windows vs Linux had some oddities. For starters, the way they name them is different, and access controls and errors are different. I don't remember specifically if there were other differences. I also vaguely remember Node's low level IPC code having a bug that was kind of nasty (I filed it somewhere on their GitHub if my memory is correct). |
WebSockets on the other hand "just work" on all operating systems, they have a nice interface, they deal with message on eloping for you, and there is a ton of quality tooling to work with them easily. What do you see as the security advantage of IPC? |
@florianlenz Have you finalised the websocket implementation on your fork? |
@sirromdev As far as I remember it had a bug somewhere and I didn't spend more time on it. I could check it next weekend. |
Sure, I can lend a hand if you want |
This is coming up on my to do list too, if you can wait. Is there a hurry for WebSocketProvider? If you do, add this please make sure it follows the shim model that other parts of the library use, so that the browser build does not contain the node ws library in its output. |
websocket support in ethers.js would be awsome :) much lighter than RPC for event watching, and we could drop web3.js for All Ethers.js yeah |
Coming VERY soon. Also, much better performance since it doesn’t need to poll. :) |
How soon is very soon? We are looking to port some code over to ethers.js for Augur but would need websocket support. |
Yes, we also need WebSockets provider like in web3. Some networks kick you out if you are doing extensive polling (which happens when you subscribe to events). Without WebSockets provider we still need to bundle with Web3 and that's a pain. |
Hey @ricmoo Any news about WS? Can't wait to test that. |
Any updates about integration of Websockets in Ethers.js? can't wait to run I'd be happy to help testing... |
I'm also switching from web3 to ethers on one of our companies products. Even though it's not a show blocker, websocket support would be awesome! |
Would LOVE this to save on polling bandwidth and use |
I've made some changes to v5 (public beta soon) that should make it easier to swap out polling. This is still coming, but my time is spread thin, especially over the next few weeks. Anyone going to ETHCapeTown? Come chat! :) |
Hi Ricmoo! I was on the ETH Cape Town! Are you planning to go to ETH NEW YORK? How are you with the Websocket implementation? |
How can I check out this v5? Would be great to test it. How do things work without Websockets nowadays anyway, hasn't nigh everyone deprecated HTTP(S) in RPC? |
Everything I’ve seen (and build) still uses HTTPS JSON-RPC, the server load required to maintain WebSockets is tremendous, and it cannot be horizontally scaled easily nor load balanced using traditional infrastructure. For scaling purposes, stateless is still far simpler. |
I agree with all of your comments with the exception of
There is traditional infrastructure to load balance web sockets, though it is certainly less common than load balancing one-off requests. Personally, I think the other reasons are enough to not have web sockets be a high priority, though I do think there are situations where web sockets make more sense. |
I suppose I meant the “as easily” to be applied to old balancing too. ;) I generally use AWS ELB, without the WAF and friends, so it is superbly affordable and simple to run a large collection of backends, without anything complex, and SSL termination at the load balancer further simplifies and reduces costs. There are certainly cases where WebSockets make sense, which is why it is still on the backlog, but for what is basically a spare-time project (that eats up 30-50 hours a week), I focus on the areas I am most interested in, or need more urgently for my own random collection of projects. :) |
The main use case is getting block notifications without HTTPS round trips. This is actually quite well solved with turning on http/2. Of course it would still be better to allow for WS subscriptions. Now, that said I sure hope you're not load balancing to a cluster of eth nodes cause it really doesn't work 🤣. Blame the ETH RPC protocol for that one of course. |
+1 would love websocket support |
What!? No Websocket? We have now a million requests on https://1inch.exchange over HTTPS provider! AAAHHHH! |
WebSocket support is coming. I'm about to start receiving regular funding, which will help. :) There are a lot of additional complications with a WebSocket provider, mostly revolving what happens when there is a disconnect; we want it to reconnect, but we also need to setup the state from before it disconnected, without replaying already-received events, and maintaining a lot of the subtleties that the standard ethers Provider provides. For example, if an ethers provider emits a There are a lot of important, non-obvious things to handle. Also, keep in mind that WebSockets work great, and you are likely thrilled to use them for low-traffic services, but at scale, millions of HTTPS requests (which can be SSL terminated at the edge cache, with dedicated hardware for SSL termination) will likely greatly out-perform the same costs for the infrastructure required for WebSockets, which requires the server maintain state, meaning much beefier server architecture, and either expensive custom load-balancing hardware or complex software. The goal of the ethers Provider is that you generally should not need to know or care what type of backend there it. That said, I'm working with some services to help give the best of both worlds, since really the only WebSocket response we really care about is Long story short, it's coming. :) |
Hey! Thanks for your very fast answer! We can promote your funding on twitter if you like! May rxjs observables can help you with you problem? |
Honestly, Based on performance testing we've done -- simply using HTTP requests and terminating with http/2 turned on + making sure your ETH endpoints use gzip which none of them do by default -- the performance is quite good. If events could be delivered by long-poll I would see no reason to use WS for the ethereum use case. |
Some input based on my personal experience: Oh and this is unrelated, but I think it's good to mention in this thread: |
@cloudonshore That is addressed almost entirely with HTTP/2. I generally recommend updating your server to HTTP/2 rather than switching to WebSockets in most cases like that. WebSockets still have advantages, but if that is all you need from it, then HTTP/2 is probably a better (easier) solution. |
@pgebheim Some corporate networks (like hospitals) are not tolerating frequent polling (frequent === dependent on the case) but still tolerate web sockets.... In one of the projects we had to throw away otherwise very nice libraries, just because of this. |
Re: max frame size, this is indeed an issue not just in browsers but will all websocket clients. For bootstrapping all eth nodes currently support websocket batching, where you can issue multiple requests in one http call. That mixed with http/2 are much simpler operational solutions to the problem. @marcinzenko Well that's an odd bummer. If that were the case it seems like any page would fail since you'll be issuing large numbers of similar http requests back to back. And sure, there are cases where websockets are a solution, so I'm glad it's being added to ethers.js, and Alchemy is now terminating WS. For non+browser based sitatuations, eg when you have a server talking to a dedicated eth node they can be also leveraged usefully. |
With the addition of websockets, would we also support https://web3js.readthedocs.io/en/1.0/web3-eth-subscribe.html I am not sure if this is official spec but parity and geth do implement those endpoints. |
For sure, re: eth_subscribe. That's really the core reason for WS anyway since the eth spec didn't specify long polling for http subscriptions 🤦♂️ |
Thanks for the work on this folks. Looking forward to v5 moving out of beta. +1 for WS support |
Anyone who is interested, there is finally a WebSocketProvider. Please try it out and let me know how it works for you. :)
:) |
I'm going to close this issue now. If you have any problems with the WebSocketProvider, please feel free to open a new issue. Thanks! :) |
Hey @ricmoo . I have a etheruem full node running and I am connecting it through web socket. I am trying to figure out a way so that if the connection fails due to error in full node, I want it to hit Infura end point. But I cant catch error.
Getting this |
I use this library a lot. Way more usable than web3...
Do you guys have a feature roadmap? I wonder if there will be an implementation to use IPC and Websockets in the near future.
Thanks, keep up the good work. 👍🏼
The text was updated successfully, but these errors were encountered: