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

Include web3 middleware in ENS.fromWeb3() #2239

Merged
merged 1 commit into from
Dec 7, 2021

Conversation

fselmo
Copy link
Collaborator

@fselmo fselmo commented Dec 7, 2021

What was wrong?

From recent comments on issue #425:

  • ENS.fromWeb3() does not make use of existing middlewares present in the Web3 instance that is passed in to the method. This led to issues using geth_poa_middleware.

Closes #1657

How was it fixed?

  • Inherit the Web3 instance's middlewares when instantiating the ENS instance from a Web3 instance.
  • Adds a middlewares property to the NamedElementOnion data structure / web3.middleware_onion that returns a list of all current middlewares in appropriate order to be passed in to a new Web3 instance.

Todo:

Cute Animal Picture

20211206_151027

@fselmo fselmo requested review from wolovim, kclowes and pacrob December 7, 2021 18:38
@fselmo fselmo force-pushed the update-ens-docs-for-poa-middleware branch 5 times, most recently from 5519282 to 80f4216 Compare December 7, 2021 22:58
Copy link
Member

@wolovim wolovim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚢

tests/core/pm-module/test_ens_integration.py Outdated Show resolved Hide resolved
- Feature: Add ``middlewares`` property to ``NamedElementOnion`` / ``web3.middleware_onion`` which returns all middlewares, as (middleware, name) tuples, in appropriate order to be imported into a new Web3 instance.
- Bugfix: Include the middlewares from the web3 instance passed into ENS.fromWeb3(). This allows geth_poa_middleware to be used as it is currently expected to be used.
@fselmo fselmo force-pushed the update-ens-docs-for-poa-middleware branch from 80f4216 to 633fc7d Compare December 7, 2021 23:21
@fselmo fselmo merged commit 557f983 into ethereum:master Dec 7, 2021
@fselmo fselmo deleted the update-ens-docs-for-poa-middleware branch December 7, 2021 23:30
self, provider: 'BaseProvider' = cast('BaseProvider', default), addr: ChecksumAddress = None
self,
provider: 'BaseProvider' = cast('BaseProvider', default),
middlewares: Optional[Sequence[Tuple['Middleware', str]]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change if someone was passing the address as the second param without the keyword before. Is it important for middlewares to be the second arg? Sorry I wasn't there for the review yesterday!

@KaiRo-at
Copy link

Note that now I do get an exception in my code that I did not get before, see partial stack here (ns has been created by ENS.fromWeb3() with a web3 object that has caching middleware applied):

[...]
    ensname = ns.name(address)
  File "/usr/local/lib/python3.10/site-packages/ens/main.py", line 150, in name
    return self.resolve(reversed_domain, get='name')
  File "/usr/local/lib/python3.10/site-packages/ens/main.py", line 241, in resolve
    resolver = self.resolver(normal_name)
  File "/usr/local/lib/python3.10/site-packages/ens/main.py", line 253, in resolver
    resolver_addr = self.ens.caller.resolver(normal_name_to_hash(normal_name))
  File "/usr/local/lib/python3.10/site-packages/web3/contract.py", line 1453, in call_function
    return fn(*args, **kwargs).call(transaction, block_identifier)
  File "/usr/local/lib/python3.10/site-packages/web3/contract.py", line 957, in call
    return call_contract_function(
  File "/usr/local/lib/python3.10/site-packages/web3/contract.py", line 1501, in call_contract_function
    return_data = web3.eth.call(
  File "/usr/local/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/usr/local/lib/python3.10/site-packages/web3/manager.py", line 197, in request_blocking
    response = self._make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/stalecheck.py", line 62, in middleware
    latest = web3.eth.get_block('latest')
  File "/usr/local/lib/python3.10/site-packages/web3/eth.py", line 642, in get_block
    return self._get_block(block_identifier, full_transactions)
  File "/usr/local/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/usr/local/lib/python3.10/site-packages/web3/manager.py", line 197, in request_blocking
    response = self._make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/stalecheck.py", line 68, in middleware
    return make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/cnp/capa_eth1.py", line 1163, in middleware
    response = make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/cache.py", line 135, in middleware
    return make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/cache.py", line 422, in middleware
    _update_block_info_cache()
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/cache.py", line 408, in _update_block_info_cache
    block_info['latest_block'] = web3.eth.get_block('latest')
  File "/usr/local/lib/python3.10/site-packages/web3/eth.py", line 642, in get_block
    return self._get_block(block_identifier, full_transactions)
  File "/usr/local/lib/python3.10/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/usr/local/lib/python3.10/site-packages/web3/manager.py", line 197, in request_blocking
    response = self._make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/manager.py", line 150, in _make_request
    return request_func(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/stalecheck.py", line 68, in middleware
    return make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/cnp/capa_eth1.py", line 1163, in middleware
    response = make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/cache.py", line 135, in middleware
    return make_request(method, params)
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/cache.py", line 422, in middleware
    _update_block_info_cache()
  File "/usr/local/lib/python3.10/site-packages/web3/middleware/cache.py", line 387, in _update_block_info_cache
    ancestor_block = web3.eth.get_block(ancestor_block_number)
  File "/usr/local/lib/python3.10/site-packages/web3/eth.py", line 642, in get_block
    return self._get_block(block_identifier, full_transactions)
[...]
RecursionError: maximum recursion depth exceeded while calling a Python object

I seem to only get this problem with the ENS lookup, not with using the normal Web3 object with the caching middleware.

@fselmo fselmo changed the title Include web3 middlewares in ENS.fromWeb3() Include web3 middleware in ENS.fromWeb3() Aug 30, 2024
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 this pull request may close these issues.

ENS.fromWeb3 not copying middleware
4 participants