Skip to content
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

ENS.fromWeb3 not copying middleware #1657

Closed
Uxio0 opened this issue May 20, 2020 · 2 comments · Fixed by #2239
Closed

ENS.fromWeb3 not copying middleware #1657

Uxio0 opened this issue May 20, 2020 · 2 comments · Fixed by #2239

Comments

@Uxio0
Copy link
Contributor

Uxio0 commented May 20, 2020

  • Version: 5.10.0
  • Python: 3.8
  • OS: linux

What was wrong?

I would expect that after configuring a Web3 instance, if I do ENS.fromWeb3(w3) it would copy the middleware and parameters needed. Instead, it just uses the provider. This is very important for using ENS with Rinkeby and Geth, as it needs the POA middleware.

Steps to reproduce:

Initialize instance of Web3, add middleware for POA and then create an ENS instance from that.

How can it be fixed?

Copy web3 instance or allow to provide one.

@wolovim
Copy link
Member

wolovim commented May 20, 2020

Thanks for the report. Seems like a reasonable expectation.

I see that fromWeb3 just peels the provider off of the web3 instance passed in, because ENS accepts a provider. Upon creation, there's also some adding and removing of middleware as a result of the init_web3 method.

@pipermerriam @carver thoughts on passing/cloning a web3 instance into ENS to preserve the middleware onion? Was this avoided in the past for any reason? If you like the idea, do you have a preferred implementation?

@carver
Copy link
Collaborator

carver commented May 20, 2020

Yeah, there are definitely some quirks there. But I think they're all managed by the methods @marcgarreau already found at

web3.py/ens/utils.py

Lines 77 to 96 in 6258d2e

def init_web3(provider: 'BaseProvider'=cast('BaseProvider', default)) -> '_Web3':
from web3 import Web3 as Web3Main
if provider is default:
w3 = Web3Main(ens=None)
else:
w3 = Web3Main(provider, ens=None)
return customize_web3(w3)
def customize_web3(w3: '_Web3') -> '_Web3':
from web3.middleware import make_stalecheck_middleware
w3.middleware_onion.remove('name_to_address')
w3.middleware_onion.add(
make_stalecheck_middleware(ACCEPTABLE_STALE_HOURS * 3600),
name='stalecheck',
)
return w3

So the bulk of the work is to pass in a "template" w3 instance and copy the existing middlewares & provider, as a kind of alternative to init_web3(), then apply customize_web3()

(Also a reminder that @Uxio0 will have to pass addr into ENS.fromWeb3() for non-mainnet usage, since ENS is hosted at a different addresses on different networks IIRC)

kchojn added a commit to EthTx/ethtx that referenced this issue Oct 8, 2021
`ENS.fromWeb3` is not copying web3 middleware (`geth_poa_middleware`). This is important for using ENS with Rinkeby and Goerli, as it needs the POA middleware.

 This is fixed by manually injecting props
- Issue: ethereum/web3.py#1657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants