ethereum / web3.py

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

raise_block_not_found gets an unexpected argument #2010

Closed istankovic closed 3 years ago

istankovic commented 3 years ago
aioice==0.7.5
aiortc==1.2.0
aiortc-pyav-stub==0.1.1
aniso8601==7.0.0
apipkg==1.5
appdirs @ file:///home/ivan/.cache/pypoetry/artifacts/47/cf/4f/4ef02fb715aa36daeebad18cc5570126159c659c41c7b5ec46a7387d9b/appdirs-1.4.4-py2.py3-none-any.whl
asn1crypto==1.3.0
astroid @ file:///home/ivan/.cache/pypoetry/artifacts/72/b8/97/8c2f91626a319336b618947c91b2f4b07516463881c3f7e9354ed427f3/astroid-2.5.6-py3-none-any.whl
attrdict==2.0.1
attrs==19.3.0
Automat==20.2.0
av==8.0.3
backcall==0.1.0
base58==2.0.0
bcrypt @ file:///home/ivan/.cache/pypoetry/artifacts/e1/8f/44/0adcd01881468523abd64d2c6666d8e74ee78d8ef417abbd7cf7d04287/bcrypt-3.2.0-cp36-abi3-manylinux2010_x86_64.whl
bitarray==1.2.1
black @ file:///home/ivan/.cache/pypoetry/artifacts/08/e6/49/369e763476cf73e24c9b18c6ea3a84e1beea9792fc5fc45ded0f40d4ec/black-21.5b2-py3-none-any.whl
blake2b-py==0.1.4
bleach==3.3.0
bump2version==1.0.1
cached-property==1.5.2
cachetools==4.2.2
canonicaljson==1.4.0
certifi==2019.3.9
cffi==1.12.3
cfgv==3.3.0
chardet==3.0.4
click==8.0.1
codecov @ file:///home/ivan/.cache/pypoetry/artifacts/e6/b6/17/0fc7066ecfb20e506ddd1f9118ea46b4304a77d8df3e1ccabdf1b3f74d/codecov-2.1.11-py2.py3-none-any.whl
coincurve==15.0.0
colorama==0.4.4
colour==0.1.5
constantly==15.1.0
coverage==5.5
crc32c==2.2
cryptography==3.4.7
cytoolz==0.10.1
decorator==4.4.2
distlib==0.3.2
dnspython==2.1.0
docutils==0.16
eth-abi==2.1.0
eth-account==0.5.4
eth-bloom==1.0.4
eth-hash==0.3.1
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.2.1
eth-tester==0.5.0b4
eth-typing==2.2.1
eth-utils==1.10.0
execnet==1.6.0
Faker==8.4.0
fancycompleter==0.8
filelock==3.0.12
flake8 @ file:///home/ivan/.cache/pypoetry/artifacts/3f/57/d5/11722093c13092cc3bfc3dd7c88aef6f8e4d5ac97cfe5fd054d5aba412/flake8-3.9.2-py2.py3-none-any.whl
flake8-bugbear @ file:///home/ivan/.cache/pypoetry/artifacts/35/be/1c/3dfc759f779be6c7227ad7edd774027cdd0ab48778d8ba0a0b7c190dd1/flake8_bugbear-20.11.1-py36.py37.py38-none-any.whl
flake8-comprehensions @ file:///home/ivan/.cache/pypoetry/artifacts/4e/10/91/04adae987aa18ee9463db75694dccee7bf7d5518118462f18252bd3e0a/flake8_comprehensions-3.5.0-py3-none-any.whl
flake8-tuple==0.4.1
flaky==3.7.0
Flask==1.1.2
Flask-Cors==3.0.10
Flask-RESTful==0.3.8
frozendict==1.2
gevent==21.1.2
graphviz==0.13.2
greenlet==0.4.17
grequests==0.6.0
guppy3==3.1.0
hexbytes==0.2.0
hyperlink==21.0.0
hypothesis==6.13.1
identify==2.2.7
idna==2.8
importlib-metadata @ file:///home/ivan/.cache/pypoetry/artifacts/76/8c/2b/352ebfae5dd374b0669149726b8d6c40817eb45be426e92c7edeca1b99/importlib_metadata-4.0.1-py3-none-any.whl
incremental @ file:///home/ivan/.cache/pypoetry/artifacts/03/0f/d8/1f9c21de086b17b28e0ed5914f384759067c88a524742b94e72eb07020/incremental-21.3.0-py2.py3-none-any.whl
iniconfig @ file:///home/ivan/.cache/pypoetry/artifacts/fa/b0/c6/10cfac68c9e6de9d2a1678366ca89fd9292b362c1760dbe758e41691cb/iniconfig-1.1.1-py2.py3-none-any.whl
ipfshttpclient==0.7.0a1
ipython==7.23.1
ipython-genutils==0.2.0
isort==5.8.0
itsdangerous==1.1.0
jedi==0.17.0
Jinja2==2.11.3
jsonschema==3.2.0
lazy-object-proxy @ file:///home/ivan/.cache/pypoetry/artifacts/fa/67/66/487627ff6d60b33d3483eda6fc6f62171481480f2eb0ce33e5c7679d17/lazy_object_proxy-1.6.0-cp39-cp39-manylinux1_x86_64.whl
lru-dict==1.1.6
MarkupSafe==1.1.1
marshmallow==3.11.1
marshmallow-dataclass==8.0.0
marshmallow-enum==1.5.1
marshmallow-polyfield==5.10
matplotlib-inline==0.1.2
matrix-client==0.3.2
matrix-synapse @ file:///home/ivan/.cache/pypoetry/artifacts/36/8d/e1/799ebbc1bbe1310f9714617c18d891a9a782e5acc831836b65d97869b4/matrix_synapse-1.19.1-py3-none-any.whl
mccabe==0.6.1
mirakuru==2.1.2
msgpack @ file:///home/ivan/.cache/pypoetry/artifacts/e0/e8/76/1a2017ea1894ce9b6bfd45a7633edeffefd940ba829eebf024a1b7a5ac/msgpack-1.0.2-cp39-cp39-manylinux1_x86_64.whl
multiaddr==0.0.9
mypy @ file:///home/ivan/.cache/pypoetry/artifacts/27/70/0f/dedc216f4bb804889f12f78af571efe8280e5035b50e106e0d65409504/mypy-0.790-py3-none-any.whl
mypy-extensions==0.4.3
nest-asyncio==1.5.1
netaddr==0.7.19
netifaces==0.10.9
nodeenv==1.6.0
objgraph==3.5.0
packaging @ file:///home/ivan/.cache/pypoetry/artifacts/c2/76/aa/699ed723689e741411dfbdbc9b8c392079d54fb1e1a1b814df7be7cf47/packaging-20.9-py2.py3-none-any.whl
parsimonious==0.8.1
parso==0.7.0
pathspec @ file:///home/ivan/.cache/pypoetry/artifacts/40/8b/b2/80a6945971d8475bcc04d09afec4845855dd74f68da6a4c18bbf8f7784/pathspec-0.8.1-py2.py3-none-any.whl
pdbpp==0.10.2
pep517==0.10.0
pexpect==4.8.0
phonenumbers @ file:///home/ivan/.cache/pypoetry/artifacts/81/8a/11/c3caf9dcc85ea9e2f08d41ca74ae41ee1db4b0e571796b364e1d4aefde/phonenumbers-8.12.24-py2.py3-none-any.whl
pickleshare==0.7.5
Pillow @ file:///home/ivan/.cache/pypoetry/artifacts/af/01/9e/9e59a2244e85a37841afdb59a3dc7feb5f6d414d71e255a4d8b25c063d/Pillow-8.2.0-cp39-cp39-manylinux1_x86_64.whl
pip-tools==6.1.0
pluggy @ file:///home/ivan/.cache/pypoetry/artifacts/29/58/fc/ed8b7451d3ef91a6465024f5656141da996e7aafd4d41a1659629a75e7/pluggy-0.13.1-py2.py3-none-any.whl
prometheus-client==0.8.0
prompt-toolkit==3.0.5
protobuf==3.11.3
psutil==5.8.0
ptyprocess==0.6.0
py==1.10.0
py-ecc==4.1.0
py-evm==0.4.0a4
py-solc-x==1.1.0
py-spy==0.3.7
pyasn1 @ file:///home/ivan/.cache/pypoetry/artifacts/7b/3a/54/42ce43b579bda01b9d79022fb733811594441e7a32e9f9a5a98f672bdc/pyasn1-0.4.8-py2.py3-none-any.whl
pyasn1-modules @ file:///home/ivan/.cache/pypoetry/artifacts/dd/b8/4f/b56433e0354274a31074995e01b8671751e9f0ed0001f5254e5b03a54f/pyasn1_modules-0.2.8-py2.py3-none-any.whl
pycodestyle==2.7.0
pycparser==2.19
pycryptodome==3.8.2
pyee==7.0.2
pyethash==0.1.27
pyfakefs==4.4.0
pyflakes==2.3.1
Pygments==2.7.4
pylibsrtp==0.6.8
pylint @ file:///home/ivan/.cache/pypoetry/artifacts/29/3e/ea/65cb07221f19ecb197c398c98a5e357b7ccdc307adfea9c511b2c83c9c/pylint-2.8.3-py3-none-any.whl
pymacaroons==0.13.0
PyNaCl @ file:///home/ivan/.cache/pypoetry/artifacts/4b/f9/06/aae0509152a3557bf78a2217db04d5ee8c6c94cd729392d66b86ac8e58/PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl
pyOpenSSL @ file:///home/ivan/.cache/pypoetry/artifacts/27/2a/6f/de8129dc1f8ba5d04f604e929a7f055c4ca7c08ceec8bf801182df8774/pyOpenSSL-20.0.1-py2.py3-none-any.whl
pyparsing @ file:///home/ivan/.cache/pypoetry/artifacts/92/0f/cf/effdcd5d76a6186df0969f85b3b030284ff8058936d5016540b5258ea3/pyparsing-2.4.7-py2.py3-none-any.whl
pyrsistent==0.15.7
pysha3==1.0.2
pytest @ file:///home/ivan/.cache/pypoetry/artifacts/17/a3/46/eb89acf91c8962553e409da649186ff5e3d2c1c93195f0643e7dfd1b57/pytest-6.2.4-py3-none-any.whl
pytest-cov @ file:///home/ivan/.cache/pypoetry/artifacts/8b/71/5b/a839115273b57e8cce75e9aae0be81d13d7e97927f18752895833ac792/pytest_cov-2.12.0-py2.py3-none-any.whl
pytest-forked==1.1.3
pytest-random==0.2
pytest-select==0.1.2
pytest-xdist==2.2.1
python-dateutil==2.8.1
pytz==2019.1
PyYAML @ file:///home/ivan/.cache/pypoetry/artifacts/dd/d9/3d/cbc42de28fcde705eb305497d2f3e5679ca7890234c51348b33c0f428f/PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl
-e git+git@github.com:istankovic/raiden.git@8f29fc271a110847b2d50d95deea1bb1835b6d34#egg=raiden
raiden-api-client==1.1.0
raiden-contracts==0.37.5
raiden-webui==1.2.1
readme-renderer==29.0
regex @ file:///home/ivan/.cache/pypoetry/artifacts/95/49/2d/6b7dba3a5f57768df53ce0dbc773ec54be586b22babe6c14330c8cdb20/regex-2021.4.4-cp39-cp39-manylinux2014_x86_64.whl
requests==2.25.1
requests-mock==1.9.3
responses==0.10.15
rlp==2.0.1
semantic-version @ file:///home/ivan/.cache/pypoetry/artifacts/72/89/57/b8a316b3250ea1e3111337d8a210808316ec5713c8a924d64319fbacd8/semantic_version-2.8.5-py2.py3-none-any.whl
service-identity @ file:///home/ivan/.cache/pypoetry/artifacts/b1/52/73/b4dbc1db0eb8a4a2e9faf4231a0f8e54b2478b020bfe5c18fdcca0cbd7/service_identity-21.1.0-py2.py3-none-any.whl
signedjson @ file:///home/ivan/.cache/pypoetry/artifacts/d9/01/4c/15a22ce4da26385e8d395a4c549a15c21c073fdc8b03b0a607fedadfcc/signedjson-1.1.1.tar.gz
simplejson==3.17.2
six==1.16.0
sortedcontainers @ file:///home/ivan/.cache/pypoetry/artifacts/b9/80/e1/4bdfa349488797fd308ecbe48f4fad57a3245777fb47c8741730583262/sortedcontainers-2.4.0-py2.py3-none-any.whl
structlog==21.1.0
text-unidecode==1.3
toml==0.10.2
toolz==0.9.0
traitlets==4.3.2
treq @ file:///home/ivan/.cache/pypoetry/artifacts/78/18/5b/faea287b6590bcbbb092cf97a449f9b8497017b426cb7a862a6d18ad4d/treq-21.5.0-py3-none-any.whl
trie==2.0.0a5
Twisted==21.2.0
typed-ast @ file:///home/ivan/.cache/pypoetry/artifacts/59/28/81/67daa4fcaa8d06f9e3fa6c476cc0594cb9c17adc966c324c29f92d8217/typed_ast-1.4.3-cp39-cp39-manylinux1_x86_64.whl
typeguard==2.11.1
typing-extensions @ file:///home/ivan/.cache/pypoetry/artifacts/3d/38/26/2c9b521373bbaf207e658ec81f51aa2a8af7454bfe4d7c15743a6533d5/typing_extensions-3.10.0.0-py3-none-any.whl
typing-inspect==0.4.0
ulid-py==1.1.0
unpaddedbase64 @ file:///home/ivan/.cache/pypoetry/artifacts/ca/50/41/2b1f267e752b7f2bf35e2bd8f31fad7c0740e0a0b861ea16d04987d6e9/unpaddedbase64-2.1.0-py3-none-any.whl
urllib3 @ file:///home/ivan/.cache/pypoetry/artifacts/41/04/6b/e8dd0262c5c5faf00f772880589c79f5dc8d80f9d994f5e23f87fed618/urllib3-1.25.8-py2.py3-none-any.whl
urwid @ file:///home/ivan/.cache/pypoetry/artifacts/21/e3/37/b89362b9e1a6d94e2f97108984c4dae2a050fc2a6d2ab4dcb6a05ea424/urwid-2.1.2.tar.gz
varint==1.0.2
virtualenv==20.4.7
wcwidth==0.1.9
web3 @ file:///home/ivan/.cache/pypoetry/artifacts/e1/75/50/0b7d95e548b13f121b5ae257fbd84bc21f88de70f105b24913fc5525c1/web3-5.19.0-py3-none-any.whl
webencodings==0.5.1
websockets==8.1
Werkzeug==1.0.1
wmctrl==0.3
wrapt @ file:///home/ivan/.cache/pypoetry/artifacts/6c/e2/d9/2c022794d212a87320efa16fd1b05654bf6656b6cf0510c072845ecc95/wrapt-1.12.1.tar.gz
zipp==3.4.1
zope.event==4.4
zope.interface==5.1.0

What was wrong?

We ran into the following exception when trying to use Raiden with an openethereum node:

Traceback (most recent call last):
  File "/home/ivan/src/raiden/raiden/ui/cli.py", line 721, in _run
    run_services(kwargs)
  File "/home/ivan/src/raiden/raiden/ui/runners.py", line 18, in run_services
    raiden_service = run_raiden_service(**options)
  File "/home/ivan/src/raiden/raiden/ui/app.py", line 457, in run_raiden_service
    raiden_service.start()
  File "/home/ivan/src/raiden/raiden/raiden_service.py", line 459, in start
    self._initialize_wal()
  File "/home/ivan/src/raiden/raiden/raiden_service.py", line 655, in _initialize_wal
    initial_state = self._make_initial_state()
  File "/home/ivan/src/raiden/raiden/raiden_service.py", line 612, in _make_initial_state
    last_log_block_hash = self.rpc_client.blockhash_from_blocknumber(last_log_block_number)
  File "/home/ivan/src/raiden/raiden/network/rpc/client.py", line 1094, in blockhash_from_blocknumber
    block = self.get_block(block_number)
  File "/home/ivan/src/raiden/raiden/network/rpc/client.py", line 1080, in get_block
    return self.web3.eth.getBlock(block_identifier)
  File "/home/ivan/venv-3.9/lib/python3.9/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str, params, error_formatters)
  File "/home/ivan/venv-3.9/lib/python3.9/site-packages/web3/manager.py", line 158, in request_blocking
    apply_error_formatters(error_formatters, response)
  File "/home/ivan/venv-3.9/lib/python3.9/site-packages/web3/manager.py", line 62, in apply_error_formatters
    formatted_response = pipe(response, error_formatters)
  File "cytoolz/functoolz.pyx", line 669, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 644, in cytoolz.functoolz.c_pipe
  File "/home/ivan/venv-3.9/lib/python3.9/site-packages/web3/_utils/method_formatters.py", line 588, in raise_block_not_found
    block_identifier = params[0]
KeyError: 0

It seems like raise_block_not_found gets an unexpected argument (it gets the response object):

[21] > /home/ivan/venv-3.9/lib/python3.9/site-packages/web3/_utils/method_formatters.py(589)raise_block_not_found()
-> block_identifier = params[0]
(Pdb++) p params
{'jsonrpc': '2.0', 'error': {'code': -32000, 'message': 'Requested block number is in a range that is not available yet, because the ancient block sync is still in progress.'}, 'id': 43}
kclowes commented 3 years ago

Ah, thanks for raising this. My first idea to fix this is to catch the KeyError and return a BlockNotFound error with the error message. So something like:

try:
    block_identifier = params[0]
    msg = f"Block with id: {block_identifier!r} not found."
except KeyError:
    msg = params['error'].get('message')
raise BlockNotFound(msg)

We may also need to do similar checks with the other methods that raise errors if the result is none, like get_block, get_uncle_count, get_uncle_by_block, etc. Full list of RPC methods that raise is here.