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
fix: validate Ape has connected to the right network and client #1038
fix: validate Ape has connected to the right network and client #1038
Conversation
i think this doesn't address the problem, we need to check that the associated chain id in the network spec matches the chain id from the provider we connected to. this needs to be done on connection to prevent user error of accidentally connecting to the wrong endpoint. such error could have dire results such as sending test transactions on live network or caching the wrong abis. |
If you look at the connect method in With these changes, if you do something like: ape console --network ethereum:rinkeby:geth and have a URI for mainnet in your config file, you will get this output (including the error): INFO: Connecting to existing Erigon node at 'https://erigon.yearn.science/'.
ERROR: (ProviderError) HTTP Connection does not match expected chain ID. Are you connected to 'rinkeby'? However, if you switch to Thus, I think this PR fixes the bug. Or no?? |
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.
checked this pr and confirmed it works for me
confirmed it works. maybe one suggestion is to also add numeric chain ids to the error.
becomes
|
145247c
to
cd63644
Compare
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.
LGTM
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.
🚀
What I did
Reorder how
Web3Provider
determines chain ID so that a fault is detected with mismatch of chain IDfixes: #1030
fixes: #1032
How I did it
We have some validation already in place for chain ID, and this solves a corner case in the logic for validating that the correct network and client is connecting when a connection already exists.
How to verify it
ape console --network :mainnet
(assumesgeth
is default)Prior to change, (2) will work just fine, and fails after this change
Checklist