# Buggy code
def _synchronize_with_blockchain(self) -> None:
    """Prepares the alarm task callback and synchronize with the blockchain
    since the last run.

     Notes about setup order:
     - The filters must be polled after the node state has been primed,
       otherwise the state changes won't have effect.
     - The synchronization must be done before the transport is started, to
       reject messages for closed/settled channels.
    """
    msg = (
        f"Transport must not be started before the node has synchronized "
        f"with the blockchain, otherwise the node may accept transfers to a "
        f"closed channel. node:{self!r}"
    )
    assert not self.transport, msg
    assert self.wal, f"The database must have been initialized. node:{self!r}"

    chain_state = views.state_from_raiden(self)

    # The `Block` state change is dispatched only after all the events for
    # that given block have been processed, filters can be safely installed
    # starting from this position without missing events.
    last_block_number = views.block_number(chain_state)

    filters = smart_contract_filters_from_node_state(
        chain_state,
        self.contract_manager,
        self.default_registry.address,
        self.default_secret_registry.address,
    )
    blockchain_events = BlockchainEvents(
        web3=self.rpc_client.web3,
        chain_id=chain_state.chain_id,
        contract_manager=self.contract_manager,
        last_fetched_block=last_block_number,
        event_filters=filters,
        block_batch_size_config=self.config.blockchain.block_batch_size_config,
    )

    latest_block_num = self.rpc_client.block_number()
    latest_confirmed_block_number = BlockNumber(
        max(GENESIS_BLOCK_NUMBER, latest_block_num - self.confirmation_blocks)
    )

    # `blockchain_events` is a requirement for `_poll_until_target`, so it
    # must be set before calling it
    self.blockchain_events = blockchain_events
    self._poll_until_target(latest_confirmed_block_number)

    self.alarm.register_callback(self._callback_new_block)


# Traceback (urllib3.exceptions.ReadTimeoutError)
Traceback (most recent call last):
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1344, in getresponse
response.begin()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 306, in begin
version, status, reason = self._read_status()
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 267, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/gevent/_socket3.py", line 496, in recv_into
self._wait(self._read_event)
File "src/gevent/_hub_primitives.py", line 290, in gevent.__hub_primitives.wait_on_socket
File "src/gevent/_hub_primitives.py", line 295, in gevent.__hub_primitives.wait_on_socket
File "src/gevent/_hub_primitives.py", line 286, in gevent.__hub_primitives._primitive_wait
File "src/gevent/_hub_primitives.py", line 287, in gevent.__hub_primitives._primitive_wait
File "src/gevent/_hub_primitives.py", line 46, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
File "src/gevent/_hub_primitives.py", line 46, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
File "src/gevent/_hub_primitives.py", line 55, in gevent.__hub_primitives.WaitOperationsGreenlet.wait
File "src/gevent/_waiter.py", line 151, in gevent.__waiter.Waiter.get
File "src/gevent/_greenlet_primitives.py", line 61, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/_greenlet_primitives.py", line 61, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/_greenlet_primitives.py", line 65, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src/gevent/__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/util/retry.py", line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/packages/six.py", line 686, in reraise
raise value
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 389, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/urllib3/connectionpool.py", line 307, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='geth.mainnet.ethnodes.brainbot.com', port=8545): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/ui/cli.py", line 610, in run
run_services(kwargs)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/ui/runners.py", line 21, in run_services
app = run_app(**options)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/ui/app.py", line 438, in run_app
raiden_app.start()
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/app.py", line 91, in start
self.raiden.start()
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/raiden_service.py", line 364, in start
self._synchronize_with_blockchain()
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/raiden_service.py", line 670, in _synchronize_with_blockchain
self._poll_until_target(latest_confirmed_block_number)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/raiden_service.py", line 993, in _poll_until_target
poll_result = self.blockchain_events.fetch_logs_in_batch(target_block_number)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/blockchain/events.py", line 488, in fetch_logs_in_batch
decoded_result = self._query_and_track(from_block, to_block)
File "/Users/ulo/Dropbox/devel/brainbot/raiden/raiden/blockchain/events.py", line 556, in _query_and_track
RPCEndpoint("eth_getLogs"), [filter_params]
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/manager.py", line 149, in request_blocking
response = self._make_request(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/manager.py", line 128, in _make_request
return request_func(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/cache.py", line 134, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/gas_price_strategy.py", line 34, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/attrdict.py", line 33, in middleware
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/normalize_errors.py", line 25, in middleware
result = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 75, in apply_formatters
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 73, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/formatting.py", line 75, in apply_formatters
response = make_request(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/middleware/exception_retry_request.py", line 104, in middleware
return make_request(method, params)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/providers/rpc.py", line 83, in make_request
**self.get_request_kwargs()
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/web3/_utils/request.py", line 34, in make_post_request
response = session.post(endpoint_uri, data=data, *args, **kwargs)  # type: ignore
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/Users/ulo/Envs/raiden/lib/python3.7/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='geth.mainnet.ethnodes.brainbot.com', port=8545): Read timed out. (read timeout=10)

# Fixed code
def _synchronize_with_blockchain(self) -> None:
    """Prepares the alarm task callback and synchronize with the blockchain
    since the last run.

     Notes about setup order:
     - The filters must be polled after the node state has been primed,
       otherwise the state changes won't have effect.
     - The synchronization must be done before the transport is started, to
       reject messages for closed/settled channels.
    """
    msg = (
        f"Transport must not be started before the node has synchronized "
        f"with the blockchain, otherwise the node may accept transfers to a "
        f"closed channel. node:{self!r}"
    )
    assert not self.transport, msg
    assert self.wal, f"The database must have been initialized. node:{self!r}"

    chain_state = views.state_from_raiden(self)

    # The `Block` state change is dispatched only after all the events for
    # that given block have been processed, filters can be safely installed
    # starting from this position without missing events.
    last_block_number = views.block_number(chain_state)

    filters = smart_contract_filters_from_node_state(
        chain_state,
        self.contract_manager,
        self.default_registry.address,
        self.default_secret_registry.address,
    )
    blockchain_events = BlockchainEvents(
        web3=self.rpc_client.web3,
        chain_id=chain_state.chain_id,
        contract_manager=self.contract_manager,
        last_fetched_block=last_block_number,
        event_filters=filters,
        block_batch_size_config=self.config.blockchain.block_batch_size_config,
    )

    self.last_log_block = last_block_number
    self.last_log_time = time.monotonic()

    latest_block_num = self.rpc_client.block_number()
    latest_confirmed_block_number = BlockNumber(
        max(GENESIS_BLOCK_NUMBER, latest_block_num - self.confirmation_blocks)
    )

    # `blockchain_events` is a requirement for `_poll_until_target`, so it
    # must be set before calling it
    self.blockchain_events = blockchain_events
    self._poll_until_target(latest_confirmed_block_number)

    self.alarm.register_callback(self._callback_new_block)