# Buggy code
def _log_sync_progress(self, to_block: BlockNumber) -> None:
    """Print a message if there are many blocks to be fetched, or if the
    time in-between polls is high.
    """
    now = datetime.now()
    blocks_to_sync = to_block - self.last_log_block
    elapsed = (now - self.last_log_time).total_seconds()

    if blocks_to_sync > 100 or elapsed > 15.0:
        log.info(
            "Synchronizing blockchain events",
            blocks_to_sync=blocks_to_sync,
            blocks_per_second=blocks_to_sync / elapsed,
            to_block=to_block,
            elapsed=elapsed,
        )
        self.last_log_time = now

    self.last_log_block = to_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 _log_sync_progress(
    self, polled_block_number: BlockNumber, target_block: BlockNumber
) -> None:
    """Print a message if there are many blocks to be fetched, or if the
    time in-between polls is high.
    """
    now = time.monotonic()
    blocks_until_target = target_block - polled_block_number
    polled_block_count = polled_block_number - self.last_log_block
    elapsed = now - self.last_log_time

    if blocks_until_target > 100 or elapsed > 15.0:
        log.info(
            "Synchronizing blockchain events",
            remaining_blocks_to_sync=blocks_until_target,
            blocks_per_second=polled_block_count / elapsed,
            to_block=target_block,
            elapsed=elapsed,
        )
        self.last_log_time = time.monotonic()
        self.last_log_block = polled_block_number