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

Event Filter missing event when running Poll in Docker container #2168

Open coleUI opened 3 years ago

coleUI commented 3 years ago
aiohttp==3.7.4.post0
alabaster==0.7.8
alembic==1.4.3.dev0
apturl==0.5.2
async-timeout==3.0.1
attrs==20.3.0
Babel==2.8.0
base58==2.1.0
bitarray==1.2.2
blinker==1.4
Brlapi==0.8.2
cached-property==1.5.2
certifi==2020.6.20
chardet==4.0.0
click==7.1.2
colorama==0.4.4
command-not-found==0.3
cryptography==3.3.2
cupshelpers==1.0
cytoolz==0.11.0
dbus-python==1.2.16
defer==1.0.6
distro==1.5.0
distro-info==1.0
docker==4.1.0
docker-compose==1.25.0
dockerpty==0.4.1
docopt==0.6.2
docutils==0.16
eth-abi==2.1.1
eth-account==0.5.6
eth-hash==0.3.2
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.2.1
eth-typing==2.2.2
eth-utils==1.10.0
feedparser==5.2.1
gitsome==0.8.0
gyp==0.1
hexbytes==0.2.2
httplib2==0.18.1
idna==2.10
imagesize==1.2.0
importlib-metadata==1.6.0
ipfshttpclient==0.8.0a2
jeepney==0.6.0
Jinja2==2.11.2
jsonschema==3.2.0
keyring==22.2.0
language-selector==0.1
launchpadlib==1.10.13
lazr.restfulclient==0.14.2
lazr.uri==1.0.5
louis==3.16.0
lru-dict==1.1.7
macaroonbakery==1.3.1
Mako==1.1.3
MarkupSafe==1.1.1
more-itertools==4.2.0
multiaddr==0.0.9
multidict==5.1.0
netaddr==0.8.0
netifaces==0.10.9
numpydoc==1.1.0
oauthlib==3.1.0
olefile==0.46
packaging==20.9
parsimonious==0.8.1
pexpect==4.8.0
Pillow==8.1.2
ply==3.11
prompt-toolkit==3.0.14
protobuf==3.12.4
pycairo==1.16.2
pycryptodome==3.10.1
pycups==2.0.1
Pygments==2.7.1
PyGObject==3.38.0
PyJWT==1.7.1
pymacaroons==0.13.0
PyNaCl==1.4.0
pyparsing==2.4.7
pyRFC3339==1.1
pyrsistent==0.15.5
python-apt==2.1.7+ubuntu2
python-dateutil==2.8.1
python-debian==0.1.39
pytz==2021.1
pyxdg==0.27
PyYAML==5.3.1
reportlab==3.5.66
requests==2.25.1
rlp==2.0.1
roman==2.0.0
SecretStorage==3.3.1
setproctitle==1.2.1
simplejson==3.17.2
six==1.15.0
snowballstemmer==2.1.0
Sphinx==3.5.4
SQLAlchemy==1.3.22
ssh-import-id==5.11
systemd-python==234
texttable==1.6.3
toolz==0.11.1
typing-extensions==3.10.0.2
ubuntu-advantage-tools==24.4
ubuntu-drivers-common==0.0.0
ufw==0.36
unattended-upgrades==0.1
urllib3==1.26.2
varint==1.0.2
wadllib==1.3.5
wcwidth==0.1.9
web3==5.23.1
websocket-client==0.57.0
websockets==9.1
xdg==5
xkit==0.0.0
xonsh==0.9.25
yarl==1.6.3
zipp==1.0.0

What was wrong?

I have a filter poll set up in a docker container that is not returning the logs to one of my events. It works perfectly when I run the poll on my local machine for some reason. The event is relatively large compared to the other event (contains lists)...maybe this is the issue?

LOCAL = {
    'provider': 'ws://host.docker.internal:8545',
    'dapp_address': '0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f',
    'nft_address': '0x7a2088a1bFc9d81c55368AE168C2C02570cB814F',
    'abi_file': './abis/CreaticlesDapp.json',
    'nft_file': './abis/CreaticlesNFT.json'
}

NETWORK_DATA = {
    'ropsten':ROPSTEN,
    'localhost':LOCAL
}

# MAIN EVENT HANDLER

def handle_event(event):
    handler_registry = {
        'RequestCreated': lambda x: handle_request_created(x),
        'ProposalAccepted': lambda x: handle_proposal_accepted(x),
        'FundsReclaimed': lambda x: handle_funds_reclaimed(x),
        'ChoosingPeriodChanged': lambda x: handle_choosing_period_changed(x),
        'NFTContractAddressChanged': lambda x: handle_nft_contract_upgraded(x),
        'DappDeployed': lambda x: handle_dapp_deployed(x),
        'TokenMinted': lambda x: handle_token_minted(x),
        'DappContractAddressChanged': lambda x: handle_dapp_contract_upgraded(x),
        'NFTDeployed': lambda x: handle_nft_deployed(x)
    }
    print(event['event'])
    # handler_registry[event['event']](event['args'])

# POLL HANDLER

async def log_loop(event_filter, poll_interval):
    while True:
        print(event_filter.get_new_entries())
        for event in event_filter.get_all_entries():
            handle_event(event)

        await asyncio.sleep(poll_interval)

# RUN WORKER

def blockchain_main(network):
    provider = NETWORK_DATA[network]['provider']
    dapp_addr = NETWORK_DATA[network]['dapp_address']
    nft_addr = NETWORK_DATA[network]['nft_address']
    abi_file = NETWORK_DATA[network]['abi_file']
    nft_file = NETWORK_DATA[network]['nft_file']
    FROM_BLOCK=1
    POLL_INTERVAL=15
    w3 = Web3(Web3.WebsocketProvider(provider))
    with open(abi_file) as ABI_FILE:
        DAPP_ABI = json.load(ABI_FILE)
    with open(nft_file) as NFT_FILE:
        NFT_ABI = json.load(NFT_FILE)

    dapp = w3.eth.contract(address=dapp_addr, abi=DAPP_ABI['abi'])
    nft = w3.eth.contract(address=nft_addr, abi=NFT_ABI['abi'])

    # Instantiate CreaticlesDapp Filters
    request_created_filter = dapp.events.RequestCreated.createFilter(fromBlock=FROM_BLOCK)
    proposal_accepted_filter = dapp.events.ProposalAccepted.createFilter(fromBlock=FROM_BLOCK)
    funds_reclaimed_filter = dapp.events.FundsReclaimed.createFilter(fromBlock=FROM_BLOCK)
    choosing_period_filter = dapp.events.ChoosingPeriodChanged.createFilter(fromBlock=FROM_BLOCK)
    nft_contract_upgraded_filter = dapp.events.NFTContractAddressChanged.createFilter(fromBlock=FROM_BLOCK)
    dapp_deployed_filter = dapp.events.DappDeployed.createFilter(fromBlock=FROM_BLOCK)

    # Instantiate CreaticlesNFT Filters
    nft_deployed_filter = nft.events.NFTDeployed.createFilter(fromBlock=FROM_BLOCK)
    # token_minted_filter = nft.events.TokenMinted.createFilter(fromBlock=FROM_BLOCK)
    dapp_contract_upgraded_filter = nft.events.DappContractAddressChanged.createFilter(fromBlock=FROM_BLOCK)

    print(dapp_contract_upgraded_filter)
    # Event Filter Loop
    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(
            asyncio.gather(
                log_loop(request_created_filter, POLL_INTERVAL),
                log_loop(proposal_accepted_filter, POLL_INTERVAL),
                log_loop(funds_reclaimed_filter, POLL_INTERVAL),
                log_loop(choosing_period_filter, POLL_INTERVAL),
                log_loop(nft_contract_upgraded_filter, POLL_INTERVAL),
                log_loop(dapp_deployed_filter, POLL_INTERVAL),
                log_loop(nft_deployed_filter, POLL_INTERVAL),
                # log_loop(token_minted_filter, POLL_INTERVAL),
                log_loop(dapp_contract_upgraded_filter, POLL_INTERVAL),
                # request_expiration_loop(POLL_INTERVAL)
            ))
    finally:
        loop.close()

*Relevant Portion of the ABI

{
      "anonymous": false,
      "inputs": [
        {
          "indexed": false,
          "internalType": "address",
          "name": "to",
          "type": "address"
        },
        {
          "indexed": false,
          "internalType": "uint256",
          "name": "requestId",
          "type": "uint256"
        },
        {
          "indexed": false,
          "internalType": "uint256[]",
          "name": "tokenId",
          "type": "uint256[]"
        },
        {
          "indexed": false,
          "internalType": "bytes32[]",
          "name": "detailsHash",
          "type": "bytes32[]"
        },
        {
          "indexed": false,
          "internalType": "string[]",
          "name": "tokenURI",
          "type": "string[]"
        },
        {
          "indexed": false,
          "internalType": "address[]",
          "name": "winner",
          "type": "address[]"
        },
        {
          "indexed": false,
          "internalType": "uint256",
          "name": "remainingValue",
          "type": "uint256"
        }
      ],
      "name": "ProposalAccepted",
      "type": "event"
    }

How can it be fixed?

The code works when running on my local machine and everything was copy and pasted onto the docker container, even ABIs. Could it have something to do with docker compatibility? This is the event: event ProposalAccepted(address to, uint256 requestId, uint256[] tokenId, bytes32[] detailsHash, string[] tokenURI, address[] winner, uint256 remainingValue);


Note: We prefer to use issues to track our work. If you think you've encountered a bug in web3py or have a feature request, you're in the right place. If you have implementation or usage questions, please refer to our documentation and/or join the conversation on discord.

coleUI commented 3 years ago

UPDATE: web3.eth.get_filter_logs() is working, contract.events.MyEvent.createFilter() is still not

enayatinfo commented 2 years ago

Also i have problem on this feature. The return value of events is empty dict... contract.events.MyEvent.createFilter() not working