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

Events filtering not working with EIP checksum addresses (Ganache-CLI) #674

Closed
jordanjambazov opened this issue Feb 26, 2018 · 15 comments
Closed

Comments

@jordanjambazov
Copy link

jordanjambazov commented Feb 26, 2018

  • Version: 4.0.0b10 - 4.1.0
  • Python: 3.5
  • OS: linux

What was wrong?

Maybe the issue is not exactly web3.py related, but when using EIP-55 checksum addresses event filtering is not working. My guess is that the reason is that Ganache-CLI is not producing proper addresses.

Event Filter done as follows:

certificate_created_filter = instance.eventFilter(
    'CertificateCreated',
    {
        'fromBlock': 0,
        'toBlock': 'latest',
    })
loop = asyncio.get_event_loop()
try:
    task = loop.create_task(
        self.log_loop(certificate_created_filter, 0.5))
    loop.run_until_complete(task)
finally:
    loop.close()

Checking for events

    async def log_loop(self, event_filter, poll_interval):
        event_filter.get_all_entries()
        while True:
            for event in event_filter.get_new_entries():
                self.handle_event(event)
            await asyncio.sleep(poll_interval)

Not Working:

for _, network in contract_interface['networks'].items():
    _contracts[contract_name] = w3.eth.contract(
        address=web3.Web3.toChecksumAddress(network['address']),
        abi=contract_interface['abi'])
    return _contracts[contract_name]

Working (with monkey patched web3.utils.validation.validate_address):

for _, network in contract_interface['networks'].items():
    _contracts[contract_name] = w3.eth.contract(
        address=network['address'],  # Address all lowercased
        abi=contract_interface['abi'])
    return _contracts[contract_name]

The monkey patch is to simply ignore the EIP checksum validation.

How can it be fixed?

Not sure what is the best way to fix it. Simply ignoring checksum validation seems not right. I'm glad to discuss.

editor: Let's add an optional middleware that can be injected to the innermost layer that forces all hex to lowercase, similar to the geth_poa_middleware

@pipermerriam
Copy link
Member

Can you expand on what "Not Working:" means. It's not clear to me what is actually broken/failing here.

@jordanjambazov
Copy link
Author

@pipermerriam What is meant there is that events filtering is not working if EIP checksum address is provided there. The filter always returns empty list on get_new_entries() invocation. With lower cased address it returns properly the events, with properly checksummed address the result is empty.

@pipermerriam
Copy link
Member

Sounds like an issue with Ganache since filtering is done on the backend and all that web3.py is doing is making RPC requests to get whatever entries the backend returns.

@EralpB
Copy link

EralpB commented Mar 12, 2018

@jordanjambazov could you solve this? Maybe by replacing ganache with something else. This is also a very important blocker for me.

@jordanjambazov
Copy link
Author

@EralpB Unfortunately currently I am using a forked monkey patched version of web3.py: jordanjambazov@a61b382

@carver
Copy link
Collaborator

carver commented Mar 21, 2018

@EralpB @jordanjambazov can you help provide the ganache version issue and such on this issue: trufflesuite/ganache#494 ?

@jordanjambazov
Copy link
Author

@carver I commented on the version of Ganache-CLI, it was reproducible in v6.1.0-beta.2

@grahamturk
Copy link

grahamturk commented Apr 25, 2018

@jordanjambazov are you getting the same problem when using the new Contract.events.<event name>.createFilter() method?

@pipermerriam
Copy link
Member

If you're dealing with this error consider speaking up in the following github issue in the ganache codebase.

trufflesuite/ganache#494

@carver
Copy link
Collaborator

carver commented Jun 11, 2018

Everyone who ran into this issue, please upgrade and try again. It's believed to be fixed!

Your versions should be:

  • ganache-core@v2.1.1
  • ganache-cli@v6.1.2

Please come back and comment if it is still not working as expected.

@carver carver closed this as completed Jun 11, 2018
@smartcontracts
Copy link

smartcontracts commented Jun 14, 2018

I'm still having this issue with:

  • ganache-core@v2.1.1
  • ganache-cli@v6.1.3
  • web3==4.3.0

The following filter does not work:

event_filter = web3.eth.filter({
    "address": contract.address
})

but this does:

event_filter = web3.eth.filter({
    "address": contract.address.lower()
})

Where contract.address is checksummed.

@carver carver reopened this Jun 18, 2018
@carver
Copy link
Collaborator

carver commented Jun 27, 2018

@kfichter

This was marked resolved in ganache-core@2.1.3 and ganache-cli@6.1.4

Can you upgrade and try again?

@carver carver closed this as completed Jun 27, 2018
@smartcontracts
Copy link

@carver Working, thank you!

@bitcoin4cashqc
Copy link

bitcoin4cashqc commented Sep 8, 2018

Me I have
Ganache CLI v7.0.0-beta.0 (ganache-core: 3.0.0-beta.0)
And I have empty arrays after running truffle test and trying to fetch obliviously made events

@dylanjw
Copy link
Contributor

dylanjw commented Sep 21, 2018

Filtering events in ganache from web3 is broken. I submitted a fix and am waiting for it to get merged and included in ganache -> MetaMask/web3-provider-engine#280

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

No branches or pull requests

8 participants