-
Notifications
You must be signed in to change notification settings - Fork 490
fix(@embark/ens): fix Infura connection and testnet use of ENS #2181
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
Conversation
DeepCode's analysis on #6b5360 found:
💬 This comment has been generated by the DeepCode bot, installed by the owner of the repository. The DeepCode bot protects your repository by detecting and commenting on security vulnerabilities or other critical issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
In general, it's nice to have Infura traffic go across the proxy first, which provides some nice features during development. For those dapp developers who want to test real-world dapp scenarios with metamask, they can still use $WEB3
in their dappConnections
list to do so.
The Infura error (rejected due to project ID settings
) sounds a lot like CORS issues I've experienced in the past. Did you try changing the CORS settings to see if this was indeed the case? To prevent the issue, is there any way to update the origin identifier that originates in the VM, maybe with some kind of header? Why does this only happen with ENS contracts and not other contracts?
I'm afraid the warning message added here may confuse some dapp developers who actually do receive a valid project settings error message from Infura. For example, an Infura project may have very restrictive CORS settings (let's say it's restricted to only talk to requests from 1.1.1.1
), and a mainnet dapp is deployed out in the wild (ie no Embark running) with the code in this PR, connecting to Infura via the project ID with restrictive CORS settings. The EmbarkJS ENS code would receive the "project settings" error from Infura and then there would also be a warning in the console about changing dappConnection settings to $EMBARK, which would be completely off the mark as Embark would not even be running in this situation.
Out of curiosity, what would the dappConnections
setting need to be in a mainnet situation (when not using embark at all)? Would it need to contain the Infura endpoint?
In summary, it makes sense, in my opinion, to connect through the proxy by default, even for external nodes. Infura project settings errors should not be succeeded by a warning that may be misleading, and in the case they a user does hit the edge case, it would be nice to find a fix for the VM instead.
I tried to find a way to change them or even know what were the original ones, but since we go through Web3 to send the request (it's a getAccounts), I can't seem to find any configuration option.
That's a good question, since ENS used to default to the contrat dappConnection, the contracts should have thrown the same error, so I went to look. and it seems like it "hardcodes" the proxy url for the connection for the blokchain: https://github.com/embark-framework/embark/blob/master/packages/stack/embarkjs/src/index.js#L121 So I guess, we should do the same, when in the console/vm, we should always use the proxy and not dappConnections, because $WEB3 will never exist for example. I'll try to change that. |
@emizzle updated to always use the Proxy in the VM and removed the warning |
Did you try whitelisting An alternative solutionI believe I have figured out why this work when going through the proxy. The proxy sets an origin header to As you can see, this only works for WebSockets, so could you please confirm that this works with Now that we know the root cause and fix, the question is: do we definitely want to force connection through the proxy for the VM? I've thought about this since my last comment, and I think I may have a different opinion now. The VM is meant to replicate the dapp in terms of comms with the node. IOW, we want the responses for requests in the VM to exactly mirror what we'd get in our dapp, otherwise it will be a source of confusion. For example, let's assume our dapp is configured to connect to a testnet endpoint (and therefore With all that in mind, an alternative approach to forcing a dappConnection to the proxy would be to modify |
Also, CI seems to be failing. |
I was only using HTTP
As for using the Origin in the VM, it might work for WS, but it's with HTTP that I was having issues. |
@emizzle I just tested with WS using the Anyway, I feel like always going through the Proxy for the VM is acceptable. |
Fixes the use of Infura to connect to the ENS contracts. When connecting directly to Infura, it would throw with `rejected due to project ID settings`, because it doesn't accept the VM as the domain Instead, when passing from the proxy, it works. So I changed the default when no dappConnection to ['$EMBARK']. I also added a message when the error happens to help users fix it themselves When in the testnet, we don,t register because we already have the addresses, which is fine, but we also didn't populate the ensConfig object which contains the important information about the addresses and ABI. There was a lot of lint problems in a couple of files so I cleaned that up
c4e373a
to
6b53608
Compare
Just rebased and fixed the test |
Infura problem
Fixes the use of Infura to connect to the ENS contracts. When
connecting directly to Infura, it would throw with
rejected due to project ID settings
, because it doesn't accept the VM as the domainInstead, when passing from the proxy, it works. So I changed the
default when no dappConnection to ['$EMBARK']. I also added a
message when the error happens to help users fix it themselves
Testnet problem
When in the testnet, we don,t register because we already have the
addresses, which is fine, but we also didn't populate the ensConfig
object which contains the important information about the addresses
and ABI.
Linting
There was a lot of lint problems in a couple of files so I cleaned
that up