ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
5.01k stars 1.71k forks source link

No event logs are returned since 4.6.0 #1019

Closed BinaryQuasar closed 6 years ago

BinaryQuasar commented 6 years ago

What was wrong?

In version 4.6.0, filtering on contract events returns no logs when the contract address is set (using ganache-cli). It still fails after updating eth-abi to the alpha 2.0 version. Version 4.5.0 works.

The following code fails to return logs in 4.6.0:

contract = web3.eth.contract(
    abi=abi,
    address=address
)
event_filter = contract.events.SomeEvent.createFilter(
    fromBlock=0,
    toBlock='latest'
)
event_filter.get_all_entries()
> []

The same code works fine in 4.5.0, returning an array of event dicts as expected.

Event logs are also returned in 4.6.0 when initializing the contract without an address:

contract = web3.eth.contract(
    abi=abi
)

How can it be fixed?

I have identified the issue is caused by the changes made in f1e8e915. Specifically these two lines:

https://github.com/ethereum/web3.py/commit/f1e8e91503153c9942db570ac88752fd63d0a278#diff-f1ec2154438a2971d779c561901b6591R27 https://github.com/ethereum/web3.py/commit/f1e8e91503153c9942db570ac88752fd63d0a278#diff-480e77d839a1bfb9e5557e00f9b9c7aeR16

Changing

https://github.com/ethereum/web3.py/blob/master/web3/utils/rpc_abi.py#L27

back to 'address': 'address', and

https://github.com/ethereum/web3.py/blob/master/web3/middleware/normalize_request_parameters.py#L16

to 'address': apply_formatter_if(is_string, lambda x: x)}) solves the issue, though this is probably not the desired fix.

dylanjw commented 6 years ago

@BinaryQuasar ganache-core v2.1.4 fixes filter.address to work with a single value or an array, in compliance with the JSON RPC wiki.

Can you check which version you are using and update ganache-core if it is less than 2.1.4?

BinaryQuasar commented 6 years ago

@dylanjw I'm running ganache-core 2.2.1, ganache-cli 6.1.8.

> ganache-cli --version
Ganache CLI v6.1.8 (ganache-core: 2.2.1)
dylanjw commented 6 years ago

@BinaryQuasar ganache-core forwards eth_newFilter to provider-engine which is missing support for address arrays. I opened a pull request with that project to get that fixed: https://github.com/MetaMask/provider-engine/pull/280. Im closing this issue because it is not a web3 bug.

While you wait for the fix, you could give the rpc endpoint eth_getLogs a try.

BinaryQuasar commented 6 years ago

@dylanjw Thanks for tracking down the issue and providing a fix!