-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Detect ENS registry's address for correct network #1396
Conversation
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.
No objection to the concept. 👍 It looks like it breaks some tests right now (which might not support self.web3.net.version
)
@carver How could this be fixed? Can tests be fixed to support |
@carver Some tests failed because Some tests are now fixed but many of them are still failing. |
@pipermerriam @carver Do you know how to fix tests? Also, are you sure that this failure is related to my changes? The failed tests don't seem to be related to ENS and ENS test also passed. I also tried to merge upstream into my PR to possible fix some tests. But this still doesn't fix tests. |
ens/main.py
Outdated
@@ -29,7 +30,12 @@ | |||
raw_name_to_hash, | |||
) | |||
|
|||
ENS_MAINNET_ADDR = '0x314159265dD8dbb310642f98f50C066173C1259b' | |||
NET_VERSION_TO_ENS_ADDR = { | |||
1: '0x314159265dD8dbb310642f98f50C066173C1259b', |
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.
Actually, sorry to keep nitpicking here but it would be nice if there was something that made it clear what chain id belonged to which network. Here are some options:
NET_VERSION_TO_ENS_ADDR = {
1: ..., # Mainnet
...
}
-or-
MAINNET_NET_VERSION = 1
...
NET_VERSION_TO_ENS_ADDR = {
MAINNET_NET_VERSION: ...,
}
The second option seems a bit nicer since it gives us other constants that could be useful. It's just as verbose as the code before my original suggestion, but it still has the advantage of using dict
methods instead of re-implementing dict
-like functionality in a custom function.
Incidentally, it looks like there's already an ens.constants
module that might be a better place to stick these values. Then you'd just import them from that module.
I want to CC @pipermerriam and @carver here and ask what's the preferred terminology we should be using: "net version" or "chain id"? Would "chain id" actually be a better term to represent in the names of these constants?
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.
I also updated this.
Regarding "net version" or "chain id" I don't know what to use. Some documentation says net version and some chain id. If needed, I can also rename this.
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.
Actually, sorry to keep nitpicking here
Yeah, I would say let's get this PR into a basic working state, make sure the high-level architecture is okay, and then get into the nits.
I want to CC @pipermerriam and @carver here and ask what's the preferred terminology we should be using: "net version" or "chain id"? Would "chain id" actually be a better term to represent in the names of these constants?
Presumably, it could even be the combination that's important: a pair of network and chain ID might actually be the right index.
@pipermerriam @carver I investigated CI failures a bit more and this is what I found:
Note that I also added How to fix those errors? |
ens/main.py
Outdated
raise UnknownNetwork( | ||
"ENS is not available on the current network by default. " | ||
"You need to manually set the `addr` parameter to the registry's address." | ||
) |
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.
I'm not convinced that swallowing StaleBlockchain
is right here, but won't have a chance to dig in. I would at least recommend raise from exc
here so that we can see the underlying exception.
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.
StaleBlockchain
is again not handled in my latest commits. It was one of my (failed) attempts to fix the tests.
You can see exception traceback in CI tests of my other commits in this PR.
Here I also resolved conflicts and added typings, and tests now also fail. Can you also check this? |
Yep, I'll take a look @filips123 |
@filips123 I'm not sure what was going on before, but I re-ran the workflow and it looks like the failures are expected failures. Looks like the parity tests are hitting your |
…ch-1 Merge branch from upstream. Also rename ENS_MAINNET_ADDR to ENS_PUBLIC_ADDR as it is now the same for all public networks. Remove old network detection code from this PR.
Because of ENS resolver migration, addresses on all networks are now the same, and this was achieved in 802c6f5. However, Rinkeby requires PoA middleware so this PR now only adds it. I also renamed |
Thanks for the contribution here but looks like this is quite stale at this point. |
What was wrong?
ENS in Web3py only supports mainnet. Even if supported testnet is used, users have to manually specify the registry's address.
How was it fixed?
The class now detects the current network and uses the correct registry's address.
Cute Animal Picture