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

local_filter_middleware doesn't work with geth nodes #1514

Closed
tsudmi opened this issue Nov 19, 2019 · 3 comments · Fixed by #1632
Closed

local_filter_middleware doesn't work with geth nodes #1514

tsudmi opened this issue Nov 19, 2019 · 3 comments · Fixed by #1632

Comments

@tsudmi
Copy link

tsudmi commented Nov 19, 2019

Hi,

get_filter_changes() raises exception when used with local_filter_middleware.

Traceback (most recent call last):
  File "/pyroot/lib/python3.7/site-packages/web3/_utils/filters.py", line 121, in get_new_entries
    log_entries = self._filter_valid_entries(self.web3.eth.getFilterChanges(self.filter_id))
  File "/pyroot/lib/python3.7/site-packages/web3/eth.py", line 402, in getFilterChanges
    "eth_getFilterChanges", [filter_id],
  File "/pyroot/lib/python3.7/site-packages/web3/manager.py", line 109, in request_blocking
    response = self._make_request(method, params)
  File "/pyroot/lib/python3.7/site-packages/web3/manager.py", line 96, in _make_request
    return request_func(method, params)
  File "/pyroot/lib/python3.7/site-packages/web3/middleware/filter.py", line 313, in middleware
    return {'result': next(_filter.filter_changes)}
StopIteration
  • Version: 5.3.0
  • Python: 3.7
  • OS: linux
  • Node type: geth
  • Node version: 1.9.7-stable
@kclowes
Copy link
Collaborator

kclowes commented Nov 19, 2019

@tsudmi will you provide a minimum reproducible example please? That will help troubleshoot exactly what is going on. Thanks!

@tsudmi
Copy link
Author

tsudmi commented Nov 19, 2019

Hi @kclowes ,

I run something like this:

from web3 import Web3
from web3.middleware import geth_poa_middleware, local_filter_middleware

WEB3_WS_ENDPOINT = ''
CONTRACT_ADDRESS = ''
ABI = []

w3 = Web3(Web3.WebsocketProvider(WEB3_WS_ENDPOINT))
w3.middleware_onion.add(local_filter_middleware)

contract = w3.eth.contract(
    abi=ABI,
    address=CONTRACT_ADDRESS
)
event_filter = contract.events.SomeEvent.createFilter(fromBlock=w3.eth.blockNumber)
events = event_filter.get_new_entries()

The error occures quite randomly, but regularly.

@pipermerriam
Copy link
Member

@kclowes it looks a lot like that StopIteration just needs to be caught and handled. Without having looked at the code I suspect it will mean "no new logs" but I'm not confident in that diagnosis.

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