ethereum/trinity

PeerDiscoveryComponent crashed when serializing ENR

gsalgado opened this issue · 1 comments

Looks like we fail to serialize a remote's ENR, and that causes the component to crash. Need to fix that and find out why the crash didn't cause trinity to stop as it should

<bound method TrioIsolatedComponent._do_run of <trinity.components.builtin.peer_discovery.component.PeerDiscoveryComponent object at 0x7f956cb4cca0>> raised an unexpected exception
Traceback (most recent call last):
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/asyncio_run_in_process/_child.py", line 205, in run_process
    runner(async_fn, args, to_parent)
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/asyncio_run_in_process/_child_trio.py", line 63, in _run_on_trio
    result = trio.run(_do_async_fn, async_fn, args, to_parent)
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/trio/_core/_run.py", line 1804, in run
    raise runner.main_task_outcome.error
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/asyncio_run_in_process/_child_trio.py", line 55, in _do_async_fn
    result = await async_fn(*args)
  File "/home/salgado/src/snakecharmers/trinity/trinity/extensibility/trio.py", line 72, in _do_run
    nursery.cancel_scope.cancel()
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/trio/_core/_run.py", line 730, in __aexit__
    raise combined_error_from_nursery
  File "/home/salgado/src/snakecharmers/trinity/trinity/extensibility/trio.py", line 39, in run_process
    await self.do_run(event_bus)
  File "/home/salgado/src/snakecharmers/trinity/trinity/components/builtin/peer_discovery/component.py", line 98, in do_run
    await async_service.run_trio_service(discovery_service)
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/async_service/trio.py", line 156, in run_service
    await manager.run()
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/async_service/trio.py", line 205, in run
    raise trio.MultiError(
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/async_service/base.py", line 300, in _run_and_manage_task
    await task.run()
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/async_service/trio.py", line 76, in run
    await self._async_fn(*self._async_fn_args)
  File "/home/salgado/src/snakecharmers/trinity/p2p/discovery.py", line 638, in lookup_random
    return await self.lookup(target_key)
  File "/home/salgado/src/snakecharmers/trinity/p2p/discovery.py", line 567, in lookup
    return await self._lookup(target_key)
  File "/home/salgado/src/snakecharmers/trinity/p2p/discovery.py", line 621, in _lookup
    results = await trio_utils.gather(*next_find_node_queries)
  File "/home/salgado/src/snakecharmers/trinity/p2p/trio_utils.py", line 49, in gather
    nursery.start_soon(get_result, index)
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/trio/_core/_run.py", line 730, in __aexit__
    raise combined_error_from_nursery
  File "/home/salgado/src/snakecharmers/trinity/p2p/trio_utils.py", line 44, in get_result
    result = await async_fn(*args)
  File "/home/salgado/src/snakecharmers/trinity/p2p/discovery.py", line 593, in _find_node
    self._ensure_nodes_are_in_db(candidates)
  File "/home/salgado/src/snakecharmers/trinity/p2p/discovery.py", line 643, in _ensure_nodes_are_in_db
    self.node_db.set_enr(node.enr)
  File "/home/salgado/src/snakecharmers/trinity/p2p/node_db.py", line 51, in set_enr
    self.db.set(self._get_enr_key(enr.node_id), rlp.encode(enr))
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/rlp/codec.py", line 63, in encode
    item = infer_sedes(obj).serialize(obj)
  File "/home/salgado/src/snakecharmers/trinity/p2p/enr.py", line 144, in serialize
    serialized_content = ENRContentSedes.serialize(enr)
  File "/home/salgado/src/snakecharmers/trinity/p2p/enr.py", line 62, in serialize
    serialized_values = tuple(
  File "/home/salgado/src/snakecharmers/trinity/p2p/enr.py", line 63, in <genexpr>
    value_serializer.serialize(value)
  File "/home/salgado/virtualenvs/trinity-trio/lib/python3.8/site-packages/rlp/sedes/binary.py", line 40, in serialize
    raise SerializationError('Object has invalid length', obj)
rlp.exceptions.SerializationError: Object has invalid length
sys:1: ResourceWarning: unclosed <socket.socket fd=10, family=AddressFamily.AF_INET, type=SocketKind.SOCK_DGRAM, proto=0, laddr=('0.0.0.0', 30303)>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
...
 WARNING  2020-08-27 10:50:34,693           ETHPeerPool  PeerCandidateRequest timed out to backend <p2p.peer_backend.DiscoveryPeerBackend object at 0x7f36f2dd3310>
raise SerializationError('Object has invalid length', obj)

Looks like we have an ENR with a signature length different from what we expect (33)

b"secp256k1": Binary.fixed_length(33),